summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2018-09-06 11:47:14 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2018-09-14 13:01:46 +0000
commitd87d7161a9267c33990a8fb172310e4ade291c13 (patch)
treee8ece1e05cdd00ab5ab4054d17e63276041e202c /tests
parente54f439758007f2212442a90a3c44333b5a60268 (diff)
downloadqtivi-d87d7161a9267c33990a8fb172310e4ade291c13.tar.gz
Make it possible to set the result for QIviPendingReply<void> from QML
The type check prevented this before. Now the type is ignored for QIviPendingReply<void> when used from QML. Change-Id: Iabdea29ba8d7af28f1b3e273260f0af013609253 Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/qivipendingreply/qivipendingreply.pro2
-rw-r--r--tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp36
2 files changed, 37 insertions, 1 deletions
diff --git a/tests/auto/core/qivipendingreply/qivipendingreply.pro b/tests/auto/core/qivipendingreply/qivipendingreply.pro
index bc9eea9..36e0a42 100644
--- a/tests/auto/core/qivipendingreply/qivipendingreply.pro
+++ b/tests/auto/core/qivipendingreply/qivipendingreply.pro
@@ -1,6 +1,6 @@
QT += testlib ivicore qml
-TARGET = tst_qiviasyncreply
+TARGET = tst_qivipendingreply
QMAKE_PROJECT_NAME = $$TARGET
CONFIG += testcase
diff --git a/tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp b/tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp
index 31bbcda..a3e36c6 100644
--- a/tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp
+++ b/tests/auto/core/qivipendingreply/tst_qivipendingreply.cpp
@@ -142,6 +142,7 @@ private Q_SLOTS:
void initTestCase();
void testSuccess();
void testSuccess_qml();
+ void testSuccessFromQml();
void testConversion_qml();
void testFailed();
void testFailed_qml();
@@ -331,6 +332,41 @@ void tst_QIviPendingReply::testSuccess_qml()
testQml<TestGadget>(&testObject, "test_TestGadget(testObject.createGadget('FOO', 5))", false, TestGadget("FOO", 5));
}
+void tst_QIviPendingReply::testSuccessFromQml()
+{
+ // Instead of using the PendingReply in QML and react on the result using then()
+ // we test here to set the result using the setSuccess function
+
+ QIviPendingReply<void> voidReply;
+ QIviPendingReply<int> intReply;
+
+ QVERIFY(!voidReply.isResultAvailable());
+ QVERIFY(!intReply.isResultAvailable());
+
+ QQmlEngine engine;
+ engine.rootContext()->setContextProperty("voidReply", QVariant::fromValue(QIviPendingReplyBase(voidReply)));
+ engine.rootContext()->setContextProperty("intReply", QVariant::fromValue(QIviPendingReplyBase(intReply)));
+
+ QByteArray qml ("import QtQuick 2.0; \n\
+ QtObject { \n\
+ Component.onCompleted: { \n\
+ voidReply.setSuccess(true) \n\
+ intReply.setSuccess(5) \n\
+ }\n\
+ }");
+ QQmlComponent component(&engine);
+ component.setData(qml, QUrl());
+ QScopedPointer<QObject> obj(component.create());
+ QVERIFY2(obj, qPrintable(component.errorString()));
+
+ QVERIFY(voidReply.isResultAvailable());
+ QVERIFY(voidReply.isSuccessful());
+
+ QVERIFY(intReply.isResultAvailable());
+ QVERIFY(intReply.isSuccessful());
+ QCOMPARE(intReply.value(), 5);
+}
+
void tst_QIviPendingReply::testConversion_qml()
{
TestObject testObject;