33 StdData(
size_t lineParam,
const char* fileParam,
34 const char* testNameParam,
bool printDotParam):
42 #define STD_DATA TestInternal::StdData(__LINE__, __FILE__, __nameOfTest, __printDots)
44 {bool ___printDots = __printDots; __printDots = false; X; __printDots = ___printDots;}
47 string toStr(
const T& t) {stringstream out;out << t;
return out.str();}
50 void assertFail(
const char* cond,
const char* expected,
const StdData&);
51 void assertFail1(
const char* cond,
const char* expected,
const StdData&,
52 const char* exp1,
string exp1Value);
53 void assertFail2(
const char* cond,
const char* expected,
const StdData&,
54 const char* exp1,
string exp1Value,
55 const char* exp2,
string exp2Value);
60 const char* testName,
const char* file,
size_t line);
62 void assertTrue(
bool value,
const char* condition,
63 const char* testName,
const char* file,
size_t line,
66 #define ASSERT_EXCEPTION(CODE, EXCEPTION_TYPE) \
67 {bool _frobby_sawException = false; \
68 try {CODE;} catch (EXCEPTION_TYPE) {_frobby_sawException = true;} \
69 if (_frobby_sawException)assertOK(STD_DATA); \
70 else assertFail(#CODE,"throw exception of type " #EXCEPTION_TYPE,STD_DATA);}
72 #define ASSERT_TRUE(VALUE) \
73 {if(VALUE)assertOK(STD_DATA);else assertFail(#VALUE,"true",STD_DATA);}
74 #define ASSERT_TRUE_SILENT(VALUE) SILENT(ASSERT_TRUE(VALUE))
76 #define ASSERT_TRUE1(VALUE, X) \
77 {if(VALUE)assertOK(STD_DATA);else assertFail1(#VALUE,"true",STD_DATA,#X,TestInternal::toStr(X));}
78 #define ASSERT_FALSE1(VALUE, X) \
79 {if(!VALUE)assertOK(STD_DATA);else assertFail1(#VALUE,"false",STD_DATA,#X,TestInternal::toStr(X));}
81 #define ASSERT_TRUE2(VALUE, X, Y) \
82 {if(VALUE)assertOK(STD_DATA);else assertFail2(#VALUE,"true",STD_DATA,#X,TestInternal::toStr(X),#Y,TestInternal::toStr(Y));}
83 #define ASSERT_FALSE2(VALUE, X, Y) \
84 {if(!VALUE)assertOK(STD_DATA);else assertFail2(#VALUE,"false",STD_DATA,#X,TestInternal::toStr(X),#Y,TestInternal::toStr(Y));}
87 const char* testName,
const char* file,
size_t line,
88 const char* expression1,
const char* expression1Value,
89 const char* expression2,
const char* expression2Value);
90 template<
class A,
class B>
92 const char* testName,
const char* file,
size_t line,
93 const char* expression1,
const A& a,
94 const char* expression2,
const B& b,
108 expression1, aValue.str().c_str(),
109 expression2, bValue.str().c_str());
111 #define ASSERT_TRUE2_SILENT(VALUE, A, B) \
112 TestInternal::assertTrue2(VALUE, #VALUE, __nameOfTest, __FILE__, __LINE__, \
116 void assertFalse(
bool value,
const char* condition,
117 const char* testName,
const char* file,
size_t line,
119 #define ASSERT_FALSE(VALUE) \
120 TestInternal::assertFalse(VALUE, #VALUE, __nameOfTest, __FILE__, __LINE__, __printDots)
121 #define ASSERT_FALSE_SILENT(VALUE) \
122 TestInternal::assertFalse(VALUE, #VALUE, __nameOfTest, __FILE__, __LINE__, false)
125 const char* aString,
const char* bString,
126 const char* testName,
const char* file,
size_t line);
127 template<
class T1,
class T2>
129 const char* aString,
const char* bString,
130 const char* testName,
const char* file,
size_t line,
145 testName, file, line);
147 #define ASSERT_EQ(A, B) \
148 TestInternal::assertEqual(A, B, #A, #B, __nameOfTest, __FILE__, __LINE__, __printDots)
149 #define ASSERT_EQ_SILENT(A, B) \
150 TestInternal::assertEqual(A, B, #A, #B, __nameOfTest, __FILE__, __LINE__, false)
153 const char* aString,
const char* bString,
154 const char* testName,
const char* file,
size_t line);
155 template<
class T1,
class T2>
157 const char* aString,
const char* bString,
158 const char* testName,
const char* file,
size_t line,
173 testName, file, line);
175 #define ASSERT_NEQ(A, B) \
176 TestInternal::assertNotEqual(A, B, #A, #B, __nameOfTest, __FILE__, __LINE__, __printDots)
177 #define ASSERT_NEQ_SILENT(A, B) \
178 TestInternal::assertNotEqual(A, B, #A, #B, __nameOfTest, __FILE__, __LINE__, false)
185 out <<
" std::vector<>: ";
186 for (
typename vector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
187 out << (it == v.begin() ?
"" :
", ") << *it;
AssertException(const string &str)
void assertOK(const StdData &data)
void assertTrue2Failed(const char *valueString, const char *testName, const char *file, size_t line, const char *expression1, const char *expression1Value, const char *expression2, const char *expression2Value)
void assertFail1(const char *cond, const char *expected, const StdData &data, const char *exp1, string exp1Value)
void assertTrue2(bool value, const char *valueString, const char *testName, const char *file, size_t line, const char *expression1, const A &a, const char *expression2, const B &b, bool printDot)
void assertEqual(const T1 &a, const T2 &b, const char *aString, const char *bString, const char *testName, const char *file, size_t line, bool printDot)
void assertTrue(bool value, const char *valueString, const char *testName, const char *file, size_t line, bool printDot)
void assertFail(const char *cond, const char *expected, const StdData &data)
void assertFailed(const char *errorMsg, const char *testName, const char *file, size_t line)
void assertSucceeded(bool printDot)
void assertFalse(bool value, const char *valueString, const char *testName, const char *file, size_t line, bool printDot)
void assertNotEqualFailed(const char *a, const char *b, const char *aString, const char *bString, const char *testName, const char *file, size_t line)
ostream & operator<<(ostream &out, const vector< T > &v)
Prints out a vector.
void assertEqualFailed(const char *a, const char *b, const char *aString, const char *bString, const char *testName, const char *file, size_t line)
void assertNotEqual(const T1 &a, const T2 &b, const char *aString, const char *bString, const char *testName, const char *file, size_t line, bool printDot)
void assertFail2(const char *cond, const char *expected, const StdData &data, const char *exp1, string exp1Value, const char *exp2, string exp2Value)
StdData(size_t lineParam, const char *fileParam, const char *testNameParam, bool printDotParam)