00001 #ifndef WIBBLE_TESTS_H
00002 #define WIBBLE_TESTS_H
00003
00010 #include <string>
00011 #include <sstream>
00012
00013 #include <wibble/tests/tut.h>
00014 #include <wibble/tests/tut_reporter.h>
00015
00016
00017 #define TESTGRP(name) \
00018 typedef test_group<name ## _shar> tg; \
00019 typedef tg::object to; \
00020 tg name ## _tg (#name);
00021
00022
00023 namespace wibble {
00024 namespace tests {
00025
00026 class Location
00027 {
00028 std::string file;
00029 int line;
00030 std::string str;
00031 std::string testfile;
00032 int testline;
00033 std::string teststr;
00034
00035 public:
00036
00037 Location(const std::string& file, int line, const std::string& str)
00038 : file(file), line(line), str(str) {}
00039 Location(const Location& loc,
00040 const std::string& testfile, int testline, const std::string& str) :
00041 file(loc.file), line(loc.line), str(loc.str),
00042 testfile(testfile), testline(testline), teststr(str) {}
00043
00044 std::string locstr() const;
00045 std::string msg(const std::string m) const;
00046 };
00047
00048 #define ensure(x) wibble::tests::impl_ensure(wibble::tests::Location(__FILE__, __LINE__, #x), (x))
00049 #define inner_ensure(x) wibble::tests::impl_ensure(wibble::tests::Location(loc, __FILE__, __LINE__, #x), (x))
00050 void impl_ensure(const Location& loc, bool res);
00051
00052 #define ensure_equals(x, y) wibble::tests::impl_ensure_equals(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
00053 #define inner_ensure_equals(x, y) wibble::tests::impl_ensure_equals(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
00054
00055 template <class Actual,class Expected>
00056 void impl_ensure_equals(const Location& loc, const Actual& actual, const Expected& expected)
00057 {
00058 if( expected != actual )
00059 {
00060 std::stringstream ss;
00061 ss << "expected '" << expected << "' actual '" << actual << "'";
00062 throw tut::failure(loc.msg(ss.str()));
00063 }
00064 }
00065
00066 }
00067 }
00068
00069 #endif