24 #include <wibble/tests.h>
35 #ifndef ensure_contains
36 #define ensure_contains(x, y) wreport::tests::impl_ensure_contains(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
37 #define inner_ensure_contains(x, y) wreport::tests::impl_ensure_contains(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
38 static inline void impl_ensure_contains(
const wibble::tests::Location& loc,
const std::string& haystack,
const std::string& needle)
40 if( haystack.find(needle) == std::string::npos )
43 ss <<
"'" << haystack <<
"' does not contain '" << needle <<
"'";
44 throw tut::failure(loc.msg(ss.str()));
48 #define ensure_not_contains(x, y) arki::tests::impl_ensure_not_contains(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
49 #define inner_ensure_not_contains(x, y) arki::tests::impl_ensure_not_contains(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
50 static inline void impl_ensure_not_contains(
const wibble::tests::Location& loc,
const std::string& haystack,
const std::string& needle)
52 if( haystack.find(needle) != std::string::npos )
55 ss <<
"'" << haystack <<
"' must not contain '" << needle <<
"'";
56 throw tut::failure(loc.msg(ss.str()));
61 #define ensure_varcode_equals(x, y) wreport::tests::_ensure_varcode_equals(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
62 #define inner_ensure_varcode_equals(x, y) wreport::tests::_ensure_varcode_equals(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
63 static inline void _ensure_varcode_equals(
const wibble::tests::Location& loc,
Varcode actual,
Varcode expected)
65 if( expected != actual )
68 snprintf(buf, 40,
"expected %01d%02d%03d actual %01d%02d%03d",
71 throw tut::failure(loc.msg(buf));
75 #define ensure_var_equals(x, y) wreport::tests::_ensure_var_equals(wibble::tests::Location(__FILE__, __LINE__, #x " == " #y), (x), (y))
76 #define inner_ensure_var_equals(x, y) wreport::tests::_ensure_var_equals(wibble::tests::Location(loc, __FILE__, __LINE__, #x " == " #y), (x), (y))
77 static inline void _ensure_var_equals(
const wibble::tests::Location& loc,
const Var& var,
int val)
79 inner_ensure_equals(var.enqi(), val);
81 static inline void _ensure_var_equals(
const wibble::tests::Location& loc,
const Var& var,
double val)
83 inner_ensure_equals(var.enqd(), val);
85 static inline void _ensure_var_equals(
const wibble::tests::Location& loc,
const Var& var,
const std::string& val)
87 inner_ensure_equals(std::string(var.enqc()), val);
90 #define ensure_var_undef(x) wreport::tests::_ensure_var_undef(wibble::tests::Location(__FILE__, __LINE__, #x " is undef"), (x))
91 #define inner_ensure_var_undef(x) wreport::tests::_ensure_var_undef(wibble::tests::Location(loc, __FILE__, __LINE__, #x " is undef"), (x))
92 static inline void _ensure_var_undef(
const wibble::tests::Location& loc,
const Var& var)
94 inner_ensure_equals(var.value(), (
const char*)0);
109 LocalEnv(
const std::string& key,
const std::string& val)
112 const char* v = getenv(key.c_str());
113 oldVal = v == NULL ?
"" : v;
114 setenv(key.c_str(), val.c_str(), 1);
118 setenv(key.c_str(), oldVal.c_str(), 1);
130 TestVarEqual(
const Var& actual,
const Var& expected,
bool inverted=
false) : avar(actual), evar(expected), inverted(inverted) {}
131 TestVarEqual operator!() {
return TestVarEqual(avar, evar, !inverted); }
133 void check(WIBBLE_TEST_LOCPRM)
const;
136 struct ActualVar :
public wibble::tests::Actual<Var>
138 ActualVar(
const Var& actual) : wibble::tests::Actual<Var>(actual) {}
140 TestVarEqual operator==(
const Var& expected)
const {
return TestVarEqual(actual, expected); }
141 TestVarEqual operator!=(
const Var& expected)
const {
return TestVarEqual(actual, expected,
true); }
152 inline wreport::tests::ActualVar actual(
const wreport::Var& actual) {
return wreport::tests::ActualVar(actual); }