2005-03-11 21:07:55 +00:00
|
|
|
/** @file
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
$Date$
|
|
|
|
$Author$
|
|
|
|
|
|
|
|
@copy © Marc Wäckerlin
|
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a>
|
|
|
|
|
|
|
|
$Log$
|
2005-04-07 20:55:21 +00:00
|
|
|
Revision 1.3 2005/04/07 20:55:21 marc
|
|
|
|
Oops, there's a make distcheck...? Now it works.
|
|
|
|
|
2005-03-11 23:18:02 +00:00
|
|
|
Revision 1.2 2005/03/11 23:18:02 marc
|
|
|
|
bugfix: linenumbers change at checkin...
|
|
|
|
|
2005-03-11 21:07:55 +00:00
|
|
|
Revision 1.1 2005/03/11 21:07:55 marc
|
|
|
|
initial version
|
|
|
|
|
|
|
|
|
|
|
|
1 2 3 4 5 6 7 8
|
|
|
|
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <mrw/functiontrace.hpp>
|
|
|
|
#include <mrw/regexp.hpp>
|
|
|
|
#include <mrw/file.hpp>
|
|
|
|
#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() {
|
2007-08-05 08:20:01 +00:00
|
|
|
MRW_METHOD("A::A()");
|
2005-03-11 21:07:55 +00:00
|
|
|
}
|
|
|
|
~A() {
|
2007-08-05 08:20:01 +00:00
|
|
|
MRW_METHOD("A::~A()");
|
2005-03-11 21:07:55 +00:00
|
|
|
}
|
|
|
|
void fn1() {
|
2007-08-05 08:20:01 +00:00
|
|
|
MRW_METHOD("A::fn1()");
|
2005-03-11 21:07:55 +00:00
|
|
|
fn2();
|
|
|
|
}
|
|
|
|
void fn2() {
|
2007-08-05 08:20:01 +00:00
|
|
|
MRW_METHOD("A::fn2()");
|
2005-03-11 21:07:55 +00:00
|
|
|
fn3();
|
|
|
|
fn4();
|
|
|
|
}
|
|
|
|
void fn3() {
|
2007-08-05 08:20:01 +00:00
|
|
|
MRW_METHOD("A::fn3()");
|
2005-03-11 21:07:55 +00:00
|
|
|
fn4();
|
|
|
|
}
|
|
|
|
void fn4(bool flag=true) {
|
2007-08-05 08:20:01 +00:00
|
|
|
MRW_METHOD("A::fn4()");
|
2005-03-11 21:07:55 +00:00
|
|
|
if (flag) fn4(false);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void fn(A a) {
|
2007-08-05 08:20:01 +00:00
|
|
|
MRW_FUNCTION("fn(A)");
|
2005-03-11 21:07:55 +00:00
|
|
|
a.fn1();
|
|
|
|
}
|
|
|
|
|
|
|
|
class FunctionTraceTest: public CppUnit::TestFixture {
|
|
|
|
public:
|
|
|
|
void Init() {
|
|
|
|
try {mrw::File::remove("functiontrace_test.log");} catch (...) {}
|
|
|
|
log4cxx::helpers::Properties properties;
|
2007-08-05 08:20:01 +00:00
|
|
|
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())));
|
2005-03-11 21:07:55 +00:00
|
|
|
log4cxx::PropertyConfigurator::configure(properties);
|
|
|
|
}
|
|
|
|
void Calls() {
|
|
|
|
fn(A());
|
|
|
|
mrw::RegExp match
|
2005-04-07 20:55:21 +00:00
|
|
|
(".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::A\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::A\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - \\\\ fn\\(A\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn1\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn2\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn3\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn4\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn4\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn4\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn4\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn3\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn4\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::fn4\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn4\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn4\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn2\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::fn1\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - / fn\\(A\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: \\\\ A::~A\\(\\)\n"
|
|
|
|
".*functiontrace_test.cpp:[0-9]+ - *0x[0-9a-fA-F]+: / A::~A\\(\\)\n");
|
2005-03-11 21:07:55 +00:00
|
|
|
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;
|
|
|
|
}
|