summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-08-30 22:16:25 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-14 21:37:39 +0200
commitfa93f1aeb0dd92acf0cbe2113425a1b21b8c82cb (patch)
tree1fc5cfa364da27f46911f84183d1161d278708fa /tests
parent0599255fcf54086ae345d289e8f761d890a91a39 (diff)
Fix compile time type normalization code
Use a simpler constexpr to generate type name on gcc This works around an ICE on gcc in release mode when compiling with PCH enabled. As the type we're getting from Q_FUNC_INFO is already in a somewhat normalized form, this requires significanlty less processing and esp. not a recursive constexpr method which I suspect triggers the ICE. Fix integer type conversions to also properly normalize long long values (to q(u)longlong. Make sure the mapping also works on MSVC, where long long types get mapped to __int64. Also, normalize unsigned short and unsigned char to ushort and uchar, respectively, to follow the convention set by uint and ulong. Add some test cases to verify the mappings. Change-Id: I3dec5764450bf22ab6f066597803c3f46c2cd5ac Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp8
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp38
-rw-r--r--tests/auto/tools/moc/tst_moc.cpp4
3 files changed, 45 insertions, 5 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
index c073e2d77f..08219d45d2 100644
--- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
+++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
@@ -1402,15 +1402,15 @@ void tst_QMetaObject::normalizedType_data()
QTest::newRow("QVector") << "QVector<int>" << "QList<int>";
QTest::newRow("refref") << "X const*const&&" << "const X*const&&";
QTest::newRow("refref2") << "const X<T const&&>&&" << "const X<const T&&>&&";
- QTest::newRow("long1") << "long unsigned int long" << "unsigned long long";
+ QTest::newRow("long1") << "long unsigned int long" << "qulonglong";
QTest::newRow("long2") << "int signed long" << "long";
QTest::newRow("long3") << "long unsigned" << "ulong";
QTest::newRow("long double") << " long double" << "long double";
QTest::newRow("signed char") << "char signed" << "signed char";
- QTest::newRow("unsigned char") << "char unsigned" << "unsigned char";
+ QTest::newRow("unsigned char") << "char unsigned" << "uchar";
QTest::newRow("signed short") << "short signed" << "short";
- QTest::newRow("unsigned shot") << "short unsigned" << "unsigned short";
- QTest::newRow("unsigned shot") << "short unsigned" << "unsigned short";
+ QTest::newRow("unsigned short") << "unsigned short" << "ushort";
+ QTest::newRow("short unsigned") << "short unsigned" << "ushort";
QTest::newRow("array1") << "unsigned int [4]" << "uint[4]";
QTest::newRow("array2") << "unsigned int const [4][5]" << "const uint[4][5]";
QTest::newRow("array3") << "unsigned[] const" << "uint[]";
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index f116684f5b..caef716656 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -235,6 +235,7 @@ private slots:
void operatorEq();
void typesWithInaccessibleDTors();
void voidIsNotUnknown();
+ void typeNameNormalization();
};
struct BaseGenericType
@@ -2715,6 +2716,43 @@ void tst_QMetaType::voidIsNotUnknown()
QVERIFY(voidType != QMetaType(QMetaType::UnknownType));
}
+void tst_QMetaType::typeNameNormalization()
+{
+ // check the we normalize types the right way
+
+#define CHECK_TYPE_NORMALIZATION(Normalized, ...) \
+ do { \
+ /*QCOMPARE(QtPrivate::typenameHelper<Type>(), Normalized);*/ \
+ QByteArray typeName = QMetaObject::normalizedType(#__VA_ARGS__); \
+ QCOMPARE(typeName, Normalized); \
+ typeName = QMetaType::fromType<__VA_ARGS__>().name(); \
+ QCOMPARE(typeName, Normalized); \
+ } while (0)
+
+ CHECK_TYPE_NORMALIZATION("QList<QString*const>", QList<QString * const>);
+ CHECK_TYPE_NORMALIZATION("QList<const QString*>", QList<const QString * >);
+ CHECK_TYPE_NORMALIZATION("QList<const QString*const>", QList<const QString * const>);
+ CHECK_TYPE_NORMALIZATION("QList<const QString*>", QList<QString const *>);
+ CHECK_TYPE_NORMALIZATION("QList<signed char>", QList<signed char>);
+ CHECK_TYPE_NORMALIZATION("QList<uint>", QList<unsigned>);
+ CHECK_TYPE_NORMALIZATION("uint", uint);
+ CHECK_TYPE_NORMALIZATION("QList<QHash<uint,QString*>>", QList<QHash<unsigned, QString *>>);
+ CHECK_TYPE_NORMALIZATION("QList<qlonglong>", QList<qlonglong>);
+ CHECK_TYPE_NORMALIZATION("QList<qulonglong>", QList<qulonglong>);
+ CHECK_TYPE_NORMALIZATION("QList<qlonglong>", QList<long long>);
+ CHECK_TYPE_NORMALIZATION("QList<qulonglong>", QList<unsigned long long>);
+ CHECK_TYPE_NORMALIZATION("QList<qulonglong*>", QList<unsigned long long *>);
+ CHECK_TYPE_NORMALIZATION("QList<ulong>", QList<long unsigned >);
+#ifdef Q_CC_MSVC
+ CHECK_TYPE_NORMALIZATION("qulonglong", __int64 unsigned);
+#endif
+ CHECK_TYPE_NORMALIZATION("std::pair<const QString&&,short>", QPair<const QString &&, signed short>);
+
+ // The string based normalization doesn't handle aliases, QMetaType::fromType() does
+// CHECK_TYPE_NORMALIZATION("qulonglong", quint64);
+ QCOMPARE(QMetaType::fromType<quint64>().name(), "qulonglong");
+}
+
// Compile-time test, it should be possible to register function pointer types
class Undefined;
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp
index d3af266e74..d6eb76feb7 100644
--- a/tests/auto/tools/moc/tst_moc.cpp
+++ b/tests/auto/tools/moc/tst_moc.cpp
@@ -872,7 +872,9 @@ void tst_Moc::uLongLong()
QVERIFY(idx != -1);
idx = mobj->indexOfSlot("slotWithULongLong(unsigned long long)");
QVERIFY(idx != -1);
- idx = mobj->indexOfSlot("slotWithULongLongP(unsigned long long*)");
+ idx = mobj->indexOfSlot("slotWithULongLong(qulonglong)");
+ QVERIFY(idx != -1);
+ idx = mobj->indexOfSlot("slotWithULongLongP(qulonglong*)");
QVERIFY(idx != -1);
idx = mobj->indexOfSlot("slotWithLong(long)");