Skip to content

Commit

Permalink
some tweaks to unit tests
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Neverlord committed Feb 5, 2013
1 parent 1880497 commit 3efb67a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
17 changes: 15 additions & 2 deletions unit_testing/test.hpp
Expand Up @@ -8,6 +8,8 @@
#include <iostream>
#include <type_traits>

#include "cppa/actor.hpp"
#include "cppa/to_string.hpp"
#include "cppa/util/scope_guard.hpp"

void cppa_inc_error_count();
Expand All @@ -34,14 +36,25 @@ inline bool cppa_check_value_fun_eq(T1 value1, T2 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>
inline bool cppa_check_value_fun(const T1& value1, const T2& value2,
const char* file_name,
int line_number) {
if (cppa_check_value_fun_eq(value1, value2) == false) {
std::cerr << "ERROR in file " << file_name << " on line " << line_number
<< " => expected value: " << value1
<< ", found: " << value2
<< " => expected value: "
<< cppa_stream_arg(value1)
<< ", found: "
<< cppa_stream_arg(value2)
<< std::endl;
cppa_inc_error_count();
return false;
Expand Down
16 changes: 4 additions & 12 deletions unit_testing/test__remote_actor.cpp
Expand Up @@ -341,20 +341,12 @@ int main(int argc, char** argv) {
cout << "test forwarding over network 'and back'" << endl;
auto ra = spawn<replier>();
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);
auto from = self->last_sender();
if (!from) {
CPPA_ERROR("from == nullptr");
}
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(); }
CPPA_CHECK_EQUAL(ra, from);
if (from) CPPA_CHECK_EQUAL(false, from->is_proxy());
}
);

cout << "wait for a last goodbye" << endl;
Expand Down
4 changes: 2 additions & 2 deletions unit_testing/test__spawn.cpp
Expand Up @@ -416,7 +416,7 @@ int main() {
receive_for(i, 10) (
on(atom("failure")) >> [] { }
);
CPPA_CHECKPOINT_CB();
CPPA_CHECKPOINT();
}
// expect 10 {'ok', value} messages
{
Expand Down Expand Up @@ -514,7 +514,7 @@ int main() {
}
);
receive (on("goodbye!") >> CPPA_CHECKPOINT_CB());
CPPA_CHECKPOINT_CB();
CPPA_CHECKPOINT();
receive (
on(atom("DOWN"), exit_reason::normal) >> [&] {
CPPA_CHECK(self->last_sender() == sync_testee);
Expand Down

0 comments on commit 3efb67a

Please sign in to comment.