summaryrefslogtreecommitdiffstats
path: root/tests/auto/dbus
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2021-01-04 16:28:45 +0100
committerAndreas Buhr <andreas.buhr@qt.io>2021-04-19 15:18:46 +0200
commit97a8727f0ed87d1f9cb79d702f7d1da3951c2e2a (patch)
tree5624ce9e9a75b147178522aabbf9d8fce2c29419 /tests/auto/dbus
parent673d9c34f4523d030282663c54c30bcc1fe3c6fa (diff)
Port of QDBusServiceWatcher::watchMode to new property system
Port watchMode in QDBusServiceWatcher to the new property system. This is the easiest part. Task-number: QTBUG-85520 Change-Id: I588212af205e77765862b8fecdbdcbf871717142 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/dbus')
-rw-r--r--tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp b/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp
index d2c3a830ca..f19091a9a3 100644
--- a/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp
+++ b/tests/auto/dbus/qdbusservicewatcher/tst_qdbusservicewatcher.cpp
@@ -54,6 +54,7 @@ private slots:
void disconnectedConnection();
void setConnection_data();
void setConnection();
+ void bindings();
private:
QString generateServiceName();
@@ -428,5 +429,45 @@ void tst_QDBusServiceWatcher::setConnection()
QCOMPARE(spyU.at(0).at(0).toString(), watchedName);
}
+void tst_QDBusServiceWatcher::bindings()
+{
+ QString serviceName("normal");
+
+ QDBusConnection con("");
+ QVERIFY(!con.isConnected());
+
+ QDBusServiceWatcher watcher(serviceName, con, QDBusServiceWatcher::WatchForRegistration);
+ QProperty<QDBusServiceWatcher::WatchMode> follower;
+ int notificationCounter = 0;
+ auto connection = follower.subscribe([&]() { notificationCounter++; });
+ QCOMPARE(notificationCounter, 1);
+ follower.setBinding([&]() { return watcher.watchMode(); });
+ QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForRegistration);
+ QCOMPARE(notificationCounter, 2);
+
+ watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
+ QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForUnregistration);
+ QCOMPARE(notificationCounter, 3);
+
+ QProperty<QDBusServiceWatcher::WatchMode> leader(QDBusServiceWatcher::WatchForRegistration);
+ watcher.bindableWatchMode().setBinding([&]() { return leader.value(); });
+ QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForRegistration);
+ QCOMPARE(notificationCounter, 4);
+
+ leader = QDBusServiceWatcher::WatchForUnregistration;
+ QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForUnregistration);
+ QCOMPARE(notificationCounter, 5);
+
+ // check that setting a value breaks the binding
+ watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
+ QCOMPARE(notificationCounter, 5);
+ leader = QDBusServiceWatcher::WatchForRegistration;
+ QCOMPARE(follower.value(), QDBusServiceWatcher::WatchForUnregistration);
+
+ // check that setting the same value again does not trigger notification
+ watcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration);
+ QCOMPARE(notificationCounter, 5);
+}
+
QTEST_MAIN(tst_QDBusServiceWatcher)
#include "tst_qdbusservicewatcher.moc"