summaryrefslogtreecommitdiffstats
path: root/tests/auto/integration/tst_integration.cpp
diff options
context:
space:
mode:
authorBrett Stottlemyer <bstottle@ford.com>2016-10-15 22:12:11 -0400
committerBrett Stottlemyer <bstottle@ford.com>2016-10-19 03:51:59 +0000
commit9c41edbf83af89f80417a2abd75454b92d6796bd (patch)
tree13ef5b7eb08333159cac958a748b6793d0ed1279 /tests/auto/integration/tst_integration.cpp
parentb9af13650a3dca00833001e27d046022962ff655 (diff)
Allow Replica property values to persist
Replicas already provide a mechanism to show a default value before the connection to the Source is established. This enhancement allows the .rep PROP definition to include a 'PERSISTED' flag as well, which saves the property value when the Replica is stopped and restores the value when it is started again. Because a shared dll (QtRO) should not know or care where and how values are persisted, a persistence class needs to be set for the owner Node for this feature to work. Change-Id: I5718b024fd268c95d1add2b1be49e6864127782e Reviewed-by: Continuous Integration (KDAB) <build@kdab.com> Reviewed-by: Michael Brasser <michael.brasser@live.com>
Diffstat (limited to 'tests/auto/integration/tst_integration.cpp')
-rw-r--r--tests/auto/integration/tst_integration.cpp88
1 files changed, 71 insertions, 17 deletions
diff --git a/tests/auto/integration/tst_integration.cpp b/tests/auto/integration/tst_integration.cpp
index 45f3dcf..f3a0084 100644
--- a/tests/auto/integration/tst_integration.cpp
+++ b/tests/auto/integration/tst_integration.cpp
@@ -79,6 +79,21 @@ Q_SIGNALS:
void send(const QByteArray &data);
};
+class Persist : public QRemoteObjectPersistedStore
+{
+public:
+ Persist() : type(EngineReplica::HYBRID) {}
+ void saveProperties(const QString &, const QByteArray &, const QVariantList &values) Q_DECL_OVERRIDE
+ {
+ type = values.at(0).value<EngineReplica::EngineType>();
+ }
+ QVariantList restoreProperties(const QString &, const QByteArray &) Q_DECL_OVERRIDE
+ {
+ return QVariantList() << QVariant::fromValue(type);
+ }
+ EngineReplica::EngineType type;
+};
+
class tst_Integration: public QObject
{
Q_OBJECT
@@ -100,6 +115,62 @@ private slots:
QTest::qWait(200);
}
+ void basicTest()
+ {
+ QRemoteObjectHost host(hostUrl);
+ SET_NODE_NAME(host);
+ Engine e;
+ e.setRpm(1234);
+ host.enableRemoting(&e);
+
+ QRemoteObjectNode client;
+ client.connectToNode(hostUrl);
+ Q_SET_OBJECT_NAME(client);
+
+ const QScopedPointer<EngineReplica> engine_r(client.acquire<EngineReplica>());
+ engine_r->waitForSource();
+ QCOMPARE(engine_r->rpm(), e.rpm());
+ }
+
+ void persistRestoreTest()
+ {
+ QRemoteObjectNode client;
+ client.connectToNode(hostUrl);
+ Q_SET_OBJECT_NAME(client);
+ client.setPersistedStore(new Persist, QRemoteObjectNode::PassOwnershipToNode);
+
+ const QScopedPointer<EngineReplica> engine_r(client.acquire<EngineReplica>());
+ QCOMPARE(engine_r->engineType(), EngineReplica::HYBRID);
+ }
+
+ void persistTest()
+ {
+ Persist persist;
+
+ QRemoteObjectHost host(hostUrl);
+ SET_NODE_NAME(host);
+ Engine e;
+ e.setEngineType(EngineSimpleSource::ELECTRIC);
+ host.enableRemoting(&e);
+
+ QRemoteObjectNode client;
+ client.connectToNode(hostUrl);
+ Q_SET_OBJECT_NAME(client);
+ client.setPersistedStore(&persist);
+
+ QScopedPointer<EngineReplica> engine_r(client.acquire<EngineReplica>());
+ engine_r->waitForSource();
+ QCOMPARE(engine_r->engineType(), EngineReplica::ELECTRIC);
+
+ // Delete to persist
+ engine_r.reset();
+ host.disableRemoting(&e);
+
+ engine_r.reset(client.acquire<EngineReplica>());
+ QCOMPARE(engine_r->waitForSource(1000), false);
+ QCOMPARE(engine_r->engineType(), EngineReplica::ELECTRIC);
+ }
+
void enumTest()
{
QRemoteObjectHost host(hostUrl);
@@ -401,23 +472,6 @@ private slots:
QVERIFY(host.registry()->sourceLocations().value(QStringLiteral("Engine")).hostUrl != registryUrl);
}
- void basicTest()
- {
- QRemoteObjectHost host(hostUrl);
- SET_NODE_NAME(host);
- Engine e;
- e.setRpm(1234);
- host.enableRemoting(&e);
-
- QRemoteObjectNode client;
- client.connectToNode(hostUrl);
- Q_SET_OBJECT_NAME(client);
-
- const QScopedPointer<EngineReplica> engine_r(client.acquire<EngineReplica>());
- engine_r->waitForSource();
- QCOMPARE(engine_r->rpm(), e.rpm());
- }
-
void defaultValueTest()
{
QRemoteObjectHost host(hostUrl);