summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRobert Griebl <robert.griebl@pelagicore.com>2015-03-24 22:20:48 +0100
committerRobert Griebl <robert.griebl@pelagicore.com>2015-04-14 23:29:04 +0000
commit91dfab223a64385f6c0d010deafbdc8b2eb69968 (patch)
tree190035bce886a5754c9ac8b72b5612d28b1aac80 /tests
parent472216da2d3e88472df3594cbc9eccc6d6b1b44b (diff)
Add support for unregistering of custom meta types.
This patch addresses a specific Qml problem, where the meta types list will grow indefinitely when unloading and reloading Qml components over and over (in an failed effort to save memory). The implementation is not specific to Qml though, but will cater to all use-cases where registered types may not live until the application's termination. Change-Id: Ic0224dcd19aeb559715ef088b22a30509be2456b Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 88b1bebb29..b3333c6d68 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -1254,6 +1254,54 @@ void tst_QMetaType::registerType()
QCOMPARE(qRegisterMetaType<MyFoo>("MyFoo"), fooId);
QCOMPARE(QMetaType::type("MyFoo"), fooId);
+
+ // cannot unregister built-in types
+ QVERIFY(!QMetaType::unregisterType(QMetaType::QString));
+ QCOMPARE(QMetaType::type("QString"), int(QMetaType::QString));
+ QCOMPARE(QMetaType::type("MyString"), int(QMetaType::QString));
+
+ // cannot unregister declared types
+ QVERIFY(!QMetaType::unregisterType(fooId));
+ QCOMPARE(QMetaType::type("TestSpace::Foo"), fooId);
+ QCOMPARE(QMetaType::type("MyFoo"), fooId);
+
+ // test unregistration of dynamic types (used by Qml)
+ int unregId = QMetaType::registerType("UnregisterMe",
+ 0,
+ 0,
+ QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct,
+ QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct,
+ 0, QMetaType::TypeFlags(), 0);
+ QCOMPARE(QMetaType::registerTypedef("UnregisterMeTypedef", unregId), unregId);
+ int unregId2 = QMetaType::registerType("UnregisterMe2",
+ 0,
+ 0,
+ QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct,
+ QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct,
+ 0, QMetaType::TypeFlags(), 0);
+ QVERIFY(unregId >= int(QMetaType::User));
+ QCOMPARE(unregId2, unregId + 2);
+
+ QVERIFY(QMetaType::unregisterType(unregId));
+ QCOMPARE(QMetaType::type("UnregisterMe"), 0);
+ QCOMPARE(QMetaType::type("UnregisterMeTypedef"), 0);
+ QCOMPARE(QMetaType::type("UnregisterMe2"), unregId2);
+ QVERIFY(QMetaType::unregisterType(unregId2));
+ QCOMPARE(QMetaType::type("UnregisterMe2"), 0);
+
+ // re-registering should always return the lowest free index
+ QCOMPARE(QMetaType::registerType("UnregisterMe2",
+ 0,
+ 0,
+ QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct,
+ QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct,
+ 0, QMetaType::TypeFlags(), 0), unregId);
+ QCOMPARE(QMetaType::registerType("UnregisterMe",
+ 0,
+ 0,
+ QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Destruct,
+ QtMetaTypePrivate::QMetaTypeFunctionHelper<void>::Construct,
+ 0, QMetaType::TypeFlags(), 0), unregId + 1);
}
class IsRegisteredDummyType { };