2004-08-28 16:21:25 +00:00
|
|
|
/** @file
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
$Date$
|
|
|
|
$Author$
|
|
|
|
|
|
|
|
@copy © Marc Wäckerlin
|
|
|
|
@license LGPL, see file <a href="license.html">COPYING</a>
|
|
|
|
|
2005-11-29 12:42:01 +00:00
|
|
|
1 2 3 4 5 6 7 8
|
|
|
|
5678901234567890123456789012345678901234567890123456789012345678901234567890
|
2004-08-28 16:21:25 +00:00
|
|
|
*/
|
2005-11-29 12:42:01 +00:00
|
|
|
|
2004-04-21 06:39:20 +00:00
|
|
|
#include <mrw/stacktrace.hpp>
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/ui/text/TestRunner.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
|
|
|
|
2004-04-21 19:03:38 +00:00
|
|
|
namespace mrw {
|
|
|
|
class StackTraceTest: public CppUnit::TestFixture {
|
|
|
|
public:
|
|
|
|
/// test if symbols are correctely evaluated
|
|
|
|
void StackTrace() {
|
2005-11-29 12:42:01 +00:00
|
|
|
bool init(mrw::StackTrace::createSymtable());
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("createSymtable() failed! ERROR="
|
|
|
|
+mrw::StackTrace::error(),
|
2007-08-05 08:20:01 +00:00
|
|
|
init
|
|
|
|
||
|
|
|
|
mrw::StackTrace::error().find("/valgrind/")
|
|
|
|
!=std::string::npos);
|
2004-04-21 19:03:38 +00:00
|
|
|
mrw::StackTrace s; int l(__LINE__); std::string f(__FILE__);
|
|
|
|
std::stringstream ss;
|
|
|
|
ss<<f<<':'<<l;
|
|
|
|
std::string st(s);
|
2005-11-29 12:42:01 +00:00
|
|
|
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";
|
2005-01-28 07:51:24 +00:00
|
|
|
std::string::size_type pos(st.find("mrw::StackTraceTest::StackTrace()"));
|
2005-11-29 12:42:01 +00:00
|
|
|
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());
|
2004-04-21 19:03:38 +00:00
|
|
|
}
|
|
|
|
CPPUNIT_TEST_SUITE(StackTraceTest);
|
|
|
|
CPPUNIT_TEST(StackTrace);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(StackTraceTest);
|
|
|
|
}
|
2004-04-21 06:39:20 +00:00
|
|
|
|
|
|
|
int main() {
|
|
|
|
CppUnit::TextUi::TestRunner runner;
|
|
|
|
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
|
|
|
return runner.run() ? 0 : 1;
|
|
|
|
}
|