mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-02 17:50:53 +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;
|
bool isRunning() const;
|
||||||
/// Returns true if the service is currently running.
|
/// Returns true if the service is currently running.
|
||||||
|
|
||||||
|
bool isStopped() const;
|
||||||
|
/// Returns true if the service is currently stopped.
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
/// Starts the service.
|
/// Starts the service.
|
||||||
|
@ -164,6 +164,15 @@ bool WinService::isRunning() const
|
|||||||
return ss.dwCurrentState == SERVICE_RUNNING;
|
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()
|
void WinService::start()
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#include "WinServiceTest.h"
|
#include "WinServiceTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/Util/WinService.h"
|
|
||||||
|
|
||||||
using Poco::Util::WinService;
|
using Poco::Util::WinService;
|
||||||
|
|
||||||
@ -25,12 +24,21 @@ void WinServiceTest::testServiceCouldCreatedWithExistingConnection() {
|
|||||||
assertTrue(spoolerService.isRegistered());
|
assertTrue(spoolerService.isRegistered());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WinServiceTest::testServiceReturnsTrueIfStopped() {
|
||||||
|
spoolerService_.stop();
|
||||||
|
assertTrue(spoolerService_.isStopped());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void WinServiceTest::setUp() {
|
void WinServiceTest::setUp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void WinServiceTest::tearDown() {
|
void WinServiceTest::tearDown() {
|
||||||
|
if (spoolerService_.isStopped()) {
|
||||||
|
spoolerService_.start();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -38,6 +46,7 @@ CppUnit::Test* WinServiceTest::suite() {
|
|||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WinServiceTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WinServiceTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, WinServiceTest, testServiceCouldCreatedWithExistingConnection);
|
CppUnit_addTest(pSuite, WinServiceTest, testServiceCouldCreatedWithExistingConnection);
|
||||||
|
CppUnit_addTest(pSuite, WinServiceTest, testServiceReturnsTrueIfStopped);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "Poco/Util/Util.h"
|
#include "Poco/Util/Util.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
#include "Poco/Util/WinService.h"
|
||||||
|
|
||||||
|
|
||||||
class WinServiceTest : public CppUnit::TestCase {
|
class WinServiceTest : public CppUnit::TestCase {
|
||||||
@ -12,6 +13,7 @@ public:
|
|||||||
~WinServiceTest();
|
~WinServiceTest();
|
||||||
|
|
||||||
void testServiceCouldCreatedWithExistingConnection();
|
void testServiceCouldCreatedWithExistingConnection();
|
||||||
|
void testServiceReturnsTrueIfStopped();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
@ -19,6 +21,7 @@ public:
|
|||||||
static CppUnit::Test* suite();
|
static CppUnit::Test* suite();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Poco::Util::WinService spoolerService_{ "Spooler" };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user