Commit bb38e40a authored by Dominik Charousset's avatar Dominik Charousset

better diagnostic on `CPPA_CHECK_NOT_EQUAL`

parent 996ab01d
......@@ -57,19 +57,21 @@ inline void cppa_failed(const V1& v1,
template<typename V1, typename V2>
inline void cppa_check_value(const V1& v1, const V2& v2,
const char* fname,
int line_number,
int line,
bool expected = true,
typename enable_integral<false,V1,V2>::type* = 0) {
if (v1 == v2) cppa_passed(fname, line_number);
else cppa_failed(v1, v2, fname, line_number);
if ((v1 == v2) == expected) cppa_passed(fname, line);
else cppa_failed(v1, v2, fname, line);
}
template<typename V1, typename V2>
inline void cppa_check_value(V1 v1, V2 v2,
const char* fname,
int line_number,
int line,
bool expected = true,
typename enable_integral<true,V1,V2>::type* = 0) {
if (v1 == static_cast<V1>(v2)) cppa_passed(fname, line_number);
else cppa_failed(v1, v2, fname, line_number);
if ((v1 == static_cast<V1>(v2)) == expected) cppa_passed(fname, line);
else cppa_failed(v1, v2, fname, line);
}
#define CPPA_TEST(name) \
......@@ -101,14 +103,14 @@ inline void cppa_check_value(V1 v1, V2 v2,
#define CPPA_CHECK_EQUAL(lhs_loc, rhs_loc) \
cppa_check_value((lhs_loc), (rhs_loc), __FILE__, __LINE__)
#define CPPA_CHECK_NOT_EQUAL(lhs_loc, rhs_loc) \
cppa_check_value((lhs_loc), (rhs_loc), __FILE__, __LINE__, false)
#define CPPA_ERROR(err_msg) \
std::cerr << "ERROR in file " << __FILE__ << " on line " << __LINE__ \
<< ": " << err_msg << std::endl; \
cppa_inc_error_count()
#define CPPA_CHECK_NOT_EQUAL(lhs_loc, rhs_loc) \
CPPA_CHECK(!((lhs_loc) == (rhs_loc)))
#define CPPA_CHECKPOINT() \
std::cout << "checkpoint at line " << __LINE__ << " passed" << std::endl
......
......@@ -35,11 +35,12 @@ int main() {
CPPA_TEST(test__atom);
// check if there are leading bits that distinguish "zzz" and "000 "
CPPA_CHECK_NOT_EQUAL(atom("zzz"), atom("000 "));
// check if there are leading bits that distinguish "abc" and " abc"
CPPA_CHECK_NOT_EQUAL(atom("abc"), atom(" abc"));
// 'illegal' characters are mapped to whitespaces
CPPA_CHECK_EQUAL(atom(" "), atom("@!?"));
CPPA_CHECK_NOT_EQUAL(atom("abc"), atom(" abc"));
// check to_string impl.
CPPA_CHECK_EQUAL(to_string(s_foo), "FooBar");
CPPA_CHECK_EQUAL("FooBar", to_string(s_foo));
self << make_cow_tuple(atom("foo"), static_cast<std::uint32_t>(42))
<< make_cow_tuple(atom(":Attach"), atom(":Baz"), "cstring")
<< make_cow_tuple(atom("b"), atom("a"), atom("c"), 23.f)
......@@ -48,22 +49,22 @@ int main() {
receive_for(i, 3) (
on<atom("foo"), std::uint32_t>() >> [&](std::uint32_t value) {
matched_pattern[0] = true;
CPPA_CHECK_EQUAL(value, 42);
CPPA_CHECK_EQUAL(42, value);
},
on<atom(":Attach"), atom(":Baz"), string>() >> [&](const string& str) {
matched_pattern[1] = true;
CPPA_CHECK_EQUAL(str, "cstring");
CPPA_CHECK_EQUAL("cstring", str);
},
on<atom("a"), atom("b"), atom("c"), float>() >> [&](float value) {
matched_pattern[2] = true;
CPPA_CHECK_EQUAL(value, 23.f);
CPPA_CHECK_EQUAL(23.f, value);
}
);
CPPA_CHECK(matched_pattern[0] && matched_pattern[1] && matched_pattern[2]);
receive (
others() >> []() {
// "erase" message { atom("b"), atom("a"), atom("c"), 23.f }
}
// "erase" message { atom("b"), atom("a"), atom("c"), 23.f }
others() >> CPPA_CHECKPOINT_CB(),
after(std::chrono::seconds(0)) >> CPPA_UNEXPECTED_TOUT_CB()
);
return CPPA_TEST_RESULT();
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment