Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

improved unit tests & harmonized output

this patch improves `test_match` and `test_sync_send` unit tests
and makes the output of all unit tests equally formatted
  • Loading branch information...
commit b8b594cbfd39320b56a25fe91f07ffc32c05008b 1 parent dd82600
@Neverlord Neverlord authored
View
29 unit_testing/test.cpp
@@ -7,12 +7,29 @@ using namespace cppa;
namespace { std::atomic<size_t> s_error_count{0}; }
+size_t cppa_error_count() {
+ return s_error_count;
+}
+
void cppa_inc_error_count() {
++s_error_count;
}
-size_t cppa_error_count() {
- return s_error_count;
+std::string cppa_fill4(int value) {
+ std::string result = std::to_string(value);
+ while (result.size() < 4) result.insert(result.begin(), '0');
+ return std::move(result);
+}
+
+const char* cppa_strip_path(const char* fname) {
+ auto res = fname;
+ auto i = fname;
+ for (char c = *i; c != '\0'; c = *++i) {
+ if (c == '/') {
+ res = i + 1;
+ }
+ }
+ return res;
}
void cppa_unexpected_message(const char* fname, size_t line_num) {
@@ -26,3 +43,11 @@ void cppa_unexpected_timeout(const char* fname, size_t line_num) {
std::cerr << "ERROR in file " << fname << " on line " << line_num
<< ": unexpected timeout" << std::endl;
}
+
+std::vector<std::string> split(const std::string& str, char delim) {
+ std::vector<std::string> result;
+ std::stringstream strs{str};
+ std::string tmp;
+ while (std::getline(strs, tmp, delim)) result.push_back(tmp);
+ return result;
+}
View
83 unit_testing/test.hpp
@@ -12,6 +12,24 @@
#include "cppa/to_string.hpp"
#include "cppa/util/scope_guard.hpp"
+size_t cppa_error_count();
+void cppa_inc_error_count();
+std::string cppa_fill4(int value);
+const char* cppa_strip_path(const char* fname);
+void cppa_unexpected_message(const char* fname, size_t line_num);
+void cppa_unexpected_timeout(const char* fname, size_t line_num);
+
+#define CPPA_FORMAT_STR(stream, fname, line, message) \
+ stream << cppa_strip_path(fname) << ":" \
+ << cppa_fill4(line) << " " << message \
+ << std::endl
+
+#define CPPA_PRINT(message) \
+ CPPA_FORMAT_STR(std::cout, __FILE__, __LINE__, message)
+
+#define CPPA_PRINTERR(message) \
+ CPPA_FORMAT_STR(std::cerr, __FILE__, __LINE__, message)
+
template<typename T1, typename T2>
struct both_integral {
static constexpr bool value = std::is_integral<T1>::value
@@ -21,11 +39,6 @@ struct both_integral {
template<bool V, typename T1, typename T2>
struct enable_integral : std::enable_if<both_integral<T1,T2>::value == V> { };
-size_t cppa_error_count();
-void cppa_inc_error_count();
-void cppa_unexpected_message(const char* fname, size_t line_num);
-void cppa_unexpected_timeout(const char* fname, size_t line_num);
-
template<typename T>
const T& cppa_stream_arg(const T& value) {
return value;
@@ -36,8 +49,7 @@ inline std::string cppa_stream_arg(const cppa::actor_ptr& ptr) {
}
inline void cppa_passed(const char* fname, int line_number) {
- std::cout << "line " << line_number << " in file " << fname
- << " passed" << std::endl;
+ CPPA_FORMAT_STR(std::cout, fname, line_number, "passed");
}
template<typename V1, typename V2>
@@ -45,17 +57,17 @@ inline void cppa_failed(const V1& v1,
const V2& v2,
const char* fname,
int line_number) {
- std::cerr << "ERROR in file " << fname << " on line " << line_number
- << " => expected value: "
- << cppa_stream_arg(v1)
- << ", found: "
- << cppa_stream_arg(v2)
- << std::endl;
+ CPPA_FORMAT_STR(std::cout, fname, line_number,
+ "ERROR: expected value: "
+ << cppa_stream_arg(v2)
+ << ", found: "
+ << cppa_stream_arg(v1));
cppa_inc_error_count();
}
template<typename V1, typename V2>
-inline void cppa_check_value(const V1& v1, const V2& v2,
+inline void cppa_check_value(const V1& v1,
+ const V2& v2,
const char* fname,
int line,
bool expected = true,
@@ -65,7 +77,8 @@ inline void cppa_check_value(const V1& v1, const V2& v2,
}
template<typename V1, typename V2>
-inline void cppa_check_value(V1 v1, V2 v2,
+inline void cppa_check_value(V1 v1,
+ V2 v2,
const char* fname,
int line,
bool expected = true,
@@ -74,6 +87,9 @@ inline void cppa_check_value(V1 v1, V2 v2,
else cppa_failed(v1, v2, fname, line);
}
+#define CPPA_VERBOSE_EVAL(LineOfCode) \
+ CPPA_PRINT(#LineOfCode << " = " << (LineOfCode));
+
#define CPPA_TEST(name) \
auto cppa_test_scope_guard = ::cppa::util::make_scope_guard([] { \
std::cout << cppa_error_count() << " error(s) detected" << std::endl; \
@@ -87,36 +103,35 @@ inline void cppa_check_value(V1 v1, V2 v2,
cppa_inc_error_count(); \
} \
else { \
- std::cout << "line " << __LINE__ << " passed" << std::endl; \
+ CPPA_PRINT("passed"); \
} ((void) 0)
#define CPPA_CHECK(line_of_code) \
if (!(line_of_code)) { \
- std::cerr << "ERROR in file " << __FILE__ << " on line " << __LINE__ \
- << " => " << #line_of_code << std::endl; \
+ CPPA_PRINTERR(#line_of_code); \
cppa_inc_error_count(); \
} \
- else { \
- std::cout << "line " << __LINE__ << " passed" << std::endl; \
- } ((void) 0)
+ else CPPA_PRINT("passed")
-#define CPPA_CHECK_EQUAL(lhs_loc, rhs_loc) \
+#define CPPA_CHECK_EQUAL(rhs_loc, lhs_loc) \
cppa_check_value((lhs_loc), (rhs_loc), __FILE__, __LINE__)
-#define CPPA_CHECK_NOT_EQUAL(lhs_loc, rhs_loc) \
+#define CPPA_CHECK_NOT_EQUAL(rhs_loc, lhs_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_ERROR(err_msg) { \
+ CPPA_PRINTERR("ERROR: " << err_msg); \
+ cppa_inc_error_count(); \
+ } ((void) 0)
#define CPPA_CHECKPOINT() \
- std::cout << "checkpoint at line " << __LINE__ << " passed" << std::endl
+ CPPA_PRINT("passed")
-#define CPPA_UNEXPECTED_TOUT() cppa_unexpected_timeout(__FILE__, __LINE__)
+#define CPPA_UNEXPECTED_TOUT() \
+ cppa_unexpected_timeout(__FILE__, __LINE__)
-#define CPPA_UNEXPECTED_MSG() cppa_unexpected_message(__FILE__, __LINE__)
+#define CPPA_UNEXPECTED_MSG() \
+ cppa_unexpected_message(__FILE__, __LINE__)
// some convenience macros for defining callbacks
#define CPPA_CHECKPOINT_CB() [] { CPPA_CHECKPOINT(); }
@@ -124,12 +139,6 @@ inline void cppa_check_value(V1 v1, V2 v2,
#define CPPA_UNEXPECTED_MSG_CB() [] { CPPA_UNEXPECTED_MSG(); }
#define CPPA_UNEXPECTED_TOUT_CB() [] { CPPA_UNEXPECTED_TOUT(); }
-inline std::vector<std::string> split(const std::string& str, char delim) {
- std::vector<std::string> result;
- std::stringstream strs{str};
- std::string tmp;
- while (std::getline(strs, tmp, delim)) result.push_back(tmp);
- return result;
-}
+std::vector<std::string> split(const std::string& str, char delim);
#endif // TEST_HPP
View
15 unit_testing/test_atom.cpp
@@ -23,11 +23,8 @@ namespace { constexpr auto s_foo = atom("FooBar"); }
template<atom_value AtomValue, typename... Types>
void foo() {
- cout << "foo(" << static_cast<std::uint64_t>(AtomValue)
- << " = "
- << to_string(AtomValue)
- << ")"
- << endl;
+ CPPA_PRINT("foo(" << static_cast<std::uint64_t>(AtomValue)
+ << " = " << to_string(AtomValue) << ")");
}
int main() {
@@ -40,7 +37,7 @@ int main() {
// 'illegal' characters are mapped to whitespaces
CPPA_CHECK_EQUAL(atom(" "), atom("@!?"));
// check to_string impl.
- CPPA_CHECK_EQUAL("FooBar", to_string(s_foo));
+ CPPA_CHECK_EQUAL(to_string(s_foo), "FooBar");
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)
@@ -49,15 +46,15 @@ int main() {
receive_for(i, 3) (
on<atom("foo"), std::uint32_t>() >> [&](std::uint32_t value) {
matched_pattern[0] = true;
- CPPA_CHECK_EQUAL(42, value);
+ CPPA_CHECK_EQUAL(value, 42);
},
on<atom(":Attach"), atom(":Baz"), string>() >> [&](const string& str) {
matched_pattern[1] = true;
- CPPA_CHECK_EQUAL("cstring", str);
+ CPPA_CHECK_EQUAL(str, "cstring");
},
on<atom("a"), atom("b"), atom("c"), float>() >> [&](float value) {
matched_pattern[2] = true;
- CPPA_CHECK_EQUAL(23.f, value);
+ CPPA_CHECK_EQUAL(value, 23.f);
}
);
CPPA_CHECK(matched_pattern[0] && matched_pattern[1] && matched_pattern[2]);
View
30 unit_testing/test_fixed_vector.cpp
@@ -22,18 +22,18 @@ int main() {
fixed_vector<int,2> vec5 {3, 4};
vec4.insert(vec4.end(), vec5.begin(), vec5.end());
auto vec6 = vec4;
- CPPA_CHECK_EQUAL(4, vec1.size());
- CPPA_CHECK_EQUAL(4, vec2.size());
- CPPA_CHECK_EQUAL(4, vec3.size());
- CPPA_CHECK_EQUAL(4, vec4.size());
- CPPA_CHECK_EQUAL(2, vec5.size());
- CPPA_CHECK_EQUAL(4, vec6.size());
- CPPA_CHECK_EQUAL(true, vec1.full());
- CPPA_CHECK_EQUAL(false, vec2.full());
- CPPA_CHECK_EQUAL(true, vec3.full());
- CPPA_CHECK_EQUAL(true, vec4.full());
- CPPA_CHECK_EQUAL(true, vec5.full());
- CPPA_CHECK_EQUAL(true, vec6.full());
+ CPPA_CHECK_EQUAL(vec1.size(), 4);
+ CPPA_CHECK_EQUAL(vec2.size(), 4);
+ CPPA_CHECK_EQUAL(vec3.size(), 4);
+ CPPA_CHECK_EQUAL(vec4.size(), 4);
+ CPPA_CHECK_EQUAL(vec5.size(), 2);
+ CPPA_CHECK_EQUAL(vec6.size(), 4);
+ CPPA_CHECK_EQUAL(vec1.full(), true);
+ CPPA_CHECK_EQUAL(vec2.full(), false);
+ CPPA_CHECK_EQUAL(vec3.full(), true);
+ CPPA_CHECK_EQUAL(vec4.full(), true);
+ CPPA_CHECK_EQUAL(vec5.full(), true);
+ CPPA_CHECK_EQUAL(vec6.full(), true);
CPPA_CHECK(std::equal(vec1.begin(), vec1.end(), arr1));
CPPA_CHECK(std::equal(vec2.rbegin(), vec2.rend(), arr1));
CPPA_CHECK(std::equal(vec4.begin(), vec4.end(), arr1));
@@ -44,17 +44,17 @@ int main() {
fixed_vector<int,10> vec9 {6, 7, 8};
vec7.insert(vec7.begin() + 1, vec9.begin(), vec9.end());
vec7.insert(vec7.begin(), vec8.begin(), vec8.end());
- CPPA_CHECK_EQUAL(false, vec7.full());
+ CPPA_CHECK_EQUAL(vec7.full(), false);
fixed_vector<int,1> vec10 {10};
vec7.insert(vec7.end(), vec10.begin(), vec10.end());
- CPPA_CHECK_EQUAL(true, vec7.full());
+ CPPA_CHECK_EQUAL(vec7.full(), true);
CPPA_CHECK((std::is_sorted(vec7.begin(), vec7.end())));
int arr2[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
CPPA_CHECK((std::equal(vec7.begin(), vec7.end(), std::begin(arr2))));
vec7.assign(std::begin(arr2), std::end(arr2));
CPPA_CHECK((std::equal(vec7.begin(), vec7.end(), std::begin(arr2))));
vec7.assign(5, 0);
- CPPA_CHECK_EQUAL(5, vec7.size());
+ CPPA_CHECK_EQUAL(vec7.size(), 5);
CPPA_CHECK((std::all_of(vec7.begin(), vec7.end(),
[](int i) { return i == 0; })));
return CPPA_TEST_RESULT();
View
8 unit_testing/test_intrusive_containers.cpp
@@ -67,16 +67,16 @@ int main() {
q.enqueue(new iint(2));
q.enqueue(new iint(3));
- CPPA_CHECK_EQUAL(s_iint_instances, 3);
+ CPPA_CHECK_EQUAL(3, s_iint_instances);
auto x = q.try_pop();
- CPPA_CHECK_EQUAL(1, x->value);
+ CPPA_CHECK_EQUAL(x->value, 1);
delete x;
x = q.try_pop();
- CPPA_CHECK_EQUAL(2, x->value);
+ CPPA_CHECK_EQUAL(x->value, 2);
delete x;
x = q.try_pop();
- CPPA_CHECK_EQUAL(3, x->value);
+ CPPA_CHECK_EQUAL(x->value, 3);
delete x;
x = q.try_pop();
CPPA_CHECK(x == nullptr);
View
30 unit_testing/test_intrusive_ptr.cpp
@@ -48,47 +48,47 @@ int main() {
CPPA_TEST(test__intrusive_ptr);
{
auto p = make_counted<class0>();
- CPPA_CHECK_EQUAL(1, class0_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 1);
CPPA_CHECK(p->unique());
}
- CPPA_CHECK_EQUAL(0, class0_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 0);
{
class0_ptr p;
p = new class0;
- CPPA_CHECK_EQUAL(1, class0_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 1);
CPPA_CHECK(p->unique());
}
- CPPA_CHECK_EQUAL(0, class0_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 0);
{
class0_ptr p1;
p1 = get_test_rc();
class0_ptr p2 = p1;
- CPPA_CHECK_EQUAL(1, class0_instances);
- CPPA_CHECK_EQUAL(false, p1->unique());
+ CPPA_CHECK_EQUAL(class0_instances, 1);
+ CPPA_CHECK_EQUAL(p1->unique(), false);
}
- CPPA_CHECK_EQUAL(0, class0_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 0);
{
std::list<class0_ptr> pl;
pl.push_back(get_test_ptr());
pl.push_back(get_test_rc());
pl.push_back(pl.front()->create());
CPPA_CHECK(pl.front()->unique());
- CPPA_CHECK_EQUAL(3, class0_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 3);
}
- CPPA_CHECK_EQUAL(0, class0_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 0);
{
auto p1 = make_counted<class0>();
p1 = new class1;
- CPPA_CHECK_EQUAL(1, class0_instances);
- CPPA_CHECK_EQUAL(1, class1_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 1);
+ CPPA_CHECK_EQUAL(class1_instances, 1);
auto p2 = make_counted<class1>();
p1 = p2;
- CPPA_CHECK_EQUAL(1, class0_instances);
- CPPA_CHECK_EQUAL(1, class1_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 1);
+ CPPA_CHECK_EQUAL(class1_instances, 1);
CPPA_CHECK(p1 == p2);
}
- CPPA_CHECK_EQUAL(0, class0_instances);
- CPPA_CHECK_EQUAL(0, class1_instances);
+ CPPA_CHECK_EQUAL(class0_instances, 0);
+ CPPA_CHECK_EQUAL(class1_instances, 0);
return CPPA_TEST_RESULT();
View
2  unit_testing/test_local_group.cpp
@@ -38,7 +38,7 @@ int main() {
int result = 0;
do_receive (
on<int>() >> [&](int value) {
- CPPA_CHECK_EQUAL(2, value);
+ CPPA_CHECK_EQUAL(value, 2);
result += value;
},
after(std::chrono::seconds(2)) >> [&]() {
View
102 unit_testing/test_match.cpp
@@ -49,10 +49,10 @@ int main() {
auto expr1 = _x1 + _x2;
auto expr2 = _x1 + _x2 < _x3;
auto expr3 = _x1 % _x2 == 0;
- CPPA_CHECK_EQUAL(5, (ge_invoke(expr1, 2, 3)));
+ CPPA_CHECK_EQUAL((ge_invoke(expr1, 2, 3)), 5);
//CPPA_CHECK(ge_invoke(expr2, 1, 2, 4));
CPPA_CHECK(expr2(1, 2, 4));
- CPPA_CHECK_EQUAL("12", (ge_invoke(expr1, std::string{"1"}, std::string{"2"})));
+ CPPA_CHECK_EQUAL((ge_invoke(expr1, std::string{"1"}, std::string{"2"})), "12");
CPPA_CHECK(expr3(100, 2));
auto expr4 = _x1 == "-h" || _x1 == "--help";
@@ -101,39 +101,39 @@ int main() {
auto expr14 = _x1 + _x2;
static_assert(std::is_same<decltype(ge_invoke(expr14, 1, 2)), int>::value,
"wrong return type");
- CPPA_CHECK_EQUAL(5, (ge_invoke(expr14, 2, 3)));
+ CPPA_CHECK_EQUAL((ge_invoke(expr14, 2, 3)), 5);
auto expr15 = _x1 + _x2 + _x3;
static_assert(std::is_same<decltype(ge_invoke(expr15,1,2,3)), int>::value,
"wrong return type");
- CPPA_CHECK_EQUAL(42, (ge_invoke(expr15, 7, 10, 25)));
+ CPPA_CHECK_EQUAL((ge_invoke(expr15, 7, 10, 25)), 42);
std::string expr16_str;// = "expr16";
auto expr16_a = _x1.size();
auto expr16_b = _x1.front() == 'e';
- CPPA_CHECK_EQUAL(false, ge_invoke(expr16_b, expr16_str));
- CPPA_CHECK_EQUAL(0, ge_invoke(expr16_a, expr16_str));
+ CPPA_CHECK_EQUAL((ge_invoke(expr16_b, expr16_str)), false);
+ CPPA_CHECK_EQUAL((ge_invoke(expr16_a, expr16_str)), 0);
expr16_str = "expr16";
- CPPA_CHECK_EQUAL(true, ge_invoke(expr16_b, expr16_str));
- CPPA_CHECK_EQUAL(expr16_str.size(), ge_invoke(expr16_a, expr16_str));
+ CPPA_CHECK_EQUAL((ge_invoke(expr16_b, expr16_str)), true);
+ CPPA_CHECK_EQUAL((ge_invoke(expr16_a, expr16_str)), expr16_str.size());
expr16_str.front() = '_';
- CPPA_CHECK_EQUAL(false, ge_invoke(expr16_b, expr16_str));
+ CPPA_CHECK_EQUAL((ge_invoke(expr16_b, expr16_str)), false);
int expr17_value = 42;
auto expr17 = gref(expr17_value) == 42;
- CPPA_CHECK_EQUAL(true, ge_invoke(expr17));
+ CPPA_CHECK_EQUAL(ge_invoke(expr17), true);
expr17_value = 0;
- CPPA_CHECK_EQUAL(false, ge_invoke(expr17));
+ CPPA_CHECK_EQUAL(ge_invoke(expr17), false);
int expr18_value = 42;
auto expr18_a = gref(expr18_value) == 42;
- CPPA_CHECK_EQUAL(true, ge_invoke(expr18_a));
+ CPPA_CHECK_EQUAL(ge_invoke(expr18_a), true);
expr18_value = 0;
- CPPA_CHECK_EQUAL(false, ge_invoke(expr18_a));
+ CPPA_CHECK_EQUAL(ge_invoke(expr18_a), false);
auto expr18_b = gref(expr18_value) == _x1;
auto expr18_c = std::ref(expr18_value) == _x1;
- CPPA_CHECK_EQUAL(true, ge_invoke(expr18_b, 0));
- CPPA_CHECK_EQUAL(true, ge_invoke(expr18_c, 0));
+ CPPA_CHECK_EQUAL((ge_invoke(expr18_b, 0)), true);
+ CPPA_CHECK_EQUAL((ge_invoke(expr18_c, 0)), true);
bool invoked = false;
@@ -144,20 +144,11 @@ int main() {
}
return {};
};
- /*
- auto kvp_split2 = [](const string& str) -> option<vector<string> > {
- auto pos = str.find('=');
- if (pos != string::npos && pos == str.rfind('=')) {
- return vector<string>{str.substr(0, pos-1), str.substr(pos+1)};
- }
- return {};
- };
- */
match("value=42") (
on(kvp_split1).when(_x1.not_empty()) >> [&](const vector<string>& vec) {
- CPPA_CHECK_EQUAL(vec[0], "value");
- CPPA_CHECK_EQUAL(vec[1], "42");
+ CPPA_CHECK_EQUAL("value", vec[0]);
+ CPPA_CHECK_EQUAL("42", vec[1]);
invoked = true;
}
);
@@ -174,7 +165,7 @@ int main() {
};
match("42") (
on(toint) >> [&](int i) {
- CPPA_CHECK_EQUAL(i, 42);
+ CPPA_CHECK_EQUAL(42, i);
invoked = true;
}
);
@@ -261,11 +252,11 @@ int main() {
CPPA_ERROR("unexpected match");
}
);
- CPPA_CHECK_EQUAL("-h--versionwtf", sum);
+ CPPA_CHECK_EQUAL(sum, "-h--versionwtf");
match(5) (
on<int>().when(_x1 < 6) >> [&](int i) {
- CPPA_CHECK_EQUAL(5, i);
+ CPPA_CHECK_EQUAL(i, 5);
invoked = true;
}
);
@@ -280,7 +271,7 @@ int main() {
}
);
if (!invoked) { CPPA_ERROR("match({\"a\", \"b\", \"c\"}) failed"); }
- CPPA_CHECK_EQUAL("C", vec.back());
+ CPPA_CHECK_EQUAL(vec.back(), "C");
invoked = false;
match_each(begin(vec), end(vec)) (
@@ -290,7 +281,7 @@ int main() {
}
);
if (!invoked) { CPPA_ERROR("match_each({\"a\", \"b\", \"C\"}) failed"); }
- CPPA_CHECK_EQUAL("A", vec.front());
+ CPPA_CHECK_EQUAL(vec.front(), "A");
invoked = false;
vector<string> vec2{"a=0", "b=1", "c=2"};
@@ -299,7 +290,7 @@ int main() {
match(c2) (
on("c", "2") >> [&]() { invoked = true; }
);
- CPPA_CHECK_EQUAL(true, invoked);
+ CPPA_CHECK_EQUAL(invoked, true);
invoked = false;
// let's get the awesomeness started
@@ -309,7 +300,7 @@ int main() {
success = match_stream<string>(iss) (
on("hello", "world") >> CPPA_CHECKPOINT_CB()
);
- CPPA_CHECK_EQUAL(true, success);
+ CPPA_CHECK_EQUAL(success, true);
auto extract_name = [](const string& kvp) -> option<string> {
auto vec = split(kvp, '=');
@@ -331,7 +322,7 @@ int main() {
on("-p", arg_match) >> [&](const string& port) -> bool {
auto i = toint(port);
if (i) {
- CPPA_CHECK_EQUAL(2, *i);
+ CPPA_CHECK_EQUAL(*i, 2);
return true;
}
else return false;
@@ -341,17 +332,17 @@ int main() {
return false;
}
);
- CPPA_CHECK_EQUAL(true, success);
+ CPPA_CHECK_EQUAL(success, true);
- cout << "check combined partial function matching" << endl;
+ CPPA_PRINT("check combined partial function matching");
std::string last_invoked_fun;
- auto check = [&](partial_function& pf, const any_tuple& tup, const string& str) {
- last_invoked_fun = "";
- pf(tup);
- CPPA_CHECK_EQUAL(str, last_invoked_fun);
- };
+# define check(pf, tup, str) { \
+ last_invoked_fun = ""; \
+ pf(tup); \
+ CPPA_CHECK_EQUAL(last_invoked_fun, str); \
+ }
partial_function pf0 = (
on<int,int>() >> [&] { last_invoked_fun = "<int,int>@1"; },
@@ -368,5 +359,34 @@ int main() {
check(pf0, make_any_tuple("hi"), "");
check(pf1, make_any_tuple("hi"), "<string>@4");
+ CPPA_PRINT("check match expressions with boolean return value");
+
+# define bhvr_check(pf, tup, expected_result, str) { \
+ last_invoked_fun = ""; \
+ CPPA_CHECK_EQUAL(pf(tup), expected_result); \
+ CPPA_CHECK_EQUAL(last_invoked_fun, str); \
+ }
+
+ behavior bhvr1 = (
+ on<int>() >> [&](int i) -> bool {
+ last_invoked_fun = "<int>@1";
+ return i != 42;
+ },
+ on<float>() >> [&] {
+ last_invoked_fun = "<float>@2";
+ },
+ on<int>() >> [&] {
+ last_invoked_fun = "<int>@3";
+ },
+ others() >> [&] {
+ last_invoked_fun = "<*>@4";
+ }
+ );
+
+ bhvr_check(bhvr1, make_any_tuple(42), false, "<int>@1");
+ bhvr_check(bhvr1, make_any_tuple(24), true, "<int>@1");
+ bhvr_check(bhvr1, make_any_tuple(2.f), true, "<float>@2");
+ bhvr_check(bhvr1, make_any_tuple(""), true, "<*>@4");
+
return CPPA_TEST_RESULT();
}
View
6 unit_testing/test_metaprogramming.cpp
@@ -25,7 +25,7 @@ int main() {
CPPA_TEST(test__metaprogramming);
- cout << "test type_list" << endl;
+ CPPA_PRINT("test type_list");
typedef type_list<int,float,std::string> l1;
typedef typename tl_reverse<l1>::type r1;
@@ -35,7 +35,7 @@ int main() {
CPPA_CHECK((is_same<std::string,element_at<2,l1>::type>::value));
CPPA_CHECK_EQUAL(3 ,tl_size<l1>::value);
- CPPA_CHECK_EQUAL(tl_size<l1>::value, tl_size<r1>::value);
+ CPPA_CHECK_EQUAL(tl_size<r1>::value, tl_size<l1>::value);
CPPA_CHECK((is_same<element_at<0,l1>::type,element_at<2,r1>::type>::value));
CPPA_CHECK((is_same<element_at<1,l1>::type,element_at<1,r1>::type>::value));
CPPA_CHECK((is_same<element_at<2,l1>::type,element_at<0,r1>::type>::value));
@@ -46,7 +46,7 @@ int main() {
CPPA_CHECK((is_same<l1,tl_tail<l2>::type>::value));
- cout << "test int_list" << endl;
+ CPPA_PRINT("test int_list");
typedef int_list<0,1,2,3,4,5> il0;
typedef int_list<4,5> il1;
View
8 unit_testing/test_primitive_variant.cpp
@@ -33,8 +33,8 @@ int main() {
primitive_variant v1(forty_two);
primitive_variant v2(pt_uint32);
// type checking
- CPPA_CHECK_EQUAL(pt_uint32, v1.ptype());
- CPPA_CHECK_EQUAL(pt_uint32, v2.ptype());
+ CPPA_CHECK_EQUAL(v1.ptype(), pt_uint32);
+ CPPA_CHECK_EQUAL(v2.ptype(), pt_uint32);
get_ref<std::uint32_t&>(v2) = forty_two;
CPPA_CHECK(equal(v1, v2));
CPPA_CHECK(equal(v1, forty_two));
@@ -42,9 +42,9 @@ int main() {
// type mismatch => unequal
CPPA_CHECK(!equal(v2, static_cast<std::int8_t>(forty_two)));
v1 = "Hello world";
- CPPA_CHECK_EQUAL(pt_u8string, v1.ptype());
+ CPPA_CHECK_EQUAL(v1.ptype(), pt_u8string);
v2 = "Hello";
- CPPA_CHECK_EQUAL(pt_u8string, v2.ptype());
+ CPPA_CHECK_EQUAL(v2.ptype(), pt_u8string);
get_ref<std::string>(v2) += " world";
CPPA_CHECK(equal(v1, v2));
v2 = u"Hello World";
View
60 unit_testing/test_remote_actor.cpp
@@ -3,6 +3,7 @@
#include <cstring>
#include <sstream>
#include <iostream>
+#include <functional>
#include "test.hpp"
#include "ping_pong.hpp"
@@ -23,12 +24,12 @@ vector<string_pair> get_kv_pairs(int argc, char** argv, int begin = 1) {
vector<string_pair> result;
for (int i = begin; i < argc; ++i) {
auto vec = split(argv[i], '=');
+ auto eq_fun = [&](const string_pair& p) { return p.first == vec[0]; };
if (vec.size() != 2) {
- cerr << "\"" << argv[i] << "\" is not a key-value pair" << endl;
+ CPPA_PRINTERR("\"" << argv[i] << "\" is not a key-value pair");
}
- else if (any_of(result.begin(), result.end(),
- [&](const string_pair& p) { return p.first == vec[0]; })) {
- cerr << "key \"" << vec[0] << "\" is already defined" << endl;
+ else if (any_of(result.begin(), result.end(), eq_fun)) {
+ CPPA_PRINTERR("key \"" << vec[0] << "\" is already defined");
}
else {
result.emplace_back(vec[0], vec[1]);
@@ -61,12 +62,7 @@ struct replier : public event_based_actor {
// receive seven reply messages (2 local, 5 remote)
void spawn5_server(actor_ptr client, bool inverted) {
- auto default_case = others() >> [] {
- cout << "unexpected message; "
- << __FILE__ << " line " << __LINE__ << ": "
- << to_string(self->last_dequeued())
- << endl;
- };
+ auto default_case = others() >> CPPA_UNEXPECTED_MSG_CB();
group_ptr grp;
if (!inverted) {
grp = group::get("local", "foobar");
@@ -85,7 +81,7 @@ void spawn5_server(actor_ptr client, bool inverted) {
on(atom("ok"), arg_match) >> [&](const actor_vector& vec) {
send(grp, "Hello reflectors!", 5.0);
if (vec.size() != 5) {
- cout << "remote client did not spawn five reflectors!\n";
+ CPPA_PRINT("remote client did not spawn five reflectors!");
}
for (auto& a : vec) {
self->monitor(a);
@@ -96,24 +92,24 @@ void spawn5_server(actor_ptr client, bool inverted) {
throw runtime_error("timeout");
}
);
- cout << "wait for reflected messages\n";
+ CPPA_PRINT("wait for reflected messages");
// receive seven reply messages (2 local, 5 remote)
int x = 0;
receive_for(x, 7) (
on("Hello reflectors!", 5.0) >> [] { }
);
- cout << "wait for DOWN messages\n";
+ CPPA_PRINT("wait for DOWN messages");
// wait for DOWN messages
{int i = 0; receive_for(i, 5) (
on(atom("DOWN"), arg_match) >> [](std::uint32_t reason) {
if (reason != exit_reason::normal) {
- cout << "reflector exited for non-normal exit reason!" << endl;
+ CPPA_PRINT("reflector exited for non-normal exit reason!");
}
},
default_case,
after(chrono::seconds(2)) >> [&] {
i = 4;
- cout << "timeout while waiting for DOWN messages!\n";
+ CPPA_PRINTERR("timeout while waiting for DOWN messages!");
}
);}
// wait for locally spawned reflectors
@@ -179,7 +175,7 @@ int client_part(const vector<string_pair>& args) {
}
},
after(chrono::seconds(5)) >> [&] {
- cerr << "sync_send timed out!" << endl;
+ CPPA_PRINTERR("sync_send timed out!");
send(server, atom("Timeout"));
}
);
@@ -228,11 +224,11 @@ int client_part(const vector<string_pair>& args) {
void verbose_terminate() {
try { if (std::uncaught_exception()) throw; }
catch (std::exception& e) {
- cerr << "terminate called after throwing "
- << to_verbose_string(e) << endl;
+ CPPA_PRINTERR("terminate called after throwing "
+ << to_verbose_string(e));
}
catch (...) {
- cerr << "terminate called after throwing an unknown exception" << endl;
+ CPPA_PRINTERR("terminate called after throwing an unknown exception");
}
abort();
@@ -280,15 +276,15 @@ int main(int argc, char** argv) {
CPPA_LOGF_TRACE("lambda expression calling system()");
string cmdstr = oss.str();
if (system(cmdstr.c_str()) != 0) {
- cerr << "FATAL: command \"" << cmdstr << "\" failed!" << endl;
+ CPPA_PRINTERR("FATAL: command \"" << cmdstr << "\" failed!");
abort();
}
});
}
else {
- cout << "actor published at port " << port << endl;
+ CPPA_PRINT("actor published at port " << port);
}
- //cout << "await SpawnPing message" << endl;
+ //CPPA_PRINT("await SpawnPing message");
actor_ptr remote_client;
CPPA_LOGF_DEBUG("send 'SpawnPing', expect 'PingPtr'");
receive (
@@ -301,8 +297,8 @@ int main(int argc, char** argv) {
);
CPPA_LOGF_DEBUG("wait until spawned ping actors are done");
await_all_others_done();
- CPPA_CHECK_EQUAL(10, pongs());
- cout << "test remote sync_send" << endl;
+ CPPA_CHECK_EQUAL(pongs(), 10);
+ CPPA_PRINT("test remote sync_send");
receive (
on(atom("SyncMsg")) >> [] {
reply(atom("SyncReply"));
@@ -320,17 +316,17 @@ int main(int argc, char** argv) {
}
);
// test 100 sync messages
- cout << "test 100 synchronous messages" << endl;
+ CPPA_PRINT("test 100 synchronous messages");
int i = 0;
receive_for(i, 100) (
others() >> [] {
reply_tuple(self->last_dequeued());
}
);
- cout << "test group communication via network" << endl;
+ CPPA_PRINT("test group communication via network");
// group test
spawn5_client();
- cout << "test group communication via network (inverted setup)" << endl;
+ CPPA_PRINT("test group communication via network (inverted setup)");
spawn5_server(remote_client, true);
self->on_sync_failure([&] {
@@ -340,18 +336,18 @@ int main(int argc, char** argv) {
});
// test forward_to "over network and back"
- cout << "test forwarding over network 'and back'" << endl;
+ CPPA_PRINT("test forwarding over network 'and back'");
auto ra = spawn<replier>();
timed_sync_send(remote_client, chrono::seconds(5), atom("fwd"), ra, "hello replier!").await(
[&](int forty_two) {
- CPPA_CHECK_EQUAL(42, forty_two);
+ CPPA_CHECK_EQUAL(forty_two, 42);
auto from = self->last_sender();
- CPPA_CHECK_EQUAL(ra, from);
- if (from) CPPA_CHECK_EQUAL(false, from->is_proxy());
+ CPPA_CHECK_EQUAL(from, ra);
+ if (from) CPPA_CHECK_EQUAL(from->is_proxy(), false);
}
);
- cout << "wait for a last goodbye" << endl;
+ CPPA_PRINT("wait for a last goodbye");
receive (
on(atom("farewell")) >> [] { }
);
View
6 unit_testing/test_serialization.cpp
@@ -177,12 +177,12 @@ int main() {
binary_deserializer bd(wr_buf.data(), wr_buf.size(), &addressing);
raw_struct rs2;
uniform_typeid<raw_struct>()->deserialize(&rs2, &bd);
- CPPA_CHECK_EQUAL(rs.str, rs2.str);
+ CPPA_CHECK_EQUAL(rs2.str, rs.str);
auto rsstr = cppa::to_string(object::from(rs));
rs2.str = "foobar";
- cout << "rs as string: " << rsstr << endl;
+ CPPA_PRINT("rs as string: " << rsstr);
rs2 = from_string<raw_struct>(rsstr);
- CPPA_CHECK_EQUAL(rs.str, rs2.str);
+ CPPA_CHECK_EQUAL(rs2.str, rs.str);
}
catch (exception& e) { CPPA_ERROR(to_verbose_string(e)); }
View
115 unit_testing/test_spawn.cpp
@@ -298,67 +298,59 @@ struct simple_mirror : sb_actor<simple_mirror> {
int main() {
CPPA_TEST(test__spawn);
- cout << "test send() ... " << flush;
+ CPPA_PRINT("test send()");
send(self, 1, 2, 3, true);
receive(on(1, 2, 3, true) >> []() { });
- cout << "... with empty message... " << flush;
self << any_tuple{};
receive(on() >> []() { });
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
self << any_tuple{};
receive(on() >> []() { });
- cout << "test receive with zero timeout ... " << flush;
+ CPPA_PRINT("test receive with zero timeout");
receive (
others() >> CPPA_UNEXPECTED_MSG_CB(),
- after(chrono::seconds(0)) >> []() {
- // mailbox empty
- }
+ after(chrono::seconds(0)) >> []() { /* mailbox empty */ }
);
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
auto mirror = spawn<simple_mirror>();
- cout << "test mirror ... " << flush;
+ CPPA_PRINT("test mirror");
send(mirror, "hello mirror");
receive(on("hello mirror") >> []() { });
send(mirror, atom("EXIT"), exit_reason::user_defined);
- cout << "await ... " << endl;
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "test echo actor ... " << flush;
+ CPPA_PRINT("test echo actor");
auto mecho = spawn(echo_actor);
send(mecho, "hello echo");
receive (
on("hello echo") >> []() { },
others() >> CPPA_UNEXPECTED_MSG_CB()
);
- cout << "await ... " << endl;
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "test delayed_send() ... " << flush;
+ CPPA_PRINT("test delayed_send()");
delayed_send(self, chrono::seconds(1), 1, 2, 3);
receive(on(1, 2, 3) >> []() { });
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "test timeout ... " << flush;
+ CPPA_PRINT("test timeout");
receive(after(chrono::seconds(1)) >> []() { });
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "testee1 ... " << flush;
spawn(testee1);
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "event_testee2 ... " << flush;
spawn_event_testee2();
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "chopstick ... " << flush;
auto cstk = spawn<chopstick>();
send(cstk, atom("take"), self);
receive (
@@ -368,9 +360,8 @@ int main() {
}
);
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "test event-based factory ... " << flush;
auto factory = factory::event_based([&](int* i, float*, string*) {
self->become (
on(atom("get_int")) >> [i]() {
@@ -391,18 +382,17 @@ int main() {
send(foobaz_actor, atom("done"));
receive (
on_arg_match >> [&](int value) {
- CPPA_CHECK_EQUAL(23, value);
+ CPPA_CHECK_EQUAL(value, 23);
}
);
receive (
on_arg_match >> [&](int value) {
- CPPA_CHECK_EQUAL(42, value);
+ CPPA_CHECK_EQUAL(value, 42);
}
);
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "test fixed_stack ... " << flush;
auto st = spawn<fixed_stack>(10);
// push 20 values
for (int i = 0; i < 20; ++i) send(st, atom("push"), i);
@@ -431,9 +421,8 @@ int main() {
// terminate st
send(st, atom("EXIT"), exit_reason::user_defined);
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "test sync send/receive ... " << flush;
auto sync_testee1 = spawn([]() {
receive (
on(atom("get")) >> []() {
@@ -450,14 +439,14 @@ int main() {
// must skip sync message
receive (
on(42, arg_match) >> [&](int i) {
- CPPA_CHECK_EQUAL(1, i);
+ CPPA_CHECK_EQUAL(i, 1);
}
);
// must skip remaining async message
receive_response (handle) (
on_arg_match >> [&](int a, int b) {
- CPPA_CHECK_EQUAL(42, a);
- CPPA_CHECK_EQUAL(2, b);
+ CPPA_CHECK_EQUAL(a, 42);
+ CPPA_CHECK_EQUAL(b, 2);
},
others() >> CPPA_UNEXPECTED_MSG_CB(),
after(chrono::seconds(10)) >> CPPA_UNEXPECTED_TOUT_CB()
@@ -470,9 +459,9 @@ int main() {
after(chrono::seconds(0)) >> []() { }
);
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
- cout << "test sync send with factory spawned actor ... " << flush;
+ CPPA_PRINT("test sync send with factory spawned actor");
auto sync_testee_factory = factory::event_based(
[&]() {
self->become (
@@ -481,7 +470,7 @@ int main() {
self->handle_response(handle) (
on_arg_match >> [&](const string& str) {
CPPA_CHECK(self->last_sender() != nullptr);
- CPPA_CHECK_EQUAL("nothing", str);
+ CPPA_CHECK_EQUAL(str, "nothing");
reply("goodbye!");
self->quit();
},
@@ -491,15 +480,11 @@ int main() {
}
);
},
- others() >> []() {
- cerr << "UNEXPECTED: " << to_string(self->last_dequeued())
- << endl;
- }
-
+ others() >> CPPA_UNEXPECTED_MSG_CB()
);
}
);
- CPPA_CHECK(true);
+ CPPA_CHECKPOINT();
auto sync_testee = sync_testee_factory.spawn();
self->monitor(sync_testee);
send(sync_testee, "hi");
@@ -511,15 +496,17 @@ int main() {
reply("nothing");
}
);
- receive (on("goodbye!") >> CPPA_CHECKPOINT_CB());
- CPPA_CHECKPOINT();
+ receive (
+ on("goodbye!") >> CPPA_CHECKPOINT_CB(),
+ after(std::chrono::seconds(5)) >> CPPA_UNEXPECTED_TOUT_CB()
+ );
receive (
on(atom("DOWN"), exit_reason::normal) >> [&] {
- CPPA_CHECK(self->last_sender() == sync_testee);
+ CPPA_CHECK_EQUAL(self->last_sender(), sync_testee);
}
);
await_all_others_done();
- cout << "ok" << endl;
+ CPPA_CHECKPOINT();
sync_send(sync_testee, "!?").await(
on(atom("EXITED"), any_vals) >> CPPA_CHECKPOINT_CB(),
@@ -583,29 +570,29 @@ int main() {
int zombie_on_exit_called = 0;
factory::event_based([&]() { ++zombie_init_called; },
[&]() { ++zombie_on_exit_called; }).spawn();
- CPPA_CHECK_EQUAL(1, zombie_init_called);
- CPPA_CHECK_EQUAL(1, zombie_on_exit_called);
+ CPPA_CHECK_EQUAL(zombie_init_called, 1);
+ CPPA_CHECK_EQUAL(zombie_on_exit_called, 1);
factory::event_based([&](int* i) {
- CPPA_CHECK_EQUAL(42, *i);
+ CPPA_CHECK_EQUAL(*i, 42);
++zombie_init_called;
},
[&](int* i) {
- CPPA_CHECK_EQUAL(42, *i);
+ CPPA_CHECK_EQUAL(*i, 42);
++zombie_on_exit_called;
})
.spawn(42);
- CPPA_CHECK_EQUAL(2, zombie_init_called);
- CPPA_CHECK_EQUAL(2, zombie_on_exit_called);
+ CPPA_CHECK_EQUAL(zombie_init_called, 2);
+ CPPA_CHECK_EQUAL(zombie_on_exit_called, 2);
factory::event_based([&](int* i) {
- CPPA_CHECK_EQUAL(23, *i);
+ CPPA_CHECK_EQUAL(*i, 23);
++zombie_init_called;
},
[&]() {
++zombie_on_exit_called;
})
.spawn(23);
- CPPA_CHECK_EQUAL(3, zombie_init_called);
- CPPA_CHECK_EQUAL(3, zombie_on_exit_called);
+ CPPA_CHECK_EQUAL(zombie_init_called, 3);
+ CPPA_CHECK_EQUAL(zombie_on_exit_called, 3);
auto f = factory::event_based([](string* name) {
self->become (
@@ -619,13 +606,13 @@ int main() {
send(a1, atom("get_name"));
receive (
on(atom("name"), arg_match) >> [&](const string& name) {
- CPPA_CHECK_EQUAL("alice", name);
+ CPPA_CHECK_EQUAL(name, "alice");
}
);
send(a2, atom("get_name"));
receive (
on(atom("name"), arg_match) >> [&](const string& name) {
- CPPA_CHECK_EQUAL("bob", name);
+ CPPA_CHECK_EQUAL(name, "bob");
}
);
auto kill_msg = make_any_tuple(atom("EXIT"), exit_reason::user_defined);
@@ -644,7 +631,7 @@ int main() {
await_all_others_done();
auto res1 = behavior_test<testee_actor>(spawn(testee_actor{}));
- CPPA_CHECK_EQUAL(res1, "wait4int");
+ CPPA_CHECK_EQUAL("wait4int", res1);
CPPA_CHECK_EQUAL(behavior_test<event_testee>(spawn<event_testee>()), "wait4int");
// create 20,000 actors linked to one single actor
@@ -671,7 +658,7 @@ int main() {
// wait for DOWN and EXIT messages of pong
receive_for(i, 4) (
on<atom("EXIT"), uint32_t>() >> [&](uint32_t reason) {
- CPPA_CHECK_EQUAL(reason, exit_reason::user_defined);
+ CPPA_CHECK_EQUAL(exit_reason::user_defined, reason);
CPPA_CHECK(self->last_sender() == pong_actor);
flags |= 0x01;
},
@@ -679,11 +666,11 @@ int main() {
auto who = self->last_sender();
if (who == pong_actor) {
flags |= 0x02;
- CPPA_CHECK_EQUAL(reason, exit_reason::user_defined);
+ CPPA_CHECK_EQUAL(exit_reason::user_defined, reason);
}
else if (who == ping_actor) {
flags |= 0x04;
- CPPA_CHECK_EQUAL(reason, exit_reason::normal);
+ CPPA_CHECK_EQUAL(exit_reason::normal, reason);
}
},
on_arg_match >> [&](const atom_value& val) {
@@ -699,8 +686,8 @@ int main() {
);
// wait for termination of all spawned actors
await_all_others_done();
- CPPA_CHECK_EQUAL(0x0F, flags);
+ CPPA_CHECK_EQUAL(flags, 0x0F);
// verify pong messages
- CPPA_CHECK_EQUAL(10, pongs());
+ CPPA_CHECK_EQUAL(pongs(), 10);
return CPPA_TEST_RESULT();
}
View
22 unit_testing/test_sync_send.cpp
@@ -120,13 +120,13 @@ int main() {
auto mirror = spawn<sync_mirror>();
bool continuation_called = false;
sync_send(mirror, 42).then(
- [](int value) { CPPA_CHECK_EQUAL(42, value); }
+ [](int value) { CPPA_CHECK_EQUAL(value, 42); }
)
.continue_with(
[&] { continuation_called = true; }
);
self->exec_behavior_stack();
- CPPA_CHECK_EQUAL(true, continuation_called);
+ CPPA_CHECK_EQUAL(continuation_called, true);
send(mirror, atom("EXIT"), exit_reason::user_defined);
await_all_others_done();
CPPA_CHECKPOINT();
@@ -142,10 +142,13 @@ int main() {
};
send(spawn_monitor<A>(self), atom("go"), spawn<B>(spawn<C>()));
await_success_message();
+ CPPA_CHECKPOINT();
await_all_others_done();
send(spawn_monitor<A>(self), atom("go"), spawn<D>(spawn<C>()));
await_success_message();
+ CPPA_CHECKPOINT();
await_all_others_done();
+ CPPA_CHECKPOINT();
timed_sync_send(self, std::chrono::milliseconds(50), atom("NoWay")).await(
on(atom("TIMEOUT")) >> CPPA_CHECKPOINT_CB(),
others() >> CPPA_UNEXPECTED_MSG_CB()
@@ -165,6 +168,21 @@ int main() {
others() >> CPPA_UNEXPECTED_MSG_CB(),
after(std::chrono::seconds(0)) >> CPPA_CHECKPOINT_CB()
);
+ // check wheter continuations are invoked correctly
+ auto c = spawn<C>(); // replies only to 'gogo' messages
+ // first test: sync error must occur, continuation must not be called
+ self->on_sync_failure(CPPA_CHECKPOINT_CB());
+ timed_sync_send(c, std::chrono::milliseconds(500), atom("HiThere"))
+ .then(CPPA_ERROR_CB("C replied to 'HiThere'!"))
+ .continue_with(CPPA_ERROR_CB("bad continuation"));
+ self->exec_behavior_stack();
+ self->on_sync_failure(CPPA_UNEXPECTED_MSG_CB());
+ sync_send(c, atom("gogo")).then(CPPA_CHECKPOINT_CB())
+ .continue_with(CPPA_CHECKPOINT_CB());
+ self->exec_behavior_stack();
+ send(c, atom("EXIT"), exit_reason::user_defined);
+ await_all_others_done();
+ CPPA_CHECKPOINT();
shutdown();
return CPPA_TEST_RESULT();
}
View
76 unit_testing/test_tuple.cpp
@@ -37,8 +37,6 @@ using std::endl;
using namespace cppa;
using namespace cppa::detail;
-#define VERBOSE(LineOfCode) cout << #LineOfCode << " = " << (LineOfCode) << endl
-
namespace { std::atomic<size_t> s_expensive_copies; }
struct expensive_copy_struct {
@@ -137,7 +135,7 @@ int main() {
announce<expensive_copy_struct>(&expensive_copy_struct::value);
cow_tuple<int> zero;
- CPPA_CHECK_EQUAL(0, get<0>(zero));
+ CPPA_CHECK_EQUAL(get<0>(zero), 0);
using namespace cppa::placeholders;
@@ -170,15 +168,15 @@ int main() {
CPPA_CHECK_INVOKED(f02, (42, 21));
CPPA_CHECK(f02.invoke(make_cow_tuple(42, 21)));
- CPPA_CHECK_EQUAL("f02", invoked);
+ CPPA_CHECK_EQUAL(invoked, "f02");
invoked = "";
- auto f03 = on(42, val<int>) >> [&](const int& a, int&) { invoked = "f03"; CPPA_CHECK_EQUAL(42, a); };
+ auto f03 = on(42, val<int>) >> [&](const int& a, int&) { invoked = "f03"; CPPA_CHECK_EQUAL(a, 42); };
CPPA_CHECK_NOT_INVOKED(f03, (0, 0));
CPPA_CHECK_INVOKED(f03, (42, 42));
auto f04 = on(42, int2str).when(_x2 == "42") >> [&](std::string& str) {
- CPPA_CHECK_EQUAL("42", str);
+ CPPA_CHECK_EQUAL(str, "42");
invoked = "f04";
};
@@ -210,26 +208,26 @@ int main() {
int f08_val = 666;
auto f08 = on<int>() >> [&](int& mref) { mref = 8; invoked = "f08"; };
CPPA_CHECK_INVOKED(f08, (f08_val));
- CPPA_CHECK_EQUAL(8, f08_val);
+ CPPA_CHECK_EQUAL(f08_val, 8);
any_tuple f08_any_val = make_cow_tuple(666);
CPPA_CHECK(f08.invoke(f08_any_val));
- CPPA_CHECK_EQUAL(8, f08_any_val.get_as<int>(0));
+ CPPA_CHECK_EQUAL(f08_any_val.get_as<int>(0), 8);
int f09_val = 666;
auto f09 = on(str2int, val<int>) >> [&](int& mref) { mref = 9; invoked = "f09"; };
CPPA_CHECK_NOT_INVOKED(f09, ("hello lambda", f09_val));
CPPA_CHECK_INVOKED(f09, ("0", f09_val));
- CPPA_CHECK_EQUAL(9, f09_val);
+ CPPA_CHECK_EQUAL(f09_val, 9);
any_tuple f09_any_val = make_cow_tuple("0", 666);
CPPA_CHECK(f09.invoke(f09_any_val));
- CPPA_CHECK_EQUAL(9, f09_any_val.get_as<int>(1));
+ CPPA_CHECK_EQUAL(f09_any_val.get_as<int>(1), 9);
f09_any_val.get_as_mutable<int>(1) = 666;
any_tuple f09_any_val_copy{f09_any_val};
CPPA_CHECK_EQUAL(f09_any_val.at(0), f09_any_val_copy.at(0));
// detaches f09_any_val from f09_any_val_copy
CPPA_CHECK(f09.invoke(f09_any_val));
- CPPA_CHECK_EQUAL(9, f09_any_val.get_as<int>(1));
- CPPA_CHECK_EQUAL(666, f09_any_val_copy.get_as<int>(1));
+ CPPA_CHECK_EQUAL(f09_any_val.get_as<int>(1), 9);
+ CPPA_CHECK_EQUAL(f09_any_val_copy.get_as<int>(1), 666);
// no longer the same data
CPPA_CHECK_NOT_EQUAL(f09_any_val.at(0), f09_any_val_copy.at(0));
@@ -240,11 +238,11 @@ int main() {
);
CPPA_CHECK(f10(9));
- CPPA_CHECK_EQUAL("f10.0", invoked);
+ CPPA_CHECK_EQUAL(invoked, "f10.0");
CPPA_CHECK(f10(10));
- CPPA_CHECK_EQUAL("f10.1", invoked);
+ CPPA_CHECK_EQUAL(invoked, "f10.1");
CPPA_CHECK(f10("42"));
- CPPA_CHECK_EQUAL("f10.2", invoked);
+ CPPA_CHECK_EQUAL(invoked, "f10.2");
CPPA_CHECK(f10("42", 42));
CPPA_CHECK(f10("a", "b", "c"));
std::string foobar = "foobar";
@@ -268,22 +266,22 @@ int main() {
);
CPPA_CHECK(f11(1));
- CPPA_CHECK_EQUAL(1, f11_fun);
+ CPPA_CHECK_EQUAL(f11_fun, 1);
CPPA_CHECK(f11(3));
- CPPA_CHECK_EQUAL(3, f11_fun);
+ CPPA_CHECK_EQUAL(f11_fun, 3);
CPPA_CHECK(f11(8));
- CPPA_CHECK_EQUAL(8, f11_fun);
+ CPPA_CHECK_EQUAL(f11_fun, 8);
CPPA_CHECK(f11(10));
- CPPA_CHECK_EQUAL(9, f11_fun);
+ CPPA_CHECK_EQUAL(f11_fun, 9);
CPPA_CHECK(f11("hello lambda"));
- CPPA_CHECK_EQUAL(11, f11_fun);
+ CPPA_CHECK_EQUAL(f11_fun, 11);
CPPA_CHECK(f11("10"));
- CPPA_CHECK_EQUAL(10, f11_fun);
+ CPPA_CHECK_EQUAL(f11_fun, 10);
auto f12 = (
on<int, anything, int>().when(_x1 < _x2) >> [&](int a, int b) {
- CPPA_CHECK_EQUAL(1, a);
- CPPA_CHECK_EQUAL(5, b);
+ CPPA_CHECK_EQUAL(a, 1);
+ CPPA_CHECK_EQUAL(b, 5);
invoked = "f12";
}
);
@@ -292,32 +290,32 @@ int main() {
int f13_fun = 0;
auto f13 = (
on<int, anything, std::string, anything, int>().when(_x1 < _x3 && _x2.starts_with("-")) >> [&](int a, const std::string& str, int b) {
- CPPA_CHECK_EQUAL("-h", str);
- CPPA_CHECK_EQUAL(1, a);
- CPPA_CHECK_EQUAL(10, b);
+ CPPA_CHECK_EQUAL(str, "-h");
+ CPPA_CHECK_EQUAL(a, 1);
+ CPPA_CHECK_EQUAL(b, 10);
f13_fun = 1;
invoked = "f13";
},
on<anything, std::string, anything, int, anything, float, anything>() >> [&](const std::string& str, int a, float b) {
- CPPA_CHECK_EQUAL("h", str);
- CPPA_CHECK_EQUAL(12, a);
- CPPA_CHECK_EQUAL(1.f, b);
+ CPPA_CHECK_EQUAL(str, "h");
+ CPPA_CHECK_EQUAL(a, 12);
+ CPPA_CHECK_EQUAL(b, 1.f);
f13_fun = 2;
invoked = "f13";
},
on<float, anything, float>().when(_x1 * 2 == _x2) >> [&](float a, float b) {
- CPPA_CHECK_EQUAL(1.f, a);
- CPPA_CHECK_EQUAL(2.f, b);
+ CPPA_CHECK_EQUAL(a, 1.f);
+ CPPA_CHECK_EQUAL(b, 2.f);
f13_fun = 3;
invoked = "f13";
}
);
CPPA_CHECK_INVOKED(f13, (1, 2, "-h", 12, 32, 10, 1.f, "--foo", 10));
- CPPA_CHECK_EQUAL(1, f13_fun);
+ CPPA_CHECK_EQUAL(f13_fun, 1);
CPPA_CHECK_INVOKED(f13, (1, 2, "h", 12, 32, 10, 1.f, "--foo", 10));
- CPPA_CHECK_EQUAL(2, f13_fun);
+ CPPA_CHECK_EQUAL(f13_fun, 2);
CPPA_CHECK_INVOKED(f13, (1.f, 1.5f, 2.f));
- CPPA_CHECK_EQUAL(3, f13_fun);
+ CPPA_CHECK_EQUAL(f13_fun, 3);
// check type correctness of make_cow_tuple()
auto t0 = make_cow_tuple("1", 2);
@@ -327,8 +325,8 @@ int main() {
// check implicit type conversion
CPPA_CHECK((std::is_same<decltype(t0_0), std::string>::value));
CPPA_CHECK((std::is_same<decltype(t0_1), int>::value));
- CPPA_CHECK_EQUAL(t0_0, "1");
- CPPA_CHECK_EQUAL(t0_1, 2);
+ CPPA_CHECK_EQUAL("1", t0_0);
+ CPPA_CHECK_EQUAL(2, t0_1);
// use tuple cast to get a subtuple
any_tuple at0(t0);
auto v0opt = tuple_cast<std::string, anything>(at0);
@@ -393,14 +391,14 @@ int main() {
}
}
- cout << "check correct tuple move operations" << endl;
+ CPPA_PRINT("check correct tuple move operations");
send(spawn<dummy_receiver>(), expensive_copy_struct());
receive (
on_arg_match >> [&](expensive_copy_struct& ecs) {
- CPPA_CHECK_EQUAL(ecs.value, 42);
+ CPPA_CHECK_EQUAL(42, ecs.value);
}
);
- CPPA_CHECK_EQUAL(s_expensive_copies, (size_t) 0);
+ CPPA_CHECK_EQUAL(s_expensive_copies.load(), 0);
await_all_others_done();
shutdown();
return CPPA_TEST_RESULT();
View
12 unit_testing/test_uniform_type.cpp
@@ -65,7 +65,7 @@ int main() {
+ int_val(announce2)
+ int_val(announce3)
+ int_val(announce4);
- CPPA_CHECK_EQUAL(successful_announces, 1);
+ CPPA_CHECK_EQUAL(1, successful_announces);
// these types (and only those) are present if
// the uniform_type_info implementation is correct
std::set<std::string> expected = {
@@ -104,13 +104,13 @@ int main() {
CPPA_CHECK(expected_equals_found);
}
if (!expected_equals_found) {
- cout << "found:" << endl;
+ CPPA_PRINT("found:");
for (const std::string& tname : found) {
- cout << " - " << tname << endl;
+ CPPA_PRINT(" - " << tname);
}
- cout << "expected: " << endl;
+ CPPA_PRINT("expected: ");
for (const std::string& tname : expected) {
- cout << " - " << tname << endl;
+ CPPA_PRINT(" - " << tname);
}
}
@@ -148,7 +148,7 @@ int main() {
uniform_typeid<intrusive_ptr<process_information> >()
};
- CPPA_CHECK_EQUAL(true, sarr.is_pure());
+ CPPA_CHECK_EQUAL(sarr.is_pure(), true);
for (size_t i = 0; i < sarr.size; ++i) {
CPPA_CHECK_EQUAL(sarr[i]->name(), rarr[i]->name());
View
11 unit_testing/test_yield_interface.cpp
@@ -38,9 +38,8 @@ void coroutine(void* worker) { (*reinterpret_cast<pseudo_worker*>(worker))(); }
int main() {
CPPA_TEST(test__yield_interface);
# ifdef CPPA_DISABLE_CONTEXT_SWITCHING
- std::cout << "WARNING: context switching was explicitly disabled using "
- "CPPA_DISABLE_CONTEXT_SWITCHING"
- << std::endl;
+ CPPA_PRINT("WARNING: context switching was explicitly disabled "
+ "using CPPA_DISABLE_CONTEXT_SWITCHING");
# else
fiber fself;
pseudo_worker worker;
@@ -53,9 +52,9 @@ int main() {
++i;
}
while (ys != yield_state::done && i < 12);
- CPPA_CHECK_EQUAL("yield_state::done", to_string(ys));
- CPPA_CHECK_EQUAL(10, worker.m_count);
- CPPA_CHECK_EQUAL(12, i);
+ CPPA_CHECK_EQUAL(to_string(ys), "yield_state::done");
+ CPPA_CHECK_EQUAL(worker.m_count, 10);
+ CPPA_CHECK_EQUAL(i, 12);
# endif
return CPPA_TEST_RESULT();
}
Please sign in to comment.
Something went wrong with that request. Please try again.