Test that a signal is created for QML property when using QQmlComponent

This is the current behavior and it does not seem to be tested
Whoever decides to change the behavior should likely also update this
test then. For now, let's use it as a reference

Change-Id: Id6952238cae7548fba1f2d907f681ffb8f1e99c5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Andrei Golubev 2021-11-15 12:35:47 +01:00
parent 6ec7953257
commit aa23202c82
1 changed files with 18 additions and 0 deletions

View File

@ -43,6 +43,7 @@
#include <private/qv4scopedvalue_p.h>
#include <private/qv4qmlcontext_p.h>
#include <qcolor.h>
#include <qsignalspy.h>
#include <algorithm>
@ -155,6 +156,7 @@ private slots:
void createInsideJSModule();
void qmlErrorIsReported();
void initJSValueProp();
void qmlPropertySignalExists();
private:
QQmlEngine engine;
@ -1101,6 +1103,22 @@ void tst_qqmlcomponent::initJSValueProp()
QCOMPARE(jsValue.toInt(), 5);
}
void tst_qqmlcomponent::qmlPropertySignalExists()
{
QQmlEngine engine;
QQmlComponent component(&engine);
component.setData("import QtQml; QtObject { property int p: 41; function doStuff() { p++; } }",
QUrl());
QVERIFY2(component.isReady(), qPrintable(component.errorString()));
QScopedPointer<QObject> o(component.create());
QVERIFY(!o.isNull());
QSignalSpy changeSignalSpy(o.get(), SIGNAL(pChanged()));
QVERIFY(QMetaObject::invokeMethod(o.get(), "doStuff"));
QCOMPARE(changeSignalSpy.count(), 1);
QCOMPARE(o->property("p").toInt(), 42);
}
QTEST_MAIN(tst_qqmlcomponent)
#include "tst_qqmlcomponent.moc"