Further stabilize tst_qqmlengine

Not only the C++ singletons but also the JS singletons can be created in
the same memory locations.

Amends commit e1614a41c8.

Change-Id: I9e68bfdaa52bc7c39ec16157db908b1e4fcbe3f0
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
This commit is contained in:
Ulf Hermann 2021-09-22 10:00:44 +02:00
parent abd488dd3d
commit c300a170ed
1 changed files with 8 additions and 2 deletions

View File

@ -134,7 +134,10 @@ uint CppSingleton::instantiations = 0;
class JsSingleton : public QObject {
Q_OBJECT
public:
JsSingleton() {}
static uint instantiations;
uint id = 0;
JsSingleton() : id(++instantiations) {}
static QJSValue create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
{
@ -144,6 +147,8 @@ public:
}
};
uint JsSingleton::instantiations = 0;
void tst_qqmlengine::initTestCase()
{
QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString()));
@ -586,6 +591,7 @@ void tst_qqmlengine::clearSingletons()
QCOMPARE(engine.singletonInstance<QJSValue>(jsValue).toUInt(), 13u);
const JsSingleton *oldJsSingleton = engine.singletonInstance<JsSingleton *>(jsObject);
QVERIFY(oldJsSingleton != nullptr);
const uint oldJsSingletonId = oldJsSingleton->id;
const QObject *oldQmlSingleton = engine.singletonInstance<QObject *>(qmlObject);
QVERIFY(oldQmlSingleton != nullptr);
@ -636,7 +642,7 @@ void tst_qqmlengine::clearSingletons()
QCOMPARE(engine.singletonInstance<QJSValue>(jsValue).toUInt(), 13u);
const JsSingleton *newJsSingleton = engine.singletonInstance<JsSingleton *>(jsObject);
QVERIFY(newJsSingleton != nullptr);
QVERIFY(newJsSingleton != oldJsSingleton);
QVERIFY(newJsSingleton->id != oldJsSingletonId);
const QObject *newQmlSingleton = engine.singletonInstance<QObject *>(qmlObject);
QVERIFY(newQmlSingleton != nullptr);
QVERIFY(newQmlSingleton != oldQmlSingleton);