middle of porting; unstable, don't checkout; refs #1
This commit is contained in:
1 parent
3bda8f9e64
commit
e5441e3465
32 files changed
-14
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,14 +0,0 @@
|
||||
/*! @file
|
||||
|
||||
@id $Id: main.cxx 9 2009-04-02 12:54:44Z marwae $
|
||||
|
||||
*/
|
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
|
||||
int main(int argv, char** argc) try {
|
||||
} catch (...) {
|
||||
// unexpected exception - just terminate
|
||||
return 1;
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.5 2005/04/07 20:55:21 marc
|
||||
Oops, there's a make distcheck...? Now it works.
|
||||
|
||||
Revision 1.4 2004/11/25 18:27:03 marc
|
||||
additional test for release and reset
|
||||
|
||||
Revision 1.3 2004/08/28 16:21:25 marc
|
||||
mrw-c++-0.92 (mrw)
|
||||
- new file: version.cxx
|
||||
- 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
|
||||
|
||||
*/
|
||||
#include <mrw/auto.hxx>
|
||||
#include <mrw/stdext.hxx> // ifelse
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <fcntl.h> // open
|
||||
#include <string.h> // strncpy
|
||||
#include <stdlib.h> // getenv
|
||||
|
||||
class AutoTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void AutoFile() {
|
||||
char c(0);
|
||||
int i(-1);
|
||||
{
|
||||
mrw::AutoFile a;
|
||||
CPPUNIT_ASSERT(a==-1); // init as -1
|
||||
i = a = open((std::string(mrw::ifelse(getenv("srcdir"), "."))
|
||||
+"/test.dat").c_str(), O_RDONLY);
|
||||
CPPUNIT_ASSERT(i==a && a>0); // file is now open
|
||||
mrw::AutoFile b(a);
|
||||
CPPUNIT_ASSERT(a==-1 && i==b); // b has taken ownership
|
||||
CPPUNIT_ASSERT(read(b, &c, 1)==1 && c=='H'); // file is good
|
||||
mrw::AutoFile cc(i);
|
||||
CPPUNIT_ASSERT(i==b && b==cc); // ooops, two owner!
|
||||
cc.release();
|
||||
CPPUNIT_ASSERT(i==b && cc==-1); // it's ok now
|
||||
b = open("test.dat", O_RDONLY);
|
||||
//close(i);
|
||||
CPPUNIT_ASSERT(read(i, &c, 1)==-1); // old file is closed
|
||||
i = b.reset();
|
||||
CPPUNIT_ASSERT(read(i, &c, 1)==-1); // new file is closed
|
||||
i = a = open("test.dat", O_RDONLY);
|
||||
}
|
||||
CPPUNIT_ASSERT(read(i, &c, 1)==-1); // file is closed now
|
||||
}
|
||||
void AutoFree() {
|
||||
const char C[] = "Hello World";
|
||||
mrw::Auto<char*>::Free c(malloc(sizeof(C)));
|
||||
CPPUNIT_ASSERT(c);
|
||||
strncpy(c, C, sizeof(C));
|
||||
CPPUNIT_ASSERT(std::string(c)==C);
|
||||
mrw::Auto<char*>::Free c2(c.release());
|
||||
CPPUNIT_ASSERT(c==0 && c2!=0);
|
||||
CPPUNIT_ASSERT(std::string(c2)==C);
|
||||
c2.reset();
|
||||
CPPUNIT_ASSERT(c2==0);
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(AutoTest);
|
||||
CPPUNIT_TEST(AutoFile);
|
||||
CPPUNIT_TEST(AutoFree);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(AutoTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#! /bin/bash
|
||||
|
||||
test -z "`diff $srcdir/configfile2.ini $srcdir/configfile.ini.result`" \
|
||||
&& rm configfile2.ini
|
||||
@@ -1,72 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2005/04/07 20:55:21 marc
|
||||
Oops, there's a make distcheck...? Now it works.
|
||||
|
||||
Revision 1.1 2005/01/07 00:31:38 marc
|
||||
initial version
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <mrw/configfile.hxx>
|
||||
#include <mrw/file.hxx>
|
||||
#include <mrw/stdext.hxx> // ifelse
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <stdlib.h> // getenv
|
||||
|
||||
class ConfigFileTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void CheckFile() {
|
||||
std::string srcdir(mrw::ifelse(getenv("srcdir"), "."));
|
||||
mrw::File::copy(srcdir+"/configfile.ini", "configfile2.ini");
|
||||
mrw::ConfigFileWriter config("configfile2.ini");
|
||||
CPPUNIT_ASSERT(config("", "xxx", ".")=="yyy");
|
||||
CPPUNIT_ASSERT(config("Section", "abc", ".")=="");
|
||||
CPPUNIT_ASSERT(config("Section", "def", ".")=="hallo welt");
|
||||
CPPUNIT_ASSERT(config("Section", "ghi", ".")=="");
|
||||
CPPUNIT_ASSERT(config("Section", "jkl", ".")=="mn\n op qr\n st");
|
||||
CPPUNIT_ASSERT(config("Other Section", "1234", ".")=="5678=90");
|
||||
CPPUNIT_ASSERT(config("Other Section", "here we are", ".")
|
||||
=="some contents");
|
||||
CPPUNIT_ASSERT(config("Other Section", "here", ".")=="");
|
||||
config("", "xxx", ".")="0";
|
||||
config("Section", "abc", ".")="1";
|
||||
CPPUNIT_ASSERT(config("New Section", "a first one", "sgadd")=="sgadd");
|
||||
config("Section", "def", ".")="Und=Tschuess";
|
||||
config("Section", "ghi", ".")="3";
|
||||
config("Section", "jkl", ".")="4";
|
||||
config("Other Section", "1234", ".")="5";
|
||||
config("Other Section", "here we are", ".")="6";
|
||||
config("Other Section", "here", ".")="7";
|
||||
CPPUNIT_ASSERT(config("Other Section", "no no", ".")==".");
|
||||
CPPUNIT_ASSERT(config("Other Section", "no no no", ".")==".");
|
||||
CPPUNIT_ASSERT(config("Other Section", "yes", ".")==".");
|
||||
CPPUNIT_ASSERT(config("Section", "guguseli", "dadaa")=="dadaa");
|
||||
CPPUNIT_ASSERT(config("Section", "guguseli zwei", "dadaa")=="dadaa");
|
||||
CPPUNIT_ASSERT(config("Section", "guguseli drei", "dadaa")=="dadaa");
|
||||
CPPUNIT_ASSERT(config("New Section", "one more", ".")==".");
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(ConfigFileTest);
|
||||
CPPUNIT_TEST(CheckFile);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(ConfigFileTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.1 2005/02/18 15:53:56 marc
|
||||
initial release
|
||||
|
||||
|
||||
1 2 3 4 5 6 7 8
|
||||
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
*/
|
||||
|
||||
#include <mrw/dynamiclibrary.hxx>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
class DynamicLibraryTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void Load() {
|
||||
mrw::DynamicLibrary lib("libdynamiclibrary_testlib");
|
||||
int(*test1)(int) = (int(*)(int))lib.symbol("test1");
|
||||
CPPUNIT_ASSERT((*test1)(2)==4);
|
||||
}
|
||||
void LoadError() {
|
||||
mrw::DynamicLibrary lib("DASist-Sicher_Keine_DynamischePHIPLIOTEEK!!!");
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(DynamicLibraryTest);
|
||||
CPPUNIT_TEST(Load);
|
||||
CPPUNIT_TEST_EXCEPTION(LoadError, mrw::DynamicLibrary::failure);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(DynamicLibraryTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.1 2005/02/18 15:53:55 marc
|
||||
initial release
|
||||
|
||||
|
||||
1 2 3 4 5 6 7 8
|
||||
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
int test1(int i) {
|
||||
return i*i;
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.9 2005/04/19 18:48:00 marc
|
||||
new feature PartialExec
|
||||
|
||||
Revision 1.8 2005/04/07 20:55:21 marc
|
||||
Oops, there's a make distcheck...? Now it works.
|
||||
|
||||
Revision 1.7 2004/12/20 13:21:21 marc
|
||||
exception tests: each exception must be in an own test case
|
||||
|
||||
Revision 1.6 2004/12/14 20:30:10 marc
|
||||
added possibility to pass string to stdin of child process
|
||||
|
||||
Revision 1.5 2004/10/13 10:43:11 marc
|
||||
test for bad exception specification
|
||||
|
||||
Revision 1.4 2004/08/28 16:21:25 marc
|
||||
mrw-c++-0.92 (mrw)
|
||||
- new file: version.cxx
|
||||
- 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
|
||||
|
||||
*/
|
||||
#include <mrw/exec.hxx>
|
||||
#include <mrw/stacktrace.hxx>
|
||||
#include <mrw/stdext.hxx>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#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();
|
||||
while (!exec.finished()) res+=exec.read().first;
|
||||
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;
|
||||
exec.finish();
|
||||
while (!exec.finished()) res+=exec.read().first;
|
||||
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();
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(ExecTest);
|
||||
CPPUNIT_TEST(lsTest);
|
||||
CPPUNIT_TEST(catTest);
|
||||
CPPUNIT_TEST_EXCEPTION(excTest1, mrw::ExecutionFailedExc);
|
||||
CPPUNIT_TEST_EXCEPTION(excTest2, mrw::ExecutionFailedExc);
|
||||
CPPUNIT_TEST_EXCEPTION(unexpectedExc, std::bad_exception);
|
||||
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);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(ExecTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.3 2005/04/07 20:55:21 marc
|
||||
Oops, there's a make distcheck...? Now it works.
|
||||
|
||||
Revision 1.2 2005/03/11 23:18:02 marc
|
||||
bugfix: linenumbers change at checkin...
|
||||
|
||||
Revision 1.1 2005/03/11 21:07:55 marc
|
||||
initial version
|
||||
|
||||
|
||||
1 2 3 4 5 6 7 8
|
||||
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
*/
|
||||
|
||||
#include <mrw/functiontrace.hxx>
|
||||
#include <mrw/regexp.hxx>
|
||||
#include <mrw/file.hxx>
|
||||
#include <log4cxx/propertyconfigurator.h>
|
||||
#include <log4cxx/helpers/properties.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
class A {
|
||||
public:
|
||||
A() {
|
||||
MRW_METHOD("A::A()");
|
||||
}
|
||||
~A() {
|
||||
MRW_METHOD("A::~A()");
|
||||
}
|
||||
void fn1() {
|
||||
MRW_METHOD("A::fn1()");
|
||||
fn2();
|
||||
}
|
||||
void fn2() {
|
||||
MRW_METHOD("A::fn2()");
|
||||
fn3();
|
||||
fn4();
|
||||
}
|
||||
void fn3() {
|
||||
MRW_METHOD("A::fn3()");
|
||||
fn4();
|
||||
}
|
||||
void fn4(bool flag=true) {
|
||||
MRW_METHOD("A::fn4()");
|
||||
if (flag) fn4(false);
|
||||
}
|
||||
};
|
||||
|
||||
void fn(A a) {
|
||||
MRW_FUNCTION("fn(A)");
|
||||
a.fn1();
|
||||
}
|
||||
|
||||
class FunctionTraceTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void Init() {
|
||||
try {mrw::File::remove("functiontrace_test.log");} catch (...) {}
|
||||
log4cxx::helpers::Properties properties;
|
||||
std::string name, cont;
|
||||
properties.setProperty((name="log4j.rootLogger",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="DEBUG, A1",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.appender.A1",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="org.apache.log4j.FileAppender",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.appender.A1.layout",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="org.apache.log4j.PatternLayout",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="%F:%L - %m%n",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.appender.A1.filename",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="functiontrace_test.log",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
log4cxx::PropertyConfigurator::configure(properties);
|
||||
}
|
||||
void Calls() {
|
||||
fn(A());
|
||||
mrw::RegExp match
|
||||
(".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::A\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::A\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - \\\\ fn\\(A\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn1\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn2\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn3\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn4\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn4\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn4\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn4\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn3\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn4\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn4\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn4\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn4\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn2\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn1\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - / fn\\(A\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::~A\\(\\)\n"
|
||||
".*functiontrace_test.cxx:[0-9]+ - *0x[0-9a-fA-F]+: / A::~A\\(\\)\n");
|
||||
CPPUNIT_ASSERT(match(mrw::File::read("functiontrace_test.log")));
|
||||
mrw::File::remove("functiontrace_test.log");
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(FunctionTraceTest);
|
||||
CPPUNIT_TEST(Init);
|
||||
CPPUNIT_TEST(Calls);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(FunctionTraceTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.3 2005/11/29 12:39:42 marc
|
||||
make it compilable with gcc 4.0.2 and newer doxygen
|
||||
|
||||
Revision 1.2 2005/04/07 20:42:38 marc
|
||||
renamed loggerhierarchy from mrw.gccfunctiontrace to mrw.fn
|
||||
|
||||
Revision 1.1 2005/03/11 21:07:55 marc
|
||||
initial version
|
||||
|
||||
|
||||
1 2 3 4 5 6 7 8
|
||||
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
*/
|
||||
|
||||
#include <log4cxx/propertyconfigurator.h>
|
||||
#include <log4cxx/helpers/properties.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <mrw/file.hxx>
|
||||
#include <mrw/regexp.hxx>
|
||||
#include <mrw/string.hxx>
|
||||
#include <mrw/stacktrace.hxx>
|
||||
#include <map>
|
||||
|
||||
#if (__GNUC__==3 && __GNUC_MINOR__<4 || __GNUC__<3) \
|
||||
&& defined(_REENTRANT) && !defined(_MT)
|
||||
#define _MT
|
||||
#endif
|
||||
|
||||
namespace HalloWelt {
|
||||
|
||||
class A {
|
||||
public:
|
||||
void method() {
|
||||
}
|
||||
};
|
||||
|
||||
void fn(int) {
|
||||
A().method();
|
||||
A().method();
|
||||
}
|
||||
|
||||
void fn1() {
|
||||
fn(1);
|
||||
fn(2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void anotherFunction() {
|
||||
HalloWelt::fn1();
|
||||
}
|
||||
|
||||
#ifdef _MT
|
||||
#include <boost/thread/thread.hxx>
|
||||
//#include <unistd.h> // sleep, the one from boost::thread does not work!
|
||||
class Thread {
|
||||
public:
|
||||
void operator()() {
|
||||
anotherFunction();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace mrw {
|
||||
class AutoFunctionTraceLog4CxxTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void testcase() {
|
||||
mrw::StackTrace::createSymtable();
|
||||
#ifdef _MT
|
||||
try {mrw::File::remove("mrwautofunctiontracelog4cxx_test-mt.log");}
|
||||
#else
|
||||
try {mrw::File::remove("mrwautofunctiontracelog4cxx_test.log");}
|
||||
#endif
|
||||
catch (...) {}
|
||||
log4cxx::helpers::Properties properties;
|
||||
std::string name, cont;
|
||||
properties.setProperty((name="log4j.rootLogger",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF, A1",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="DEBUG",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.global",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.allocator",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.std.*",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.log4cxx",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.boost",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.Thread",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.mrw",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.std",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.new",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.CppUnit",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.logger.mrw.fn.__gnu_cxx",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="OFF",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.appender.A1",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="org.apache.log4j.FileAppender",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.appender.A1.layout",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="org.apache.log4j.PatternLayout",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
#ifdef _MT
|
||||
properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="%t-%-27c%m%n",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.appender.A1.filename",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="mrwautofunctiontracelog4cxx_test-mt.log",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
#else
|
||||
properties.setProperty((name="log4j.appender.A1.layout.ConversionPattern",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="%-27c%m%n",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
properties.setProperty((name="log4j.appender.A1.filename",
|
||||
log4cxx::String(name.begin(), name.end())),
|
||||
(cont="mrwautofunctiontracelog4cxx_test.log",
|
||||
log4cxx::String(cont.begin(), cont.end())));
|
||||
#endif
|
||||
log4cxx::PropertyConfigurator::configure(properties);
|
||||
#ifdef _MT
|
||||
// sleep(4); // to be reproducable, wait for "main" flag
|
||||
Thread threadFunction;
|
||||
boost::thread::thread thread1(threadFunction);
|
||||
boost::thread::thread thread2(threadFunction);
|
||||
boost::thread::thread thread3(threadFunction);
|
||||
#endif
|
||||
anotherFunction();
|
||||
#ifdef _MT
|
||||
thread1.join();
|
||||
thread2.join();
|
||||
thread3.join();
|
||||
#endif
|
||||
}
|
||||
void checkfile() {
|
||||
mrw::RegExp match
|
||||
("^mrw\\.fn\\.anotherFunction ( ? ? ?)\\\\ anotherFunction\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.fn1 \\1 \\\\ HalloWelt::fn1\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.fn \\1 \\\\ HalloWelt::fn\\(int\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.A\\.method \\1 \\\\ HalloWelt::A::method\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.A\\.method \\1 / HalloWelt::A::method\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.A\\.method \\1 \\\\ HalloWelt::A::method\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.A\\.method \\1 / HalloWelt::A::method\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.fn \\1 / HalloWelt::fn\\(int\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.fn \\1 \\\\ HalloWelt::fn\\(int\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.A\\.method \\1 \\\\ HalloWelt::A::method\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.A\\.method \\1 / HalloWelt::A::method\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.A\\.method \\1 \\\\ HalloWelt::A::method\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.A\\.method \\1 / HalloWelt::A::method\\(\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.fn \\1 / HalloWelt::fn\\(int\\)\n"
|
||||
"mrw\\.fn\\.HalloWelt\\.fn1 \\1 / HalloWelt::fn1\\(\\)\n"
|
||||
"mrw\\.fn\\.anotherFunction \\1/ anotherFunction\\(\\)\n$");
|
||||
#ifdef _MT
|
||||
std::string log(mrw::File::read("mrwautofunctiontracelog4cxx_test-mt.log"));
|
||||
typedef std::map<unsigned long, std::string> Logs;
|
||||
Logs logs;
|
||||
for (std::string::size_type pos(0), last(0);
|
||||
(pos=log.find('\n', pos+1))!=std::string::npos; last=pos) {
|
||||
std::string::size_type dash(log.find('-', last));
|
||||
CPPUNIT_ASSERT_MESSAGE("\"-\" not found",
|
||||
dash!=std::string::npos);
|
||||
logs[mrw::to<unsigned long>(log.substr(last, dash-last))] +=
|
||||
log.substr(dash+1, pos-dash);
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL((Logs::size_type)4, logs.size()); // 4 threads
|
||||
for (Logs::iterator it(logs.begin()); it!=logs.end(); ++it)
|
||||
CPPUNIT_ASSERT_MESSAGE("The following text does not match the "
|
||||
"Expectation:\n--------------------\n"
|
||||
+it->second+"--------------------",
|
||||
match(it->second));
|
||||
mrw::File::remove("mrwautofunctiontracelog4cxx_test-mt.log");
|
||||
#else
|
||||
CPPUNIT_ASSERT_MESSAGE
|
||||
("The following text does not match the "
|
||||
"Expectation:\n--------------------\n"
|
||||
+mrw::File::read("mrwautofunctiontracelog4cxx_test.log")
|
||||
+"--------------------",
|
||||
match(mrw::File::read("mrwautofunctiontracelog4cxx_test.log")));
|
||||
mrw::File::remove("mrwautofunctiontracelog4cxx_test.log");
|
||||
#endif
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(AutoFunctionTraceLog4CxxTest);
|
||||
CPPUNIT_TEST(testcase);
|
||||
CPPUNIT_TEST(checkfile);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(AutoFunctionTraceLog4CxxTest);
|
||||
}
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2004/08/28 16:21:25 marc
|
||||
mrw-c++-0.92 (mrw)
|
||||
- new file: version.cxx
|
||||
- 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
|
||||
|
||||
*/
|
||||
#include <mrw/exception.hxx>
|
||||
#include <log4cxx/basicconfigurator.h>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
namespace mrw {
|
||||
class AutoExcLog4CxxTest: public CppUnit::TestFixture {
|
||||
private:
|
||||
bool enter_unexpectedThrow;
|
||||
bool exit_unexpectedThrow;
|
||||
bool enter_passUnexpected;
|
||||
bool exit_passUnexpected;
|
||||
bool enter_catchUnexpected;
|
||||
bool exit_catchUnexpected;
|
||||
public:
|
||||
void setUp() {
|
||||
enter_unexpectedThrow = false;
|
||||
exit_unexpectedThrow = false;
|
||||
enter_passUnexpected = false;
|
||||
exit_passUnexpected = false;
|
||||
enter_catchUnexpected = false;
|
||||
exit_catchUnexpected = false;
|
||||
}
|
||||
void unexpectedThrow() throw(std::bad_exception) {
|
||||
enter_unexpectedThrow = true;
|
||||
throw mrw::exception();
|
||||
exit_unexpectedThrow = true;
|
||||
}
|
||||
void passUnexpected() throw(std::bad_exception) {
|
||||
enter_passUnexpected = true;
|
||||
unexpectedThrow();
|
||||
exit_passUnexpected = true;
|
||||
}
|
||||
void catchUnexpected() throw() {
|
||||
enter_catchUnexpected = true;
|
||||
bool caught(false);
|
||||
try {
|
||||
passUnexpected();
|
||||
} catch (std::bad_exception&) {
|
||||
caught = true;
|
||||
}
|
||||
CPPUNIT_ASSERT(caught);
|
||||
exit_catchUnexpected = true;
|
||||
}
|
||||
void testcase() {
|
||||
catchUnexpected();
|
||||
CPPUNIT_ASSERT(enter_catchUnexpected &&
|
||||
enter_passUnexpected &&
|
||||
enter_unexpectedThrow &&
|
||||
exit_catchUnexpected &&
|
||||
!exit_passUnexpected &&
|
||||
!exit_unexpectedThrow);
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(AutoExcLog4CxxTest);
|
||||
CPPUNIT_TEST(testcase);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(AutoExcLog4CxxTest);
|
||||
}
|
||||
|
||||
int main() {
|
||||
log4cxx::BasicConfigurator::configure();
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2004/08/28 16:21:25 marc
|
||||
mrw-c++-0.92 (mrw)
|
||||
- new file: version.cxx
|
||||
- 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
|
||||
|
||||
*/
|
||||
#include <mrw/exception.hxx>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
namespace mrw {
|
||||
class AutoExcStderrTest: public CppUnit::TestFixture {
|
||||
private:
|
||||
bool enter_unexpectedThrow;
|
||||
bool exit_unexpectedThrow;
|
||||
bool enter_passUnexpected;
|
||||
bool exit_passUnexpected;
|
||||
bool enter_catchUnexpected;
|
||||
bool exit_catchUnexpected;
|
||||
public:
|
||||
void setUp() {
|
||||
enter_unexpectedThrow = false;
|
||||
exit_unexpectedThrow = false;
|
||||
enter_passUnexpected = false;
|
||||
exit_passUnexpected = false;
|
||||
enter_catchUnexpected = false;
|
||||
exit_catchUnexpected = false;
|
||||
}
|
||||
void unexpectedThrow() throw(std::bad_exception) {
|
||||
enter_unexpectedThrow = true;
|
||||
throw mrw::exception();
|
||||
exit_unexpectedThrow = true;
|
||||
}
|
||||
void passUnexpected() throw(std::bad_exception) {
|
||||
enter_passUnexpected = true;
|
||||
unexpectedThrow();
|
||||
exit_passUnexpected = true;
|
||||
}
|
||||
void catchUnexpected() throw() {
|
||||
enter_catchUnexpected = true;
|
||||
bool caught(false);
|
||||
try {
|
||||
passUnexpected();
|
||||
} catch (std::bad_exception&) {
|
||||
caught = true;
|
||||
}
|
||||
CPPUNIT_ASSERT(caught);
|
||||
exit_catchUnexpected = true;
|
||||
}
|
||||
void testcase() {
|
||||
catchUnexpected();
|
||||
CPPUNIT_ASSERT(enter_catchUnexpected &&
|
||||
enter_passUnexpected &&
|
||||
enter_unexpectedThrow &&
|
||||
exit_catchUnexpected &&
|
||||
!exit_passUnexpected &&
|
||||
!exit_unexpectedThrow);
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(AutoExcStderrTest);
|
||||
CPPUNIT_TEST(testcase);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(AutoExcStderrTest);
|
||||
}
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2004/12/16 13:09:31 marc
|
||||
possibility to evaluate and extract sub expressions
|
||||
|
||||
Revision 1.1 2004/12/14 20:20:30 marc
|
||||
initial version
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <mrw/regexp.hxx>
|
||||
#include <mrw/exception.hxx>
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
class RegExpTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void CheckRegExp() {
|
||||
mrw::RegExp findHalloWelt("^Hallo.*Welt$");
|
||||
CPPUNIT_ASSERT(findHalloWelt("Hallo Meine Welt"));
|
||||
CPPUNIT_ASSERT(!findHalloWelt("xxx"));
|
||||
CPPUNIT_ASSERT(!findHalloWelt(""));
|
||||
CPPUNIT_ASSERT(!findHalloWelt(" Hallo Welt "));
|
||||
CPPUNIT_ASSERT(findHalloWelt("HalloWelt"));
|
||||
mrw::RegExp extractTest("^Guten (.*) (Herr|Frau) (.*)$", true);
|
||||
CPPUNIT_ASSERT(extractTest("Guten Tag Frau Zuercher"));
|
||||
CPPUNIT_ASSERT(extractTest[1]=="Tag" &&
|
||||
extractTest[2]=="Frau" &&
|
||||
extractTest[3]=="Zuercher");
|
||||
}
|
||||
void ExceptionTest() {
|
||||
mrw::RegExp extractTest("^Guten (.*) (Herr|Frau) (.*)$", true);
|
||||
CPPUNIT_ASSERT(extractTest("Guten Tag Herr Schweizer"));
|
||||
CPPUNIT_ASSERT(extractTest[1]=="Tag" &&
|
||||
extractTest[2]=="Herr" &&
|
||||
extractTest[3]=="Schweizer");
|
||||
std::string s = extractTest[4];
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(RegExpTest);
|
||||
CPPUNIT_TEST(CheckRegExp);
|
||||
CPPUNIT_TEST_EXCEPTION(ExceptionTest, mrw::invalid_argument);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(RegExpTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.1 2004/08/28 16:13:42 marc
|
||||
mrw-c++-0.92 (mrw)
|
||||
- new file: version.cxx
|
||||
- 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
|
||||
|
||||
*/
|
||||
#include <mrw/smartpointer.hxx>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <string>
|
||||
|
||||
class Content {
|
||||
private:
|
||||
int& _drop;
|
||||
Content();
|
||||
public:
|
||||
Content(int& drop): _drop(drop) {}
|
||||
virtual ~Content() {++_drop;}
|
||||
};
|
||||
class A: public Content {public: A(int& d): Content(d) {} virtual void fn() {}};
|
||||
class B: public A {public: B(int& d): A(d) {}};
|
||||
class C: public A {public: C(int& d): A(d) {}};
|
||||
class SmartPointerTest:
|
||||
public mrw::SmartPointerParent, public CppUnit::TestFixture {
|
||||
public:
|
||||
void SimpleConstructor() {
|
||||
mrw::SmartPointer<Content> p1;
|
||||
CPPUNIT_ASSERT(!(getPointer(p1) || getCounter(p1)));
|
||||
}
|
||||
void CopyConstructor() {
|
||||
mrw::SmartPointer<Content> p1;
|
||||
mrw::SmartPointer<Content> p2(p1);
|
||||
CPPUNIT_ASSERT(!(getPointer(p1) || getCounter(p1) ||
|
||||
getPointer(p2) || getCounter(p2)));
|
||||
}
|
||||
void PointerConstructor() {
|
||||
int drops(0);
|
||||
mrw::SmartPointer<Content> p1(0);
|
||||
mrw::SmartPointer<Content> p2(new Content(drops));
|
||||
CPPUNIT_ASSERT(!(getPointer(p1) || getCounter(p1) ||
|
||||
drops!=0 || !getPointer(p2) || !getCounter(p2) ||
|
||||
getCounter(p2)->get()!=1));
|
||||
}
|
||||
void CastConstructor() {
|
||||
int drops1(0);
|
||||
mrw::SmartPointer<A> pa(new B(drops1));
|
||||
mrw::SmartPointer<B> pb(pa);
|
||||
mrw::SmartPointer<C> pc(pa);
|
||||
mrw::SmartPointer<A> pa2(pb);
|
||||
CPPUNIT_ASSERT(!(drops1!=0 || !getPointer(pa) || !getCounter(pa) ||
|
||||
getPointer(pb)!=getPointer(pa) ||
|
||||
getCounter(pb)!=getCounter(pa) ||
|
||||
getPointer(pc) || getCounter(pc) ||
|
||||
getCounter(pa)->get()!=3 ||
|
||||
getPointer(pa2)!=getPointer(pa) ||
|
||||
getCounter(pa2)!=getCounter(pa)));
|
||||
}
|
||||
void Destructor() {
|
||||
int drops(0);
|
||||
mrw::SmartPointer<Content>* p1 =
|
||||
new mrw::SmartPointer<Content>(new Content(drops));
|
||||
delete p1;
|
||||
CPPUNIT_ASSERT(!(drops!=1));
|
||||
}
|
||||
void CopyAssign() {
|
||||
int drops1(0);
|
||||
int drops2(0);
|
||||
mrw::SmartPointer<Content> p1(new Content(drops1));
|
||||
mrw::SmartPointer<Content> p2(new Content(drops2));
|
||||
p2 = p1;
|
||||
p1 = p2;
|
||||
CPPUNIT_ASSERT(!(drops1!=0 || !getPointer(p1) || !getCounter(p1) ||
|
||||
getCounter(p1)->get()!=2 ||
|
||||
getPointer(p1)!=getPointer(p2) ||
|
||||
drops2!=1 || !getPointer(p2) || !getCounter(p2) ||
|
||||
getCounter(p2)->get()!=2 ||
|
||||
getCounter(p1)!=getCounter(p2)));
|
||||
}
|
||||
void PointerAssign() {
|
||||
int drops1(0);
|
||||
int drops2(0);
|
||||
int drops3(0);
|
||||
mrw::SmartPointer<Content> p1(new Content(drops1));
|
||||
mrw::SmartPointer<Content> p2(0);
|
||||
p1 = new Content(drops2);
|
||||
p1 = 0;
|
||||
p2 = new Content(drops3);
|
||||
CPPUNIT_ASSERT(!(drops1!=1 || getPointer(p1) || getCounter(p1) ||
|
||||
drops2!=1 || !getPointer(p2) || !getCounter(p2) ||
|
||||
drops3!=0 || getCounter(p2)->get()!=1));
|
||||
}
|
||||
void CastAssign() {
|
||||
int drops1(0);
|
||||
int drops2(0);
|
||||
int drops3(0);
|
||||
mrw::SmartPointer<A> pa(new B(drops1));
|
||||
mrw::SmartPointer<B> pb(new B(drops2));
|
||||
mrw::SmartPointer<C> pc(new C(drops3));
|
||||
pa = pa;
|
||||
pa = pb;
|
||||
pa = pc;
|
||||
pb = pa;
|
||||
pc = pa;
|
||||
CPPUNIT_ASSERT(!(drops1!=1 || drops2!=1 || drops3!=0 ||
|
||||
!getPointer(pa) || getPointer(pa)!=getPointer(pc) ||
|
||||
!getCounter(pa) || getCounter(pa)!=getCounter(pc) ||
|
||||
getCounter(pa)->get()!=2 || getPointer(pb) ||
|
||||
getCounter(pb)));
|
||||
}
|
||||
void PointerAccess() {
|
||||
mrw::SmartPointer<std::string> p1(new std::string);
|
||||
mrw::SmartPointer<std::string> p2;
|
||||
*p1 = "Hallo Welt!";
|
||||
CPPUNIT_ASSERT(!(p1.operator->()!=&*p1 || p1->find("Welt")!=6 ||
|
||||
p2.operator->()));
|
||||
}
|
||||
void OperatorBool() {
|
||||
mrw::SmartPointer<std::string> p1(new std::string);
|
||||
mrw::SmartPointer<std::string> p2;
|
||||
CPPUNIT_ASSERT(!(!p1 || p2));
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(SmartPointerTest);
|
||||
CPPUNIT_TEST(SimpleConstructor);
|
||||
CPPUNIT_TEST(CopyConstructor);
|
||||
CPPUNIT_TEST(PointerConstructor);
|
||||
CPPUNIT_TEST(CastConstructor);
|
||||
CPPUNIT_TEST(Destructor);
|
||||
CPPUNIT_TEST(CopyAssign);
|
||||
CPPUNIT_TEST(PointerAssign);
|
||||
CPPUNIT_TEST(CastAssign);
|
||||
CPPUNIT_TEST(PointerAccess);
|
||||
CPPUNIT_TEST(OperatorBool);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(SmartPointerTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
1 2 3 4 5 6 7 8
|
||||
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
*/
|
||||
|
||||
#include <mrw/stacktrace.hxx>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
namespace mrw {
|
||||
class StackTraceTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
/// test if symbols are correctely evaluated
|
||||
void StackTrace() {
|
||||
bool init(mrw::StackTrace::createSymtable());
|
||||
CPPUNIT_ASSERT_MESSAGE("createSymtable() failed! ERROR="
|
||||
+mrw::StackTrace::error(),
|
||||
init
|
||||
||
|
||||
mrw::StackTrace::error().find("/valgrind/")
|
||||
!=std::string::npos);
|
||||
mrw::StackTrace s; int l(__LINE__); std::string f(__FILE__);
|
||||
std::stringstream ss;
|
||||
ss<<f<<':'<<l;
|
||||
std::string st(s);
|
||||
mrw::StackTrace::BinFiles files(mrw::StackTrace::filename());
|
||||
std::string msg("----------------------------------------\n"
|
||||
"Stacktrace:\n-----------\n"+st+
|
||||
"Files:\n------\n");
|
||||
for (mrw::StackTrace::BinFiles::iterator it(files.begin());
|
||||
it!=files.end(); ++it)
|
||||
msg += " - \""+it->first+"\"\n";
|
||||
msg += "----------------------------------------\n";
|
||||
std::string::size_type pos(st.find("mrw::StackTraceTest::StackTrace()"));
|
||||
CPPUNIT_ASSERT_MESSAGE("\"mrw::StackTraceTest::StackTrace()\""
|
||||
" not found!\n"+msg, pos!=std::string::npos);
|
||||
CPPUNIT_ASSERT_MESSAGE('"'+ss.str()+"\" not found!\n"+msg,
|
||||
st.find(ss.str(), pos) < st.size());
|
||||
CPPUNIT_ASSERT_MESSAGE("\"CppUnit::TestCaller<mrw::StackTraceTest>"
|
||||
"::runTest()\" not found!\n"+msg,
|
||||
st.find("CppUnit::TestCaller<mrw::StackTraceTest>"
|
||||
"::runTest()")<st.size());
|
||||
// The following test case does not work any more!
|
||||
// Probable reason: The library has been stripped:
|
||||
// > nm /usr/lib/libcppunit-1.10.so.2.0.0
|
||||
// nm: /usr/lib/libcppunit-1.10.so.2.0.0: no symbols
|
||||
// > file /usr/lib/libcppunit-1.10.so.2.0.0
|
||||
// /usr/lib/libcppunit-1.10.so.2.0.0:
|
||||
// ELF 32-bit LSB shared object, Intel 80386,
|
||||
// version 1 (SYSV), stripped
|
||||
//CPPUNIT_ASSERT_MESSAGE("\"CppUnit::TestCase::run\" not found!\n"+msg,
|
||||
// st.find("CppUnit::TestCase::run")<st.size());
|
||||
// The folowing test is probably wrong, because the syntax should be
|
||||
// different:
|
||||
// "???? ????:0"
|
||||
// Anyway, with the problem of stripped libraries, as above, it doesn't
|
||||
// pass anymore, if it is tested correctly...
|
||||
//CPPUNIT_ASSERT_MESSAGE("\"????:0 ????\" should not be in stack!\n"+msg,
|
||||
// st.find("????:0 ????")>=st.size());
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(StackTraceTest);
|
||||
CPPUNIT_TEST(StackTrace);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(StackTraceTest);
|
||||
}
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.3 2004/12/20 13:23:00 marc
|
||||
new tests for string exceptions
|
||||
|
||||
Revision 1.2 2004/10/13 11:19:22 marc
|
||||
remove stdout, print stack trace
|
||||
|
||||
Revision 1.1 2004/10/07 09:31:30 marc
|
||||
new feature
|
||||
|
||||
|
||||
*/
|
||||
#include <mrw/string.hxx>
|
||||
#include <mrw/list.hxx>
|
||||
#include <mrw/vector.hxx>
|
||||
#include <mrw/deque.hxx>
|
||||
#include <mrw/set.hxx>
|
||||
#include <mrw/map.hxx>
|
||||
#include <mrw/multiset.hxx>
|
||||
#include <mrw/multimap.hxx>
|
||||
#include <mrw/stacktrace.hxx>
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
class StdExtTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void StringConv() {
|
||||
std::string s("Integer=");
|
||||
int i(4);
|
||||
CPPUNIT_ASSERT(s+mrw::string(i) == "Integer=4");
|
||||
}
|
||||
void StringShift() {
|
||||
std::string s("Integer=");
|
||||
int i(4);
|
||||
CPPUNIT_ASSERT((s<<i<<" test "<<4<<(long)5<<" xx") == "Integer=4 test 45 xx");
|
||||
int i2 = 0;
|
||||
std::string s2, s3;
|
||||
s>>s2>>s3>>i2;
|
||||
CPPUNIT_ASSERT(s2=="Integer=4");
|
||||
CPPUNIT_ASSERT(s3=="test");
|
||||
CPPUNIT_ASSERT(i2==45);
|
||||
CPPUNIT_ASSERT(s==" xx");
|
||||
s2=""; s3="";
|
||||
s>>s2;
|
||||
CPPUNIT_ASSERT(s2=="xx");
|
||||
CPPUNIT_ASSERT(s=="");
|
||||
}
|
||||
void StringAdd() {
|
||||
std::string s;
|
||||
s=s+(signed short)1+(signed int)2+(signed long)3+(signed char)'A'+
|
||||
(unsigned short)1+(unsigned int)2+(unsigned long)3+(unsigned char)'A'+'c';
|
||||
CPPUNIT_ASSERT(s=="1236512365c");
|
||||
s=(signed short)-4+s;
|
||||
s=(signed int)5+s;
|
||||
s=(signed long)6+s;
|
||||
s=(signed char)8+s;
|
||||
s=(unsigned short)4+s;
|
||||
s=(unsigned int)5+s;
|
||||
s=(unsigned long)6+s;
|
||||
s=(unsigned char)8+s;
|
||||
s='a'+s;
|
||||
CPPUNIT_ASSERT(s=="a8654865-41236512365c");
|
||||
s+=(signed short)-4;
|
||||
s+=(signed int)5 ;
|
||||
s+=(signed long)6;
|
||||
s+=(signed char)8 ;
|
||||
s+=(unsigned short)4;
|
||||
s+=(unsigned int)5 ;
|
||||
s+=(unsigned long)6;
|
||||
s+=(unsigned char)8 ;
|
||||
s+='a';
|
||||
CPPUNIT_ASSERT(s=="a8654865-41236512365c-45684568a");
|
||||
}
|
||||
void ListShift() {
|
||||
std::list<int> l;
|
||||
l<<1<<2<<3<<4<<5<<6<<7<<8;
|
||||
int i1(0), i2(0), i3(0), i4(0);
|
||||
l>>i1>>i2>>i3>>i4;
|
||||
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||
CPPUNIT_ASSERT(l.size()==4);
|
||||
for (int i=0; i<4; (l.pop_front(), ++i)) {
|
||||
CPPUNIT_ASSERT(l.front()==i+5);
|
||||
}
|
||||
bool exc(false);
|
||||
try {
|
||||
l>>i1;
|
||||
} catch (mrw::length_error&) {
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
}
|
||||
void VectorShift() {
|
||||
std::vector<int> l;
|
||||
l<<1<<2<<3<<4<<5<<6<<7<<8;
|
||||
int i1(0), i2(0), i3(0), i4(0);
|
||||
l>>i1>>i2>>i3>>i4;
|
||||
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||
CPPUNIT_ASSERT(l.size()==4);
|
||||
for (int i=0; i<4; (l.erase(l.begin()), ++i)) {
|
||||
CPPUNIT_ASSERT(l.front()==i+5);
|
||||
}
|
||||
bool exc(false);
|
||||
try {
|
||||
l>>i1;
|
||||
} catch (mrw::length_error&) {
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
}
|
||||
void DequeShift() {
|
||||
std::deque<int> l;
|
||||
l<<1<<2<<3<<4<<5<<6<<7<<8;
|
||||
int i1(0), i2(0), i3(0), i4(0);
|
||||
l>>i1>>i2>>i3>>i4;
|
||||
// now: i1==1 i2==2 i3==3 i4==4 l=={5, 6, 7, 8}
|
||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||
CPPUNIT_ASSERT(l.size()==4);
|
||||
for (int i=0; i<4; (l.erase(l.begin()), ++i)) {
|
||||
CPPUNIT_ASSERT(l.front()==i+5);
|
||||
}
|
||||
bool exc(false);
|
||||
try {
|
||||
l>>i1;
|
||||
} catch (mrw::length_error&) {
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
}
|
||||
void SetShift() {
|
||||
std::set<int> s;
|
||||
bool exc(false);
|
||||
try {
|
||||
s<<1<<2<<3<<4<<5<<6<<7<<8<<8;
|
||||
} catch (mrw::invalid_argument& e) {
|
||||
mrw::StackTrace::createSymtable();
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
int i1(0), i2(0), i3(0), i4(0);
|
||||
s>>i1>>i2>>i3>>i4;
|
||||
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||
CPPUNIT_ASSERT(s.size()==4);
|
||||
for (int i=0; i<4; ++i) {
|
||||
CPPUNIT_ASSERT(s.find(i+5)!=s.end());
|
||||
}
|
||||
s.erase(s.begin(), s.end());
|
||||
exc=false;
|
||||
try {
|
||||
s>>i1;
|
||||
} catch (mrw::length_error&) {
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
}
|
||||
void MapShift() {
|
||||
std::map<int, std::string> s;
|
||||
bool exc(false);
|
||||
try {
|
||||
s<<std::make_pair(1, std::string("one"))
|
||||
<<std::make_pair(2, std::string("two"))
|
||||
<<std::make_pair(2, std::string("two"));
|
||||
} catch (mrw::invalid_argument& e) {
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
std::pair<int, std::string> i1, i2;
|
||||
s>>i1>>i2;
|
||||
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
||||
CPPUNIT_ASSERT(i1==std::make_pair(1, std::string("one")) &&
|
||||
i2==std::make_pair(2, std::string("two")));
|
||||
CPPUNIT_ASSERT(s.size()==0);
|
||||
exc=false;
|
||||
try {
|
||||
s>>i1;
|
||||
} catch (mrw::length_error&) {
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
}
|
||||
void MultisetShift() {
|
||||
std::multiset<int> s;
|
||||
s<<1<<2<<3<<4<<5<<6<<7<<8<<9;
|
||||
int i1(0), i2(0), i3(0), i4(0);
|
||||
s>>i1>>i2>>i3>>i4;
|
||||
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
||||
CPPUNIT_ASSERT(i1==1 && i2==2 && i3==3 && i4==4);
|
||||
CPPUNIT_ASSERT(s.size()==5);
|
||||
for (int i=0; i<5; ++i) {
|
||||
CPPUNIT_ASSERT(s.find(i+5)!=s.end());
|
||||
}
|
||||
s.erase(s.begin(), s.end());
|
||||
bool exc(false);
|
||||
try {
|
||||
s>>i1;
|
||||
} catch (mrw::length_error&) {
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
}
|
||||
void MultimapShift() {
|
||||
std::multimap<int, std::string> s;
|
||||
s<<std::make_pair(1, std::string("one"))
|
||||
<<std::make_pair(2, std::string("two"))
|
||||
<<std::make_pair(2, std::string("two"));
|
||||
std::pair<int, std::string> i1, i2;
|
||||
s>>i1>>i2;
|
||||
// now: i1==1 i2==2 i3==3 i4==4 s=={5, 6, 7, 8}
|
||||
CPPUNIT_ASSERT(i1==std::make_pair(1, std::string("one")) &&
|
||||
i2==std::make_pair(2, std::string("two")));
|
||||
CPPUNIT_ASSERT(s.size()==1);
|
||||
s>>i1;
|
||||
CPPUNIT_ASSERT(i1==std::make_pair(2, std::string("two")));
|
||||
bool exc(false);
|
||||
try {
|
||||
s>>i1;
|
||||
} catch (mrw::length_error&) {
|
||||
exc=true;
|
||||
}
|
||||
CPPUNIT_ASSERT(exc);
|
||||
}
|
||||
void StringException1() {
|
||||
std::string s("Hello World");
|
||||
int hello;
|
||||
s>>hello; // not an int, exception expected
|
||||
}
|
||||
void StringException2() {
|
||||
std::string s("Hello World");
|
||||
mrw::to<int>(s); // not an int, exception expected
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(StdExtTest);
|
||||
CPPUNIT_TEST(StringConv);
|
||||
CPPUNIT_TEST(StringShift);
|
||||
CPPUNIT_TEST(StringAdd);
|
||||
CPPUNIT_TEST(ListShift);
|
||||
CPPUNIT_TEST(VectorShift);
|
||||
CPPUNIT_TEST(DequeShift);
|
||||
CPPUNIT_TEST(SetShift);
|
||||
CPPUNIT_TEST(MapShift);
|
||||
CPPUNIT_TEST(MultisetShift);
|
||||
CPPUNIT_TEST(MultimapShift);
|
||||
CPPUNIT_TEST_EXCEPTION(StringException1, mrw::invalid_argument);
|
||||
CPPUNIT_TEST_EXCEPTION(StringException2, mrw::invalid_argument);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(StdExtTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
|
||||
1 2 3 4 5 6 7 8
|
||||
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
*/
|
||||
#include <mrw/string.hxx>
|
||||
#include <mrw/list.hxx>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
class StringTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void Join() {
|
||||
std::list<std::string> l;
|
||||
l<<"Hello"<<"World"<<"here"<<"I"<<"am";
|
||||
CPPUNIT_ASSERT(mrw::join(l)=="Hello World here I am");
|
||||
}
|
||||
void Split() {
|
||||
std::string text("Hello World here I am");
|
||||
std::list<std::string> a(mrw::split(text)), b;
|
||||
b<<"Hello"<<"World"<<"here"<<"I"<<"am";
|
||||
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin()));
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(StringTest);
|
||||
CPPUNIT_TEST(Join);
|
||||
CPPUNIT_TEST(Split);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(StringTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
Hallo Welt
|
||||
@@ -1,74 +0,0 @@
|
||||
/** @file
|
||||
|
||||
$Id$
|
||||
|
||||
$Date$
|
||||
$Author$
|
||||
|
||||
@copy © Marc Wäckerlin
|
||||
@license LGPL, see file <a href="license.html">COPYING</a>
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2005/01/07 00:35:17 marc
|
||||
initial version
|
||||
|
||||
Revision 1.1 2004/12/17 16:26:58 marc
|
||||
initial version
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <mrw/tokenizer.hxx>
|
||||
#include <mrw/list.hxx>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
|
||||
class TokenizerTest: public CppUnit::TestFixture {
|
||||
public:
|
||||
void CheckNonGreedy() {
|
||||
const std::string aux[] = {"first", "second", "third", "", "fifth"};
|
||||
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b;
|
||||
mrw::Tokenizer token("first,second,third,,fifth", false, ",");
|
||||
while (token) b<<token();
|
||||
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin()));
|
||||
}
|
||||
void CheckGreedy() {
|
||||
const std::string aux[] = {"Hello", "world", "here", "I", "am"};
|
||||
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b;
|
||||
mrw::Tokenizer token("Hello world, here I am!", true, " \t\n,.?!");
|
||||
while (token) b<<token();
|
||||
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin()));
|
||||
}
|
||||
void CheckReset() {
|
||||
const std::string aux[] = {"first", "second", "third", "", "fifth"};
|
||||
std::list<std::string> a(aux, aux+sizeof(aux)/sizeof(std::string)), b;
|
||||
mrw::Tokenizer token("first,second,third,,fifth", false, ",");
|
||||
while (token) b<<token();
|
||||
CPPUNIT_ASSERT(equal(a.begin(), a.end(), b.begin()));
|
||||
const std::string aux2[] = {"a", "b", "c", "d", "e"};
|
||||
std::list<std::string> a2(aux2, aux2+sizeof(aux2)/sizeof(std::string)),
|
||||
b2, b3;
|
||||
token.reset("a,b,c,d,e");
|
||||
while (token) b2<<token();
|
||||
CPPUNIT_ASSERT(equal(a2.begin(), a2.end(), b2.begin()));
|
||||
token.reset();
|
||||
while (token) b3<<token();
|
||||
CPPUNIT_ASSERT(equal(a2.begin(), a2.end(), b3.begin()));
|
||||
}
|
||||
CPPUNIT_TEST_SUITE(TokenizerTest);
|
||||
CPPUNIT_TEST(CheckNonGreedy);
|
||||
CPPUNIT_TEST(CheckGreedy);
|
||||
CPPUNIT_TEST(CheckReset);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
};
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TokenizerTest);
|
||||
|
||||
int main() {
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
return runner.run() ? 0 : 1;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user