diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2016-06-16 12:46:42 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2016-07-13 14:35:31 +0000 |
commit | e35346cf70598c47a456946327927643910aa277 (patch) | |
tree | 773bae4e840087b7235ceac3e5cf53bdb7c6bc72 /tests | |
parent | d3c594c382761241742cd6713f249abeb538ffaa (diff) | |
download | qtwebchannel-e35346cf70598c47a456946327927643910aa277.tar.gz |
Add test to verify that bools get properly converted.
This test passes and seems to indicate that the signal-delivery has
an issue, or that the issue lies on the JavaScript side.
Change-Id: Ic2436147b3af49d35dc556da57aed3e54408f1f9
Task-number: QTBUG-54074
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.cpp | 28 | ||||
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.h | 5 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index 7ae6f78..71779b9 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -192,6 +192,7 @@ TestWebChannel::TestWebChannel(QObject *parent) : QObject(parent) , m_dummyTransport(new DummyTransport(this)) , m_lastInt(0) + , m_lastBool(false) , m_lastDouble(0) { } @@ -200,6 +201,7 @@ TestWebChannel::~TestWebChannel() { } + int TestWebChannel::readInt() const { return m_lastInt; @@ -211,6 +213,17 @@ void TestWebChannel::setInt(int i) emit lastIntChanged(); } +bool TestWebChannel::readBool() const +{ + return m_lastBool; +} + +void TestWebChannel::setBool(bool b) +{ + m_lastBool = b; + emit lastBoolChanged(); +} + double TestWebChannel::readDouble() const { return m_lastDouble; @@ -484,6 +497,14 @@ void TestWebChannel::testInvokeMethodConversion() QCOMPARE(m_lastInt, args.at(0).toInt()); } { + int method = metaObject()->indexOfMethod("setBool(bool)"); + QVERIFY(method != -1); + QJsonArray args; + args.append(QJsonValue(!m_lastBool)); + channel.d_func()->publisher->invokeMethod(this, method, args); + QCOMPARE(m_lastBool, args.at(0).toBool()); + } + { int method = metaObject()->indexOfMethod("setDouble(double)"); QVERIFY(method != -1); channel.d_func()->publisher->invokeMethod(this, method, args); @@ -535,6 +556,13 @@ void TestWebChannel::testSetPropertyConversion() QCOMPARE(m_lastInt, 42); } { + int property = metaObject()->indexOfProperty("lastBool"); + QVERIFY(property != -1); + bool newValue = !m_lastBool; + channel.d_func()->publisher->setProperty(this, property, QJsonValue(newValue)); + QCOMPARE(m_lastBool, newValue); + } + { int property = metaObject()->indexOfProperty("lastDouble"); QVERIFY(property != -1); channel.d_func()->publisher->setProperty(this, property, QJsonValue(-4.2)); diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h index 5a9fa11..3469d41 100644 --- a/tests/auto/webchannel/tst_webchannel.h +++ b/tests/auto/webchannel/tst_webchannel.h @@ -241,6 +241,7 @@ class TestWebChannel : public QObject Q_OBJECT Q_PROPERTY(int lastInt READ readInt WRITE setInt NOTIFY lastIntChanged); + Q_PROPERTY(bool lastBool READ readBool WRITE setBool NOTIFY lastBoolChanged); Q_PROPERTY(double lastDouble READ readDouble WRITE setDouble NOTIFY lastDoubleChanged); Q_PROPERTY(QVariant lastVariant READ readVariant WRITE setVariant NOTIFY lastVariantChanged); Q_PROPERTY(QJsonValue lastJsonValue READ readJsonValue WRITE setJsonValue NOTIFY lastJsonValueChanged); @@ -252,6 +253,8 @@ public: int readInt() const; Q_INVOKABLE void setInt(int i); + bool readBool() const; + Q_INVOKABLE void setBool(bool b); double readDouble() const; Q_INVOKABLE void setDouble(double d); QVariant readVariant() const; @@ -265,6 +268,7 @@ public: signals: void lastIntChanged(); + void lastBoolChanged(); void lastDoubleChanged(); void lastVariantChanged(); void lastJsonValueChanged(); @@ -293,6 +297,7 @@ private: DummyTransport *m_dummyTransport; int m_lastInt; + bool m_lastBool; double m_lastDouble; QVariant m_lastVariant; QJsonValue m_lastJsonValue; |