From 04116d6593eb91ab50fa79e8fb4c5915803173f2 Mon Sep 17 00:00:00 2001 From: Yuval Kashtan Date: Tue, 12 Aug 2014 11:03:54 +0300 Subject: [PATCH] add tests for Process::isRunning --- Foundation/testsuite/src/ProcessTest.cpp | 30 ++++++++++++++++++++++++ Foundation/testsuite/src/ProcessTest.h | 1 + 2 files changed, 31 insertions(+) diff --git a/Foundation/testsuite/src/ProcessTest.cpp b/Foundation/testsuite/src/ProcessTest.cpp index 8acd6fa4f..c4099bab0 100644 --- a/Foundation/testsuite/src/ProcessTest.cpp +++ b/Foundation/testsuite/src/ProcessTest.cpp @@ -92,6 +92,35 @@ void ProcessTest::testLaunchRedirectIn() #endif // !defined(_WIN32_WCE) } +void ProcessTest::testIsRunning() +{ + std::string name("TestApp"); + std::string cmd; +#if defined(_DEBUG) + name += "d"; +#endif + +#if defined(POCO_OS_FAMILY_UNIX) + cmd = "./"; + cmd += name; +#else + cmd = name; +#endif + + std::vector args; + args.push_back("-count"); + Pipe inPipe; + ProcessHandle ph = Process::launch(cmd, args, &inPipe, 0, 0); + Process::PID id = ph.id(); + assert (Process::isRunning(ph)); + assert (Process::isRunning(id)); + PipeOutputStream ostr(inPipe); + ostr << std::string(100, 'x'); + ostr.close(); + int rc = ph.wait(); + assert (!Process::isRunning(ph)); + assert (!Process::isRunning(id)); +} void ProcessTest::testLaunchRedirectOut() { @@ -175,6 +204,7 @@ CppUnit::Test* ProcessTest::suite() CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectIn); CppUnit_addTest(pSuite, ProcessTest, testLaunchRedirectOut); CppUnit_addTest(pSuite, ProcessTest, testLaunchEnv); + CppUnit_addTest(pSuite, ProcessTest, testIsRunning); return pSuite; } diff --git a/Foundation/testsuite/src/ProcessTest.h b/Foundation/testsuite/src/ProcessTest.h index 7c9d858d5..a4fee2ea0 100644 --- a/Foundation/testsuite/src/ProcessTest.h +++ b/Foundation/testsuite/src/ProcessTest.h @@ -30,6 +30,7 @@ public: void testLaunchRedirectIn(); void testLaunchRedirectOut(); void testLaunchEnv(); + void testIsRunning(); void setUp(); void tearDown();