Permalink
Browse files

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
  • Loading branch information...
1 parent 1880497 commit 3efb67a36d8bdc3771bb26478083a7f85fa3b57d @Neverlord Neverlord committed Feb 5, 2013
Showing with 21 additions and 16 deletions.
  1. +15 −2 unit_testing/test.hpp
  2. +4 −12 unit_testing/test__remote_actor.cpp
  3. +2 −2 unit_testing/test__spawn.cpp
View
@@ -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();
@@ -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;
@@ -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;
@@ -416,7 +416,7 @@ int main() {
receive_for(i, 10) (
on(atom("failure")) >> [] { }
);
- CPPA_CHECKPOINT_CB();
+ CPPA_CHECKPOINT();
}
// expect 10 {'ok', value} messages
{
@@ -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);

0 comments on commit 3efb67a

Please sign in to comment.