diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 12:01:25 +0100 |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 12:02:41 +0100 |
commit | 79f2480c868523a7d8ffc9fb15055e8eab3237ba (patch) | |
tree | 8336143e8c09810dc97324970fed61af27e26a97 /tests/auto/corelib/kernel | |
parent | 7e4f32993498db0e06346e32458a1ec7d0c7b3ec (diff) | |
parent | 12f221410fbe41d0b2efda4cd3289dfcf9044aa8 (diff) |
Merge remote-tracking branch 'origin/api_changes' into containters
Conflicts:
src/corelib/kernel/qmetaobject.cpp
src/corelib/kernel/qvariant.cpp
src/tools/moc/moc.h
Change-Id: I2cd3d95b41d2636738c6b98064864941e3b0b4e6
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r-- | tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp | 2 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 189 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 15 |
3 files changed, 205 insertions, 1 deletions
diff --git a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp index e2144134d9..61484c1736 100644 --- a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp +++ b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp @@ -132,7 +132,7 @@ public: class StartStopEvent: public QEvent { public: - StartStopEvent(int type, QEventLoop *loop = 0) + explicit StartStopEvent(int type, QEventLoop *loop = 0) : QEvent(Type(type)), el(loop) { } diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 4f283cef90..84d28c7959 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -100,12 +100,29 @@ private slots: struct Foo { int i; }; + +class CustomQObject : public QObject +{ + Q_OBJECT +public: + CustomQObject(QObject *parent = 0) + : QObject(parent) + { + } +}; + +class CustomNonQObject {}; + void tst_QMetaType::defined() { QCOMPARE(int(QMetaTypeId2<QString>::Defined), 1); QCOMPARE(int(QMetaTypeId2<Foo>::Defined), 0); QCOMPARE(int(QMetaTypeId2<void*>::Defined), 1); QCOMPARE(int(QMetaTypeId2<int*>::Defined), 0); + QVERIFY(QMetaTypeId2<CustomQObject*>::Defined); + QVERIFY(!QMetaTypeId2<CustomQObject>::Defined); + QVERIFY(!QMetaTypeId2<CustomNonQObject>::Defined); + QVERIFY(!QMetaTypeId2<CustomNonQObject*>::Defined); } struct Bar @@ -685,6 +702,36 @@ public: }; Q_DECLARE_METATYPE(CustomMultiInheritanceObject*); +class C { char _[4]; }; +class M { char _[4]; }; +class P { char _[4]; }; + +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(M, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(P, Q_PRIMITIVE_TYPE); +QT_END_NAMESPACE + +// avoid the comma: +typedef QPair<C,C> QPairCC; +typedef QPair<C,M> QPairCM; +typedef QPair<C,P> QPairCP; +typedef QPair<M,C> QPairMC; +typedef QPair<M,M> QPairMM; +typedef QPair<M,P> QPairMP; +typedef QPair<P,C> QPairPC; +typedef QPair<P,M> QPairPM; +typedef QPair<P,P> QPairPP; + +Q_DECLARE_METATYPE(QPairCC) +Q_DECLARE_METATYPE(QPairCM) +Q_DECLARE_METATYPE(QPairCP) +Q_DECLARE_METATYPE(QPairMC) +Q_DECLARE_METATYPE(QPairMM) +Q_DECLARE_METATYPE(QPairMP) +Q_DECLARE_METATYPE(QPairPC) +Q_DECLARE_METATYPE(QPairPM) +Q_DECLARE_METATYPE(QPairPP) + void tst_QMetaType::flags_data() { QTest::addColumn<int>("type"); @@ -703,6 +750,15 @@ QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) QTest::newRow("CustomMovable") << ::qMetaTypeId<CustomMovable>() << true << true << false; QTest::newRow("CustomObject*") << ::qMetaTypeId<CustomObject*>() << true << false << true; QTest::newRow("CustomMultiInheritanceObject*") << ::qMetaTypeId<CustomMultiInheritanceObject*>() << true << false << true; + QTest::newRow("QPair<C,C>") << ::qMetaTypeId<QPair<C,C> >() << false << true << false; + QTest::newRow("QPair<C,M>") << ::qMetaTypeId<QPair<C,M> >() << false << true << false; + QTest::newRow("QPair<C,P>") << ::qMetaTypeId<QPair<C,P> >() << false << true << false; + QTest::newRow("QPair<M,C>") << ::qMetaTypeId<QPair<M,C> >() << false << true << false; + QTest::newRow("QPair<M,M>") << ::qMetaTypeId<QPair<M,M> >() << true << true << false; + QTest::newRow("QPair<M,P>") << ::qMetaTypeId<QPair<M,P> >() << true << true << false; + QTest::newRow("QPair<P,C>") << ::qMetaTypeId<QPair<P,C> >() << false << true << false; + QTest::newRow("QPair<P,M>") << ::qMetaTypeId<QPair<P,M> >() << true << true << false; + QTest::newRow("QPair<P,P>") << ::qMetaTypeId<QPair<P,P> >() << true << false << false; } void tst_QMetaType::flags() @@ -1018,6 +1074,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() { { @@ -1059,6 +1170,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 diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index ffe1d2bec4..c48a384e58 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -2541,9 +2541,24 @@ public: }; Q_DECLARE_METATYPE(CustomQObjectDerived*) +class CustomQObjectDerivedNoMetaType : public CustomQObject { + Q_OBJECT +public: + CustomQObjectDerivedNoMetaType(QObject *parent = 0) : CustomQObject(parent) {} +}; + void tst_QVariant::qvariant_cast_QObject_derived() { { + CustomQObjectDerivedNoMetaType *object = new CustomQObjectDerivedNoMetaType(this); + QVariant data = QVariant::fromValue(object); + QVERIFY(data.userType() == qMetaTypeId<CustomQObjectDerivedNoMetaType*>()); + QCOMPARE(data.value<QObject *>(), object); + QCOMPARE(data.value<CustomQObjectDerivedNoMetaType *>(), object); + QCOMPARE(data.value<CustomQObject *>(), object); + QVERIFY(data.value<CustomQWidget*>() == 0); + } + { CustomQObjectDerived *object = new CustomQObjectDerived(this); QVariant data = QVariant::fromValue(object); |