13#include <QDBusConnection>
55 void CTestSharedState::initTestCase()
61 void CTestSharedState::testPromise()
67 bool ok =
qWaitFor([&] {
return result == 42; });
68 QVERIFY2(ok,
"future contains expected result");
71 void CTestSharedState::localScalar()
73 CDataLinkLocal dataLink;
74 CTestScalarMutator mutator(
this);
75 CTestScalarJournal journal(
this);
76 CTestScalarObserver observer(
this);
77 mutator.initialize(&dataLink);
78 journal.initialize(&dataLink);
79 observer.initialize(&dataLink);
82 bool ok =
qWaitFor([&] {
return observer.value() == 42; });
83 QVERIFY2(ok,
"expected value received");
85 QVERIFY2(observer.value() == 42,
"still has expected value");
87 CTestScalarObserver observer2(
this);
88 observer2.initialize(&dataLink);
90 ok =
qWaitFor([&] {
return observer2.value() == 42; });
91 QVERIFY2(ok,
"new observer got existing value");
93 QVERIFY2(observer2.value() == 42,
"still has correct value");
96 void CTestSharedState::localList()
98 CDataLinkLocal dataLink;
99 CTestListMutator mutator(
this);
100 CTestListJournal journal(
this);
101 CTestListObserver observer(
this);
102 mutator.initialize(&dataLink);
103 journal.initialize(&dataLink);
104 observer.initialize(&dataLink);
106 observer.setFilter({});
107 mutator.addElement(1);
108 bool ok =
qWaitFor([&] {
return observer.allValues() == QList<int> { 1 }; });
109 QVERIFY2(ok,
"expected value received");
111 QVERIFY2(observer.allValues() == QList<int> { 1 },
"still has expected value");
113 for (
int e = 2; e <= 6; ++e)
115 mutator.addElement(e);
117 ok =
qWaitFor([&] {
return observer.allValues() == QList<int> { 1, 2, 3, 4, 5, 6 }; });
118 QVERIFY2(ok,
"expected value received");
120 observer.allValues() = {};
121 observer.setFilter({ 1 });
122 ok =
qWaitFor([&] {
return observer.allValues() == QList<int> { 1, 3, 5 }; });
123 QVERIFY2(ok,
"expected value received");
135 qDebug() <<
"Server process exited" << (status ?
"abnormally" :
"normally")
136 <<
"with exit code" << code;
139 if (!m_process.waitForStarted())
141 qDebug() <<
"Server failed to start";
147 m_process.disconnect();
149 m_process.waitForFinished();
156 void CTestSharedState::dbusScalar()
161 QSKIP(
"No session bus");
165 CDataLinkDBus dataLink;
170 CTestScalarObserver observer(
this);
171 CTestScalarMutator mutator(
this);
172 observer.initialize(&dataLink);
173 mutator.initialize(&dataLink);
175 ok =
qWaitFor([&] {
return observer.value() == 42; });
176 QVERIFY2(ok,
"expected value received");
178 QVERIFY2(observer.value() == 42,
"still has expected value");
180 mutator.setValue(69);
181 ok =
qWaitFor([&] {
return observer.value() == 69; });
182 QVERIFY2(ok,
"expected value received");
184 QVERIFY2(observer.value() == 69,
"still has expected value");
187 void CTestSharedState::dbusList()
192 QSKIP(
"No session bus");
196 CDataLinkDBus dataLink;
201 CTestListObserver observer(
this);
202 CTestListMutator mutator(
this);
203 observer.initialize(&dataLink);
204 mutator.initialize(&dataLink);
206 observer.setFilter({});
207 ok =
qWaitFor([&] {
return observer.allValues() == QList<int> { 1, 2, 3, 4, 5, 6 }; });
208 QVERIFY2(ok,
"expected value received");
210 QVERIFY2(observer.allValues() == QList<int>({ 1, 2, 3, 4, 5, 6 }),
"still has expected value");
212 observer.allValues() = {};
213 observer.setFilter({ 1 });
214 ok =
qWaitFor([&] {
return observer.allValues() == QList<int> { 1, 3, 5 }; });
215 QVERIFY2(ok,
"expected value received");
217 mutator.addElement(7);
218 ok =
qWaitFor([&] {
return observer.allValues() == QList<int> { 1, 3, 5, 7 }; });
219 QVERIFY2(ok,
"expected value received");
221 QVERIFY2(observer.allValues() == QList<int>({ 1, 3, 5, 7 }),
"still has expected value");
228#include "testsharedstate.moc"
DBus implementation classes tests.
A promise-based interface to QFuture, similar to std::promise for std::future.
QFuture< T > future()
Return a future that can be used to access the result.
void setResult(const T &value)
Set the result value that will be made available through the future.
bool isConnected() const
True if connected to the transport layer.
void initializeRemote(const QDBusConnection &connection, const QString &service)
Initialize on client side.
CDataLinkConnectionWatcher * watcher()
Get a connection status watcher.
@ Server
What server are you on?
#define SWIFT_SERVICENAME
Service name of DBus service.
Utilities for sharing state between multiple objects.
Free functions in swift::misc.
void registerMetadata()
Register all relevant metadata in Misc.
void doAfter(QFuture< T > future, QObject *context, F &&func)
Connect a slot or function to be invoked in the given context when a QFuture is finished.
QString applicationDirPath()
bool isConnected() const const
QDBusConnection sessionBus()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void finished(int exitCode, QProcess::ExitStatus exitStatus)
QVERIFY2(condition, message)
bool qWaitFor(Functor predicate, QDeadlineTimer deadline)
#define SWIFTTEST_MAIN(TestObject)
Implements a main() function that executes all tests in TestObject including instantiating a QCoreApp...