aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp')
-rw-r--r--tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
index cfea7c0da1..589f95a3de 100644
--- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
+++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
@@ -8,6 +8,7 @@
#include <QtQml/qqmlcomponent.h>
#include <private/qmetaobjectbuilder_p.h>
#include <private/qqmlcontextdata_p.h>
+#include <private/qqmlpropertycachecreator_p.h>
#include <QCryptographicHash>
#include <QtQuickTestUtils/private/qmlutils_p.h>
@@ -34,6 +35,7 @@ private slots:
void derivedGadgetMethod();
void restrictRegistrationVersion();
void rejectOverriddenFinal();
+ void overriddenSignals();
private:
QQmlEngine engine;
@@ -164,6 +166,19 @@ Q_SIGNALS:
void signalB();
};
+class OverriddenSignal : public BaseObject
+{
+ Q_OBJECT
+public:
+ OverriddenSignal(QObject *parent = nullptr) : BaseObject(parent) {}
+
+ Q_INVOKABLE void propertyAChanged() { ++propertyAChangedCalled; }
+ int propertyAChangedCalled = 0;
+
+Q_SIGNALS:
+ void signalA();
+};
+
const QQmlPropertyData *cacheProperty(const QQmlPropertyCache::ConstPtr &cache, const char *name)
{
return cache->property(QLatin1String(name), nullptr, nullptr);
@@ -707,4 +722,56 @@ void tst_qqmlpropertycache::rejectOverriddenFinal()
QCOMPARE(o->property("c").toInt(), 0);
}
+void tst_qqmlpropertycache::overriddenSignals()
+{
+ qmlRegisterTypesAndRevisions<BaseObject>("Test.PropertyCache", 3);
+ QQmlEngine engine;
+
+ QQmlComponent c1(&engine, testFileUrl("overriddenSignal.qml"));
+ QVERIFY2(!c1.isError(), qPrintable(c1.errorString()));
+
+ QScopedPointer<QObject> o(c1.create());
+
+ // the propertyAChanged _signal_ is sent once (initially).
+ QCOMPARE(o->property("a").toInt(), 1);
+
+ // signalA() is invoked once as signal, and the other time as method since both are C++.
+ QCOMPARE(o->property("b").toInt(), 1);
+
+ OverriddenSignal *derived = new OverriddenSignal(o.data());
+
+ // Does call our overridden method, since that is defined in C++
+ QCOMPARE(derived->propertyAChangedCalled, 0);
+ o->setProperty("obj", QVariant::fromValue(derived));
+ QCOMPARE(derived->propertyAChangedCalled, 1);
+
+ o->setProperty("obj2", QVariant::fromValue(derived));
+
+ // the propertyAChanged _signal_ is sent once (initially).
+ QCOMPARE(o->property("a").toInt(), 1);
+
+ // We get to receive both signalA() signals since we only match by name.
+ QCOMPARE(o->property("b").toInt(), 2);
+
+ // We shouldn't be allowed to define such things in QML, though.
+
+ const QUrl c2Url = testFileUrl("qmlOverriddenSignal.qml");
+ QTest::ignoreMessage(
+ QtWarningMsg,
+ qPrintable(c2Url.toString() + QLatin1String(
+ ":6:14: Duplicate method name: "
+ "invalid override of property change signal or superclass signal")));
+ QQmlComponent c2(&engine, c2Url);
+ // Should be an error, but we can't enforce it yet.
+
+ const QUrl c3Url = testFileUrl("qmlOverriddenSignal2.qml");
+ QTest::ignoreMessage(
+ QtWarningMsg,
+ qPrintable(c3Url.toString() + QLatin1String(
+ ":5:12: Duplicate signal name: "
+ "invalid override of property change signal or superclass signal")));
+ QQmlComponent c3(&engine, c3Url);
+ // Should be an error, but we can't enforce it yet.
+}
+
QTEST_MAIN(tst_qqmlpropertycache)