Go to the documentation of this file.
   54     std::ostringstream oss;
 
   55     oss << 
"[" << filename << 
":" << line << 
"] Assertion failed: " << expression;
 
   59 inline std::string 
unit_assert_equal_message(
const char* filename, 
int line, 
const std::string& 
x, 
const std::string& 
y, 
const char* expression)
 
   61     std::ostringstream oss;
 
   62     oss << 
"[" << filename << 
":" << line << 
"] Assertion failed: expected \"" << x << 
"\" but got \"" << y << 
"\" (" << expression << 
")";
 
   68     std::ostringstream oss;
 
   70     oss << 
"[" << filename << 
":" << line << 
"] Assertion failed: |" << x << 
" - " << y << 
"| < " << 
epsilon;
 
   76     std::ostringstream oss;
 
   77     oss << 
"[" << filename << 
":" << line << 
"] Assertion failed to throw \"" << exception << 
"\": " << expression;
 
   82 #define unit_assert(x) \ 
   83     (!(x) ? throw std::runtime_error(unit_assert_message(__FILE__, __LINE__, #x)) : 0)  
   86 #define unit_assert_operator_equal(expected, actual) \ 
   87     (!(expected == actual) ? throw std::runtime_error(unit_assert_equal_message(__FILE__, __LINE__, lexical_cast<string>(expected), lexical_cast<string>(actual), #actual)) : 0) 
   90 #define unit_assert_equal(x, y, epsilon) \ 
   91     (!(fabs((x)-(y)) <= (epsilon)) ? throw std::runtime_error(unit_assert_numeric_equal_message(__FILE__, __LINE__, (x), (y), (epsilon))) : 0) 
   94 #define unit_assert_throws(x, exception) \ 
  103             throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, #exception)); \ 
  107 #define unit_assert_throws_what(x, exception, whatStr) \ 
  109         bool threw = false; \ 
  111         catch (exception& e) \ 
  113             if (e.what() == std::string(whatStr)) \ 
  116                 throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, std::string(#exception)+" "+(whatStr)+"\nBut a different exception was thrown: ")+(e.what())); \ 
  119             throw std::runtime_error(unit_assert_exception_message(__FILE__, __LINE__, #x, std::string(#exception)+" "+(whatStr))); \ 
  123 #define unit_assert_matrices_equal(A, B, epsilon) \ 
  124     unit_assert(boost::numeric::ublas::norm_frobenius((A)-(B)) < (epsilon)) 
  127 #define unit_assert_vectors_equal(A, B, epsilon) \ 
  128     unit_assert(boost::numeric::ublas::norm_2((A)-(B)) < (epsilon)) 
  136     bal::replace_all(result, 
"'", 
"|'");
 
  137     bal::replace_all(result, 
"\n", 
"|n");
 
  138     bal::replace_all(result, 
"\r", 
"|r");
 
  139     bal::replace_all(result, 
"|", 
"||");
 
  140     bal::replace_all(result, 
"[", 
"|[");
 
  141     bal::replace_all(result, 
"]", 
"|]");
 
  145 #define TEST_PROLOG_EX(argc, argv, suffix) \ 
  146     bfs::path testName = bfs::change_extension(bfs::basename(argv[0]), (suffix)); \ 
  147     string teamcityTestName = pwiz::util::escape_teamcity_string(testName.string()); \ 
  148     bpt::ptime testStartTime; \ 
  149     vector<string> testArgs(argv, argv+argc); \ 
  150     bool teamcityTestDecoration = find(testArgs.begin(), testArgs.end(), "--teamcity-test-decoration") != testArgs.end(); \ 
  151     if (teamcityTestDecoration) \ 
  153         testStartTime = bpt::microsec_clock::local_time(); \ 
  154         cout << "##teamcity[testStarted name='" << teamcityTestName << "']" << endl; \ 
  156     int testExitStatus = 0; 
  158 #define TEST_PROLOG(argc, argv) TEST_PROLOG_EX(argc, argv, "") 
  160 #define TEST_FAILED(x) \ 
  161     if (teamcityTestDecoration) \ 
  162         cout << "##teamcity[testFailed name='" << teamcityTestName << "' message='" << pwiz::util::escape_teamcity_string((x)) << "']\n"; \ 
  163     cerr << (x) << endl; \ 
  166 #define TEST_EPILOG \ 
  167     if (teamcityTestDecoration) \ 
  168         cout << "##teamcity[testFinished name='" << teamcityTestName << \ 
  169                 "' duration='" << round((bpt::microsec_clock::local_time() - testStartTime).total_microseconds() / 1000.0) << "']" << endl; \ 
  170     return testExitStatus;