|
|
|
@ -48,27 +48,40 @@ |
|
|
|
|
#include <string> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
|
#ifdef __GNUG__ |
|
|
|
|
#define LOG std::clog<<__PRETTY_FUNCTION__<<'@'<<__FILE__<<':'<<__LINE__; |
|
|
|
|
#else |
|
|
|
|
#define LOG std::clog<<__FUNCTION__<<'@'<<__FILE__<<':'<<__LINE__; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
class ExecTest: public CppUnit::TestFixture { |
|
|
|
|
public: |
|
|
|
|
void lsTest() { |
|
|
|
|
LOG; |
|
|
|
|
std::string res = (mrw::Cmd("/bin/ls"), "-l", |
|
|
|
|
std::string(getenv("srcdir"))+"/..").execute(); |
|
|
|
|
CPPUNIT_ASSERT(res.find("COPYING")<res.size()); |
|
|
|
|
} |
|
|
|
|
void catTest() { |
|
|
|
|
LOG; |
|
|
|
|
std::string res = mrw::Cmd("/bin/cat").execute("This is a test"); |
|
|
|
|
CPPUNIT_ASSERT(res=="This is a test"); |
|
|
|
|
} |
|
|
|
|
void excTest1() { |
|
|
|
|
LOG; |
|
|
|
|
std::string res = (mrw::Cmd("/bin/false")).execute().result(); |
|
|
|
|
} |
|
|
|
|
void excTest2() { |
|
|
|
|
LOG; |
|
|
|
|
std::string res = (mrw::Cmd("/bin/false")).execute("").result(); |
|
|
|
|
} |
|
|
|
|
void unexpectedExc() throw(std::bad_exception) { |
|
|
|
|
LOG; |
|
|
|
|
std::string res = (mrw::Cmd("/bin/false")).execute().result(); |
|
|
|
|
} |
|
|
|
|
void lsTest2() { |
|
|
|
|
LOG; |
|
|
|
|
std::string res; |
|
|
|
|
mrw::PartialExec exec = (mrw::Cmd("/bin/ls"), "-l", |
|
|
|
|
std::string(getenv("srcdir"))+"/..").start(); |
|
|
|
@ -76,6 +89,7 @@ public: |
|
|
|
|
CPPUNIT_ASSERT(res.find("COPYING")<res.size()); |
|
|
|
|
} |
|
|
|
|
void catTest2() { |
|
|
|
|
LOG; |
|
|
|
|
mrw::PartialExec exec = mrw::Cmd("/bin/cat").start(true); |
|
|
|
|
std::string res = exec.read("This is a test\n").first; |
|
|
|
|
res += exec.read("More to come...\n").first; |
|
|
|
@ -84,14 +98,17 @@ public: |
|
|
|
|
CPPUNIT_ASSERT(res=="This is a test\nMore to come...\n"); |
|
|
|
|
} |
|
|
|
|
void excTest12() { |
|
|
|
|
LOG; |
|
|
|
|
mrw::PartialExec exec = (mrw::Cmd("/bin/false")).start(); |
|
|
|
|
while (!exec.finished()) exec.read(); |
|
|
|
|
} |
|
|
|
|
void excTest22() { |
|
|
|
|
LOG; |
|
|
|
|
mrw::PartialExec exec = (mrw::Cmd("/bin/false")).start(true); |
|
|
|
|
while (!exec.finished()) exec.read("xxx"); |
|
|
|
|
} |
|
|
|
|
void unexpectedExc2() throw(std::bad_exception) { |
|
|
|
|
LOG; |
|
|
|
|
mrw::PartialExec exec = (mrw::Cmd("/bin/false")).start(); |
|
|
|
|
while (!exec.finished()) exec.read(); |
|
|
|
|
} |
|
|
|
|