summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntti Hölttä <AHoelttae@luxoft.com>2018-03-14 10:55:55 +0100
committerDominik Holland <dominik.holland@pelagicore.com>2018-03-15 10:52:54 +0000
commit7c70805cfde54d840b39bdfeb1d02e95a3c84d5b (patch)
tree4f60c037fa5cff5687ff0f81f200e548d082d5b4
parent45b8001bc1e656bf2e6248d7706670de5f565ac9 (diff)
downloadqtivi-7c70805cfde54d840b39bdfeb1d02e95a3c84d5b.tar.gz
Fix the custom signals and slots in qtro templates
Fix the custom slot implememtation in qtro templates. Calling a slot on a remote object replica causes an asynchronous call and returns a pending result object. The current backend slot implementation merely waits for the call to finish before returning to the code that uses it. This behavior will change when all method calls are made asynchronous. Also add tests for passing a remote objects initial values to newly connected clients. Change-Id: I278bfc583a657e8a30265af8ec6c02e178f0f245 Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
-rw-r--r--.gitignore1
-rw-r--r--src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl11
-rw-r--r--tests/auto/core/ivigenerator/org.example.echo.qface2
-rw-r--r--tests/auto/core/ivigenerator/org.example.echo.qtro.qface12
-rw-r--r--tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp35
-rw-r--r--tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h18
-rw-r--r--tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp5
-rw-r--r--tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h2
-rw-r--r--tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp178
-rw-r--r--tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h5
10 files changed, 242 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index 70c9427..ee83038 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@ ui_*
*.version*
.qmake.*
!.qmake.conf
+*.qmlc
# Test generated files
tst_*
diff --git a/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl b/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl
index 12d6e94..a30437b 100644
--- a/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl
+++ b/src/tools/ivigenerator/templates_backend_qtro/backend.cpp.tpl
@@ -103,9 +103,18 @@ void {{class}}::set{{property|upperfirst}}({{ property|parameter_type }})
{% set operation_parameters = operation.parameters|map('parameter_type')|join(', ') %}
{{operation|return_type}} {{class}}::{{operation}}({{operation_parameters}}){%if operation.const %} const{% endif %}
{
- m_replica->{{operation}}({{operation.parameters|join(', ')}});
+{% if not operation.type.is_void %}
+ QRemoteObjectPendingReply<{{operation|return_type}}> reply;
+ reply = m_replica->{{operation}}({{operation.parameters|join(', ')}});
+ if (reply.waitForFinished())
+ return reply.returnValue();
+ qDebug() << "{{class}}, remote call of method {{operation}} failed";
return {{operation|default_value}};
+{% else %}
+ m_replica->{{operation}}({{operation.parameters|join(', ')}});
+{% endif %}
}
+
{% endfor %}
void {{class}}::setupConnections()
diff --git a/tests/auto/core/ivigenerator/org.example.echo.qface b/tests/auto/core/ivigenerator/org.example.echo.qface
index 743d521..e1bf983 100644
--- a/tests/auto/core/ivigenerator/org.example.echo.qface
+++ b/tests/auto/core/ivigenerator/org.example.echo.qface
@@ -37,6 +37,8 @@ interface Echo {
string echo(string msg);
string id() const;
Combo getCombo();
+ void voidSlot();
+ void voidSlot2(int param);
signal anotherChanged(AnotherStruct another);
signal foobar(string foo);
signal somethingHappened();
diff --git a/tests/auto/core/ivigenerator/org.example.echo.qtro.qface b/tests/auto/core/ivigenerator/org.example.echo.qtro.qface
index af7be12..d9a446a 100644
--- a/tests/auto/core/ivigenerator/org.example.echo.qtro.qface
+++ b/tests/auto/core/ivigenerator/org.example.echo.qtro.qface
@@ -33,10 +33,18 @@ interface Echo {
list<Contact> contactList;
Contact contact;
WeekDay weekDay;
+
+ string echo(string msg);
+ string id() const;
+ Combo getCombo();
+ void voidSlot();
+ void voidSlot2(int param);
+ signal anotherChanged(AnotherStruct another);
+ signal foobar(string foo);
+ signal somethingHappened();
}
-@config: { type: "DaysOfTheWeek" }
-flag WeekDay {
+enum WeekDay {
Monday = 1,
Tuesday = 2,
Wednesday = 3,
diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp
index d8bbf82..0751330 100644
--- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp
+++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.cpp
@@ -29,6 +29,41 @@
#include "echoservice.h"
EchoService::EchoService()
+ :m_testCombo(Contact("Antti", 34, true), EchoModule::Friday),
+ m_testId("id123")
{
}
+
+void EchoService::setLastMessage(QString lastMessage)
+{
+ EchoSimpleSource::setLastMessage(lastMessage);
+}
+
+QString EchoService::echo(const QString &msg)
+{
+ emit echoSlotCalled(msg);
+ return msg;
+}
+
+QString EchoService::id()
+{
+ emit idSlotCalled();
+ return m_testId;
+}
+
+Combo EchoService::getCombo()
+{
+ emit getComboSlotCalled();
+ return m_testCombo;
+}
+
+void EchoService::voidSlot()
+{
+ emit voidSlotCalled();
+}
+
+void EchoService::voidSlot2(int param)
+{
+ emit voidSlot2Called(param);
+}
diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h
index f3f1268..a6dc32e 100644
--- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h
+++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/echoservice.h
@@ -38,6 +38,24 @@ class EchoService: public EchoSimpleSource
public:
EchoService();
+ Combo m_testCombo;
+ QString m_testId;
+
+ virtual void setLastMessage(QString lastMessage) override;
+
+public Q_SLOTS:
+ virtual QString echo(const QString &msg) override;
+ virtual QString id() override;
+ virtual Combo getCombo() override;
+ virtual void voidSlot();
+ virtual void voidSlot2(int param);
+
+Q_SIGNALS:
+ void echoSlotCalled(const QString &msg);
+ void idSlotCalled();
+ void getComboSlotCalled();
+ void voidSlotCalled();
+ void voidSlot2Called(int param);
};
#endif // ECHOSERVICE_H
diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp
index e18ad2d..eac8f57 100644
--- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp
+++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.cpp
@@ -33,3 +33,8 @@ bool Server::start()
{
return Core::instance()->host()->enableRemoting(&m_service, "org.example.echo.Echo");
}
+
+Server::~Server()
+{
+ qWarning() << "disableRemoting, returned=" << Core::instance()->host()->disableRemoting(&m_service);
+}
diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h
index 9168ee6..da18928 100644
--- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h
+++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/server.h
@@ -41,6 +41,8 @@ public Q_SLOTS:
public:
EchoService m_service;
+ ~Server();
+
};
#endif // SERVER_H
diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp
index 0a2eaa6..9c61799 100644
--- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp
+++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.cpp
@@ -41,10 +41,21 @@ void EchoQtroTest::cleanup()
{
}
-void EchoQtroTest::testInitServer()
+void EchoQtroTest::testInit()
{
+ Echo client;
+ QVERIFY(client.startAutoDiscovery()==QIviAbstractFeature::ProductionBackendLoaded);
+
+ QCOMPARE(client.lastMessage(), QString());
+ QCOMPARE(client.intValue(), 0);
+ QCOMPARE(client.floatValue1(), qreal(0.0));
+ QCOMPARE(client.floatValue2(), qreal(0.0));
+ QCOMPARE(client.stringValue(), QString());
+ QCOMPARE(client.contactList(), QVariantList());
+ QCOMPARE(client.contact(), Contact());
+ QCOMPARE(client.weekDay(), EchoModule::WeekDay());
+
Server server;
- QVERIFY(server.start());
//test initial values
QCOMPARE(server.m_service.lastMessage(), QString());
@@ -54,22 +65,52 @@ void EchoQtroTest::testInitServer()
QCOMPARE(server.m_service.stringValue(), QString());
QCOMPARE(server.m_service.contactList(), QVariantList());
QCOMPARE(server.m_service.contact(), Contact());
- QCOMPARE(server.m_service.weekDay(), EchoModule::DaysOfTheWeek());
-}
+ QCOMPARE(server.m_service.weekDay(), EchoModule::WeekDay());
-void EchoQtroTest::testInitClient()
-{
- Echo client;
- QVERIFY(client.startAutoDiscovery()==QIviAbstractFeature::ProductionBackendLoaded);
+ QString lastMessageTestValue("this is the last message");
+ int intValueTestValue(789);
+ float floatValue1TestValue(3.14);
+ float floatValue2TestValue(2.71);
+ QString stringValueTestValue("test string");
+ QVariantList contactListTestValue(
+ { QVariant::fromValue<Contact>(Contact("Mr A.", 20, false)),
+ QVariant::fromValue<Contact>(Contact("Mr B.", 40, true)) });
+ Contact contactTestValue("Nemo", 47, true);
+ EchoModule::WeekDay weekDayTestValue = EchoModule::Wednesday;
- QCOMPARE(client.lastMessage(), QString());
- QCOMPARE(client.intValue(), 0);
- QCOMPARE(client.floatValue1(), qreal(0.0));
- QCOMPARE(client.floatValue2(), qreal(0.0));
- QCOMPARE(client.stringValue(), QString());
- QCOMPARE(client.contactList(), QVariantList());
- QCOMPARE(client.contact(), Contact());
- QCOMPARE(client.weekDay(), EchoModule::DaysOfTheWeek());
+
+ server.m_service.setLastMessage(lastMessageTestValue);
+ server.m_service.setIntValue(intValueTestValue);
+ server.m_service.setFloatValue1(floatValue1TestValue);
+ server.m_service.setFloatValue2(floatValue2TestValue);
+ server.m_service.setStringValue(stringValueTestValue);
+ server.m_service.setContactList(contactListTestValue);
+ server.m_service.setContact(contactTestValue);
+ server.m_service.setWeekDay(weekDayTestValue);
+
+ QVERIFY(server.start());
+
+
+ //hack that makes sure we wait until the client is connected to the server
+ //QSignalSpy spy(&client, SIGNAL(weekDayChanged(EchoModule::WeekDay)));
+ QSignalSpy spy(&client, SIGNAL(floatValue1Changed(qreal)));
+ QVERIFY(spy.isValid());
+ spy.wait(1000);
+ // end of hack
+
+
+ //test that client gets the same values that were set at the server before connection was established
+ QCOMPARE(client.lastMessage(),lastMessageTestValue);
+ QCOMPARE(client.intValue(), intValueTestValue);
+ QCOMPARE(client.floatValue1(), floatValue1TestValue);
+ QCOMPARE(client.floatValue2(), floatValue2TestValue);
+ QCOMPARE(client.stringValue(), stringValueTestValue);
+ QVariantList contactList = client.contactList();
+ QCOMPARE(contactList[0].value<Contact>(), contactListTestValue[0].value<Contact>());
+ QCOMPARE(contactList[1].value<Contact>(), contactListTestValue[1].value<Contact>());
+ QCOMPARE(client.contact(), contactTestValue);
+ QCOMPARE(server.m_service.weekDay(), weekDayTestValue);
+ QCOMPARE(client.weekDay(), weekDayTestValue);
}
void EchoQtroTest::testClient2Server()
@@ -143,13 +184,13 @@ void EchoQtroTest::testClient2Server()
QCOMPARE(server.m_service.contact(), contactTestValue);
QCOMPARE(contactSpy[0][0].value<Contact>(), contactTestValue);
- QSignalSpy weekDaySpy(&server.m_service, SIGNAL(weekDayChanged(EchoModule::DaysOfTheWeek)));
+ QSignalSpy weekDaySpy(&server.m_service, SIGNAL(weekDayChanged(EchoModule::WeekDay)));
QVERIFY(weekDaySpy.isValid());
- EchoModule::DaysOfTheWeek weekDayTestValue = EchoModule::Wednesday;
+ EchoModule::WeekDay weekDayTestValue = EchoModule::Thursday;
client.setWeekDay(weekDayTestValue);
weekDaySpy.wait(1000);
QCOMPARE(server.m_service.weekDay(), weekDayTestValue);
- QCOMPARE(weekDaySpy[0][0].value<EchoModule::DaysOfTheWeek>(), weekDayTestValue);
+ QCOMPARE(weekDaySpy[0][0].value<EchoModule::WeekDay>(), weekDayTestValue);
}
void EchoQtroTest::testServer2Client()
@@ -223,13 +264,106 @@ void EchoQtroTest::testServer2Client()
QCOMPARE(client.contact(), contactTestValue);
QCOMPARE(contactSpy[0][0].value<Contact>(), contactTestValue);
- QSignalSpy weekDaySpy(&client, SIGNAL(weekDayChanged(EchoModule::DaysOfTheWeek)));
+ QSignalSpy weekDaySpy(&client, SIGNAL(weekDayChanged(EchoModule::WeekDay)));
QVERIFY(weekDaySpy.isValid());
- EchoModule::DaysOfTheWeek weekDayTestValue = EchoModule::Wednesday;
+ EchoModule::WeekDay weekDayTestValue = EchoModule::Friday;
server.m_service.setWeekDay(weekDayTestValue);
weekDaySpy.wait(1000);
QCOMPARE(client.weekDay(), weekDayTestValue);
- QCOMPARE(weekDaySpy[0][0].value<EchoModule::DaysOfTheWeek>(), weekDayTestValue);
+ QCOMPARE(weekDaySpy[0][0].value<EchoModule::WeekDay>(), weekDayTestValue);
+}
+
+void EchoQtroTest::testSlots()
+{
+ Server server;
+ server.start();
+
+ Echo client;
+ client.startAutoDiscovery();
+
+
+ //hack that makes sure we wait until the client is connected to the server
+ server.m_service.setFloatValue1(1.0);
+ QSignalSpy spy(&client, SIGNAL(floatValue1Changed(qreal)));
+ spy.wait(1000);
+ // end of hack
+
+
+ //test slots by calling them on the client
+ QSignalSpy echoSpy(&server.m_service, SIGNAL(echoSlotCalled(const QString&)));
+ QVERIFY(echoSpy.isValid());
+ QString echoTestValue("this will be echoed");
+ QString echoReturnValue = client.echo(echoTestValue);
+ //echoSpy.wait(1000);
+ QCOMPARE(echoReturnValue, echoTestValue);
+ QCOMPARE(echoSpy.count(),1);
+ QCOMPARE(echoSpy[0][0].toString(), echoTestValue);
+
+ QSignalSpy idSpy(&server.m_service, SIGNAL(idSlotCalled()));
+ QVERIFY(idSpy.isValid());
+ QString idReturnValue = client.id();
+ //idSpy.wait(1000);
+ QCOMPARE(idReturnValue, server.m_service.m_testId);
+ QCOMPARE(idSpy.count(),1);
+
+ QSignalSpy getComboSpy(&server.m_service, SIGNAL(getComboSlotCalled()));
+ QVERIFY(getComboSpy.isValid());
+ Combo comboReturnValue = client.getCombo();
+ //getComboSpy.wait(1000);
+ QCOMPARE(comboReturnValue, server.m_service.m_testCombo);
+ QCOMPARE(getComboSpy.count(),1);
+
+ QSignalSpy voidSlotSpy(&server.m_service, SIGNAL(voidSlotCalled()));
+ QVERIFY(voidSlotSpy.isValid());
+ client.voidSlot();
+ voidSlotSpy.wait(1000);
+ QCOMPARE(voidSlotSpy.count(),1);
+
+ QSignalSpy voidSlot2Spy(&server.m_service, SIGNAL(voidSlot2Called(int)));
+ int voidSlot2TestValue = 776;
+ QVERIFY(voidSlot2Spy.isValid());
+ client.voidSlot2(voidSlot2TestValue);
+ voidSlot2Spy.wait(1000);
+ QCOMPARE(voidSlot2Spy.count(),1);
+ QCOMPARE(voidSlot2Spy[0][0].toInt(), voidSlot2TestValue);
}
+void EchoQtroTest::testSignals()
+{
+ Server server;
+ server.start();
+
+ Echo client;
+ client.startAutoDiscovery();
+
+
+ //hack that makes sure we wait until the client is connected to the server
+ server.m_service.setFloatValue1(1.0);
+ QSignalSpy spy(&client, SIGNAL(floatValue1Changed(qreal)));
+ spy.wait(1000);
+ // end of hack
+
+ //test custom signals (other than property notifiers) from server to client
+ QSignalSpy anotherChangedSpy(&client, SIGNAL(anotherChanged(AnotherStruct)));
+ QVERIFY(anotherChangedSpy.isValid());
+ AnotherStruct anotherTestValue(7);
+ server.m_service.anotherChanged(anotherTestValue);
+ anotherChangedSpy.wait(1000);
+ QCOMPARE(anotherChangedSpy.count(),1);
+ QCOMPARE(anotherChangedSpy[0][0].value<AnotherStruct>(), anotherTestValue);
+
+ QSignalSpy foobarSpy(&client, SIGNAL(foobar(QString)));
+ QVERIFY(foobarSpy.isValid());
+ QString foobarTestValue("foo and bar");
+ server.m_service.foobar(foobarTestValue);
+ foobarSpy.wait(1000);
+ QCOMPARE(foobarSpy.count(),1);
+ QCOMPARE(foobarSpy[0][0].toString(), foobarTestValue);
+
+ QSignalSpy somethingSpy(&client, SIGNAL(somethingHappened()));
+ QVERIFY(somethingSpy.isValid());;
+ server.m_service.somethingHappened();
+ somethingSpy.wait(1000);
+ QCOMPARE(somethingSpy.count(),1);
+}
diff --git a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h
index a8b5315..cf58a40 100644
--- a/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h
+++ b/tests/auto/core/ivigenerator/projects/org-example-echo-qtro/server_qtro_test/tst_echoqtro.h
@@ -41,10 +41,11 @@ public:
private slots:
void cleanup();
- void testInitServer();
- void testInitClient();
+ void testInit();
void testClient2Server();
void testServer2Client();
+ void testSlots();
+ void testSignals();
};
#endif // ECHOQTROTEST_H