X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fformatter.cc;h=7cb3ea0ab8fb55ca8b7e0083b66638527128017a;hb=6730933820b3c3f7b016b4d33a209198d195a37a;hp=8e6b3ffb282bc089576218bec7367c735fd718be;hpb=23dca174eef8d846e3d4402729b57f6ded035e64;p=awesomized%2Flibmemcached diff --git a/libtest/formatter.cc b/libtest/formatter.cc index 8e6b3ffb..7cb3ea0a 100644 --- a/libtest/formatter.cc +++ b/libtest/formatter.cc @@ -34,15 +34,66 @@ * */ -#include "mem_config.h" +#include "libtest/yatlcon.h" #include -#include +#include #include +#include namespace libtest { +std::string& escape4XML(std::string const& arg, std::string& escaped_string) +{ + escaped_string.clear(); + + escaped_string+= '"'; + for (std::string::const_iterator x= arg.begin(), end= arg.end(); x != end; ++x) + { + unsigned char c= *x; + if (c == '&') + { + escaped_string+= "&"; + } + else if (c == '>') + { + escaped_string+= ">"; + } + else if (c == '<') + { + escaped_string+= "<"; + } + else if (c == '\'') + { + escaped_string+= "'"; break; + } + else if (c == '"') + { + escaped_string+= """; + } + else if (c == ' ') + { + escaped_string+= ' '; + } + else if (isalnum(c)) + { + escaped_string+= c; + } + else + { + char const* const hexdig= "0123456789ABCDEF"; + escaped_string+= "&#x"; + escaped_string+= hexdig[c >> 4]; + escaped_string+= hexdig[c & 0xF]; + escaped_string+= ';'; + } + } + escaped_string+= '"'; + + return escaped_string; +} + class TestCase { public: TestCase(const std::string& arg): @@ -88,17 +139,17 @@ private: libtest::Timer _timer; }; -Formatter::Formatter(const std::string& arg) : - _suite_name(arg) +Formatter::Formatter(const std::string& frame_name, const std::string& arg) { + _suite_name= frame_name; + _suite_name+= "."; + _suite_name+= arg; } Formatter::~Formatter() { - for (TestCases::iterator iter= _testcases.begin(); iter != _testcases.end(); ++iter) - { - delete *iter; - } + std::for_each(_testcases.begin(), _testcases.end(), DeleteFromVector()); + _testcases.clear(); } TestCase* Formatter::current() @@ -109,7 +160,10 @@ TestCase* Formatter::current() void Formatter::skipped() { current()->result(TEST_SKIPPED); - Out << name() << "." << current()->name() << "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]"; + Out << name() << "." + << current()->name() + << "\t\t\t\t\t" + << "[ " << test_strerror(current()->result()) << " ]"; reset(); } @@ -119,7 +173,9 @@ void Formatter::failed() assert(current()); current()->result(TEST_FAILURE); - Out << name() << "." << current()->name() << "\t\t\t\t\t" << "[ " << test_strerror(current()->result()) << " ]"; + Out << name() + << "." << current()->name() << "\t\t\t\t\t" + << "[ " << test_strerror(current()->result()) << " ]"; reset(); } @@ -128,6 +184,7 @@ void Formatter::success(const libtest::Timer& timer_) { assert(current()); current()->result(TEST_SUCCESS, timer_); + std::string escaped_string; Out << name() << "." << current()->name() @@ -140,38 +197,50 @@ void Formatter::success(const libtest::Timer& timer_) void Formatter::xml(libtest::Framework& framework_, std::ofstream& output) { - output << "" << std::endl; + std::string escaped_string; + + output << "" << std::endl; + for (Suites::iterator framework_iter= framework_.suites().begin(); framework_iter != framework_.suites().end(); ++framework_iter) { - output << "\tname() << "\" classname=\"\" package=\"\">" << std::endl; + output << "\t" << std::endl; for (TestCases::iterator case_iter= (*framework_iter)->formatter()->testcases().begin(); case_iter != (*framework_iter)->formatter()->testcases().end(); ++case_iter) { - output << "\t\tname() - << "\" time=\"" + output << "\t\ttimer().elapsed_milliseconds() - << "\">" - << std::endl; + << "\""; switch ((*case_iter)->result()) { case TEST_SKIPPED: + output << ">" << std::endl; output << "\t\t " << std::endl; + output << "\t\t" << std::endl; break; case TEST_FAILURE: + output << ">" << std::endl; output << "\t\t "<< std::endl; + output << "\t\t" << std::endl; break; case TEST_SUCCESS: + output << "/>" << std::endl; break; } - output << "\t\t" << std::endl; } output << "\t" << std::endl; }