35 #include <boost/filesystem/detail/utf8_codecvt_facet.hpp> 55 std::ostringstream oss;
56 oss <<
"[" << filename <<
":" << line <<
"] Assertion failed: " << expression;
60 inline std::string
unit_assert_equal_message(
const char* filename,
int line,
const std::string&
x,
const std::string&
y,
const char* expression)
62 std::ostringstream oss;
63 oss <<
"[" << filename <<
":" << line <<
"] Assertion failed: expected \"" << x <<
"\" but got \"" << y <<
"\" (" << expression <<
")";
69 std::ostringstream oss;
71 oss <<
"[" << filename <<
":" << line <<
"] Assertion failed: |" << x <<
" - " << y <<
"| < " <<
epsilon;
77 std::ostringstream oss;
78 oss <<
"[" << filename <<
":" << line <<
"] Assertion \"" << expression <<
"\" failed to throw " << exception;
82 inline std::string
quote_string(
const string& str) {
return "\"" + str +
"\"";}
85 #define unit_assert(x) \ 86 (!(x) ? throw std::runtime_error(unit_assert_message(__FILE__, __LINE__, #x)) : 0) 89 #define unit_assert_operator_equal(expected, actual) \ 90 (!(expected == actual) ? throw std::runtime_error(unit_assert_equal_message(__FILE__, __LINE__, lexical_cast<string>(expected), lexical_cast<string>(actual), #actual)) : 0) 93 #define unit_assert_equal(x, y, epsilon) \ 94 (!(fabs((x)-(y)) <= (epsilon)) ? throw std::runtime_error(unit_assert_numeric_equal_message(__FILE__, __LINE__, (x), (y), (epsilon))) : 0) 97 #define unit_assert_throws(x, exception) \ 106 throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, #exception)); \ 110 #define unit_assert_throws_what(x, exception, whatStr) \ 112 bool threw = false; \ 114 catch (exception& e) \ 116 if (e.what() == std::string(whatStr)) \ 119 throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, std::string(#exception)+" "+quote_string(whatStr)+"\nBut a different exception was thrown: ")+quote_string(e.what())); \ 122 throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, std::string(#exception)+" "+quote_string(whatStr))); \ 126 #define unit_assert_matrices_equal(A, B, epsilon) \ 127 unit_assert(boost::numeric::ublas::norm_frobenius((A)-(B)) < (epsilon)) 130 #define unit_assert_vectors_equal(A, B, epsilon) \ 131 unit_assert(boost::numeric::ublas::norm_2((A)-(B)) < (epsilon)) 139 bal::replace_all(result,
"'",
"|'");
140 bal::replace_all(result,
"\n",
"|n");
141 bal::replace_all(result,
"\r",
"|r");
142 bal::replace_all(result,
"|",
"||");
143 bal::replace_all(result,
"[",
"|[");
144 bal::replace_all(result,
"]",
"|]");
148 #define TEST_PROLOG_EX(argc, argv, suffix) \ 149 bnw::args args(argc, argv); \ 150 std::locale global_loc = std::locale(); \ 151 std::locale loc(global_loc, new boost::filesystem::detail::utf8_codecvt_facet); \ 152 bfs::path::imbue(loc); \ 153 bfs::path testName = bfs::change_extension(bfs::basename(argv[0]), (suffix)); \ 154 string teamcityTestName = pwiz::util::escape_teamcity_string(testName.string()); \ 155 bpt::ptime testStartTime; \ 156 vector<string> testArgs(argv, argv+argc); \ 157 bool teamcityTestDecoration = find(testArgs.begin(), testArgs.end(), "--teamcity-test-decoration") != testArgs.end(); \ 158 if (teamcityTestDecoration) \ 160 testStartTime = bpt::microsec_clock::local_time(); \ 161 cout << "##teamcity[testStarted name='" << teamcityTestName << "']" << endl; \ 163 int testExitStatus = 0; 165 #define TEST_PROLOG(argc, argv) TEST_PROLOG_EX(argc, argv, "") 167 #define TEST_FAILED(x) \ 168 if (teamcityTestDecoration) \ 169 cout << "##teamcity[testFailed name='" << teamcityTestName << "' message='" << pwiz::util::escape_teamcity_string((x)) << "']\n"; \ 170 cerr << (x) << endl; \ 173 #define TEST_EPILOG \ 174 if (teamcityTestDecoration) \ 175 cout << "##teamcity[testFinished name='" << teamcityTestName << \ 176 "' duration='" << round((bpt::microsec_clock::local_time() - testStartTime).total_microseconds() / 1000.0) << "']" << endl; \ 177 return testExitStatus;
std::string escape_teamcity_string(const std::string &str)
std::string unit_assert_numeric_equal_message(const char *filename, int line, double x, double y, double epsilon)
std::string quote_string(const string &str)
std::string unit_assert_message(const char *filename, int line, const char *expression)
std::string unit_assert_exception_message(const char *filename, int line, const char *expression, const std::string &exception)
std::string unit_assert_equal_message(const char *filename, int line, const std::string &x, const std::string &y, const char *expression)
KernelTraitsBase< Kernel >::space_type::abscissa_type x
KernelTraitsBase< Kernel >::space_type::ordinate_type y