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