Commit 3efb67a3 authored by Dominik Charousset's avatar Dominik Charousset

some tweaks to unit tests

this patch enables actor_ptr to be used in `CPPA_CHECK_EQUAL` and
uses the new functor-based `timed_sync_send` API in test__remote_actor.hpp
parent 1880497d
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <iostream> #include <iostream>
#include <type_traits> #include <type_traits>
#include "cppa/actor.hpp"
#include "cppa/to_string.hpp"
#include "cppa/util/scope_guard.hpp" #include "cppa/util/scope_guard.hpp"
void cppa_inc_error_count(); void cppa_inc_error_count();
...@@ -34,14 +36,25 @@ inline bool cppa_check_value_fun_eq(T1 value1, T2 value2, ...@@ -34,14 +36,25 @@ inline bool cppa_check_value_fun_eq(T1 value1, T2 value2,
return value1 == static_cast<T1>(value2); return value1 == static_cast<T1>(value2);
} }
template<typename T>
const T& cppa_stream_arg(const T& value) {
return value;
}
inline std::string cppa_stream_arg(const cppa::actor_ptr& ptr) {
return cppa::to_string(ptr);
}
template<typename T1, typename T2> template<typename T1, typename T2>
inline bool cppa_check_value_fun(const T1& value1, const T2& value2, inline bool cppa_check_value_fun(const T1& value1, const T2& value2,
const char* file_name, const char* file_name,
int line_number) { int line_number) {
if (cppa_check_value_fun_eq(value1, value2) == false) { if (cppa_check_value_fun_eq(value1, value2) == false) {
std::cerr << "ERROR in file " << file_name << " on line " << line_number std::cerr << "ERROR in file " << file_name << " on line " << line_number
<< " => expected value: " << value1 << " => expected value: "
<< ", found: " << value2 << cppa_stream_arg(value1)
<< ", found: "
<< cppa_stream_arg(value2)
<< std::endl; << std::endl;
cppa_inc_error_count(); cppa_inc_error_count();
return false; return false;
......
...@@ -341,20 +341,12 @@ int main(int argc, char** argv) { ...@@ -341,20 +341,12 @@ int main(int argc, char** argv) {
cout << "test forwarding over network 'and back'" << endl; cout << "test forwarding over network 'and back'" << endl;
auto ra = spawn<replier>(); auto ra = spawn<replier>();
timed_sync_send(remote_client, chrono::seconds(5), atom("fwd"), ra, "hello replier!").await( timed_sync_send(remote_client, chrono::seconds(5), atom("fwd"), ra, "hello replier!").await(
on_arg_match >> [&](int forty_two) { [&](int forty_two) {
CPPA_CHECK_EQUAL(42, forty_two); CPPA_CHECK_EQUAL(42, forty_two);
auto from = self->last_sender(); auto from = self->last_sender();
if (!from) { CPPA_CHECK_EQUAL(ra, from);
CPPA_ERROR("from == nullptr"); if (from) CPPA_CHECK_EQUAL(false, from->is_proxy());
} }
else if (from != ra) {
CPPA_ERROR("response came from wrong actor");
if (from->is_proxy()) {
CPPA_ERROR("received response from a remote actor");
}
}
},
others() >> [] { self->handle_sync_failure(); }
); );
cout << "wait for a last goodbye" << endl; cout << "wait for a last goodbye" << endl;
......
...@@ -416,7 +416,7 @@ int main() { ...@@ -416,7 +416,7 @@ int main() {
receive_for(i, 10) ( receive_for(i, 10) (
on(atom("failure")) >> [] { } on(atom("failure")) >> [] { }
); );
CPPA_CHECKPOINT_CB(); CPPA_CHECKPOINT();
} }
// expect 10 {'ok', value} messages // expect 10 {'ok', value} messages
{ {
...@@ -514,7 +514,7 @@ int main() { ...@@ -514,7 +514,7 @@ int main() {
} }
); );
receive (on("goodbye!") >> CPPA_CHECKPOINT_CB()); receive (on("goodbye!") >> CPPA_CHECKPOINT_CB());
CPPA_CHECKPOINT_CB(); CPPA_CHECKPOINT();
receive ( receive (
on(atom("DOWN"), exit_reason::normal) >> [&] { on(atom("DOWN"), exit_reason::normal) >> [&] {
CPPA_CHECK(self->last_sender() == sync_testee); CPPA_CHECK(self->last_sender() == sync_testee);
......
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