C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
4.0 KiB
135 lines
4.0 KiB
21 years ago
|
/** @file
|
||
|
|
||
|
$Id$
|
||
|
|
||
|
$Date$
|
||
|
$Author$
|
||
|
|
||
|
@copy © Marc Wäckerlin
|
||
|
@license LGPL, see file <a href="license.html">COPYING</a>
|
||
|
|
||
|
$Log$
|
||
20 years ago
|
Revision 1.9 2005/04/19 18:48:00 marc
|
||
|
new feature PartialExec
|
||
|
|
||
20 years ago
|
Revision 1.8 2005/04/07 20:55:21 marc
|
||
|
Oops, there's a make distcheck...? Now it works.
|
||
|
|
||
20 years ago
|
Revision 1.7 2004/12/20 13:21:21 marc
|
||
|
exception tests: each exception must be in an own test case
|
||
|
|
||
20 years ago
|
Revision 1.6 2004/12/14 20:30:10 marc
|
||
|
added possibility to pass string to stdin of child process
|
||
|
|
||
20 years ago
|
Revision 1.5 2004/10/13 10:43:11 marc
|
||
|
test for bad exception specification
|
||
|
|
||
21 years ago
|
Revision 1.4 2004/08/28 16:21:25 marc
|
||
|
mrw-c++-0.92 (mrw)
|
||
13 years ago
|
- new file: version.cxx
|
||
21 years ago
|
- new file header for all sources
|
||
|
- work around warning in mrw::auto<T>
|
||
|
- possibility to compile without log4cxx
|
||
|
- work around bugs in demangle.h and libiberty.h
|
||
|
- corrections in documentation
|
||
|
- added simple tracing mechanism
|
||
|
- more warnings
|
||
|
- small corrections in Auto<>::Free and a new test for it
|
||
|
- possibility to compile without stack trace
|
||
|
|
||
|
*/
|
||
13 years ago
|
#include <mrw/exec.hxx>
|
||
|
#include <mrw/stacktrace.hxx>
|
||
|
#include <mrw/stdext.hxx>
|
||
21 years ago
|
#include <cppunit/TestFixture.h>
|
||
|
#include <cppunit/ui/text/TestRunner.h>
|
||
|
#include <cppunit/extensions/HelperMacros.h>
|
||
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||
|
#include <string>
|
||
20 years ago
|
#include <stdlib.h>
|
||
21 years ago
|
|
||
18 years ago
|
#include <iostream>
|
||
|
#ifdef __GNUG__
|
||
|
#define LOG std::clog<<__PRETTY_FUNCTION__<<'@'<<__FILE__<<':'<<__LINE__;
|
||
|
#else
|
||
|
#define LOG std::clog<<__FUNCTION__<<'@'<<__FILE__<<':'<<__LINE__;
|
||
|
#endif
|
||
|
|
||
21 years ago
|
class ExecTest: public CppUnit::TestFixture {
|
||
|
public:
|
||
|
void lsTest() {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
std::string res = (mrw::Cmd("/bin/ls"), "-l",
|
||
|
std::string(getenv("srcdir"))+"/..").execute();
|
||
21 years ago
|
CPPUNIT_ASSERT(res.find("COPYING")<res.size());
|
||
|
}
|
||
20 years ago
|
void catTest() {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
std::string res = mrw::Cmd("/bin/cat").execute("This is a test");
|
||
20 years ago
|
CPPUNIT_ASSERT(res=="This is a test");
|
||
|
}
|
||
20 years ago
|
void excTest1() {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
std::string res = (mrw::Cmd("/bin/false")).execute().result();
|
||
|
}
|
||
|
void excTest2() {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
std::string res = (mrw::Cmd("/bin/false")).execute("").result();
|
||
21 years ago
|
}
|
||
20 years ago
|
void unexpectedExc() throw(std::bad_exception) {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
std::string res = (mrw::Cmd("/bin/false")).execute().result();
|
||
|
}
|
||
20 years ago
|
void lsTest2() {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
std::string res;
|
||
|
mrw::PartialExec exec = (mrw::Cmd("/bin/ls"), "-l",
|
||
|
std::string(getenv("srcdir"))+"/..").start();
|
||
|
while (!exec.finished()) res+=exec.read().first;
|
||
|
CPPUNIT_ASSERT(res.find("COPYING")<res.size());
|
||
|
}
|
||
|
void catTest2() {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
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;
|
||
|
exec.finish();
|
||
|
while (!exec.finished()) res+=exec.read().first;
|
||
|
CPPUNIT_ASSERT(res=="This is a test\nMore to come...\n");
|
||
|
}
|
||
|
void excTest12() {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
mrw::PartialExec exec = (mrw::Cmd("/bin/false")).start();
|
||
|
while (!exec.finished()) exec.read();
|
||
|
}
|
||
|
void excTest22() {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
mrw::PartialExec exec = (mrw::Cmd("/bin/false")).start(true);
|
||
|
while (!exec.finished()) exec.read("xxx");
|
||
|
}
|
||
|
void unexpectedExc2() throw(std::bad_exception) {
|
||
18 years ago
|
LOG;
|
||
20 years ago
|
mrw::PartialExec exec = (mrw::Cmd("/bin/false")).start();
|
||
|
while (!exec.finished()) exec.read();
|
||
|
}
|
||
21 years ago
|
CPPUNIT_TEST_SUITE(ExecTest);
|
||
|
CPPUNIT_TEST(lsTest);
|
||
20 years ago
|
CPPUNIT_TEST(catTest);
|
||
20 years ago
|
CPPUNIT_TEST_EXCEPTION(excTest1, mrw::ExecutionFailedExc);
|
||
|
CPPUNIT_TEST_EXCEPTION(excTest2, mrw::ExecutionFailedExc);
|
||
20 years ago
|
CPPUNIT_TEST_EXCEPTION(unexpectedExc, std::bad_exception);
|
||
20 years ago
|
CPPUNIT_TEST(lsTest2);
|
||
|
CPPUNIT_TEST(catTest2);
|
||
|
CPPUNIT_TEST_EXCEPTION(excTest12, mrw::ExecutionFailedExc);
|
||
|
CPPUNIT_TEST_EXCEPTION(excTest22, mrw::ExecutionFailedExc);
|
||
|
CPPUNIT_TEST_EXCEPTION(unexpectedExc2, std::bad_exception);
|
||
21 years ago
|
CPPUNIT_TEST_SUITE_END();
|
||
|
};
|
||
|
CPPUNIT_TEST_SUITE_REGISTRATION(ExecTest);
|
||
21 years ago
|
|
||
|
int main() {
|
||
21 years ago
|
CppUnit::TextUi::TestRunner runner;
|
||
|
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||
|
return runner.run() ? 0 : 1;
|
||
21 years ago
|
}
|