diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-01-03 13:30:19 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-01-03 13:59:55 +0000 |
commit | 29c7a1d566f9bbdcf3cadc270f4481e05a71eefb (patch) | |
tree | e7d39cdb08333416879eadf28e6f5c47e966260f /tests/auto/qml/qqmlpropertycache | |
parent | dca7fc3e3a0fe428ed97762a44c15e83607e6d28 (diff) |
QQmlPropertyCache: Add test that reads and writes short enums
This is to guard against any problems from casting those to int and
back.
Change-Id: I740a5250158ce47195ab04d42d967ff9c82bf9bd
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlpropertycache')
-rw-r--r-- | tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp | 26 |
2 files changed, 31 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml b/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml index 7ceb231c8d..b7492e507e 100644 --- a/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml +++ b/tests/auto/qml/qqmlpropertycache/data/foreignEnums.qml @@ -7,5 +7,11 @@ QtObject { mydata.opt1 = opt1; mydata.setOpt1(opt1); mydata.setOption1(opt1); + + var opt2 = mydata.opt2; + opt2 = (opt2 === MyEnum.Short8 ? MyEnum.Short16 : MyEnum.Short0); + mydata.opt2 = opt2; + mydata.setOpt2(opt2); + mydata.setOption2(opt2); } } diff --git a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp index 1c8e3c50ab..5abda7b854 100644 --- a/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp +++ b/tests/auto/qml/qqmlpropertycache/tst_qqmlpropertycache.cpp @@ -290,17 +290,27 @@ class MyEnum : public QObject }; Q_DECLARE_FLAGS(Option1, Option1Flag) Q_FLAG(Option1) + + enum ShortEnum: quint16 { + Short0 = 0, + Short8 = 0xff, + Short16 = 0xffff + }; + Q_ENUM(ShortEnum); }; class MyData : public QObject { Q_OBJECT Q_PROPERTY(MyEnum::Option1 opt1 READ opt1 WRITE setOpt1 NOTIFY opt1Changed) + Q_PROPERTY(MyEnum::ShortEnum opt2 READ opt2 WRITE setOpt2 NOTIFY opt2Changed) public: MyEnum::Option1 opt1() const { return m_opt1; } + MyEnum::ShortEnum opt2() const { return m_opt2; } signals: void opt1Changed(MyEnum::Option1 opt1); + void opt2Changed(MyEnum::ShortEnum opt2); public slots: void setOpt1(MyEnum::Option1 opt1) @@ -312,10 +322,21 @@ public slots: } } + void setOpt2(MyEnum::ShortEnum opt2) + { + QCOMPARE(opt2, MyEnum::Short16); + if (opt2 != m_opt2) { + m_opt2 = opt2; + emit opt2Changed(opt2); + } + } + void setOption1(MyEnum::Option1 opt1) { setOpt1(opt1); } + void setOption2(MyEnum::ShortEnum opt2) { setOpt2(opt2); } private: MyEnum::Option1 m_opt1 = MyEnum::Option10; + MyEnum::ShortEnum m_opt2 = MyEnum::Short8; }; void tst_qqmlpropertycache::passForeignEnums() @@ -332,11 +353,14 @@ void tst_qqmlpropertycache::passForeignEnums() QQmlComponent component(&engine, testFile("foreignEnums.qml")); QVERIFY(component.isReady()); - QObject *obj = component.create(engine.rootContext()); + QScopedPointer<QObject> obj(component.create(engine.rootContext())); + QVERIFY(!obj.isNull()); QCOMPARE(data.opt1(), MyEnum::Option1AD); + QCOMPARE(data.opt2(), MyEnum::Short16); } Q_DECLARE_METATYPE(MyEnum::Option1) +Q_DECLARE_METATYPE(MyEnum::ShortEnum) class TestClass : public QObject { |