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
0d30b74b
Commit
0d30b74b
authored
Apr 28, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement ping-pong example unit test
parent
d1a25387
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
examples/CMakeLists.txt
examples/CMakeLists.txt
+3
-0
examples/testing/ping_pong.cpp
examples/testing/ping_pong.cpp
+65
-0
No files found.
examples/CMakeLists.txt
View file @
0d30b74b
...
...
@@ -55,6 +55,9 @@ add(remoting distributed_calculator)
add
(
broker simple_broker
)
add
(
broker simple_http_broker
)
# testing DSL
add
(
testing ping_pong
)
if
(
CAF_BUILD_PROTOBUF_EXAMPLES
)
find_package
(
Protobuf
)
if
(
PROTOBUF_FOUND AND PROTOBUF_PROTOC_EXECUTABLE
)
...
...
examples/testing/ping_pong.cpp
0 → 100644
View file @
0d30b74b
// Manual refs: lines 12-65 (Testing)
#define CAF_SUITE ping_pong
#include "caf/test/dsl.hpp"
#include "caf/test/unit_test_impl.hpp"
#include "caf/all.hpp"
using
namespace
caf
;
namespace
{
using
ping_atom
=
atom_constant
<
atom
(
"ping"
)
>
;
using
pong_atom
=
atom_constant
<
atom
(
"pong"
)
>
;
behavior
ping
(
event_based_actor
*
self
,
actor
pong_actor
,
int
n
)
{
self
->
send
(
pong_actor
,
ping_atom
::
value
,
n
);
return
{
[
=
](
pong_atom
,
int
x
)
{
if
(
x
>
1
)
self
->
send
(
pong_actor
,
ping_atom
::
value
,
x
-
1
);
}
};
}
behavior
pong
()
{
return
{
[
=
](
ping_atom
,
int
x
)
{
return
std
::
make_tuple
(
pong_atom
::
value
,
x
);
}
};
}
struct
ping_pong_fixture
:
test_coordinator_fixture
<>
{
actor
pong_actor
;
ping_pong_fixture
()
{
// Spawn the Pong actor.
pong_actor
=
sys
.
spawn
(
pong
);
// Run initialization code for Pong.
run
();
}
};
}
// namespace
CAF_TEST_FIXTURE_SCOPE
(
ping_pong_tests
,
ping_pong_fixture
)
CAF_TEST
(
three
pings
)
{
// Spawn the Ping actor and run its initialization code.
auto
ping_actor
=
sys
.
spawn
(
ping
,
pong_actor
,
3
);
sched
.
run_once
();
// Test communication between Ping and Pong.
expect
((
ping_atom
,
int
),
from
(
ping_actor
).
to
(
pong_actor
).
with
(
_
,
3
));
expect
((
pong_atom
,
int
),
from
(
pong_actor
).
to
(
ping_actor
).
with
(
_
,
3
));
expect
((
ping_atom
,
int
),
from
(
ping_actor
).
to
(
pong_actor
).
with
(
_
,
2
));
expect
((
pong_atom
,
int
),
from
(
pong_actor
).
to
(
ping_actor
).
with
(
_
,
2
));
expect
((
ping_atom
,
int
),
from
(
ping_actor
).
to
(
pong_actor
).
with
(
_
,
1
));
expect
((
pong_atom
,
int
),
from
(
pong_actor
).
to
(
ping_actor
).
with
(
_
,
1
));
// No further messages allowed.
disallow
((
ping_atom
,
int
),
from
(
ping_actor
).
to
(
pong_actor
).
with
(
_
,
1
));
}
CAF_TEST_FIXTURE_SCOPE_END
()
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