diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-07-14 10:19:16 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-07-16 16:25:23 +0200 |
commit | c0f4442ae0d83e63fc90f1d5058081355f83b701 (patch) | |
tree | 49808334a7e6afb02b4a25259db4a3f1af02b83d /tests/auto/qml/qqmlpropertycache | |
parent | f5ef090960f82f53318ca0fd15331bb7ef394366 (diff) |
Restrict qmlRegisterTypesAndRevisions to major version given
We should not register any revisions larger than the given major version
as that allows importing an incomplete module, as the version-less
import. Typically the offending version is pulled in via some
QML_FOREIGN and only the types derived from that foreign class are
available in the higher major version.
Change-Id: I186fb010d704bea514cefff9f66eb58186df5c91
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlpropertycache')
-rw-r--r-- | tests/auto/qml/qqmlpropertycache/data/highVersion.qml | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp | 26 |
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlpropertycache/data/highVersion.qml b/tests/auto/qml/qqmlpropertycache/data/highVersion.qml new file mode 100644 index 0000000000..9e52cd725c --- /dev/null +++ b/tests/auto/qml/qqmlpropertycache/data/highVersion.qml @@ -0,0 +1,4 @@ +import Test.PropertyCache 4.0 +BaseObject { + highVersion: 200 +} diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp index e885a26057..f00525a37c 100644 --- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp +++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp @@ -57,6 +57,7 @@ private slots: void metaObjectChecksum(); void metaObjectsForRootElements(); void derivedGadgetMethod(); + void restrictRegistrationVersion(); private: QQmlEngine engine; @@ -126,21 +127,38 @@ private: class BaseObject : public QObject { Q_OBJECT + QML_ELEMENT Q_PROPERTY(int propertyA READ propertyA NOTIFY propertyAChanged) Q_PROPERTY(QString propertyB READ propertyB NOTIFY propertyBChanged) + Q_PROPERTY(int highVersion READ highVersion WRITE setHighVersion NOTIFY highVersionChanged REVISION(4, 0)) + public: BaseObject(QObject *parent = nullptr) : QObject(parent) {} int propertyA() const { return 0; } QString propertyB() const { return QString(); } + int highVersion() const { return m_highVersion; } public Q_SLOTS: void slotA() {} + void setHighVersion(int highVersion) + { + if (m_highVersion == highVersion) + return; + + m_highVersion = highVersion; + emit highVersionChanged(); + } + Q_SIGNALS: void propertyAChanged(); void propertyBChanged(); void signalA(); + void highVersionChanged(); + +private: + int m_highVersion = 0; }; class DerivedObject : public BaseObject @@ -648,4 +666,12 @@ void tst_qqmlpropertycache::derivedGadgetMethod() QCOMPARE(gadgetUser->derivedString(), QString::fromLatin1("derived")); } +void tst_qqmlpropertycache::restrictRegistrationVersion() +{ + qmlRegisterTypesAndRevisions<BaseObject>("Test.PropertyCache", 3); + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("highVersion.qml")); + QVERIFY(c.isError()); +} + QTEST_MAIN(tst_qqmlpropertycache) |