mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 09:24:55 +02:00
Added Method to check if a service is stopped
This commit is contained in:
parent
5a484c1896
commit
34ad48d16c
@ -95,6 +95,9 @@ public:
|
||||
|
||||
bool isRunning() const;
|
||||
/// Returns true if the service is currently running.
|
||||
|
||||
bool isStopped() const;
|
||||
/// Returns true if the service is currently stopped.
|
||||
|
||||
void start();
|
||||
/// Starts the service.
|
||||
|
@ -164,6 +164,15 @@ bool WinService::isRunning() const
|
||||
return ss.dwCurrentState == SERVICE_RUNNING;
|
||||
}
|
||||
|
||||
bool WinService::isStopped() const
|
||||
{
|
||||
open();
|
||||
SERVICE_STATUS ss;
|
||||
if (!QueryServiceStatus(_svcHandle, &ss))
|
||||
throw SystemException("cannot query service status", _name);
|
||||
return ss.dwCurrentState == SERVICE_STOPPED;
|
||||
}
|
||||
|
||||
|
||||
void WinService::start()
|
||||
{
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "WinServiceTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Util/WinService.h"
|
||||
|
||||
using Poco::Util::WinService;
|
||||
|
||||
@ -25,12 +24,21 @@ void WinServiceTest::testServiceCouldCreatedWithExistingConnection() {
|
||||
assertTrue(spoolerService.isRegistered());
|
||||
}
|
||||
|
||||
void WinServiceTest::testServiceReturnsTrueIfStopped() {
|
||||
spoolerService_.stop();
|
||||
assertTrue(spoolerService_.isStopped());
|
||||
}
|
||||
|
||||
|
||||
void WinServiceTest::setUp() {
|
||||
}
|
||||
|
||||
|
||||
void WinServiceTest::tearDown() {
|
||||
if (spoolerService_.isStopped()) {
|
||||
spoolerService_.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -38,6 +46,7 @@ CppUnit::Test* WinServiceTest::suite() {
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WinServiceTest");
|
||||
|
||||
CppUnit_addTest(pSuite, WinServiceTest, testServiceCouldCreatedWithExistingConnection);
|
||||
CppUnit_addTest(pSuite, WinServiceTest, testServiceReturnsTrueIfStopped);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "Poco/Util/WinService.h"
|
||||
|
||||
|
||||
class WinServiceTest : public CppUnit::TestCase {
|
||||
@ -12,6 +13,7 @@ public:
|
||||
~WinServiceTest();
|
||||
|
||||
void testServiceCouldCreatedWithExistingConnection();
|
||||
void testServiceReturnsTrueIfStopped();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
@ -19,6 +21,7 @@ public:
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
Poco::Util::WinService spoolerService_{ "Spooler" };
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user