diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2019-12-11 18:13:28 +0100 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2020-02-20 16:11:02 +0100 |
commit | 4dbac23e5354638224d8d99ba3342067c015a04b (patch) | |
tree | ac262e76f0e6b04378fb653192b216a6f8d1ef68 /tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | |
parent | 33cd680ddbaccf6139e215d851a39e657ae36394 (diff) |
Normalize types at compile time
This also fix the normalization algorithm:
- Some 'const' after pointers were not removed as they should.
- No need to keep the space in '> >' and '< :' in C++11 anymore
- Fix normalization of 'long unsigned int' and similar
Change-Id: I2b72f0fede96c1063e7b155d9f25a85fccfc7bf9
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp')
-rw-r--r-- | tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 04c4777e07..0d9dfc1c4c 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -124,6 +124,8 @@ private slots: void customDebugStream(); void unknownType(); void fromType(); + void operatorEq_data(); + void operatorEq(); }; struct BaseGenericType @@ -579,11 +581,11 @@ void tst_QMetaType::typeName_data() // automatic registration QTest::newRow("QHash<int,int>") << ::qMetaTypeId<QHash<int, int> >() << QString::fromLatin1("QHash<int,int>"); QTest::newRow("QMap<int,int>") << ::qMetaTypeId<QMap<int, int> >() << QString::fromLatin1("QMap<int,int>"); - QTest::newRow("QVector<QMap<int,int>>") << ::qMetaTypeId<QVector<QMap<int, int> > >() << QString::fromLatin1("QVector<QMap<int,int> >"); + QTest::newRow("QVector<QMap<int,int>>") << ::qMetaTypeId<QVector<QMap<int, int> > >() << QString::fromLatin1("QVector<QMap<int,int>>"); // automatic registration with automatic QList to QVector aliasing QTest::newRow("QList<int>") << ::qMetaTypeId<QList<int> >() << QString::fromLatin1("QVector<int>"); - QTest::newRow("QVector<QList<int>>") << ::qMetaTypeId<QVector<QList<int> > >() << QString::fromLatin1("QVector<QVector<int> >"); + QTest::newRow("QVector<QList<int>>") << ::qMetaTypeId<QVector<QList<int> > >() << QString::fromLatin1("QVector<QVector<int>>"); QTest::newRow("CustomQObject*") << ::qMetaTypeId<CustomQObject*>() << QString::fromLatin1("CustomQObject*"); QTest::newRow("CustomGadget") << ::qMetaTypeId<CustomGadget>() << QString::fromLatin1("CustomGadget"); @@ -1745,7 +1747,7 @@ void tst_QMetaType::automaticTemplateRegistration() PRINT_2ARG_TEMPLATE ) - CREATE_AND_VERIFY_CONTAINER(QList, QList<QMap<int, QHash<char, QVariantList> > >) + CREATE_AND_VERIFY_CONTAINER(QList, QList<QMap<int, QHash<char, QList<QVariant> > > >) CREATE_AND_VERIFY_CONTAINER(QVector, void*) CREATE_AND_VERIFY_CONTAINER(QVector, const void*) CREATE_AND_VERIFY_CONTAINER(QList, void*) @@ -2527,6 +2529,50 @@ void tst_QMetaType::fromType() #undef FROMTYPE_CHECK } +template<char X, typename T = void> +struct CharTemplate +{ + struct + { + int a; + } x; +}; + +void tst_QMetaType::operatorEq_data() +{ + QTest::addColumn<QMetaType>("typeA"); + QTest::addColumn<QMetaType>("typeB"); + QTest::addColumn<bool>("eq"); + + QTest::newRow("String") << QMetaType(QMetaType::QString) + << QMetaType::fromType<const QString &>() << true; + QTest::newRow("void1") << QMetaType(QMetaType::UnknownType) << QMetaType::fromType<void>() + << true; + QTest::newRow("void2") << QMetaType::fromType<const void>() << QMetaType::fromType<void>() + << true; + QTest::newRow("vec1") << QMetaType::fromType<QVector<const int *>>() + << QMetaType::fromType<QVector<const int *>>() << true; + QTest::newRow("vec2") << QMetaType::fromType<QVector<const int *>>() + << QMetaType::fromType<QVector<int *>>() << false; + QTest::newRow("char1") << QMetaType::fromType<CharTemplate<'>'>>() + << QMetaType::fromType<CharTemplate<'>', void>>() << true; + QTest::newRow("annon1") << QMetaType::fromType<decltype(CharTemplate<'>'>::x)>() + << QMetaType::fromType<decltype(CharTemplate<'>'>::x)>() << true; + QTest::newRow("annon2") << QMetaType::fromType<decltype(CharTemplate<'>'>::x)>() + << QMetaType::fromType<decltype(CharTemplate<'<'>::x)>() << false; +} + +void tst_QMetaType::operatorEq() +{ + QFETCH(QMetaType, typeA); + QFETCH(QMetaType, typeB); + QFETCH(bool, eq); + + QCOMPARE(typeA == typeB, eq); + QCOMPARE(typeB == typeA, eq); + QCOMPARE(typeA != typeB, !eq); + QCOMPARE(typeB != typeA, !eq); +} // Compile-time test, it should be possible to register function pointer types class Undefined; |