Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
0b167399
Commit
0b167399
authored
Jan 19, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #412 from Lingxi-Li/topic/caf_error
Add `CAF_ERROR()` and fix `CAF_FAIL()`
parents
e703fecb
216004e0
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
142 additions
and
118 deletions
+142
-118
libcaf_core/test/actor_pool.cpp
libcaf_core/test/actor_pool.cpp
+4
-4
libcaf_core/test/atom.cpp
libcaf_core/test/atom.cpp
+2
-2
libcaf_core/test/dynamic_spawn.cpp
libcaf_core/test/dynamic_spawn.cpp
+23
-23
libcaf_core/test/match.cpp
libcaf_core/test/match.cpp
+2
-2
libcaf_core/test/message.cpp
libcaf_core/test/message.cpp
+1
-1
libcaf_core/test/message_lifetime.cpp
libcaf_core/test/message_lifetime.cpp
+1
-1
libcaf_core/test/request.cpp
libcaf_core/test/request.cpp
+21
-21
libcaf_core/test/request_timeout.cpp
libcaf_core/test/request_timeout.cpp
+6
-6
libcaf_core/test/serial_reply.cpp
libcaf_core/test/serial_reply.cpp
+1
-1
libcaf_core/test/typed_spawn.cpp
libcaf_core/test/typed_spawn.cpp
+2
-2
libcaf_io/test/automatic_connection.cpp
libcaf_io/test/automatic_connection.cpp
+2
-2
libcaf_io/test/dynamic_broker.cpp
libcaf_io/test/dynamic_broker.cpp
+6
-6
libcaf_io/test/remote_actor.cpp
libcaf_io/test/remote_actor.cpp
+7
-7
libcaf_io/test/remote_spawn.cpp
libcaf_io/test/remote_spawn.cpp
+2
-2
libcaf_io/test/typed_broker.cpp
libcaf_io/test/typed_broker.cpp
+4
-4
libcaf_io/test/unpublish.cpp
libcaf_io/test/unpublish.cpp
+1
-1
libcaf_test/caf/test/unit_test.hpp
libcaf_test/caf/test/unit_test.hpp
+26
-31
libcaf_test/caf/test/unit_test_impl.hpp
libcaf_test/caf/test/unit_test_impl.hpp
+31
-2
No files found.
libcaf_core/test/actor_pool.cpp
View file @
0b167399
...
...
@@ -127,7 +127,7 @@ CAF_TEST(round_robin_actor_pool) {
);
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_
TEST_
ERROR
(
"didn't receive a down message"
);
CAF_ERROR
(
"didn't receive a down message"
);
}
);
CAF_MESSAGE
(
"about to send exit to workers"
);
...
...
@@ -143,7 +143,7 @@ CAF_TEST(round_robin_actor_pool) {
workers
.
erase
(
pos
);
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_
TEST_
ERROR
(
"didn't receive a down message"
);
CAF_ERROR
(
"didn't receive a down message"
);
}
);
}
...
...
@@ -164,7 +164,7 @@ CAF_TEST(broadcast_actor_pool) {
results
.
push_back
(
res
);
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_
TEST_
ERROR
(
"didn't receive a result"
);
CAF_ERROR
(
"didn't receive a result"
);
}
);
CAF_CHECK_EQUAL
(
results
.
size
(),
25u
);
...
...
@@ -182,7 +182,7 @@ CAF_TEST(random_actor_pool) {
CAF_CHECK_EQUAL
(
res
,
3
);
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_
TEST_
ERROR
(
"didn't receive a down message"
);
CAF_ERROR
(
"didn't receive a down message"
);
}
);
}
...
...
libcaf_core/test/atom.cpp
View file @
0b167399
...
...
@@ -101,7 +101,7 @@ CAF_TEST(receive_atoms) {
CAF_MESSAGE
(
"drain mailbox"
);
},
after
(
std
::
chrono
::
seconds
(
0
))
>>
[]
{
CAF_
TEST_
ERROR
(
"mailbox empty"
);
CAF_ERROR
(
"mailbox empty"
);
}
);
atom_value
x
=
atom
(
"abc"
);
...
...
@@ -114,7 +114,7 @@ CAF_TEST(receive_atoms) {
CAF_MESSAGE
(
"received 'abc'"
);
},
others
>>
[]
{
CAF_
TEST_
ERROR
(
"unexpected message"
);
CAF_ERROR
(
"unexpected message"
);
}
);
}
...
...
libcaf_core/test/dynamic_spawn.cpp
View file @
0b167399
...
...
@@ -246,7 +246,7 @@ behavior high_priority_testee(event_based_actor* self) {
// 'a' must be self->received before 'b'
return
{
[
=
](
b_atom
)
{
CAF_
TEST_
ERROR
(
"received 'b' before 'a'"
);
CAF_ERROR
(
"received 'b' before 'a'"
);
self
->
quit
();
},
[
=
](
a_atom
)
{
...
...
@@ -257,12 +257,12 @@ behavior high_priority_testee(event_based_actor* self) {
self
->
quit
();
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
@@ -291,7 +291,7 @@ behavior slave(event_based_actor* self, actor master) {
self
->
quit
(
msg
.
reason
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
@@ -359,7 +359,7 @@ CAF_TEST(self_receive_with_zero_timeout) {
scoped_actor
self
{
system
};
self
->
receive
(
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
},
after
(
chrono
::
seconds
(
0
))
>>
[]
{
/* mailbox empty */
}
);
...
...
@@ -374,7 +374,7 @@ CAF_TEST(mirror) {
CAF_CHECK_EQUAL
(
msg
,
"hello mirror"
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
...
...
@@ -384,11 +384,11 @@ CAF_TEST(mirror) {
CAF_MESSAGE
(
"received `down_msg`"
);
}
else
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
}
...
...
@@ -402,7 +402,7 @@ CAF_TEST(detached_mirror) {
CAF_CHECK_EQUAL
(
msg
,
"hello mirror"
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
...
...
@@ -412,11 +412,11 @@ CAF_TEST(detached_mirror) {
CAF_MESSAGE
(
"received `down_msg`"
);
}
else
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
}
...
...
@@ -431,7 +431,7 @@ CAF_TEST(priority_aware_mirror) {
CAF_CHECK_EQUAL
(
msg
,
"hello mirror"
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
...
...
@@ -441,11 +441,11 @@ CAF_TEST(priority_aware_mirror) {
CAF_MESSAGE
(
"received `down_msg`"
);
}
else
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
}
...
...
@@ -474,7 +474,7 @@ CAF_TEST(echo_actor_messaging) {
CAF_CHECK_EQUAL
(
arg
,
"hello echo"
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
}
...
...
@@ -521,13 +521,13 @@ CAF_TEST(requests) {
return
"goodbye!"
;
},
after
(
chrono
::
minutes
(
1
))
>>
[]
{
CAF_
TEST_
ERROR
(
"Error in unit test."
);
CAF_ERROR
(
"Error in unit test."
);
abort
();
}
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
});
...
...
@@ -543,7 +543,7 @@ CAF_TEST(requests) {
);
self
->
receive
(
on
(
"goodbye!"
)
>>
[]
{
CAF_MESSAGE
(
"Received
\"
goodbye!
\"
"
);
},
after
(
chrono
::
seconds
(
1
))
>>
[]
{
CAF_
TEST_
ERROR
(
"Unexpected timeout"
);
}
after
(
chrono
::
seconds
(
1
))
>>
[]
{
CAF_ERROR
(
"Unexpected timeout"
);
}
);
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
...
...
@@ -554,17 +554,17 @@ CAF_TEST(requests) {
self
->
await_all_other_actors_done
();
self
->
request
(
sync_testee
,
"!?"
).
receive
(
[]
{
CAF_
TEST_
ERROR
(
"Unexpected empty message"
);
CAF_ERROR
(
"Unexpected empty message"
);
},
[
&
](
error
&
err
)
{
if
(
err
==
sec
::
request_receiver_down
)
CAF_MESSAGE
(
"received `request_receiver_down`"
);
else
CAF_
TEST_
ERROR
(
"received unexpected error: "
CAF_ERROR
(
"received unexpected error: "
<<
self
->
system
().
render
(
err
));
},
after
(
chrono
::
microseconds
(
1
))
>>
[]
{
CAF_
TEST_
ERROR
(
"Unexpected timeout"
);
CAF_ERROR
(
"Unexpected timeout"
);
}
);
}
...
...
@@ -634,7 +634,7 @@ CAF_TEST(constructor_attach) {
behavior
make_behavior
()
{
return
{
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
@@ -755,7 +755,7 @@ CAF_TEST(kill_the_immortal) {
self
->
trap_exit
(
true
);
return
{
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
});
...
...
libcaf_core/test/match.cpp
View file @
0b167399
...
...
@@ -91,8 +91,8 @@ ptrdiff_t invoked(message_handler expr, const Ts&... xs) {
reset
();
}
if
(
results
.
size
()
>
1
)
{
CAF_
TEST_
ERROR
(
"make_message() yielded a different result than "
"message_builder(...).to_message()"
);
CAF_ERROR
(
"make_message() yielded a different result than "
"message_builder(...).to_message()"
);
return
-
2
;
}
return
*
results
.
begin
();
...
...
libcaf_core/test/message.cpp
View file @
0b167399
...
...
@@ -42,7 +42,7 @@ using namespace caf;
CAF_TEST
(
apply
)
{
auto
f1
=
[]
{
CAF_
TEST_
ERROR
(
"f1 invoked!"
);
CAF_ERROR
(
"f1 invoked!"
);
};
auto
f2
=
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
42
);
...
...
libcaf_core/test/message_lifetime.cpp
View file @
0b167399
...
...
@@ -85,7 +85,7 @@ behavior tester::make_behavior() {
quit
();
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
libcaf_core/test/request.cpp
View file @
0b167399
...
...
@@ -237,7 +237,7 @@ behavior server(event_based_actor* self) {
return
skip_message
();
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message:"
<<
to_string
(
self
->
current_message
()));
CAF_ERROR
(
"Unexpected message:"
<<
to_string
(
self
->
current_message
()));
die
();
}
);
...
...
@@ -246,7 +246,7 @@ behavior server(event_based_actor* self) {
return
skip_message
();
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message:"
<<
to_string
(
self
->
current_message
()));
CAF_ERROR
(
"Unexpected message:"
<<
to_string
(
self
->
current_message
()));
die
();
}
};
...
...
@@ -288,7 +288,7 @@ CAF_TEST(pending_quit) {
system
.
spawn
([
mirror
](
event_based_actor
*
self
)
{
self
->
request
(
mirror
,
42
).
then
(
[](
int
)
{
CAF_
TEST_
ERROR
(
"received result, should've been terminated already"
);
CAF_ERROR
(
"received result, should've been terminated already"
);
},
[](
const
error
&
err
)
{
CAF_CHECK
(
err
==
sec
::
request_receiver_down
);
...
...
@@ -315,7 +315,7 @@ CAF_TEST(request) {
++
invocations
;
},
[
&
](
const
error
&
err
)
{
CAF_
TEST_
ERROR
(
"Error: "
<<
s
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
s
->
system
().
render
(
err
));
}
);
s
->
request
(
foi
,
f_atom
::
value
).
receive
(
...
...
@@ -324,7 +324,7 @@ CAF_TEST(request) {
++
invocations
;
},
[
&
](
const
error
&
err
)
{
CAF_
TEST_
ERROR
(
"Error: "
<<
s
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
s
->
system
().
render
(
err
));
}
);
CAF_CHECK_EQUAL
(
invocations
,
2
);
...
...
@@ -350,8 +350,8 @@ CAF_TEST(request) {
CAF_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
CAF_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
);
auto
mirror
=
system
.
spawn
<
sync_mirror
>
();
...
...
@@ -371,13 +371,13 @@ CAF_TEST(request) {
CAF_MESSAGE
(
"received `ok_atom`"
);
},
[](
error_atom
)
{
CAF_
TEST_
ERROR
(
"A didn't receive sync response"
);
CAF_ERROR
(
"A didn't receive sync response"
);
},
[
&
](
const
down_msg
&
dm
)
->
maybe
<
skip_message_t
>
{
if
(
dm
.
reason
==
exit_reason
::
normal
)
{
return
skip_message
();
}
CAF_
TEST_
ERROR
(
"A exited for reason "
<<
to_string
(
dm
.
reason
));
CAF_ERROR
(
"A exited for reason "
<<
to_string
(
dm
.
reason
));
return
none
;
}
);
...
...
@@ -398,7 +398,7 @@ CAF_TEST(request) {
CAF_MESSAGE
(
"`await_all_other_actors_done` finished"
);
self
->
request
(
self
,
no_way_atom
::
value
).
receive
(
[
&
](
int
)
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
},
after
(
milliseconds
(
50
))
>>
[]
{
CAF_MESSAGE
(
"Got timeout"
);
...
...
@@ -416,18 +416,18 @@ CAF_TEST(request) {
"synchronous request message
\"
"
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message: "
CAF_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
},
after
(
milliseconds
(
0
))
>>
[]
{
CAF_
TEST_
ERROR
(
"Unexpected timeout"
);
CAF_ERROR
(
"Unexpected timeout"
);
}
);
// mailbox should be empty now
self
->
receive
(
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
CAF_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
},
after
(
milliseconds
(
0
))
>>
[]
{
CAF_MESSAGE
(
"Mailbox is empty, all good"
);
...
...
@@ -439,11 +439,11 @@ CAF_TEST(request) {
bool
timeout_occured
=
false
;
self
->
request
(
c
,
milliseconds
(
500
),
hi_there_atom
::
value
).
receive
(
[
&
](
hi_there_atom
)
{
CAF_
TEST_
ERROR
(
"C did reply to 'HiThere'"
);
CAF_ERROR
(
"C did reply to 'HiThere'"
);
},
[
&
](
const
error
&
err
)
{
CAF_LOG_TRACE
(
""
);
CAF_
TEST_
ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
},
after
(
milliseconds
(
500
))
>>
[
&
]
{
CAF_MESSAGE
(
"timeout occured"
);
...
...
@@ -457,7 +457,7 @@ CAF_TEST(request) {
},
[
&
](
const
error
&
err
)
{
CAF_LOG_TRACE
(
""
);
CAF_
TEST_
ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
}
);
self
->
send_exit
(
c
,
exit_reason
::
user_shutdown
);
...
...
@@ -482,7 +482,7 @@ CAF_TEST(request) {
CAF_CHECK
(
s
->
current_sender
()
==
work
);
},
[
&
](
const
error
&
err
)
{
CAF_
TEST_
ERROR
(
"Error: "
<<
s
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
s
->
system
().
render
(
err
));
}
);
// first 'request', then 'idle'
...
...
@@ -493,7 +493,7 @@ CAF_TEST(request) {
CAF_CHECK
(
s
->
current_sender
()
==
work
);
},
[
&
](
const
error
&
err
)
{
CAF_
TEST_
ERROR
(
"Error: "
<<
s
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
s
->
system
().
render
(
err
));
}
);
s
->
quit
(
exit_reason
::
user_shutdown
);
...
...
@@ -503,8 +503,8 @@ CAF_TEST(request) {
CAF_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
);
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
CAF_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
);
}
...
...
libcaf_core/test/request_timeout.cpp
View file @
0b167399
...
...
@@ -51,7 +51,7 @@ behavior ping1(event_based_actor* self, const actor& pong_actor) {
[
=
](
send_ping_atom
)
{
self
->
request
(
pong_actor
,
ping_atom
::
value
).
then
(
[
=
](
pong_atom
)
{
CAF_
TEST_
ERROR
(
"received pong atom"
);
CAF_ERROR
(
"received pong atom"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
},
after
(
std
::
chrono
::
milliseconds
(
100
))
>>
[
=
]
{
...
...
@@ -71,7 +71,7 @@ behavior ping2(event_based_actor* self, const actor& pong_actor) {
[
=
](
send_ping_atom
)
{
self
->
request
(
pong_actor
,
ping_atom
::
value
).
then
(
[
=
](
pong_atom
)
{
CAF_
TEST_
ERROR
(
"received pong atom"
);
CAF_ERROR
(
"received pong atom"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
},
after
(
std
::
chrono
::
milliseconds
(
100
))
>>
[
=
]
{
...
...
@@ -94,7 +94,7 @@ behavior ping3(event_based_actor* self, const actor& pong_actor) {
[
=
](
send_ping_atom
)
{
self
->
request
(
pong_actor
,
ping_atom
::
value
).
then
(
[
=
](
pong_atom
)
{
CAF_
TEST_
ERROR
(
"received pong atom"
);
CAF_ERROR
(
"received pong atom"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
},
after
(
std
::
chrono
::
milliseconds
(
100
))
>>
[
=
]
{
...
...
@@ -114,7 +114,7 @@ behavior ping4(event_based_actor* self, const actor& pong_actor) {
[
=
](
send_ping_atom
)
{
self
->
request
(
pong_actor
,
ping_atom
::
value
).
then
(
[
=
](
pong_atom
)
{
CAF_
TEST_
ERROR
(
"received pong atom"
);
CAF_ERROR
(
"received pong atom"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
},
after
(
std
::
chrono
::
milliseconds
(
100
))
>>
[
=
]
{
...
...
@@ -135,7 +135,7 @@ void ping5(event_based_actor* self, const actor& pong_actor) {
auto
flag
=
std
::
make_shared
<
int
>
(
0
);
self
->
request
(
pong_actor
,
ping_atom
::
value
).
then
(
[
=
](
pong_atom
)
{
CAF_
TEST_
ERROR
(
"received pong atom"
);
CAF_ERROR
(
"received pong atom"
);
*
flag
=
1
;
},
after
(
std
::
chrono
::
milliseconds
(
100
))
>>
[
=
]
{
...
...
@@ -147,7 +147,7 @@ void ping5(event_based_actor* self, const actor& pong_actor) {
);
self
->
request
(
pong_actor
,
ping_atom
::
value
).
await
(
[
=
](
pong_atom
)
{
CAF_
TEST_
ERROR
(
"received pong atom"
);
CAF_ERROR
(
"received pong atom"
);
*
flag
=
3
;
},
after
(
std
::
chrono
::
milliseconds
(
100
))
>>
[
=
]
{
...
...
libcaf_core/test/serial_reply.cpp
View file @
0b167399
...
...
@@ -94,7 +94,7 @@ CAF_TEST(test_serial_reply) {
CAF_MESSAGE
(
"received 'ho'"
);
},
[
&
](
const
error
&
err
)
{
CAF_
TEST_
ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
}
);
self
->
send_exit
(
master
,
exit_reason
::
user_shutdown
);
...
...
libcaf_core/test/typed_spawn.cpp
View file @
0b167399
...
...
@@ -321,7 +321,7 @@ int_actor::behavior_type int_fun2(int_actor::pointer self) {
self
->
quit
();
},
[
=
](
const
exit_msg
&
)
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
@@ -399,7 +399,7 @@ CAF_TEST(event_testee_series) {
result
=
str
;
},
after
(
chrono
::
minutes
(
1
))
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"event_testee does not reply"
);
CAF_ERROR
(
"event_testee does not reply"
);
throw
runtime_error
(
"event_testee does not reply"
);
}
);
...
...
libcaf_io/test/automatic_connection.cpp
View file @
0b167399
...
...
@@ -261,8 +261,8 @@ CAF_TEST(triangle_setup) {
bool is_jupiter = r.opts.count("jupiter") > 0;
bool has_port = r.opts.count("port") > 0;
if (((is_mars || is_jupiter) && ! has_port) || (is_mars && is_jupiter)) {
CAF_
TEST_
ERROR("need a port when running Mars or Jupiter and cannot "
"both at the same time");
CAF_ERROR("need a port when running Mars or Jupiter and cannot "
"both at the same time");
return;
}
// enable automatic connections
...
...
libcaf_io/test/dynamic_broker.cpp
View file @
0b167399
...
...
@@ -58,11 +58,11 @@ void ping(event_based_actor* self, size_t num_pings) {
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
});
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
}
...
...
@@ -83,14 +83,14 @@ void pong(event_based_actor* self) {
self
->
quit
(
dm
.
reason
);
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
// reply to 'ping'
return
std
::
make_tuple
(
pong_atom
::
value
,
value
);
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
}
...
...
@@ -157,7 +157,7 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) {
return
self
->
add_tcp_doorman
(
0
,
"127.0.0.1"
).
second
;
},
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
@@ -186,7 +186,7 @@ void run_server(int argc, char** argv) {
child
=
std
::
thread
([
=
]
{
run_client
(
argc
,
argv
,
port
);
});
},
[
&
](
const
error
&
err
)
{
CAF_
TEST_
ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
}
);
self
->
await_all_other_actors_done
();
...
...
libcaf_io/test/remote_actor.cpp
View file @
0b167399
...
...
@@ -62,7 +62,7 @@ behavior ping_behavior(local_actor* self, size_t ping_msgs) {
[
=
](
pong_atom
,
int
value
)
->
message
{
CAF_LOG_TRACE
(
CAF_ARG
(
value
));
if
(
!
self
->
current_sender
())
{
CAF_
TEST_
ERROR
(
"current_sender() invalid!"
);
CAF_ERROR
(
"current_sender() invalid!"
);
}
CAF_MESSAGE
(
"received {'pong', "
<<
value
<<
"}"
);
if
(
++
s_pongs
>=
ping_msgs
)
{
...
...
@@ -166,7 +166,7 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
self
->
become
(
[
=
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
!=
exit_reason
::
normal
)
{
CAF_
TEST_
ERROR
(
"reflector exited for non-normal exit reason!"
);
CAF_ERROR
(
"reflector exited for non-normal exit reason!"
);
}
if
(
++*
downs
==
5
)
{
CAF_MESSAGE
(
"down increased to 5, about to quit"
);
...
...
@@ -175,11 +175,11 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
}
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
},
after
(
chrono
::
seconds
(
3
))
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"did only receive "
<<
*
downs
<<
" down messages"
);
CAF_ERROR
(
"did only receive "
<<
*
downs
<<
" down messages"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
}
);
...
...
@@ -187,18 +187,18 @@ void spawn5_server_impl(event_based_actor* self, actor client, group grp) {
},
after
(
std
::
chrono
::
seconds
(
6
))
>>
[
=
]
{
CAF_LOG_TRACE
(
""
);
CAF_
TEST_
ERROR
(
"Unexpected timeout"
);
CAF_ERROR
(
"Unexpected timeout"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
}
);
},
[
=
](
const
error
&
err
)
{
CAF_
TEST_
ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
self
->
quit
(
exit_reason
::
user_shutdown
);
},
after
(
chrono
::
seconds
(
10
))
>>
[
=
]
{
CAF_LOG_TRACE
(
""
);
CAF_
TEST_
ERROR
(
"Unexpected timeout"
);
CAF_ERROR
(
"Unexpected timeout"
);
self
->
quit
(
exit_reason
::
user_shutdown
);
}
);
...
...
libcaf_io/test/remote_spawn.cpp
View file @
0b167399
...
...
@@ -48,7 +48,7 @@ behavior client(event_based_actor* self, actor serv) {
self
->
send
(
serv
,
ok_atom
::
value
);
return
{
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
@@ -90,7 +90,7 @@ behavior server(stateful_actor<server_state>* self) {
},
[
=
](
const
error
&
err
)
{
CAF_LOG_TRACE
(
""
);
CAF_
TEST_
ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
CAF_ERROR
(
"Error: "
<<
self
->
system
().
render
(
err
));
}
};
}
...
...
libcaf_io/test/typed_broker.cpp
View file @
0b167399
...
...
@@ -67,11 +67,11 @@ behavior ping(event_based_actor* self, size_t num_pings) {
return
std
::
make_tuple
(
ping_atom
::
value
,
value
+
1
);
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
});
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
@@ -92,14 +92,14 @@ behavior pong(event_based_actor* self) {
self
->
quit
(
dm
.
reason
);
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
);
// reply to 'ping'
return
std
::
make_tuple
(
pong_atom
::
value
,
value
);
},
others
>>
[
=
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
libcaf_io/test/unpublish.cpp
View file @
0b167399
...
...
@@ -48,7 +48,7 @@ public:
behavior
make_behavior
()
override
{
return
{
others
>>
[
&
]
{
CAF_
TEST_
ERROR
(
"Unexpected message"
);
CAF_ERROR
(
"Unexpected message"
);
}
};
}
...
...
libcaf_test/caf/test/unit_test.hpp
View file @
0b167399
...
...
@@ -132,6 +132,8 @@ public:
// constructs spacing given a line number.
const
char
*
fill
(
size_t
line
);
void
remove_trailing_spaces
(
std
::
string
&
x
);
}
// namespace detail
/// Logs messages for the test framework.
...
...
@@ -175,12 +177,15 @@ public:
stream
&
operator
<<
(
const
std
::
string
&
str
);
std
::
string
str
()
const
;
private:
void
flush
();
logger
&
logger_
;
level
level_
;
std
::
ostringstream
buf_
;
std
::
string
str_
;
};
static
bool
init
(
int
lvl_cons
,
int
lvl_file
,
const
std
::
string
&
logfile
);
...
...
@@ -377,24 +382,8 @@ showable<T> show(const T &x) {
return
showable
<
T
>
{
x
};
}
inline
bool
check
(
test
*
parent
,
const
char
*
file
,
size_t
line
,
const
char
*
expr
,
bool
should_fail
,
bool
result
)
{
std
::
stringstream
ss
;
if
(
result
)
{
ss
<<
engine
::
color
(
green
)
<<
"** "
<<
engine
::
color
(
blue
)
<<
file
<<
engine
::
color
(
yellow
)
<<
":"
<<
engine
::
color
(
blue
)
<<
line
<<
fill
(
line
)
<<
engine
::
color
(
reset
)
<<
expr
;
parent
->
pass
(
ss
.
str
());
}
else
{
ss
<<
engine
::
color
(
red
)
<<
"!! "
<<
engine
::
color
(
blue
)
<<
file
<<
engine
::
color
(
yellow
)
<<
":"
<<
engine
::
color
(
blue
)
<<
line
<<
fill
(
line
)
<<
engine
::
color
(
reset
)
<<
expr
;
parent
->
fail
(
ss
.
str
(),
should_fail
);
}
return
result
;
}
bool
check
(
test
*
parent
,
const
char
*
file
,
size_t
line
,
const
char
*
expr
,
bool
should_fail
,
bool
result
);
template
<
class
T
,
class
U
>
bool
check
(
test
*
parent
,
const
char
*
file
,
size_t
line
,
...
...
@@ -427,19 +416,14 @@ bool check(test* parent, const char *file, size_t line,
// on the global namespace so that it can hidden via namespace-scoping
using
caf_test_case_auto_fixture
=
caf
::
test
::
dummy_fixture
;
#define CAF_TEST_PR
(level, msg, colorcode)
\
::caf::test::logger::instance(). level ()
\
#define CAF_TEST_PR
INT(level, msg, colorcode)
\
(::caf::test::logger::instance(). level ()
\
<< ::caf::test::engine::color(::caf::test:: colorcode ) \
<< " -> " << ::caf::test::engine::color(::caf::test::reset) << msg << '\n'
#define CAF_TEST_ERROR(msg) \
CAF_TEST_PR(info, msg, red)
<< " -> " << ::caf::test::engine::color(::caf::test::reset) << msg << '\n')
#define CAF_TEST_INFO(msg) \
CAF_TEST_PR(info, msg, yellow)
#define CAF_TEST_VERBOSE(msg) \
CAF_TEST_PR(verbose, msg, yellow)
#define CAF_TEST_PRINT_ERROR(msg) CAF_TEST_PRINT(info, msg, red)
#define CAF_TEST_PRINT_INFO(msg) CAF_TEST_PRINT(info, msg, yellow)
#define CAF_TEST_PRINT_VERBOSE(msg) CAF_TEST_PRINT(verbose, msg, yellow)
#define CAF_PASTE_CONCAT(lhs, rhs) lhs ## rhs
...
...
@@ -458,6 +442,15 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_PRED_EXPR(pred, x_expr, y_expr) "("#x_expr") "#pred" ("#y_expr")"
#define CAF_FUNC_EXPR(func, x_expr, y_expr) #func"("#x_expr", "#y_expr")"
#define CAF_ERROR(msg) \
do { \
auto CAF_UNIQUE(__str) = CAF_TEST_PRINT_ERROR(msg).str(); \
::caf::test::detail::remove_trailing_spaces(CAF_UNIQUE(__str)); \
::caf::test::engine::current_test()->fail(CAF_UNIQUE(__str), false); \
::caf::test::engine::last_check_file(__FILE__); \
::caf::test::engine::last_check_line(__LINE__); \
} while(false)
#define CAF_CHECK(...) \
do { \
static_cast<void>(::caf::test::detail::check( \
...
...
@@ -502,7 +495,9 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_FAIL(msg) \
do { \
CAF_TEST_ERROR(msg); \
auto CAF_UNIQUE(__str) = CAF_TEST_PRINT_ERROR(msg).str(); \
::caf::test::detail::remove_trailing_spaces(CAF_UNIQUE(__str)); \
::caf::test::engine::current_test()->fail(CAF_UNIQUE(__str), false); \
throw ::caf::test::detail::require_error{"test failure"}; \
} while(false)
...
...
@@ -583,6 +578,6 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_REQUIRE_GREATER(x, y) CAF_REQUIRE_PRED(> , x, y)
#define CAF_REQUIRE_GREATER_EQUAL(x, y) CAF_REQUIRE_PRED(>=, x, y)
#define CAF_MESSAGE(msg) CAF_TEST_VERBOSE(msg)
#define CAF_MESSAGE(msg) CAF_TEST_
PRINT_
VERBOSE(msg)
#endif // CAF_TEST_UNIT_TEST_HPP
libcaf_test/caf/test/unit_test_impl.hpp
View file @
0b167399
...
...
@@ -21,6 +21,7 @@
#define CAF_TEST_UNIT_TEST_IMPL_HPP
#include <regex>
#include <cctype>
#include <thread>
#include <cassert>
#include <cstdlib>
...
...
@@ -140,6 +141,29 @@ const char* fill(size_t line) {
}
}
void
remove_trailing_spaces
(
std
::
string
&
x
)
{
x
.
erase
(
std
::
find_if_not
(
x
.
rbegin
(),
x
.
rend
(),
::
isspace
).
base
(),
x
.
end
());
}
bool
check
(
test
*
parent
,
const
char
*
file
,
size_t
line
,
const
char
*
expr
,
bool
should_fail
,
bool
result
)
{
std
::
stringstream
ss
;
if
(
result
)
{
ss
<<
engine
::
color
(
green
)
<<
"** "
<<
engine
::
color
(
blue
)
<<
file
<<
engine
::
color
(
yellow
)
<<
":"
<<
engine
::
color
(
blue
)
<<
line
<<
fill
(
line
)
<<
engine
::
color
(
reset
)
<<
expr
;
parent
->
pass
(
ss
.
str
());
}
else
{
ss
<<
engine
::
color
(
red
)
<<
"!! "
<<
engine
::
color
(
blue
)
<<
file
<<
engine
::
color
(
yellow
)
<<
":"
<<
engine
::
color
(
blue
)
<<
line
<<
fill
(
line
)
<<
engine
::
color
(
reset
)
<<
expr
;
parent
->
fail
(
ss
.
str
(),
should_fail
);
}
return
result
;
}
}
// namespace detail
logger
::
stream
::
stream
(
logger
&
l
,
level
lvl
)
:
logger_
(
l
),
level_
(
lvl
)
{
...
...
@@ -183,12 +207,17 @@ logger::stream& logger::stream::operator<<(const std::string& str) {
return
*
this
;
}
std
::
string
logger
::
stream
::
str
()
const
{
return
str_
;
}
void
logger
::
stream
::
flush
()
{
logger_
.
log
(
level_
,
buf_
.
str
()
);
auto
str
=
buf_
.
str
(
);
buf_
.
str
(
""
);
logger_
.
log
(
level_
,
str
);
str_
+=
str
;
}
bool
logger
::
init
(
int
lvl_cons
,
int
lvl_file
,
const
std
::
string
&
logfile
)
{
instance
().
level_console_
=
static_cast
<
level
>
(
lvl_cons
);
instance
().
level_file_
=
static_cast
<
level
>
(
lvl_file
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment