21 virtual void print_error(std::ostream& os)
const = 0;
23 virtual void print_descr(std::ostream& os)
const = 0;
48 should_be_equal_(should_be_equal),
56 return equal_ == should_be_equal_;
60 if (should_be_equal_) {
61 os <<
"SHOULD BE EQUAL";
64 os <<
"SHOULD NOT BE EQUAL";
93 tests_.push_back(test_case);
99 int validate(std::ostream& os = std::cout);
103 return nfailed == 0 ? 0 : 1;
108 template <
class T,
class A>
119 bool should_be_equal =
true) {
137 bool should_be_equal =
true) {
144 template <
class T,
class A>
153 const std::vector<T>& test,
155 bool should_be_equal =
true) {
156 std::vector<T> asserted_vec;
157 asserted_vec.push_back(asserted);
173 const std::vector<T>& test,
174 const std::vector<T>& asserted,
175 bool should_be_equal =
true) {
194 template <
class T,
class A>
201 bool should_be_equal)
207 template <
class T,
class A>
215 bool should_be_equal)
224 template <
class T,
class A>
233 bool should_be_equal)
243 template <
class T,
class A>
253 bool should_be_equal)
264 template <
class T,
class A>
275 bool should_be_equal)
287 template <
class T,
class A>
299 bool should_be_equal)
312 template <
class T,
class A>
320 _assertEqual(test_set, descr, file, line, test, asserted,
true);
323 template <
class T,
class A>
332 _assertEqual(test_set, descr, file, line, test, assert1, assert2,
true);
335 template <
class T,
class A>
345 _assertEqual(test_set, descr, file, line, test, assert1, assert2, assert3,
349 template <
class T,
class A>
360 _assertEqual(test_set, descr, file, line, test, assert1, assert2, assert3,
364 template <
class T,
class A>
376 _assertEqual(test_set, descr, file, line, test, assert1, assert2, assert3,
377 assert4, assert5,
true);
380 template <
class T,
class A>
393 _assertEqual(test_set, descr, file, line, test, assert1, assert2, assert3,
394 assert4, assert5, assert6,
true);
397 template <
class T,
class A>
405 _assertEqual(test_set, descr, file, line, test, asserted,
false);
408 template <
class T,
class A>
417 _assertEqual(test_set, descr, file, line, test, assert1, assert2,
false);
420 template <
class T,
class A>
430 _assertEqual(test_set, descr, file, line, test, assert1, assert2, assert3,
434 template <
class T,
class A>
445 _assertEqual(test_set, descr, file, line, test, assert1, assert2, assert3,
449 template <
class T,
class A>
461 _assertEqual(test_set, descr, file, line, test, assert1, assert2, assert3,
462 assert4, assert5,
false);
465 template <
class T,
class A>
478 _assertEqual(test_set, descr, file, line, test, assert1, assert2, assert3,
479 assert4, assert5, assert6,
false);
498 const std::string& exc,
499 const std::string& test,
500 const std::string& errormsg,
509 const char* data = test.c_str();
510 for (
int i=0; i < test.size(); ++i){
511 if (data[i] ==
'\n'){
512 int length = i - last_split;
513 test_ += test.substr(last_split, length) +
"\n ";
517 test_ += test.substr(last_split);
546 int line,
const char* exc,
TestFxn* fxn)
551 "SHOULD THROW",
false));
555 "SHOULD THROW",
true));
557 catch (std::exception& e) {
559 "WRONG EXCEPTION THROWN",
false));
563 "Unknown Exception",
"WRONG EXCEPTION THROWN",
false));
567 #define THIS_FILE truncate_file(__FILE__) 569 #define SPROCKIT_RUN_TEST(fxn, unit_tester, ...) \ 571 fxn(unit_tester, __VA_ARGS__); \ 572 } catch (std::exception& e) { \ 573 unit_tester.append(new ExceptionTestCase("unexpected exception in " #fxn, THIS_FILE, __LINE__, "none", e.what(), "exception thown", false)); \ 576 #define SPROCKIT_RUN_TEST_NO_ARGS(fxn, unit_tester) \ 579 } catch (std::exception& e) { \ 580 unit_tester.append(new ExceptionTestCase("unexpected exception in " #fxn, THIS_FILE, __LINE__, "none", e.what(), "exception thown", false)); \ 583 #define assertThrows(test_set, descr, exc, fxn) \ 584 assertThrows_impl<exc>(test_set, descr, THIS_FILE, __LINE__, #exc, fxn) 586 #define assertEqual(test_set, descr, ...) \ 587 _assertEqual(test_set, descr, THIS_FILE, __LINE__, __VA_ARGS__) 589 #define assertNotEqual(test_set, descr, ...) \ 590 _assertNotEqual(test_set, descr, THIS_FILE, __LINE__, __VA_ARGS__) 592 #define assertTrue(test_set, descr, ...) \ 593 _assertTrue(test_set, descr, THIS_FILE, __LINE__, __VA_ARGS__) 595 #define assertFalse(test_set, descr, ...) \ 596 _assertFalse(test_set, descr, THIS_FILE, __LINE__, __VA_ARGS__) TestCase_impl(const std::string &descr, bool should_be_equal, const T &test, const T &asserted)
void _assertTrue(UnitTest &test_set, const char *descr, const char *file, int line, bool test)
static void add_test(UnitTest &test_set, const char *descr, const char *file, int line, const std::vector< T > &test, const A &asserted, bool should_be_equal=true)
virtual void print_test_value(std::ostream &os) const =0
static void add_test(UnitTest &test_set, const char *descr, const char *file, int line, const T &test, const A &asserted, bool should_be_equal=true)
static int exit_status(int nfailed)
virtual void print_descr(std::ostream &os) const =0
virtual bool is_correct() const =0
static void append(C &c, const A &a)
void _assertFalse(UnitTest &test_set, const char *descr, const char *file, int line, bool test)
void _assertEqual(UnitTest &test_set, const char *descr, const char *file, int line, const T &test, const A &asserted, bool should_be_equal)
void _assertNotEqual(UnitTest &test_set, const char *descr, const char *file, int line, const T &test, const A &asserted)
void print_asserted_value(std::ostream &os) const
std::string printf(const char *fmt,...)
ExceptionTestCase(const std::string &descr, const char *file, int line, const std::string &exc, const std::string &test, const std::string &errormsg, bool success)
void print_error(std::ostream &os) const
static bool equals(size_t n, const T *test, const T *right)
void append(TestCase *test_case)
static void print(const T &t, std::ostream &os)
virtual void print_asserted_value(std::ostream &os) const =0
void assertThrows_impl(UnitTest &test_set, const char *descr, const char *file, int line, const char *exc, TestFxn *fxn)
std::vector< TestCase * > tests_
virtual void print_error(std::ostream &os) const =0
void print_test_value(std::ostream &os) const
void print_asserted_value(std::ostream &os) const
static void add_test(UnitTest &test_set, const char *descr, const char *file, int line, const T &test, const T &asserted, bool should_be_equal=true)
static void add_test(UnitTest &test_set, const char *descr, const char *file, int line, const std::vector< T > &test, const std::vector< T > &asserted, bool should_be_equal=true)
void print_error(std::ostream &os) const
void print_test_value(std::ostream &os) const
void print_descr(std::ostream &os) const
void print_descr(std::ostream &os) const
const char * truncate_file(const char *file)