summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-04-26 14:40:48 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-18 15:22:22 +0200
commit1c7421ad14f9321422cdfeede3902552a34ccf3b (patch)
tree1f157269aca954b8852cf036047a90f8fd26ff9b /tests
parentbdc28e35806d93b259830f8b3fecdf60761c62d0 (diff)
Add test of automated container metatype declaration.
Change-Id: Iddaf444ead6d9f0147b9b11452ccea46aa712ba3 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index e09517678e..c3e2bd299d 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -1331,6 +1331,110 @@ void tst_QMetaType::automaticTemplateRegistration()
typedef QList<UnregisteredType> UnregisteredTypeList;
QVERIFY(qRegisterMetaType<UnregisteredTypeList>("UnregisteredTypeList") > 0);
}
+
+#ifdef Q_COMPILER_VARIADIC_MACROS
+
+ #define FOR_EACH_STATIC_PRIMITIVE_TYPE(F, ...) \
+ F(bool, __VA_ARGS__) \
+ F(int, __VA_ARGS__) \
+ F(uint, __VA_ARGS__) \
+ F(qlonglong, __VA_ARGS__) \
+ F(qulonglong, __VA_ARGS__) \
+ F(double, __VA_ARGS__) \
+ F(long, __VA_ARGS__) \
+ F(short, __VA_ARGS__) \
+ F(char, __VA_ARGS__) \
+ F(ulong, __VA_ARGS__) \
+ F(ushort, __VA_ARGS__) \
+ F(uchar, __VA_ARGS__) \
+ F(float, __VA_ARGS__) \
+ F(QObject*, __VA_ARGS__) \
+ F(QString, __VA_ARGS__) \
+ F(CustomMovable, __VA_ARGS__)
+
+ #define FOR_EACH_STATIC_PRIMITIVE_TYPE2(F, ...) \
+ F(bool, __VA_ARGS__) \
+ F(int, __VA_ARGS__) \
+ F(uint, __VA_ARGS__) \
+ F(qlonglong, __VA_ARGS__) \
+ F(qulonglong, __VA_ARGS__) \
+ F(double, __VA_ARGS__) \
+ F(long, __VA_ARGS__) \
+ F(short, __VA_ARGS__) \
+ F(char, __VA_ARGS__) \
+ F(ulong, __VA_ARGS__) \
+ F(ushort, __VA_ARGS__) \
+ F(uchar, __VA_ARGS__) \
+ F(float, __VA_ARGS__) \
+ F(QObject*, __VA_ARGS__) \
+ F(QString, __VA_ARGS__) \
+ F(CustomMovable, __VA_ARGS__)
+
+
+ #define CREATE_AND_VERIFY_CONTAINER(CONTAINER, ...) \
+ { \
+ CONTAINER< __VA_ARGS__ > t; \
+ const QVariant v = QVariant::fromValue(t); \
+ QByteArray tn = #CONTAINER + QByteArray("<"); \
+ const QList<QByteArray> args = QByteArray(#__VA_ARGS__).split(','); \
+ tn += args.first().trimmed(); \
+ if (args.size() > 1) { \
+ QList<QByteArray>::const_iterator it = args.constBegin() + 1; \
+ const QList<QByteArray>::const_iterator end = args.constEnd(); \
+ for (; it != end; ++it) { \
+ tn += ","; \
+ tn += it->trimmed(); \
+ } \
+ } \
+ tn += ">"; \
+ const int type = QMetaType::type(tn); \
+ const int expectedType = ::qMetaTypeId<CONTAINER< __VA_ARGS__ > >(); \
+ QCOMPARE(type, expectedType); \
+ }
+
+ #define FOR_EACH_1ARG_TEMPLATE_TYPE(F, TYPE) \
+ F(QList, TYPE) \
+ F(QVector, TYPE) \
+ F(QLinkedList, TYPE) \
+ F(QVector, TYPE) \
+ F(QVector, TYPE) \
+ F(QQueue, TYPE) \
+ F(QStack, TYPE) \
+ F(QSet, TYPE) \
+ F(QSharedPointer, TYPE)
+
+ #define PRINT_1ARG_TEMPLATE(RealName, ...) \
+ FOR_EACH_1ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, RealName)
+
+ #define FOR_EACH_2ARG_TEMPLATE_TYPE(F, RealName, ...) \
+ F(QHash, __VA_ARGS__) \
+ F(QMap, __VA_ARGS__) \
+ F(QPair, __VA_ARGS__)
+
+ #define PRINT_2ARG_TEMPLATE_INTERNAL(RealName, ...) \
+ FOR_EACH_2ARG_TEMPLATE_TYPE(CREATE_AND_VERIFY_CONTAINER, 0, RealName, __VA_ARGS__)
+
+ #define PRINT_2ARG_TEMPLATE(RealName, ...) \
+ FOR_EACH_STATIC_PRIMITIVE_TYPE2(PRINT_2ARG_TEMPLATE_INTERNAL, RealName)
+
+ #define REGISTER_TYPEDEF(TYPE, ARG1, ARG2) \
+ qRegisterMetaType<TYPE <ARG1, ARG2> >(#TYPE "<" #ARG1 "," #ARG2 ">");
+
+ REGISTER_TYPEDEF(QHash, int, uint)
+ REGISTER_TYPEDEF(QMap, int, uint)
+ REGISTER_TYPEDEF(QPair, int, uint)
+
+ FOR_EACH_STATIC_PRIMITIVE_TYPE(
+ PRINT_1ARG_TEMPLATE
+ )
+ FOR_EACH_STATIC_PRIMITIVE_TYPE(
+ PRINT_2ARG_TEMPLATE
+ )
+
+ CREATE_AND_VERIFY_CONTAINER(QList, QList<QMap<int, QHash<char, QVariantList> > >)
+
+#endif // Q_COMPILER_VARIADIC_MACROS
+
}
template <typename T>