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
6dd8b6c7
Commit
6dd8b6c7
authored
May 15, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved unit tests
parent
8b341bc0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
0 deletions
+67
-0
unit_testing/test__spawn.cpp
unit_testing/test__spawn.cpp
+67
-0
No files found.
unit_testing/test__spawn.cpp
View file @
6dd8b6c7
...
@@ -270,7 +270,39 @@ std::string behavior_test(actor_ptr et) {
...
@@ -270,7 +270,39 @@ std::string behavior_test(actor_ptr et) {
return
result
;
return
result
;
}
}
template
<
class
MatchExpr
>
class
actor_template
{
MatchExpr
m_expr
;
public:
actor_template
(
MatchExpr
me
)
:
m_expr
(
std
::
move
(
me
))
{
}
actor_ptr
spawn
()
const
{
struct
impl
:
fsm_actor
<
impl
>
{
behavior
init_state
;
impl
(
MatchExpr
const
&
mx
)
:
init_state
(
mx
.
as_partial_function
())
{
}
};
return
cppa
::
spawn
(
new
impl
{
m_expr
});
}
actor_ptr
spawn_detached
()
const
{
return
cppa
::
spawn
<
detached
>
([
m_expr
]()
{
receive_loop
(
m_expr
);
});
}
};
template
<
typename
...
Args
>
auto
actor_prototype
(
Args
const
&
...
args
)
->
actor_template
<
decltype
(
mexpr_concat
(
args
...))
>
{
return
{
mexpr_concat
(
args
...)};
}
size_t
test__spawn
()
{
size_t
test__spawn
()
{
using
std
::
string
;
CPPA_TEST
(
test__spawn
);
CPPA_TEST
(
test__spawn
);
CPPA_IF_VERBOSE
(
cout
<<
"test send() ... "
<<
std
::
flush
);
CPPA_IF_VERBOSE
(
cout
<<
"test send() ... "
<<
std
::
flush
);
...
@@ -278,6 +310,41 @@ size_t test__spawn() {
...
@@ -278,6 +310,41 @@ size_t test__spawn() {
receive
(
on
(
1
,
2
,
3
)
>>
[]()
{
});
receive
(
on
(
1
,
2
,
3
)
>>
[]()
{
});
CPPA_IF_VERBOSE
(
cout
<<
"ok"
<<
endl
);
CPPA_IF_VERBOSE
(
cout
<<
"ok"
<<
endl
);
auto
mirror
=
actor_prototype
(
others
()
>>
[]()
{
self
->
last_sender
()
<<
self
->
last_dequeued
();
}
).
spawn
();
CPPA_IF_VERBOSE
(
cout
<<
"test mirror ... "
<<
std
::
flush
);
send
(
mirror
,
"hello mirror"
);
receive
(
on
(
"hello mirror"
)
>>
[]()
{
});
send
(
mirror
,
atom
(
"EXIT"
),
exit_reason
::
user_defined
);
CPPA_IF_VERBOSE
(
cout
<<
"ok"
<<
endl
);
auto
svec
=
std
::
make_shared
<
std
::
vector
<
string
>
>
();
auto
avec
=
actor_prototype
(
on
(
atom
(
"push_back"
),
arg_match
)
>>
[
svec
](
const
string
&
str
)
{
svec
->
push_back
(
str
);
},
on
(
atom
(
"get"
))
>>
[
svec
]()
{
reply
(
*
svec
);
}
).
spawn
();
send
(
avec
,
atom
(
"push_back"
),
"hello"
);
send
(
avec
,
atom
(
"push_back"
),
" world"
);
send
(
avec
,
atom
(
"get"
));
send
(
avec
,
atom
(
"EXIT"
),
exit_reason
::
user_defined
);
receive
(
on_arg_match
>>
[](
const
std
::
vector
<
string
>&
vec
)
{
if
(
vec
.
size
()
==
2
)
{
cout
<<
vec
.
front
()
<<
vec
.
back
()
<<
endl
;
}
}
);
CPPA_IF_VERBOSE
(
cout
<<
"test future_send() ... "
<<
std
::
flush
);
CPPA_IF_VERBOSE
(
cout
<<
"test future_send() ... "
<<
std
::
flush
);
future_send
(
self
,
std
::
chrono
::
seconds
(
1
),
1
,
2
,
3
);
future_send
(
self
,
std
::
chrono
::
seconds
(
1
),
1
,
2
,
3
);
receive
(
on
(
1
,
2
,
3
)
>>
[]()
{
});
receive
(
on
(
1
,
2
,
3
)
>>
[]()
{
});
...
...
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