summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 06919c6f58..f8403f11a1 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -1053,6 +1053,61 @@ void tst_QMetaType::registerStreamBuiltin()
Q_DECLARE_METATYPE(QSharedPointer<QObject>)
+typedef QHash<int, uint> IntUIntHash;
+Q_DECLARE_METATYPE(IntUIntHash)
+typedef QMap<int, uint> IntUIntMap;
+Q_DECLARE_METATYPE(IntUIntMap)
+typedef QPair<int, uint> IntUIntPair;
+Q_DECLARE_METATYPE(IntUIntPair)
+
+struct CustomComparable
+{
+ CustomComparable(int i_ = 0) :i(i_) { }
+ bool operator==(const CustomComparable &other) const
+ {
+ return i == other.i;
+ }
+ int i;
+};
+
+struct UnregisteredType {};
+
+typedef QHash<int, CustomComparable> IntComparableHash;
+Q_DECLARE_METATYPE(IntComparableHash)
+typedef QMap<int, CustomComparable> IntComparableMap;
+Q_DECLARE_METATYPE(IntComparableMap)
+typedef QPair<int, CustomComparable> IntComparablePair;
+Q_DECLARE_METATYPE(IntComparablePair)
+
+typedef QHash<int, int> IntIntHash;
+typedef int NaturalNumber;
+class AutoMetaTypeObject : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(IntIntHash someHash READ someHash CONSTANT)
+ Q_PROPERTY(NaturalNumber someInt READ someInt CONSTANT)
+public:
+ AutoMetaTypeObject(QObject *parent = 0)
+ : QObject(parent), m_int(42)
+ {
+ m_hash.insert(4, 2);
+ }
+
+ QHash<int,int> someHash() const
+ {
+ return m_hash;
+ }
+
+ int someInt() const
+ {
+ return m_int;
+ }
+
+private:
+ QHash<int,int> m_hash;
+ int m_int;
+};
+
void tst_QMetaType::automaticTemplateRegistration()
{
{
@@ -1094,6 +1149,84 @@ void tst_QMetaType::automaticTemplateRegistration()
vectorList << sharedPointerList;
QVERIFY(QVariant::fromValue(vectorList).value<QVector<QList<QSharedPointer<QObject> > > >().first().first() == testObject);
}
+ {
+ IntIntHash intIntHash;
+ intIntHash.insert(4, 2);
+ QCOMPARE(QVariant::fromValue(intIntHash).value<IntIntHash>().value(4), 2);
+
+ AutoMetaTypeObject amto;
+
+ qRegisterMetaType<QHash<int, int> >("IntIntHash");
+ QVariant hashVariant = amto.property("someHash");
+ QCOMPARE(hashVariant.value<IntIntHash>().value(4), 2);
+
+ qRegisterMetaType<int>("NaturalNumber");
+ QVariant intVariant = amto.property("someInt");
+ QCOMPARE(intVariant.value<NaturalNumber>(), 42);
+ }
+ {
+ IntUIntHash intUIntHash;
+ intUIntHash.insert(4, 2);
+ QCOMPARE(QVariant::fromValue(intUIntHash).value<IntUIntHash>().value(4), (uint)2);
+ }
+ {
+ IntComparableHash intComparableHash;
+ CustomComparable m;
+ intComparableHash.insert(4, m);
+ QCOMPARE(QVariant::fromValue(intComparableHash).value<IntComparableHash>().value(4), m);
+ }
+ {
+ QVariantHash variantHash;
+ variantHash.insert(QStringLiteral("4"), 2);
+ QCOMPARE(QVariant::fromValue(variantHash).value<QVariantHash>().value(QStringLiteral("4")), QVariant(2));
+ }
+ {
+ typedef QMap<int, int> IntIntMap;
+ IntIntMap intIntMap;
+ intIntMap.insert(4, 2);
+ QCOMPARE(QVariant::fromValue(intIntMap).value<IntIntMap>().value(4), 2);
+ }
+ {
+ IntUIntMap intUIntMap;
+ intUIntMap.insert(4, 2);
+ QCOMPARE(QVariant::fromValue(intUIntMap).value<IntUIntMap>().value(4), (uint)2);
+ }
+ {
+ IntComparableMap intComparableMap;
+ CustomComparable m;
+ intComparableMap.insert(4, m);
+ QCOMPARE(QVariant::fromValue(intComparableMap).value<IntComparableMap>().value(4), m);
+ }
+ {
+ QVariantMap variantMap;
+ variantMap.insert(QStringLiteral("4"), 2);
+ QCOMPARE(QVariant::fromValue(variantMap).value<QVariantMap>().value(QStringLiteral("4")), QVariant(2));
+ }
+ {
+ typedef QPair<int, int> IntIntPair;
+ IntIntPair intIntPair = qMakePair(4, 2);
+ QCOMPARE(QVariant::fromValue(intIntPair).value<IntIntPair>().first, 4);
+ QCOMPARE(QVariant::fromValue(intIntPair).value<IntIntPair>().second, 2);
+ }
+ {
+ IntUIntPair intUIntPair = qMakePair<int, uint>(4, 2);
+ QCOMPARE(QVariant::fromValue(intUIntPair).value<IntUIntPair>().first, 4);
+ QCOMPARE(QVariant::fromValue(intUIntPair).value<IntUIntPair>().second, (uint)2);
+ }
+ {
+ CustomComparable m;
+ IntComparablePair intComparablePair = qMakePair(4, m);
+ QCOMPARE(QVariant::fromValue(intComparablePair).value<IntComparablePair>().first, 4);
+ QCOMPARE(QVariant::fromValue(intComparablePair).value<IntComparablePair>().second, m);
+ }
+ {
+ typedef QHash<int, UnregisteredType> IntUnregisteredTypeHash;
+ QVERIFY(qRegisterMetaType<IntUnregisteredTypeHash>("IntUnregisteredTypeHash") > 0);
+ }
+ {
+ typedef QList<UnregisteredType> UnregisteredTypeList;
+ QVERIFY(qRegisterMetaType<UnregisteredTypeList>("UnregisteredTypeList") > 0);
+ }
}
// Compile-time test, it should be possible to register function pointer types