From d54ababd5f67bb621c1b3a911d0853c23df817a1 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Mar 2006 18:58:58 +0000 Subject: * test/qt/*: Sync with KDE Subversion revision 523647. Update the testcases to the new API. Remove testcases for classes that are no longer public or have been removed. --- test/qt/common.h | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 125 insertions(+), 8 deletions(-) (limited to 'test/qt/common.h') diff --git a/test/qt/common.h b/test/qt/common.h index e3c78bd6..943d3d95 100644 --- a/test/qt/common.h +++ b/test/qt/common.h @@ -1,3 +1,17 @@ +#include // isnan + +Q_DECLARE_METATYPE(QVariant) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +Q_DECLARE_METATYPE(QList) +#if 0 +#include "../qdbusintrospection_p.h" + // just to make it easier: typedef QDBusIntrospection::Interfaces InterfaceMap; typedef QDBusIntrospection::Objects ObjectMap; @@ -17,7 +31,7 @@ Q_DECLARE_METATYPE(PropertyMap) inline QDBusIntrospection::Argument arg(const char* type, const char *name = 0) { QDBusIntrospection::Argument retval; - retval.type = QDBusType(type); + retval.type = QLatin1String(type); retval.name = QLatin1String(name); return retval; } @@ -40,12 +54,10 @@ 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.toString(QDBusType::ConventionalNames)) - .arg(arg.name); + .arg(arg.type, arg.name); foreach (QDBusIntrospection::Argument arg, m.outputArgs) result += QString("out %1 %2, ") - .arg(arg.type.toString(QDBusType::ConventionalNames)) - .arg(arg.name); + .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()); @@ -59,8 +71,7 @@ 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.toString(QDBusType::ConventionalNames)) - .arg(arg.name); + .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()); @@ -78,7 +89,7 @@ QString printable(const QDBusIntrospection::Property& p) result = "property write %1 %2, "; else result = "property readwrite %1 %2, "; - result = result.arg(p.type.toString(QDBusType::ConventionalNames)).arg(p.name); + result = result.arg(p.type, p.name); AnnotationsMap::const_iterator it = p.annotations.begin(); for ( ; it != p.annotations.end(); ++it) @@ -125,3 +136,109 @@ namespace QTest { return printableMap(map); } } +#endif +bool compare(const QVariantList &l1, const QVariantList &l2); +bool compare(const QVariantMap &m1, const QVariantMap &m2); +bool compare(const QVariant &v1, const QVariant &v2); + +bool compare(const QList &l1, const QList &l2) +{ + if (l1.count() != l2.count()) + return false; + + QList::ConstIterator it1 = l1.constBegin(); + QList::ConstIterator it2 = l2.constBegin(); + QList::ConstIterator end = l1.constEnd(); + for ( ; it1 != end; ++it1, ++it2) + if (isnan(*it1) && isnan(*it2)) + continue; + else if (*it1 != *it2) + return false; + return true; +} + +bool compare(const QVariant &v1, const QVariant &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 < int(QVariant::UserType)) // yes, v1.type() + // QVariant can compare + return v1 == v2; + + else if (id == QMetaType::UChar) + return qvariant_cast(v1) == qvariant_cast(v2); + + else if (id == QMetaType::Short) + return qvariant_cast(v1) == qvariant_cast(v2); + + else if (id == QMetaType::UShort) + return qvariant_cast(v1) == qvariant_cast(v2); + + else if (id == qMetaTypeId()) + return compare(qvariant_cast(v1), qvariant_cast(v2)); + + else if (id == qMetaTypeId >()) + return qvariant_cast >(v1) == qvariant_cast >(v2); + + else if (id == qMetaTypeId >()) + return qvariant_cast >(v1) == qvariant_cast >(v2); + + else if (id == qMetaTypeId >()) + return qvariant_cast >(v1) == qvariant_cast >(v2); + + else if (id == qMetaTypeId >()) + return qvariant_cast >(v1) == qvariant_cast >(v2); + + else if (id == qMetaTypeId >()) + return qvariant_cast >(v1) == qvariant_cast >(v2); + + else if (id == qMetaTypeId >()) + return qvariant_cast >(v1) == qvariant_cast >(v2); + + else if (id == qMetaTypeId >()) + return qvariant_cast >(v2) == qvariant_cast >(v2); + + else if (id == qMetaTypeId >()) + return compare(qvariant_cast >(v1), qvariant_cast >(v2)); + + else + return false; // unknown type +} + +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; +} -- cgit