22#include < QtTest>
33#include < QCoreApplication>
44#include < QProcess>
5+ #include < QtService/ServiceControl>
56#include < testlib.h>
67#include < mockclient.h>
78
@@ -93,7 +94,7 @@ private Q_SLOTS:
9394 void testStop ();
9495
9596private:
96- QProcess *server; // TODO replace with debug ServiceControl
97+ QtService::ServiceControl *server;
9798
9899 MockClient *client;
99100 QString devName;
@@ -122,18 +123,23 @@ void TestAppServer::initTestCase()
122123 QVERIFY (QFile::exists (QString::fromUtf8 (confPath)));
123124 qputenv (" QDSAPP_CONFIG_FILE" , confPath);
124125
126+ const QString launchPath { QStringLiteral (BUILD_BIN_DIR " qdsapp" ) };
125127#ifdef Q_OS_UNIX
126- QString binPath { QStringLiteral (BUILD_BIN_DIR " qdsappd" ) };
128+ const QString binPath { QStringLiteral (BUILD_BIN_DIR " qdsappd" ) };
127129#elif Q_OS_WIN
128- QString binPath { QStringLiteral (BUILD_BIN_DIR " qdsappsvc" ) };
130+ const QString binPath { QStringLiteral (BUILD_BIN_DIR " qdsappsvc" ) };
129131#else
130- QString binPath { QStringLiteral (BUILD_BIN_DIR " qdsapp " ) } ;
132+ const auto binPath = launchPath ;
131133#endif
132134 QVERIFY (QFile::exists (binPath));
135+ if (!QFile::exists (launchPath))
136+ QVERIFY (QFile::link (binPath, launchPath));
137+ QVERIFY (QFile::exists (launchPath));
133138
134- server = new QProcess (this );
135- server->setProgram (binPath);
136- server->setProcessChannelMode (QProcess::ForwardedErrorChannel);
139+ server = QtService::ServiceControl::create (QStringLiteral (" debug" ), launchPath, this );
140+ QVERIFY (server);
141+ QVERIFY (server->serviceExists ());
142+ server->setBlocking (true );
137143
138144 try {
139145 client = nullptr ;
@@ -156,18 +162,19 @@ void TestAppServer::cleanupTestCase()
156162{
157163 clean ();
158164 clean (partner);
159- if (server->isOpen () ) {
160- server->kill ();
161- QVERIFY (server->waitForFinished ( 5000 ) );
165+ if (server->status () == QtService::ServiceControl::ServiceRunning ) {
166+ server->stop ();
167+ QTRY_COMPARE (server->status (), QtService::ServiceControl::ServiceStopped );
162168 }
163169 server->deleteLater ();
164170}
165171
166172void TestAppServer::testStart ()
167173{
168174 server->start ();
169- QVERIFY (server->waitForStarted (5000 ));
170- QVERIFY (!server->waitForFinished (5000 ));
175+ QTRY_COMPARE (server->status (), QtService::ServiceControl::ServiceRunning);
176+ QEXPECT_FAIL (" " , " Server should not stop easily" , Continue);
177+ QTRY_COMPARE (server->status (), QtService::ServiceControl::ServiceStopped);
171178}
172179
173180void TestAppServer::testInvalidVersion ()
@@ -1816,16 +1823,8 @@ void TestAppServer::testRemoveSelf()
18161823
18171824void TestAppServer::testStop ()
18181825{
1819- // send a signal to stop
1820- #ifdef Q_OS_UNIX
1821- server->terminate (); // same as kill(SIGTERM)
1822- #elif Q_OS_WIN
1823- GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, server->processId ());
1824- #endif
1825- QVERIFY (server->waitForFinished (5000 ));
1826- QCOMPARE (server->exitStatus (), QProcess::NormalExit);
1827- QCOMPARE (server->exitCode (), 0 );
1828- server->close ();
1826+ server->stop ();
1827+ QTRY_COMPARE (server->status (), QtService::ServiceControl::ServiceStopped);
18291828}
18301829
18311830void TestAppServer::clean (bool disconnect)
0 commit comments