aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlpropertycache
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlpropertycache')
-rw-r--r--tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml11
-rw-r--r--tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro4
-rw-r--r--tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp69
3 files changed, 83 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml b/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml
new file mode 100644
index 0000000000..7ceb231c8d
--- /dev/null
+++ b/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml
@@ -0,0 +1,11 @@
+import QtQml 2.2
+import example 1.0
+
+QtObject {
+ Component.onCompleted: {
+ var opt1 = MyEnum.Option1A | MyEnum.Option1D // 0x09
+ mydata.opt1 = opt1;
+ mydata.setOpt1(opt1);
+ mydata.setOption1(opt1);
+ }
+}
diff --git a/tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro b/tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro
index 9a04c899fe..26d41bbdbf 100644
--- a/tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro
+++ b/tests/auto/qml/qqmlpropertycache/qqmlpropertycache.pro
@@ -4,4 +4,8 @@ macx:CONFIG -= app_bundle
SOURCES += tst_qqmlpropertycache.cpp
+include (../../shared/util.pri)
+
+TESTDATA = data/*
+
QT += core-private gui-private qml-private testlib
diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
index 29f70c4e46..1c8e3c50ab 100644
--- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
+++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp
@@ -29,12 +29,14 @@
#include <qtest.h>
#include <private/qqmlpropertycache_p.h>
#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQml/qqmlcomponent.h>
#include <private/qv8engine_p.h>
#include <private/qmetaobjectbuilder_p.h>
#include <QCryptographicHash>
#include "../../shared/util.h"
-class tst_qqmlpropertycache : public QObject
+class tst_qqmlpropertycache : public QQmlDataTest
{
Q_OBJECT
public:
@@ -47,6 +49,7 @@ private slots:
void methodsDerived();
void signalHandlers();
void signalHandlersDerived();
+ void passForeignEnums();
void metaObjectSize_data();
void metaObjectSize();
void metaObjectChecksum();
@@ -271,6 +274,70 @@ void tst_qqmlpropertycache::signalHandlersDerived()
QCOMPARE(data->coreIndex(), metaObject->indexOfMethod("propertyDChanged()"));
}
+class MyEnum : public QObject
+ {
+ Q_OBJECT
+ public:
+ enum Option1Flag {
+ Option10 = 0,
+ Option1A = 1,
+ Option1B = 2,
+ Option1C = 4,
+ Option1D = 8,
+ Option1E = 16,
+ Option1F = 32,
+ Option1AD = Option1A | Option1D,
+ };
+ Q_DECLARE_FLAGS(Option1, Option1Flag)
+ Q_FLAG(Option1)
+};
+
+class MyData : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(MyEnum::Option1 opt1 READ opt1 WRITE setOpt1 NOTIFY opt1Changed)
+public:
+ MyEnum::Option1 opt1() const { return m_opt1; }
+
+signals:
+ void opt1Changed(MyEnum::Option1 opt1);
+
+public slots:
+ void setOpt1(MyEnum::Option1 opt1)
+ {
+ QCOMPARE(opt1, MyEnum::Option1AD);
+ if (opt1 != m_opt1) {
+ m_opt1 = opt1;
+ emit opt1Changed(opt1);
+ }
+ }
+
+ void setOption1(MyEnum::Option1 opt1) { setOpt1(opt1); }
+
+private:
+ MyEnum::Option1 m_opt1 = MyEnum::Option10;
+};
+
+void tst_qqmlpropertycache::passForeignEnums()
+{
+ qmlRegisterType<MyEnum>("example", 1, 0, "MyEnum");
+ qmlRegisterType<MyData>("example", 1, 0, "MyData");
+
+ MyEnum myenum;
+ MyData data;
+
+ engine.rootContext()->setContextProperty("myenum", &myenum);
+ engine.rootContext()->setContextProperty("mydata", &data);
+
+ QQmlComponent component(&engine, testFile("foreignEnums.qml"));
+ QVERIFY(component.isReady());
+
+ QObject *obj = component.create(engine.rootContext());
+ QCOMPARE(data.opt1(), MyEnum::Option1AD);
+}
+
+Q_DECLARE_METATYPE(MyEnum::Option1)
+
class TestClass : public QObject
{
Q_OBJECT