X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fformatter.cc;h=443256b617ecf66ddeb8c98144f8710f8e629c2e;hb=62d142cd69b5b6b7e044319085bc011e85dd90eb;hp=ad5b163541b4f14a11e003431331f7facc79ea79;hpb=7db3b0483da2a158f2559cd55f13ef7769e36d10;p=awesomized%2Flibmemcached diff --git a/libtest/formatter.cc b/libtest/formatter.cc index ad5b1635..443256b6 100644 --- a/libtest/formatter.cc +++ b/libtest/formatter.cc @@ -41,7 +41,8 @@ #include #include #include - +#include + namespace libtest { std::string& escape4XML(std::string const& arg, std::string& escaped_string) @@ -52,39 +53,41 @@ std::string& escape4XML(std::string const& arg, std::string& escaped_string) for (std::string::const_iterator x= arg.begin(), end= arg.end(); x != end; ++x) { unsigned char c= *x; - if (' ' <= c and c <= '~' and c != '\\' and c != '"' and c != '>' and c != '<') + if (c == '&') { - escaped_string+= c; + escaped_string+= "&"; } else if (c == '>') { - escaped_string+= '&'; - escaped_string+= 'g'; - escaped_string+= 't'; - escaped_string+= ';'; + escaped_string+= ">"; } else if (c == '<') { - escaped_string+= '&'; - escaped_string+= 'l'; - escaped_string+= 't'; - escaped_string+= ';'; + 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 { - escaped_string+= '\\'; - switch (c) { - case '"': escaped_string+= '"'; break; - case '\\': escaped_string+= '\\'; break; - case '\t': escaped_string+='t'; break; - case '\r': escaped_string+='r'; break; - case '\n': escaped_string+='n'; break; - default: - char const* const hexdig= "0123456789ABCDEF"; - escaped_string+= 'x'; - escaped_string+= hexdig[c >> 4]; - escaped_string+= hexdig[c & 0xF]; - } + char const* const hexdig= "0123456789ABCDEF"; + escaped_string+= "&#x"; + escaped_string+= hexdig[c >> 4]; + escaped_string+= hexdig[c & 0xF]; + escaped_string+= ';'; } } escaped_string+= '"'; @@ -157,11 +160,14 @@ TestCase* Formatter::current() void Formatter::skipped() { + assert(current()); current()->result(TEST_SKIPPED); - Out << name() << "." - << current()->name() - << "\t\t\t\t\t" - << "[ " << test_strerror(current()->result()) << " ]"; + + Out + << "[ " << test_strerror(current()->result()) << " ]" + << "\t\t" + << name() << "." << current()->name() + ; reset(); } @@ -171,9 +177,11 @@ void Formatter::failed() assert(current()); current()->result(TEST_FAILURE); - Out << name() - << "." << current()->name() << "\t\t\t\t\t" - << "[ " << test_strerror(current()->result()) << " ]"; + Out + << "[ " << test_strerror(current()->result()) << " ]" + << "\t\t" + << name() << "." << current()->name() + ; reset(); } @@ -182,13 +190,14 @@ void Formatter::success(const libtest::Timer& timer_) { assert(current()); current()->result(TEST_SUCCESS, timer_); - std::string escaped_string; - Out << name() << "." - << current()->name() - << "\t\t\t\t\t" - << current()->timer() - << " [ " << test_strerror(current()->result()) << " ]"; + Out + << "[ " << test_strerror(current()->result()) << " ]" + << "\t" + << current()->timer() + << "\t" + << name() << "." << current()->name() + ; reset(); } @@ -206,8 +215,10 @@ void Formatter::xml(libtest::Framework& framework_, std::ofstream& output) { output << "\t" - << std::endl; +#if 0 + << " classname=\"\" package=\"\"" +#endif + << ">" << std::endl; for (TestCases::iterator case_iter= (*framework_iter)->formatter()->testcases().begin(); case_iter != (*framework_iter)->formatter()->testcases().end(); @@ -217,23 +228,26 @@ void Formatter::xml(libtest::Framework& framework_, std::ofstream& output) << escape4XML((*case_iter)->name(), escaped_string) << " time=\"" << (*case_iter)->timer().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; } @@ -245,6 +259,14 @@ void Formatter::push_testcase(const std::string& arg) assert(_suite_name.empty() == false); TestCase* _current_testcase= new TestCase(arg); _testcases.push_back(_current_testcase); + + assert(current()); + + Echo + << "\t\t\t" + << name() << "." << current()->name() + << "... \r" + ; } void Formatter::reset()