diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-04-17 14:06:06 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-04-17 14:06:06 (GMT) |
commit | f15b8a83e2e51955776a3f07cb85ebfc342dd8ef (patch) | |
tree | c5dc684986051654898db11ce73e03b9fec8db99 /tests/auto/qdbusmarshall | |
download | Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.zip Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.gz Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.bz2 |
Initial import of statemachine branch from the old kinetic repository
Diffstat (limited to 'tests/auto/qdbusmarshall')
-rw-r--r-- | tests/auto/qdbusmarshall/.gitignore | 2 | ||||
-rw-r--r-- | tests/auto/qdbusmarshall/common.h | 651 | ||||
-rw-r--r-- | tests/auto/qdbusmarshall/dummy.cpp | 44 | ||||
-rw-r--r-- | tests/auto/qdbusmarshall/qdbusmarshall.pro | 10 | ||||
-rw-r--r-- | tests/auto/qdbusmarshall/qpong/qpong.cpp | 81 | ||||
-rw-r--r-- | tests/auto/qdbusmarshall/qpong/qpong.pro | 6 | ||||
-rw-r--r-- | tests/auto/qdbusmarshall/test/test.pro | 8 | ||||
-rw-r--r-- | tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp | 786 |
8 files changed, 1588 insertions, 0 deletions
diff --git a/tests/auto/qdbusmarshall/.gitignore b/tests/auto/qdbusmarshall/.gitignore new file mode 100644 index 0000000..d227388 --- /dev/null +++ b/tests/auto/qdbusmarshall/.gitignore @@ -0,0 +1,2 @@ +tst_qdbusmarshall +qpong/qpong diff --git a/tests/auto/qdbusmarshall/common.h b/tests/auto/qdbusmarshall/common.h new file mode 100644 index 0000000..4c728ef --- /dev/null +++ b/tests/auto/qdbusmarshall/common.h @@ -0,0 +1,651 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <math.h> // isnan + +Q_DECLARE_METATYPE(QVariant) +Q_DECLARE_METATYPE(QList<bool>) +Q_DECLARE_METATYPE(QList<short>) +Q_DECLARE_METATYPE(QList<ushort>) +Q_DECLARE_METATYPE(QList<int>) +Q_DECLARE_METATYPE(QList<uint>) +Q_DECLARE_METATYPE(QList<qlonglong>) +Q_DECLARE_METATYPE(QList<qulonglong>) +Q_DECLARE_METATYPE(QList<double>) +Q_DECLARE_METATYPE(QList<QDBusVariant>) +Q_DECLARE_METATYPE(QList<QDateTime>) + +Q_DECLARE_METATYPE(QList<QByteArray>) +Q_DECLARE_METATYPE(QList<QVariantList>) +Q_DECLARE_METATYPE(QList<QStringList>) +Q_DECLARE_METATYPE(QList<QList<bool> >) +Q_DECLARE_METATYPE(QList<QList<short> >) +Q_DECLARE_METATYPE(QList<QList<ushort> >) +Q_DECLARE_METATYPE(QList<QList<int> >) +Q_DECLARE_METATYPE(QList<QList<uint> >) +Q_DECLARE_METATYPE(QList<QList<qlonglong> >) +Q_DECLARE_METATYPE(QList<QList<qulonglong> >) +Q_DECLARE_METATYPE(QList<QList<double> >) +Q_DECLARE_METATYPE(QList<QList<QDBusObjectPath> >) +Q_DECLARE_METATYPE(QList<QList<QDBusSignature> >) + +typedef QMap<int, QString> IntStringMap; +typedef QMap<QString, QString> StringStringMap; +typedef QMap<QDBusObjectPath, QString> ObjectPathStringMap; +typedef QHash<qlonglong, QDateTime> LLDateTimeMap; +typedef QHash<QDBusSignature, QString> SignatureStringMap; +Q_DECLARE_METATYPE(IntStringMap) +Q_DECLARE_METATYPE(StringStringMap) +Q_DECLARE_METATYPE(ObjectPathStringMap) +Q_DECLARE_METATYPE(LLDateTimeMap) +Q_DECLARE_METATYPE(SignatureStringMap) + +struct MyStruct +{ + int i; + QString s; + + inline bool operator==(const MyStruct &other) const + { return i == other.i && s == other.s; } +}; +Q_DECLARE_METATYPE(MyStruct) + +QDBusArgument &operator<<(QDBusArgument &arg, const MyStruct &ms) +{ + arg.beginStructure(); + arg << ms.i << ms.s; + arg.endStructure(); + return arg; +} + +const QDBusArgument &operator>>(const QDBusArgument &arg, MyStruct &ms) +{ + arg.beginStructure(); + arg >> ms.i >> ms.s; + arg.endStructure(); + return arg; +} + +void commonInit() +{ + qDBusRegisterMetaType<QList<QDateTime> >(); + qDBusRegisterMetaType<QList<QStringList> >(); + qDBusRegisterMetaType<QList<QByteArray> >(); + qDBusRegisterMetaType<QList<QList<bool> > >(); + qDBusRegisterMetaType<QList<QList<short> > >(); + qDBusRegisterMetaType<QList<QList<ushort> > >(); + qDBusRegisterMetaType<QList<QList<int> > >(); + qDBusRegisterMetaType<QList<QList<uint> > >(); + qDBusRegisterMetaType<QList<QList<qlonglong> > >(); + qDBusRegisterMetaType<QList<QList<qulonglong> > >(); + qDBusRegisterMetaType<QList<QList<double> > >(); + qDBusRegisterMetaType<QList<QList<QDBusObjectPath> > >(); + qDBusRegisterMetaType<QList<QList<QDBusSignature> > >(); + qDBusRegisterMetaType<QList<QVariantList> >(); + + qDBusRegisterMetaType<QMap<int, QString> >(); + qDBusRegisterMetaType<QMap<QString, QString> >(); + qDBusRegisterMetaType<QMap<QDBusObjectPath, QString> >(); + qDBusRegisterMetaType<QHash<qlonglong, QDateTime> >(); + qDBusRegisterMetaType<QHash<QDBusSignature, QString> >(); + + qDBusRegisterMetaType<MyStruct>(); +} +#ifdef USE_PRIVATE_CODE +#include "private/qdbusintrospection_p.h" + +// just to make it easier: +typedef QDBusIntrospection::Interfaces InterfaceMap; +typedef QDBusIntrospection::Objects ObjectMap; +typedef QDBusIntrospection::Arguments ArgumentList; +typedef QDBusIntrospection::Annotations AnnotationsMap; +typedef QDBusIntrospection::Methods MethodMap; +typedef QDBusIntrospection::Signals SignalMap; +typedef QDBusIntrospection::Properties PropertyMap; + +Q_DECLARE_METATYPE(QDBusIntrospection::Method) +Q_DECLARE_METATYPE(QDBusIntrospection::Signal) +Q_DECLARE_METATYPE(QDBusIntrospection::Property) +Q_DECLARE_METATYPE(MethodMap) +Q_DECLARE_METATYPE(SignalMap) +Q_DECLARE_METATYPE(PropertyMap) + +inline QDBusIntrospection::Argument arg(const char* type, const char *name = 0) +{ + QDBusIntrospection::Argument retval; + retval.type = QLatin1String(type); + retval.name = QLatin1String(name); + return retval; +} + +template<typename T> +inline QMap<QString, T>& operator<<(QMap<QString, T>& map, const T& m) +{ map.insertMulti(m.name, m); return map; } + +inline const char* mapName(const MethodMap&) +{ return "MethodMap"; } + +inline const char* mapName(const SignalMap&) +{ return "SignalMap"; } + +inline const char* mapName(const PropertyMap&) +{ return "PropertyMap"; } + +QString printable(const QDBusIntrospection::Method& m) +{ + QString result = "method " + m.name + "("; + foreach (QDBusIntrospection::Argument arg, m.inputArgs) + result += QString("in %1 %2, ") + .arg(arg.type, arg.name); + foreach (QDBusIntrospection::Argument arg, m.outputArgs) + result += QString("out %1 %2, ") + .arg(arg.type, arg.name); + AnnotationsMap::const_iterator it = m.annotations.begin(); + for ( ; it != m.annotations.end(); ++it) + result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); + + result += ")"; + return result; +} + +QString printable(const QDBusIntrospection::Signal& s) +{ + QString result = "signal " + s.name + "("; + foreach (QDBusIntrospection::Argument arg, s.outputArgs) + result += QString("out %1 %2, ") + .arg(arg.type, arg.name); + AnnotationsMap::const_iterator it = s.annotations.begin(); + for ( ; it != s.annotations.end(); ++it) + result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); + + result += ")"; + return result; +} + +QString printable(const QDBusIntrospection::Property& p) +{ + QString result; + if (p.access == QDBusIntrospection::Property::Read) + result = "property read %1 %2, "; + else if (p.access == QDBusIntrospection::Property::Write) + result = "property write %1 %2, "; + else + result = "property readwrite %1 %2, "; + result = result.arg(p.type, p.name); + + AnnotationsMap::const_iterator it = p.annotations.begin(); + for ( ; it != p.annotations.end(); ++it) + result += QString("%1 \"%2\", ").arg(it.key()).arg(it.value()); + + return result; +} + +template<typename T> +char* printableMap(const QMap<QString, T>& map) +{ + QString contents = "\n"; + typename QMap<QString, T>::const_iterator it = map.begin(); + for ( ; it != map.end(); ++it) { + if (it.key() != it.value().name) + contents += it.value().name + ":"; + contents += printable(it.value()); + contents += ";\n"; + } + + QString result("%1(size = %2): {%3}"); + return qstrdup(qPrintable(result + .arg(mapName(map)) + .arg(map.size()) + .arg(contents))); +} + +QT_BEGIN_NAMESPACE +namespace QTest { + template<> + inline char* toString(const MethodMap& map) + { + return printableMap(map); + } + + template<> + inline char* toString(const SignalMap& map) + { + return printableMap(map); + } + + template<> + inline char* toString(const PropertyMap& map) + { + return printableMap(map); + } +} +QT_END_NAMESPACE + +#endif + +//bool compare(const QVariantList &l1, const QVariantList &l2); +//bool compare(const QVariantMap &m1, const QVariantMap &m2); +template<typename T> +bool compare(const T &t1, const T &t2) +{ return t1 == t2; } + +template<> +bool compare(const QVariant &v1, const QVariant &v2); + +bool compare(double d1, double d2) +{ + if (isnan(d1) && isnan(d2)) + return true; + return d1 == d2; +} + +template<> +bool compare(const QString &s1, const QString &s2) +{ + if (s1.isEmpty() && s2.isEmpty()) + return true; // regardless of whether one of them is null + return s1 == s2; +} + +template<> +bool compare(const QByteArray &ba1, const QByteArray &ba2) +{ + if (ba1.isEmpty() && ba2.isEmpty()) + return true; // regardless of whether one of them is null + return ba1 == ba2; +} + +template<> +bool compare(const QDBusVariant &s1, const QDBusVariant &s2) +{ + return compare(s1.variant(), s2.variant()); +} + +template<typename T> +bool compare(const QList<T> &l1, const QList<T> &l2) +{ + if (l1.count() != l2.count()) + return false; + + typename QList<T>::ConstIterator it1 = l1.constBegin(); + typename QList<T>::ConstIterator it2 = l2.constBegin(); + typename QList<T>::ConstIterator end = l1.constEnd(); + for ( ; it1 != end; ++it1, ++it2) + if (!compare(*it1, *it2)) + return false; + return true; +} + +template<typename Key, typename T> +bool compare(const QMap<Key, T> &m1, const QMap<Key, T> &m2) +{ + if (m1.count() != m2.size()) + return false; + typename QMap<Key, T>::ConstIterator i1 = m1.constBegin(); + typename QMap<Key, T>::ConstIterator end = m1.constEnd(); + for ( ; i1 != end; ++i1) { + typename QMap<Key, T>::ConstIterator i2 = m2.find(i1.key()); + if (i2 == m2.constEnd()) + return false; + if (!compare(*i1, *i2)) + return false; + } + return true; +} + +template<typename Key, typename T> +bool compare(const QHash<Key, T> &m1, const QHash<Key, T> &m2) +{ + if (m1.count() != m2.size()) + return false; + typename QHash<Key, T>::ConstIterator i1 = m1.constBegin(); + typename QHash<Key, T>::ConstIterator end = m1.constEnd(); + for ( ; i1 != end; ++i1) { + typename QHash<Key, T>::ConstIterator i2 = m2.find(i1.key()); + if (i2 == m2.constEnd()) + return false; + if (!compare(*i1, *i2)) + return false; + } + return true; +} + +template<typename T> +inline bool compare(const QDBusArgument &arg, const QVariant &v2, T * = 0) +{ + return compare(qdbus_cast<T>(arg), qvariant_cast<T>(v2)); +} + +bool compareToArgument(const QDBusArgument &arg, const QVariant &v2) +{ + if (arg.currentSignature() != QDBusMetaType::typeToSignature(v2.userType())) + return false; + + // try to demarshall the arg according to v2 + switch (v2.userType()) + { + case QVariant::Bool: + return compare<bool>(arg, v2); + case QMetaType::UChar: + return compare<uchar>(arg, v2); + case QMetaType::Short: + return compare<short>(arg, v2); + case QMetaType::UShort: + return compare<ushort>(arg, v2); + case QVariant::Int: + return compare<int>(arg, v2); + case QVariant::UInt: + return compare<uint>(arg, v2); + case QVariant::LongLong: + return compare<qlonglong>(arg, v2); + case QVariant::ULongLong: + return compare<qulonglong>(arg, v2); + case QVariant::Double: + return compare<double>(arg, v2); + case QVariant::String: + return compare<QString>(arg, v2); + case QVariant::ByteArray: + return compare<QByteArray>(arg, v2); + case QVariant::List: + return compare<QVariantList>(arg, v2); + case QVariant::Map: + return compare<QVariantMap>(arg, v2); + case QVariant::Point: + return compare<QPoint>(arg, v2); + case QVariant::PointF: + return compare<QPointF>(arg, v2); + case QVariant::Size: + return compare<QSize>(arg, v2); + case QVariant::SizeF: + return compare<QSizeF>(arg, v2); + case QVariant::Line: + return compare<QLine>(arg, v2); + case QVariant::LineF: + return compare<QLineF>(arg, v2); + case QVariant::Rect: + return compare<QRect>(arg, v2); + case QVariant::RectF: + return compare<QRectF>(arg, v2); + case QVariant::Date: + return compare<QDate>(arg, v2); + case QVariant::Time: + return compare<QTime>(arg, v2); + case QVariant::DateTime: + return compare<QDateTime>(arg, v2); + default: + register int id = v2.userType(); + if (id == qMetaTypeId<QDBusObjectPath>()) + return compare<QDBusObjectPath>(arg, v2); + else if (id == qMetaTypeId<QDBusSignature>()) + return compare<QDBusSignature>(arg, v2); + else if (id == qMetaTypeId<QDBusVariant>()) + return compare<QDBusVariant>(arg, v2); + else if (id == qMetaTypeId<QList<bool> >()) + return compare<QList<bool> >(arg, v2); + else if (id == qMetaTypeId<QList<short> >()) + return compare<QList<short> >(arg, v2); + else if (id == qMetaTypeId<QList<ushort> >()) + return compare<QList<ushort> >(arg, v2); + else if (id == qMetaTypeId<QList<int> >()) + return compare<QList<int> >(arg, v2); + else if (id == qMetaTypeId<QList<uint> >()) + return compare<QList<uint> >(arg, v2); + else if (id == qMetaTypeId<QList<qlonglong> >()) + return compare<QList<qlonglong> >(arg, v2); + else if (id == qMetaTypeId<QList<qulonglong> >()) + return compare<QList<qulonglong> >(arg, v2); + else if (id == qMetaTypeId<QList<double> >()) + return compare<QList<double> >(arg, v2); + else if (id == qMetaTypeId<QList<QDBusObjectPath> >()) + return compare<QList<QDBusObjectPath> >(arg, v2); + else if (id == qMetaTypeId<QList<QDBusSignature> >()) + return compare<QList<QDBusSignature> >(arg, v2); + else if (id == qMetaTypeId<QList<QDateTime> >()) + return compare<QList<QDateTime> >(arg, v2); + + else if (id == qMetaTypeId<QMap<int, QString> >()) + return compare<QMap<int, QString> >(arg, v2); + else if (id == qMetaTypeId<QMap<QString, QString> >()) + return compare<QMap<QString, QString> >(arg, v2); + else if (id == qMetaTypeId<QMap<QDBusObjectPath, QString> >()) + return compare<QMap<QDBusObjectPath, QString> >(arg, v2); + else if (id == qMetaTypeId<QHash<qlonglong, QDateTime> >()) + return compare<QHash<qlonglong, QDateTime> >(arg, v2); + else if (id == qMetaTypeId<QHash<QDBusSignature, QString> >()) + return compare<QHash<QDBusSignature, QString> >(arg, v2); + + else if (id == qMetaTypeId<QList<QByteArray> >()) + return compare<QList<QByteArray> >(arg, v2); + else if (id == qMetaTypeId<QList<QList<bool> > >()) + return compare<QList<QList<bool> > >(arg, v2); + else if (id == qMetaTypeId<QList<QList<short> > >()) + return compare<QList<QList<short> > >(arg, v2); + else if (id == qMetaTypeId<QList<QList<ushort> > >()) + return compare<QList<QList<ushort> > >(arg, v2); + else if (id == qMetaTypeId<QList<QList<int> > >()) + return compare<QList<QList<int> > >(arg, v2); + else if (id == qMetaTypeId<QList<QList<uint> > >()) + return compare<QList<QList<uint> > >(arg, v2); + else if (id == qMetaTypeId<QList<QList<qlonglong> > >()) + return compare<QList<QList<qlonglong> > >(arg, v2); + else if (id == qMetaTypeId<QList<QList<qulonglong> > >()) + return compare<QList<QList<qulonglong> > >(arg, v2); + else if (id == qMetaTypeId<QList<QList<double> > >()) + return compare<QList<QList<double> > >(arg, v2); + else if (id == qMetaTypeId<QList<QStringList> >()) + return compare<QList<QStringList> >(arg, v2); + else if (id == qMetaTypeId<QList<QVariantList> >()) + return compare<QList<QVariantList> >(arg, v2); + + else if (id == qMetaTypeId<MyStruct>()) + return compare<MyStruct>(arg, v2); + } + + qWarning() << "Unexpected QVariant type" << v2.userType() + << QByteArray(QDBusMetaType::typeToSignature(v2.userType())) + << QVariant::typeToName(QVariant::Type(v2.userType())); + return false; +} + +template<> bool compare(const QVariant &v1, const QVariant &v2) +{ + // v1 is the one that came from the network + // v2 is the one that we sent + + if (v1.userType() == qMetaTypeId<QDBusArgument>()) + // this argument has been left un-demarshalled + return compareToArgument(qvariant_cast<QDBusArgument>(v1), v2); + + if (v1.userType() != v2.userType()) + return false; + + int id = v1.userType(); + if (id == QVariant::List) + return compare(v1.toList(), v2.toList()); + + else if (id == QVariant::Map) + return compare(v1.toMap(), v2.toMap()); + + else if (id == QVariant::String) + return compare(v1.toString(), v2.toString()); + + else if (id == QVariant::ByteArray) + return compare(v1.toByteArray(), v2.toByteArray()); + + else if (id < int(QVariant::UserType)) // yes, v1.type() + // QVariant can compare + return v1 == v2; + + else if (id == QMetaType::UChar) + return qvariant_cast<uchar>(v1) == qvariant_cast<uchar>(v2); + + else if (id == QMetaType::Short) + return qvariant_cast<short>(v1) == qvariant_cast<short>(v2); + + else if (id == QMetaType::UShort) + return qvariant_cast<ushort>(v1) == qvariant_cast<ushort>(v2); + + else if (id == qMetaTypeId<QDBusObjectPath>()) + return qvariant_cast<QDBusObjectPath>(v1).path() == qvariant_cast<QDBusObjectPath>(v2).path(); + + else if (id == qMetaTypeId<QDBusSignature>()) + return qvariant_cast<QDBusSignature>(v1).signature() == qvariant_cast<QDBusSignature>(v2).signature(); + + else if (id == qMetaTypeId<QDBusVariant>()) + return compare(qvariant_cast<QDBusVariant>(v1).variant(), qvariant_cast<QDBusVariant>(v2).variant()); + + else if (id == qMetaTypeId<QVariant>()) + return compare(qvariant_cast<QVariant>(v1), qvariant_cast<QVariant>(v2)); + + else if (id == qMetaTypeId<QList<bool> >()) + return qvariant_cast<QList<bool> >(v1) == qvariant_cast<QList<bool> >(v2); + + else if (id == qMetaTypeId<QList<short> >()) + return qvariant_cast<QList<short> >(v1) == qvariant_cast<QList<short> >(v2); + + else if (id == qMetaTypeId<QList<ushort> >()) + return qvariant_cast<QList<ushort> >(v1) == qvariant_cast<QList<ushort> >(v2); + + else if (id == qMetaTypeId<QList<int> >()) + return qvariant_cast<QList<int> >(v1) == qvariant_cast<QList<int> >(v2); + + else if (id == qMetaTypeId<QList<uint> >()) + return qvariant_cast<QList<uint> >(v1) == qvariant_cast<QList<uint> >(v2); + + else if (id == qMetaTypeId<QList<qlonglong> >()) + return qvariant_cast<QList<qlonglong> >(v1) == qvariant_cast<QList<qlonglong> >(v2); + + else if (id == qMetaTypeId<QList<qulonglong> >()) + return qvariant_cast<QList<qulonglong> >(v2) == qvariant_cast<QList<qulonglong> >(v2); + + else if (id == qMetaTypeId<QList<double> >()) + return compare(qvariant_cast<QList<double> >(v1), qvariant_cast<QList<double> >(v2)); + + else if (id == qMetaTypeId<QVariant>()) + return compare(qvariant_cast<QVariant>(v1), qvariant_cast<QVariant>(v2)); + + else if (id == qMetaTypeId<QList<QList<bool> > >()) + return qvariant_cast<QList<QList<bool> > >(v1) == qvariant_cast<QList<QList<bool> > >(v2); + + else if (id == qMetaTypeId<QList<QList<short> > >()) + return qvariant_cast<QList<QList<short> > >(v1) == qvariant_cast<QList<QList<short> > >(v2); + + else if (id == qMetaTypeId<QList<QList<ushort> > >()) + return qvariant_cast<QList<QList<ushort> > >(v1) == qvariant_cast<QList<QList<ushort> > >(v2); + + else if (id == qMetaTypeId<QList<QList<int> > >()) + return qvariant_cast<QList<QList<int> > >(v1) == qvariant_cast<QList<QList<int> > >(v2); + + else if (id == qMetaTypeId<QList<QList<uint> > >()) + return qvariant_cast<QList<QList<uint> > >(v1) == qvariant_cast<QList<QList<uint> > >(v2); + + else if (id == qMetaTypeId<QList<QList<qlonglong> > >()) + return qvariant_cast<QList<QList<qlonglong> > >(v1) == qvariant_cast<QList<QList<qlonglong> > >(v2); + + else if (id == qMetaTypeId<QList<QList<qulonglong> > >()) + return qvariant_cast<QList<QList<qulonglong> > >(v1) == qvariant_cast<QList<QList<qulonglong> > >(v2); + + else if (id == qMetaTypeId<QList<QList<double> > >()) + return compare(qvariant_cast<QList<QList<double> > >(v1), qvariant_cast<QList<QList<double> > >(v2)); + + else if (id == qMetaTypeId<QList<QStringList> >()) + return qvariant_cast<QList<QStringList> >(v1) == qvariant_cast<QList<QStringList> >(v2); + + else if (id == qMetaTypeId<QList<QByteArray> >()) + return qvariant_cast<QList<QByteArray> >(v1) == qvariant_cast<QList<QByteArray> >(v2); + + else if (id == qMetaTypeId<QList<QVariantList> >()) + return compare(qvariant_cast<QList<QVariantList> >(v1), qvariant_cast<QList<QVariantList> >(v2)); + + else if (id == qMetaTypeId<QMap<int, QString> >()) + return compare(qvariant_cast<QMap<int, QString> >(v1), qvariant_cast<QMap<int, QString> >(v2)); + + else if (id == qMetaTypeId<QMap<QString, QString> >()) // ssmap + return compare(qvariant_cast<QMap<QString, QString> >(v1), qvariant_cast<QMap<QString, QString> >(v2)); + + else if (id == qMetaTypeId<QMap<QDBusObjectPath, QString> >()) + return compare(qvariant_cast<QMap<QDBusObjectPath, QString> >(v1), qvariant_cast<QMap<QDBusObjectPath, QString> >(v2)); + + else if (id == qMetaTypeId<QHash<qlonglong, QDateTime> >()) // lldtmap + return compare(qvariant_cast<QHash<qint64, QDateTime> >(v1), qvariant_cast<QHash<qint64, QDateTime> >(v2)); + + else if (id == qMetaTypeId<QHash<QDBusSignature, QString> >()) + return compare(qvariant_cast<QHash<QDBusSignature, QString> >(v1), qvariant_cast<QHash<QDBusSignature, QString> >(v2)); + + else if (id == qMetaTypeId<MyStruct>()) // (is) + return qvariant_cast<MyStruct>(v1) == qvariant_cast<MyStruct>(v2); + + else { + qWarning() << "Please write a comparison case for type" << v1.typeName(); + return false; // unknown type + } +} + +#if 0 +bool compare(const QVariantList &l1, const QVariantList &l2) +{ + if (l1.count() != l2.size()) + return false; + QVariantList::ConstIterator i1 = l1.constBegin(); + QVariantList::ConstIterator i2 = l2.constBegin(); + QVariantList::ConstIterator end = l1.constEnd(); + for ( ; i1 != end; ++i1, ++i2) { + if (!compare(*i1, *i2)) + return false; + } + return true; +} + +bool compare(const QVariantMap &m1, const QVariantMap &m2) +{ + if (m1.count() != m2.size()) + return false; + QVariantMap::ConstIterator i1 = m1.constBegin(); + QVariantMap::ConstIterator end = m1.constEnd(); + for ( ; i1 != end; ++i1) { + QVariantMap::ConstIterator i2 = m2.find(i1.key()); + if (i2 == m2.constEnd()) + return false; + if (!compare(*i1, *i2)) + return false; + } + return true; +} +#endif diff --git a/tests/auto/qdbusmarshall/dummy.cpp b/tests/auto/qdbusmarshall/dummy.cpp new file mode 100644 index 0000000..2a34bb9 --- /dev/null +++ b/tests/auto/qdbusmarshall/dummy.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtTest/QtTest> + +QTEST_NOOP_MAIN + diff --git a/tests/auto/qdbusmarshall/qdbusmarshall.pro b/tests/auto/qdbusmarshall/qdbusmarshall.pro new file mode 100644 index 0000000..f8e0875 --- /dev/null +++ b/tests/auto/qdbusmarshall/qdbusmarshall.pro @@ -0,0 +1,10 @@ +load(qttest_p4) +contains(QT_CONFIG,dbus): { + TEMPLATE = subdirs + CONFIG += ordered + SUBDIRS = qpong test +} else { + SOURCES += dummy.cpp +} + + diff --git a/tests/auto/qdbusmarshall/qpong/qpong.cpp b/tests/auto/qdbusmarshall/qpong/qpong.cpp new file mode 100644 index 0000000..9a5753d --- /dev/null +++ b/tests/auto/qdbusmarshall/qpong/qpong.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtCore/QtCore> +#include <QtDBus/QtDBus> + +static const char serviceName[] = "com.trolltech.autotests.qpong"; +static const char objectPath[] = "/com/trolltech/qpong"; +//static const char *interfaceName = serviceName; + +class Pong: public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "com.trolltech.autotests.qpong") +public slots: + + void ping(QDBusMessage msg) + { + msg.setDelayedReply(true); + if (!QDBusConnection::sessionBus().send(msg.createReply(msg.arguments()))) + exit(1); + } +}; + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QDBusConnection con = QDBusConnection::sessionBus(); + if (!con.isConnected()) + exit(1); + + if (!con.registerService(serviceName)) + exit(2); + + Pong pong; + con.registerObject(objectPath, &pong, QDBusConnection::ExportAllSlots); + + printf("ready.\n"); + + return app.exec(); +} + +#include "qpong.moc" diff --git a/tests/auto/qdbusmarshall/qpong/qpong.pro b/tests/auto/qdbusmarshall/qpong/qpong.pro new file mode 100644 index 0000000..5cd9acd --- /dev/null +++ b/tests/auto/qdbusmarshall/qpong/qpong.pro @@ -0,0 +1,6 @@ +SOURCES = qpong.cpp +TARGET = qpong +QT += dbus +QT -= gui + + diff --git a/tests/auto/qdbusmarshall/test/test.pro b/tests/auto/qdbusmarshall/test/test.pro new file mode 100644 index 0000000..8901999 --- /dev/null +++ b/tests/auto/qdbusmarshall/test/test.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +SOURCES += ../tst_qdbusmarshall.cpp +TARGET = ../tst_qdbusmarshall + +QT = core +QT += dbus + + diff --git a/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp new file mode 100644 index 0000000..ad1a1b8 --- /dev/null +++ b/tests/auto/qdbusmarshall/tst_qdbusmarshall.cpp @@ -0,0 +1,786 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#define DBUS_API_SUBJECT_TO_CHANGE +#include <QtCore/QtCore> +#include <QtTest/QtTest> +#include <QtDBus/QtDBus> +#include <QtDBus/private/qdbusutil_p.h> + +#include "common.h" +#include <limits> + +static const char serviceName[] = "com.trolltech.autotests.qpong"; +static const char objectPath[] = "/com/trolltech/qpong"; +static const char *interfaceName = serviceName; + +class tst_QDBusMarshall: public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void sendBasic_data(); + void sendBasic(); + + void sendVariant_data(); + void sendVariant(); + + void sendArrays_data(); + void sendArrays(); + + void sendArrayOfArrays_data(); + void sendArrayOfArrays(); + + void sendMaps_data(); + void sendMaps(); + + void sendStructs_data(); + void sendStructs(); + + void sendComplex_data(); + void sendComplex(); + + void sendArgument_data(); + void sendArgument(); + +private: + QProcess proc; +}; + +class WaitForQPong: public QObject +{ + Q_OBJECT +public: + WaitForQPong(); + bool ok(); +public Q_SLOTS: + void ownerChange(const QString &name) + { + if (name == serviceName) + loop.quit(); + } + +private: + QEventLoop loop; +}; + +WaitForQPong::WaitForQPong() +{ + QDBusConnection con = QDBusConnection::sessionBus(); + if (!ok()) { + connect(con.interface(), SIGNAL(serviceOwnerChanged(QString,QString,QString)), + SLOT(ownerChange(QString))); + QTimer::singleShot(2000, &loop, SLOT(quit())); + loop.exec(); + } +} + +bool WaitForQPong::ok() +{ + return QDBusConnection::sessionBus().isConnected() && + QDBusConnection::sessionBus().interface()->isServiceRegistered(serviceName); +} + +void tst_QDBusMarshall::initTestCase() +{ + commonInit(); +#ifdef Q_OS_WIN + proc.start("qpong"); +#else + proc.start("./qpong/qpong"); +#endif + QVERIFY(proc.waitForStarted()); + + WaitForQPong w; + QVERIFY(w.ok()); + //QTest::qWait(2000); +} + +void tst_QDBusMarshall::cleanupTestCase() +{ + proc.close(); + proc.kill(); +} + +void tst_QDBusMarshall::sendBasic_data() +{ + QTest::addColumn<QVariant>("value"); + QTest::addColumn<QString>("sig"); + QTest::addColumn<QString>("stringResult"); + + // basic types: + QTest::newRow("bool") << QVariant(false) << "b" << "false"; +#if 1 + QTest::newRow("bool2") << QVariant(true) << "b" << "true"; + QTest::newRow("byte") << qVariantFromValue(uchar(1)) << "y" << "1"; + QTest::newRow("int16") << qVariantFromValue(short(2)) << "n" << "2"; + QTest::newRow("uint16") << qVariantFromValue(ushort(3)) << "q" << "3"; + QTest::newRow("int") << QVariant(1) << "i" << "1"; + QTest::newRow("uint") << QVariant(2U) << "u" << "2"; + QTest::newRow("int64") << QVariant(Q_INT64_C(3)) << "x" << "3"; + QTest::newRow("uint64") << QVariant(Q_UINT64_C(4)) << "t" << "4"; + QTest::newRow("double") << QVariant(42.5) << "d" << "42.5"; + QTest::newRow("string") << QVariant("ping") << "s" << "\"ping\""; + QTest::newRow("objectpath") << qVariantFromValue(QDBusObjectPath("/org/kde")) << "o" << "[ObjectPath: /org/kde]"; + QTest::newRow("signature") << qVariantFromValue(QDBusSignature("g")) << "g" << "[Signature: g]"; + QTest::newRow("emptystring") << QVariant("") << "s" << "\"\""; + QTest::newRow("nullstring") << QVariant(QString()) << "s" << "\"\""; +#endif +} + +void tst_QDBusMarshall::sendVariant_data() +{ + sendBasic_data(); + + QTest::newRow("variant") << qVariantFromValue(QDBusVariant(1)) << "v" << "[Variant(int): 1]"; + + QDBusVariant nested(1); + QTest::newRow("variant-variant") << qVariantFromValue(QDBusVariant(qVariantFromValue(nested))) << "v" + << "[Variant(QDBusVariant): [Variant(int): 1]]"; +} + +void tst_QDBusMarshall::sendArrays_data() +{ + QTest::addColumn<QVariant>("value"); + QTest::addColumn<QString>("sig"); + QTest::addColumn<QString>("stringResult"); + + // arrays + QStringList strings; + QTest::newRow("emptystringlist") << QVariant(strings) << "as" << "{}"; + strings << "hello" << "world"; + QTest::newRow("stringlist") << QVariant(strings) << "as" << "{\"hello\", \"world\"}"; + + strings.clear(); + strings << "" << "" << ""; + QTest::newRow("list-of-emptystrings") << QVariant(strings) << "as" << "{\"\", \"\", \"\"}"; + + strings.clear(); + strings << QString() << QString() << QString() << QString(); + QTest::newRow("list-of-nullstrings") << QVariant(strings) << "as" << "{\"\", \"\", \"\", \"\"}"; + + QByteArray bytearray; + QTest::newRow("nullbytearray") << QVariant(bytearray) << "ay" << "{}"; + bytearray = ""; // empty, not null + QTest::newRow("emptybytearray") << QVariant(bytearray) << "ay" << "{}"; + bytearray = "foo"; + QTest::newRow("bytearray") << QVariant(bytearray) << "ay" << "{102, 111, 111}"; + + QList<bool> bools; + QTest::newRow("emptyboollist") << qVariantFromValue(bools) << "ab" << "[Argument: ab {}]"; + bools << false << true << false; + QTest::newRow("boollist") << qVariantFromValue(bools) << "ab" << "[Argument: ab {false, true, false}]"; + + QList<short> shorts; + QTest::newRow("emptyshortlist") << qVariantFromValue(shorts) << "an" << "[Argument: an {}]"; + shorts << 42 << -43 << 44 << 45 << -32768 << 32767; + QTest::newRow("shortlist") << qVariantFromValue(shorts) << "an" + << "[Argument: an {42, -43, 44, 45, -32768, 32767}]"; + + QList<ushort> ushorts; + QTest::newRow("emptyushortlist") << qVariantFromValue(ushorts) << "aq" << "[Argument: aq {}]"; + ushorts << 12u << 13u << 14u << 15 << 65535; + QTest::newRow("ushortlist") << qVariantFromValue(ushorts) << "aq" << "[Argument: aq {12, 13, 14, 15, 65535}]"; + + QList<int> ints; + QTest::newRow("emptyintlist") << qVariantFromValue(ints) << "ai" << "[Argument: ai {}]"; + ints << 42 << -43 << 44 << 45 << 2147483647 << -2147483647-1; + QTest::newRow("intlist") << qVariantFromValue(ints) << "ai" << "[Argument: ai {42, -43, 44, 45, 2147483647, -2147483648}]"; + + QList<uint> uints; + QTest::newRow("emptyuintlist") << qVariantFromValue(uints) << "au" << "[Argument: au {}]"; + uints << uint(12) << uint(13) << uint(14) << 4294967295U; + QTest::newRow("uintlist") << qVariantFromValue(uints) << "au" << "[Argument: au {12, 13, 14, 4294967295}]"; + + QList<qlonglong> llints; + QTest::newRow("emptyllintlist") << qVariantFromValue(llints) << "ax" << "[Argument: ax {}]"; + llints << Q_INT64_C(99) << Q_INT64_C(-100) + << Q_INT64_C(-9223372036854775807)-1 << Q_INT64_C(9223372036854775807); + QTest::newRow("llintlist") << qVariantFromValue(llints) << "ax" + << "[Argument: ax {99, -100, -9223372036854775808, 9223372036854775807}]"; + + QList<qulonglong> ullints; + QTest::newRow("emptyullintlist") << qVariantFromValue(ullints) << "at" << "[Argument: at {}]"; + ullints << Q_UINT64_C(66) << Q_UINT64_C(67) + << Q_UINT64_C(18446744073709551615); + QTest::newRow("ullintlist") << qVariantFromValue(ullints) << "at" << "[Argument: at {66, 67, 18446744073709551615}]"; + + QList<double> doubles; + QTest::newRow("emptydoublelist") << qVariantFromValue(doubles) << "ad" << "[Argument: ad {}]"; + doubles << 1.2 << 2.2 << 4.4 + << -std::numeric_limits<double>::infinity() + << std::numeric_limits<double>::infinity() + << std::numeric_limits<double>::quiet_NaN(); + QTest::newRow("doublelist") << qVariantFromValue(doubles) << "ad" << "[Argument: ad {1.2, 2.2, 4.4, -inf, inf, nan}]"; + + QVariantList variants; + QTest::newRow("emptyvariantlist") << QVariant(variants) << "av" << "[Argument: av {}]"; + variants << QString("Hello") << QByteArray("World") << 42 << -43.0 << 44U << Q_INT64_C(-45) + << Q_UINT64_C(46) << true << qVariantFromValue(short(-47)) + << qVariantFromValue(QDBusSignature("av")) + << qVariantFromValue(QDBusVariant(qVariantFromValue(QDBusObjectPath("/")))); + QTest::newRow("variantlist") << QVariant(variants) << "av" + << "[Argument: av {[Variant(QString): \"Hello\"], [Variant(QByteArray): {87, 111, 114, 108, 100}], [Variant(int): 42], [Variant(double): -43], [Variant(uint): 44], [Variant(qlonglong): -45], [Variant(qulonglong): 46], [Variant(bool): true], [Variant(short): -47], [Variant: [Signature: av]], [Variant: [Variant: [ObjectPath: /]]]}]"; +} + +void tst_QDBusMarshall::sendArrayOfArrays_data() +{ + QTest::addColumn<QVariant>("value"); + QTest::addColumn<QString>("sig"); + QTest::addColumn<QString>("stringResult"); + + // arrays: + QList<QStringList> strings; + QTest::newRow("empty-list-of-stringlist") << qVariantFromValue(strings) << "aas" + << "[Argument: aas {}]"; + strings << QStringList(); + QTest::newRow("list-of-emptystringlist") << qVariantFromValue(strings) << "aas" + << "[Argument: aas {{}}]"; + strings << (QStringList() << "hello" << "world") + << (QStringList() << "hi" << "there") + << (QStringList() << QString()); + QTest::newRow("stringlist") << qVariantFromValue(strings) << "aas" + << "[Argument: aas {{}, {\"hello\", \"world\"}, {\"hi\", \"there\"}, {\"\"}}]"; + + QList<QByteArray> bytearray; + QTest::newRow("empty-list-of-bytearray") << qVariantFromValue(bytearray) << "aay" + << "[Argument: aay {}]"; + bytearray << QByteArray(); + QTest::newRow("list-of-emptybytearray") << qVariantFromValue(bytearray) << "aay" + << "[Argument: aay {{}}]"; + bytearray << "foo" << "bar" << "baz" << "" << QByteArray(); + QTest::newRow("bytearray") << qVariantFromValue(bytearray) << "aay" + << "[Argument: aay {{}, {102, 111, 111}, {98, 97, 114}, {98, 97, 122}, {}, {}}]"; + + QList<QList<bool> > bools; + QTest::newRow("empty-list-of-boollist") << qVariantFromValue(bools) << "aab" + << "[Argument: aab {}]"; + bools << QList<bool>(); + QTest::newRow("list-of-emptyboollist") << qVariantFromValue(bools) << "aab" + << "[Argument: aab {[Argument: ab {}]}]"; + bools << (QList<bool>() << false << true) << (QList<bool>() << false) << (QList<bool>()); + QTest::newRow("boollist") << qVariantFromValue(bools) << "aab" + << "[Argument: aab {[Argument: ab {}], [Argument: ab {false, true}], [Argument: ab {false}], [Argument: ab {}]}]"; + QList<QList<short> > shorts; + QTest::newRow("empty-list-of-shortlist") << qVariantFromValue(shorts) << "aan" + << "[Argument: aan {}]"; + shorts << QList<short>(); + QTest::newRow("list-of-emptyshortlist") << qVariantFromValue(shorts) << "aan" + << "[Argument: aan {[Argument: an {}]}]"; + shorts << (QList<short>() << 42 << -43 << 44 << 45) + << (QList<short>() << -32768 << 32767) + << (QList<short>()); + QTest::newRow("shortlist") << qVariantFromValue(shorts) << "aan" + << "[Argument: aan {[Argument: an {}], [Argument: an {42, -43, 44, 45}], [Argument: an {-32768, 32767}], [Argument: an {}]}]"; + + QList<QList<ushort> > ushorts; + QTest::newRow("empty-list-of-ushortlist") << qVariantFromValue(ushorts) << "aaq" + << "[Argument: aaq {}]"; + ushorts << QList<ushort>(); + QTest::newRow("list-of-emptyushortlist") << qVariantFromValue(ushorts) << "aaq" + << "[Argument: aaq {[Argument: aq {}]}]"; + ushorts << (QList<ushort>() << 12u << 13u << 14u << 15) + << (QList<ushort>() << 65535) + << (QList<ushort>()); + QTest::newRow("ushortlist") << qVariantFromValue(ushorts) << "aaq" + << "[Argument: aaq {[Argument: aq {}], [Argument: aq {12, 13, 14, 15}], [Argument: aq {65535}], [Argument: aq {}]}]"; + + QList<QList<int> > ints; + QTest::newRow("empty-list-of-intlist") << qVariantFromValue(ints) << "aai" + << "[Argument: aai {}]"; + ints << QList<int>(); + QTest::newRow("list-of-emptyintlist") << qVariantFromValue(ints) << "aai" + << "[Argument: aai {[Argument: ai {}]}]"; + ints << (QList<int>() << 42 << -43 << 44 << 45) + << (QList<int>() << 2147483647 << -2147483647-1) + << (QList<int>()); + QTest::newRow("intlist") << qVariantFromValue(ints) << "aai" + << "[Argument: aai {[Argument: ai {}], [Argument: ai {42, -43, 44, 45}], [Argument: ai {2147483647, -2147483648}], [Argument: ai {}]}]"; + + QList<QList<uint> > uints; + QTest::newRow("empty-list-of-uintlist") << qVariantFromValue(uints) << "aau" + << "[Argument: aau {}]"; + uints << QList<uint>(); + QTest::newRow("list-of-emptyuintlist") << qVariantFromValue(uints) << "aau" + << "[Argument: aau {[Argument: au {}]}]"; + uints << (QList<uint>() << uint(12) << uint(13) << uint(14)) + << (QList<uint>() << 4294967295U) + << (QList<uint>()); + QTest::newRow("uintlist") << qVariantFromValue(uints) << "aau" + << "[Argument: aau {[Argument: au {}], [Argument: au {12, 13, 14}], [Argument: au {4294967295}], [Argument: au {}]}]"; + + QList<QList<qlonglong> > llints; + QTest::newRow("empty-list-of-llintlist") << qVariantFromValue(llints) << "aax" + << "[Argument: aax {}]"; + llints << QList<qlonglong>(); + QTest::newRow("list-of-emptyllintlist") << qVariantFromValue(llints) << "aax" + << "[Argument: aax {[Argument: ax {}]}]"; + llints << (QList<qlonglong>() << Q_INT64_C(99) << Q_INT64_C(-100)) + << (QList<qlonglong>() << Q_INT64_C(-9223372036854775807)-1 << Q_INT64_C(9223372036854775807)) + << (QList<qlonglong>()); + QTest::newRow("llintlist") << qVariantFromValue(llints) << "aax" + << "[Argument: aax {[Argument: ax {}], [Argument: ax {99, -100}], [Argument: ax {-9223372036854775808, 9223372036854775807}], [Argument: ax {}]}]"; + + QList<QList<qulonglong> > ullints; + QTest::newRow("empty-list-of-ullintlist") << qVariantFromValue(ullints) << "aat" + << "[Argument: aat {}]"; + ullints << QList<qulonglong>(); + QTest::newRow("list-of-emptyullintlist") << qVariantFromValue(ullints) << "aat" + << "[Argument: aat {[Argument: at {}]}]"; + ullints << (QList<qulonglong>() << Q_UINT64_C(66) << Q_UINT64_C(67)) + << (QList<qulonglong>() << Q_UINT64_C(18446744073709551615)) + << (QList<qulonglong>()); + QTest::newRow("ullintlist") << qVariantFromValue(ullints) << "aat" + << "[Argument: aat {[Argument: at {}], [Argument: at {66, 67}], [Argument: at {18446744073709551615}], [Argument: at {}]}]"; + + QList<QList<double> > doubles; + QTest::newRow("empty-list-ofdoublelist") << qVariantFromValue(doubles) << "aad" + << "[Argument: aad {}]"; + doubles << QList<double>(); + QTest::newRow("list-of-emptydoublelist") << qVariantFromValue(doubles) << "aad" + << "[Argument: aad {[Argument: ad {}]}]"; + doubles << (QList<double>() << 1.2 << 2.2 << 4.4) + << (QList<double>() << -std::numeric_limits<double>::infinity() + << std::numeric_limits<double>::infinity() + << std::numeric_limits<double>::quiet_NaN()) + << (QList<double>()); + QTest::newRow("doublelist") << qVariantFromValue(doubles) << "aad" + << "[Argument: aad {[Argument: ad {}], [Argument: ad {1.2, 2.2, 4.4}], [Argument: ad {-inf, inf, nan}], [Argument: ad {}]}]"; + + QList<QVariantList> variants; + QTest::newRow("emptyvariantlist") << qVariantFromValue(variants) << "aav" + << "[Argument: aav {}]"; + variants << QVariantList(); + QTest::newRow("emptyvariantlist") << qVariantFromValue(variants) << "aav" + << "[Argument: aav {[Argument: av {}]}]"; + variants << (QVariantList() << QString("Hello") << QByteArray("World")) + << (QVariantList() << 42 << -43.0 << 44U << Q_INT64_C(-45)) + << (QVariantList() << Q_UINT64_C(46) << true << qVariantFromValue(short(-47))); + QTest::newRow("variantlist") << qVariantFromValue(variants) << "aav" + << "[Argument: aav {[Argument: av {}], [Argument: av {[Variant(QString): \"Hello\"], [Variant(QByteArray): {87, 111, 114, 108, 100}]}], [Argument: av {[Variant(int): 42], [Variant(double): -43], [Variant(uint): 44], [Variant(qlonglong): -45]}], [Argument: av {[Variant(qulonglong): 46], [Variant(bool): true], [Variant(short): -47]}]}]"; +} + +void tst_QDBusMarshall::sendMaps_data() +{ + QTest::addColumn<QVariant>("value"); + QTest::addColumn<QString>("sig"); + QTest::addColumn<QString>("stringResult"); + + QMap<int, QString> ismap; + QTest::newRow("empty-is-map") << qVariantFromValue(ismap) << "a{is}" + << "[Argument: a{is} {}]"; + ismap[1] = "a"; + ismap[2000] = "b"; + ismap[-47] = "c"; + QTest::newRow("is-map") << qVariantFromValue(ismap) << "a{is}" + << "[Argument: a{is} {-47 = \"c\", 1 = \"a\", 2000 = \"b\"}]"; + + QMap<QString, QString> ssmap; + QTest::newRow("empty-ss-map") << qVariantFromValue(ssmap) << "a{ss}" + << "[Argument: a{ss} {}]"; + ssmap["a"] = "a"; + ssmap["c"] = "b"; + ssmap["b"] = "c"; + QTest::newRow("ss-map") << qVariantFromValue(ssmap) << "a{ss}" + << "[Argument: a{ss} {\"a\" = \"a\", \"b\" = \"c\", \"c\" = \"b\"}]"; + + QVariantMap svmap; + QTest::newRow("empty-sv-map") << qVariantFromValue(svmap) << "a{sv}" + << "[Argument: a{sv} {}]"; + svmap["a"] = 1; + svmap["c"] = "b"; + svmap["b"] = QByteArray("c"); + svmap["d"] = 42U; + svmap["e"] = qVariantFromValue(short(-47)); + svmap["f"] = qVariantFromValue(QDBusVariant(0)); + QTest::newRow("sv-map1") << qVariantFromValue(svmap) << "a{sv}" + << "[Argument: a{sv} {\"a\" = [Variant(int): 1], \"b\" = [Variant(QByteArray): {99}], \"c\" = [Variant(QString): \"b\"], \"d\" = [Variant(uint): 42], \"e\" = [Variant(short): -47], \"f\" = [Variant: [Variant(int): 0]]}]"; + + QMap<QDBusObjectPath, QString> osmap; + QTest::newRow("empty-os-map") << qVariantFromValue(osmap) << "a{os}" + << "[Argument: a{os} {}]"; + osmap[QDBusObjectPath("/")] = "root"; + osmap[QDBusObjectPath("/foo")] = "foo"; + osmap[QDBusObjectPath("/bar/baz")] = "bar and baz"; + QTest::newRow("os-map") << qVariantFromValue(osmap) << "a{os}" + << "[Argument: a{os} {[ObjectPath: /] = \"root\", [ObjectPath: /bar/baz] = \"bar and baz\", [ObjectPath: /foo] = \"foo\"}]"; + + QHash<QDBusSignature, QString> gsmap; + QTest::newRow("empty-gs-map") << qVariantFromValue(gsmap) << "a{gs}" + << "[Argument: a{gs} {}]"; + gsmap[QDBusSignature("i")] = "int32"; + gsmap[QDBusSignature("s")] = "string"; + gsmap[QDBusSignature("a{gs}")] = "array of dict_entry of (signature, string)"; + QTest::newRow("gs-map") << qVariantFromValue(gsmap) << "a{gs}" + << "[Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]"; + + svmap.clear(); + svmap["ismap"] = qVariantFromValue(ismap); + svmap["ssmap"] = qVariantFromValue(ssmap); + svmap["osmap"] = qVariantFromValue(osmap); + svmap["gsmap"] = qVariantFromValue(gsmap); + QTest::newRow("sv-map2") << qVariantFromValue(svmap) << "a{sv}" + << "[Argument: a{sv} {\"gsmap\" = [Variant: [Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]], \"ismap\" = [Variant: [Argument: a{is} {-47 = \"c\", 1 = \"a\", 2000 = \"b\"}]], \"osmap\" = [Variant: [Argument: a{os} {[ObjectPath: /] = \"root\", [ObjectPath: /bar/baz] = \"bar and baz\", [ObjectPath: /foo] = \"foo\"}]], \"ssmap\" = [Variant: [Argument: a{ss} {\"a\" = \"a\", \"b\" = \"c\", \"c\" = \"b\"}]]}]"; +} + +void tst_QDBusMarshall::sendStructs_data() +{ + QTest::addColumn<QVariant>("value"); + QTest::addColumn<QString>("sig"); + QTest::addColumn<QString>("stringResult"); + + QTest::newRow("point") << QVariant(QPoint(1, 2)) << "(ii)" << "[Argument: (ii) 1, 2]"; + QTest::newRow("pointf") << QVariant(QPointF(1.5, -1.5)) << "(dd)" << "[Argument: (dd) 1.5, -1.5]"; + + QTest::newRow("size") << QVariant(QSize(1, 2)) << "(ii)" << "[Argument: (ii) 1, 2]"; + QTest::newRow("sizef") << QVariant(QSizeF(1.5, 1.5)) << "(dd)" << "[Argument: (dd) 1.5, 1.5]"; + + QTest::newRow("rect") << QVariant(QRect(1, 2, 3, 4)) << "(iiii)" << "[Argument: (iiii) 1, 2, 3, 4]"; + QTest::newRow("rectf") << QVariant(QRectF(0.5, 0.5, 1.5, 1.5)) << "(dddd)" << "[Argument: (dddd) 0.5, 0.5, 1.5, 1.5]"; + + QTest::newRow("line") << QVariant(QLine(1, 2, 3, 4)) << "((ii)(ii))" + << "[Argument: ((ii)(ii)) [Argument: (ii) 1, 2], [Argument: (ii) 3, 4]]"; + QTest::newRow("linef") << QVariant(QLineF(0.5, 0.5, 1.5, 1.5)) << "((dd)(dd))" + << "[Argument: ((dd)(dd)) [Argument: (dd) 0.5, 0.5], [Argument: (dd) 1.5, 1.5]]"; + + QDate date(2006, 6, 18); + QTime time(12, 25, 00); // the date I wrote this test on :-) + QTest::newRow("date") << QVariant(date) << "(iii)" << "[Argument: (iii) 2006, 6, 18]"; + QTest::newRow("time") << QVariant(time) << "(iiii)" << "[Argument: (iiii) 12, 25, 0, 0]"; + QTest::newRow("datetime") << QVariant(QDateTime(date, time)) << "((iii)(iiii)i)" + << "[Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 12, 25, 0, 0], 0]"; +} + +void tst_QDBusMarshall::sendComplex_data() +{ + QTest::addColumn<QVariant>("value"); + QTest::addColumn<QString>("sig"); + QTest::addColumn<QString>("stringResult"); + + QList<QDateTime> dtlist; + QTest::newRow("empty-datetimelist") << qVariantFromValue(dtlist) << "a((iii)(iiii)i)" + << "[Argument: a((iii)(iiii)i) {}]"; + dtlist << QDateTime(); + QTest::newRow("list-of-emptydatetime") << qVariantFromValue(dtlist) << "a((iii)(iiii)i)" + << "[Argument: a((iii)(iiii)i) {[Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0]}]"; + dtlist << QDateTime(QDate(1977, 9, 13), QTime(0, 0, 0)) + << QDateTime(QDate(2006, 6, 18), QTime(13, 14, 0)); + QTest::newRow("datetimelist") << qVariantFromValue(dtlist) << "a((iii)(iiii)i)" + << "[Argument: a((iii)(iiii)i) {[Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 1977, 9, 13], [Argument: (iiii) 0, 0, 0, 0], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 13, 14, 0, 0], 0]}]"; + + QHash<qlonglong, QDateTime> lldtmap; + QTest::newRow("empty-lldtmap") << qVariantFromValue(lldtmap) << "a{x((iii)(iiii)i)}" + << "[Argument: a{x((iii)(iiii)i)} {}]"; + lldtmap[0] = QDateTime(); + lldtmap[1] = QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC); + lldtmap[1150629776] = QDateTime(QDate(2006, 6, 18), QTime(11, 22, 56), Qt::UTC); + QTest::newRow("lldtmap") << qVariantFromValue(lldtmap) << "a{x((iii)(iiii)i)}" + << "[Argument: a{x((iii)(iiii)i)} {0 = [Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], 1 = [Argument: ((iii)(iiii)i) [Argument: (iii) 1970, 1, 1], [Argument: (iiii) 0, 0, 1, 0], 1], 1150629776 = [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 11, 22, 56, 0], 1]}]"; + + + QMap<int, QString> ismap; + ismap[1] = "a"; + ismap[2000] = "b"; + ismap[-47] = "c"; + + QMap<QString, QString> ssmap; + ssmap["a"] = "a"; + ssmap["c"] = "b"; + ssmap["b"] = "c"; + + QHash<QDBusSignature, QString> gsmap; + gsmap[QDBusSignature("i")] = "int32"; + gsmap[QDBusSignature("s")] = "string"; + gsmap[QDBusSignature("a{gs}")] = "array of dict_entry of (signature, string)"; + + QVariantMap svmap; + svmap["a"] = 1; + svmap["c"] = "b"; + svmap["b"] = QByteArray("c"); + svmap["d"] = 42U; + svmap["e"] = qVariantFromValue(short(-47)); + svmap["f"] = qVariantFromValue(QDBusVariant(0)); + svmap["date"] = QDate(1977, 1, 1); + svmap["time"] = QTime(8, 58, 0); + svmap["datetime"] = QDateTime(QDate(13, 9, 2008), QTime(8, 59, 31)); + svmap["pointf"] = QPointF(0.5, -0.5); + svmap["ismap"] = qVariantFromValue(ismap); + svmap["ssmap"] = qVariantFromValue(ssmap); + svmap["gsmap"] = qVariantFromValue(gsmap); + svmap["dtlist"] = qVariantFromValue(dtlist); + svmap["lldtmap"] = qVariantFromValue(lldtmap); + QTest::newRow("sv-map") << qVariantFromValue(svmap) << "a{sv}" + << "[Argument: a{sv} {\"a\" = [Variant(int): 1], \"b\" = [Variant(QByteArray): {99}], \"c\" = [Variant(QString): \"b\"], \"d\" = [Variant(uint): 42], \"date\" = [Variant: [Argument: (iii) 1977, 1, 1]], \"datetime\" = [Variant: [Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) 8, 59, 31, 0], 0]], \"dtlist\" = [Variant: [Argument: a((iii)(iiii)i) {[Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 1977, 9, 13], [Argument: (iiii) 0, 0, 0, 0], 0], [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 13, 14, 0, 0], 0]}]], \"e\" = [Variant(short): -47], \"f\" = [Variant: [Variant(int): 0]], \"gsmap\" = [Variant: [Argument: a{gs} {[Signature: a{gs}] = \"array of dict_entry of (signature, string)\", [Signature: i] = \"int32\", [Signature: s] = \"string\"}]], \"ismap\" = [Variant: [Argument: a{is} {-47 = \"c\", 1 = \"a\", 2000 = \"b\"}]], \"lldtmap\" = [Variant: [Argument: a{x((iii)(iiii)i)} {0 = [Argument: ((iii)(iiii)i) [Argument: (iii) 0, 0, 0], [Argument: (iiii) -1, -1, -1, -1], 0], 1 = [Argument: ((iii)(iiii)i) [Argument: (iii) 1970, 1, 1], [Argument: (iiii) 0, 0, 1, 0], 1], 1150629776 = [Argument: ((iii)(iiii)i) [Argument: (iii) 2006, 6, 18], [Argument: (iiii) 11, 22, 56, 0], 1]}]], \"pointf\" = [Variant: [Argument: (dd) 0.5, -0.5]], \"ssmap\" = [Variant: [Argument: a{ss} {\"a\" = \"a\", \"b\" = \"c\", \"c\" = \"b\"}]], \"time\" = [Variant: [Argument: (iiii) 8, 58, 0, 0]]}]"; +} + +void tst_QDBusMarshall::sendArgument_data() +{ + QTest::addColumn<QVariant>("value"); + QTest::addColumn<QString>("sig"); + QTest::addColumn<int>("classification"); + + QDBusArgument(); + QDBusArgument arg; + + arg = QDBusArgument(); + arg << true; + QTest::newRow("bool") << qVariantFromValue(arg) << "b" << int(QDBusArgument::BasicType);; + + arg = QDBusArgument(); + arg << false; + QTest::newRow("bool2") << qVariantFromValue(arg) << "b" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << uchar(1); + QTest::newRow("byte") << qVariantFromValue(arg) << "y" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << short(2); + QTest::newRow("int16") << qVariantFromValue(arg) << "n" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << ushort(3); + QTest::newRow("uint16") << qVariantFromValue(arg) << "q" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << 1; + QTest::newRow("int32") << qVariantFromValue(arg) << "i" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << 2U; + QTest::newRow("uint32") << qVariantFromValue(arg) << "u" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << Q_INT64_C(3); + QTest::newRow("int64") << qVariantFromValue(arg) << "x" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << Q_UINT64_C(4); + QTest::newRow("uint64") << qVariantFromValue(arg) << "t" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << 42.5; + QTest::newRow("double") << qVariantFromValue(arg) << "d" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << QLatin1String("ping"); + QTest::newRow("string") << qVariantFromValue(arg) << "s" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << QDBusObjectPath("/org/kde"); + QTest::newRow("objectpath") << qVariantFromValue(arg) << "o" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << QDBusSignature("g"); + QTest::newRow("signature") << qVariantFromValue(arg) << "g" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << QLatin1String(""); + QTest::newRow("emptystring") << qVariantFromValue(arg) << "s" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << QString(); + QTest::newRow("nullstring") << qVariantFromValue(arg) << "s" << int(QDBusArgument::BasicType); + + arg = QDBusArgument(); + arg << QDBusVariant(1); + QTest::newRow("variant") << qVariantFromValue(arg) << "v" << int(QDBusArgument::VariantType); + + arg = QDBusArgument(); + arg << QDBusVariant(qVariantFromValue(QDBusVariant(1))); + QTest::newRow("variant-variant") << qVariantFromValue(arg) << "v" << int(QDBusArgument::VariantType); + + arg = QDBusArgument(); + arg.beginArray(QVariant::Int); + arg << 1 << 2 << 3 << -4; + arg.endArray(); + QTest::newRow("array-of-int") << qVariantFromValue(arg) << "ai" << int(QDBusArgument::ArrayType); + + arg = QDBusArgument(); + arg.beginMap(QVariant::Int, QVariant::UInt); + arg.beginMapEntry(); + arg << 1 << 2U; + arg.endMapEntry(); + arg.beginMapEntry(); + arg << 3 << 4U; + arg.endMapEntry(); + arg.endMap(); + QTest::newRow("map") << qVariantFromValue(arg) << "a{iu}" << int(QDBusArgument::MapType); + + arg = QDBusArgument(); + arg.beginStructure(); + arg << 1 << 2U << short(-3) << ushort(4) << 5.0 << false; + arg.endStructure(); + QTest::newRow("structure") << qVariantFromValue(arg) << "(iunqdb)" << int(QDBusArgument::StructureType); + +#if 0 + // this is now unsupported + arg << 1 << 2U << short(-3) << ushort(4) << 5.0 << false; + QTest::newRow("many-args") << qVariantFromValue(arg) << "(iunqdb)iunqdb"; +#endif +} + +void tst_QDBusMarshall::sendBasic() +{ + QFETCH(QVariant, value); + QFETCH(QString, stringResult); + + QDBusConnection con = QDBusConnection::sessionBus(); + + QVERIFY(con.isConnected()); + + QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, + objectPath, interfaceName, "ping"); + msg << value; + + QDBusMessage reply = con.call(msg); + //qDebug() << reply; + + QCOMPARE(reply.arguments().count(), msg.arguments().count()); + QTEST(reply.signature(), "sig"); + for (int i = 0; i < reply.arguments().count(); ++i) { + QVERIFY(compare(reply.arguments().at(i), msg.arguments().at(i))); + //printf("\n! %s\n* %s\n", qPrintable(qDBusArgumentToString(reply.arguments().at(i))), qPrintable(stringResult)); + QCOMPARE(QDBusUtil::argumentToString(reply.arguments().at(i)), stringResult); + } +} + +void tst_QDBusMarshall::sendVariant() +{ + QFETCH(QVariant, value); + + QDBusConnection con = QDBusConnection::sessionBus(); + + QVERIFY(con.isConnected()); + + QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, + objectPath, interfaceName, "ping"); + msg << qVariantFromValue(QDBusVariant(value)); + + QDBusMessage reply = con.call(msg); + // qDebug() << reply; + + QCOMPARE(reply.arguments().count(), msg.arguments().count()); + QCOMPARE(reply.signature(), QString("v")); + for (int i = 0; i < reply.arguments().count(); ++i) + QVERIFY(compare(reply.arguments().at(i), msg.arguments().at(i))); +} + +void tst_QDBusMarshall::sendArrays() +{ + sendBasic(); +} + +void tst_QDBusMarshall::sendArrayOfArrays() +{ + sendBasic(); +} + +void tst_QDBusMarshall::sendMaps() +{ + sendBasic(); +} + +void tst_QDBusMarshall::sendStructs() +{ + sendBasic(); +} + +void tst_QDBusMarshall::sendComplex() +{ + sendBasic(); +} + +void tst_QDBusMarshall::sendArgument() +{ + QFETCH(QVariant, value); + QFETCH(QString, sig); + + QDBusConnection con = QDBusConnection::sessionBus(); + + QVERIFY(con.isConnected()); + + QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, objectPath, + interfaceName, "ping"); + msg << value; + + QDBusMessage reply = con.call(msg); + +// QCOMPARE(reply.arguments().count(), msg.arguments().count()); + QCOMPARE(reply.signature(), sig); +// for (int i = 0; i < reply.arguments().count(); ++i) +// QVERIFY(compare(reply.arguments().at(i), msg.arguments().at(i))); + + // do it again inside a STRUCT now + QDBusArgument sendArg; + sendArg.beginStructure(); + sendArg.appendVariant(value); + sendArg.endStructure(); + msg.setArguments(QVariantList() << qVariantFromValue(sendArg)); + reply = con.call(msg); + + QCOMPARE(reply.signature(), QString("(%1)").arg(sig)); + QCOMPARE(reply.arguments().at(0).userType(), qMetaTypeId<QDBusArgument>()); + + const QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.arguments().at(0)); + QCOMPARE(int(arg.currentType()), int(QDBusArgument::StructureType)); + + arg.beginStructure(); + QVERIFY(!arg.atEnd()); + QCOMPARE(arg.currentSignature(), sig); + QTEST(int(arg.currentType()), "classification"); + + QVariant extracted = arg.asVariant(); + QVERIFY(arg.atEnd()); + + arg.endStructure(); + QVERIFY(arg.atEnd()); + QCOMPARE(arg.currentType(), QDBusArgument::UnknownType); + + if (value.type() != QVariant::UserType) + QCOMPARE(extracted, value); +} + +QTEST_MAIN(tst_QDBusMarshall) +#include "tst_qdbusmarshall.moc" |