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
a850de8e
Commit
a850de8e
authored
Oct 02, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port actor_factory test to deterministic API
parent
cb4f6977
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
79 deletions
+64
-79
libcaf_core/test/actor_factory.cpp
libcaf_core/test/actor_factory.cpp
+64
-79
No files found.
libcaf_core/test/actor_factory.cpp
View file @
a850de8e
...
@@ -16,109 +16,94 @@
...
@@ -16,109 +16,94 @@
* http://www.boost.org/LICENSE_1_0.txt. *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
******************************************************************************/
#include "caf/config.hpp"
#define CAF_SUITE actor_factory
#define CAF_SUITE actor_factory
#include "caf/test/unit_test.hpp"
#include "caf/all.hpp"
#include "caf/actor_registry.hpp"
#include "caf/actor_registry.hpp"
#include "caf/test/dsl.hpp"
#include "caf/all.hpp"
using
namespace
caf
;
using
namespace
caf
;
using
std
::
endl
;
using
std
::
endl
;
namespace
{
namespace
{
using
down_atom
=
atom_constant
<
atom
(
"down"
)
>
;
behavior
no_args_1
()
{
return
{};
struct
fixture
{
}
actor_system_config
cfg
;
behavior
no_args_2
(
event_based_actor
*
)
{
void
test_spawn
(
message
args
,
bool
expect_fail
=
false
)
{
return
{};
actor_system
system
{
cfg
};
}
scoped_actor
self
{
system
};
CAF_MESSAGE
(
"set aut"
);
strong_actor_ptr
res
;
std
::
set
<
std
::
string
>
ifs
;
scoped_execution_unit
context
{
&
system
};
actor_config
actor_cfg
{
&
context
};
auto
aut
=
system
.
spawn
<
actor
>
(
"test_actor"
,
std
::
move
(
args
));
if
(
expect_fail
)
{
CAF_REQUIRE
(
!
aut
);
return
;
}
CAF_REQUIRE
(
aut
);
self
->
wait_for
(
*
aut
);
CAF_MESSAGE
(
"aut done"
);
}
};
struct
test_actor_no_args
:
event_based_actor
{
struct
no_args_3
:
event_based_actor
{
using
event_based_actor
::
event_based_actor
;
using
super
=
event_based_actor
;
using
super
::
super
;
};
};
struct
test_actor_one_arg
:
event_based_actor
{
behavior
one_arg_1
(
int
value
)
{
test_actor_one_arg
(
actor_config
&
conf
,
int
value
)
:
event_based_actor
(
conf
)
{
CAF_CHECK_EQUAL
(
value
,
42
);
CAF_CHECK_EQUAL
(
value
,
42
);
}
return
{};
}
;
}
}
// namespace <anonymous>
behavior
one_arg_2
(
event_based_actor
*
,
int
value
)
{
CAF_CHECK_EQUAL
(
value
,
42
);
return
{};
}
CAF_TEST_FIXTURE_SCOPE
(
add_actor_type_tests
,
fixture
)
struct
one_arg_3
:
event_based_actor
{
using
super
=
event_based_actor
;
CAF_TEST
(
fun_no_args
)
{
one_arg_3
(
actor_config
&
conf
,
int
value
)
:
super
(
conf
)
{
auto
test_actor_one_arg
=
[]
{
CAF_CHECK_EQUAL
(
value
,
42
);
CAF_MESSAGE
(
"inside test_actor"
);
}
};
};
cfg
.
add_actor_type
(
"test_actor"
,
test_actor_one_arg
);
test_spawn
(
make_message
());
CAF_MESSAGE
(
"test_spawn done"
);
}
CAF_TEST
(
fun_no_args_selfptr
)
{
struct
config
:
actor_system_config
{
auto
test_actor_one_arg
=
[](
event_based_actor
*
)
{
config
()
{
CAF_MESSAGE
(
"inside test_actor"
);
add_actor_type
(
"no_args_1"
,
no_args_1
);
};
add_actor_type
(
"no_args_2"
,
no_args_2
);
cfg
.
add_actor_type
(
"test_actor"
,
test_actor_one_arg
);
add_actor_type
<
no_args_3
>
(
"no_args_3"
);
test_spawn
(
make_message
());
add_actor_type
(
"one_arg_1"
,
one_arg_1
);
}
add_actor_type
(
"one_arg_2"
,
one_arg_2
);
CAF_TEST
(
fun_one_arg
)
{
add_actor_type
<
one_arg_3
,
const
int
&>
(
"one_arg_3"
);
auto
test_actor_one_arg
=
[](
int
i
)
{
}
CAF_CHECK_EQUAL
(
i
,
42
);
};
};
cfg
.
add_actor_type
(
"test_actor"
,
test_actor_one_arg
);
test_spawn
(
make_message
(
42
));
}
CAF_TEST
(
fun_one_arg_selfptr
)
{
struct
fixture
:
test_coordinator_fixture
<
config
>
{
auto
test_actor_one_arg
=
[](
event_based_actor
*
,
int
i
)
{
template
<
class
...
Ts
>
CAF_CHECK_EQUAL
(
i
,
42
);
expected
<
actor
>
test_spawn
(
const
char
*
name
,
Ts
&&
...
xs
)
{
}
;
CAF_MESSAGE
(
"spawn testee of type "
<<
name
)
;
cfg
.
add_actor_type
(
"test_actor"
,
test_actor_one_arg
)
;
actor_config
actor_cfg
{
sys
.
dummy_execution_unit
()}
;
test_spawn
(
make_message
(
42
));
return
sys
.
spawn
<
actor
>
(
name
,
make_message
(
std
::
forward
<
Ts
>
(
xs
)...
));
}
}
CAF_TEST
(
class_no_arg_invalid
)
{
error
invalid_args
=
sec
::
cannot_spawn_actor_from_arguments
;
cfg
.
add_actor_type
<
test_actor_no_args
>
(
"test_actor"
);
};
test_spawn
(
make_message
(
42
),
true
);
}
CAF_TEST
(
class_no_arg_valid
)
{
}
// namespace <anonymous>
cfg
.
add_actor_type
<
test_actor_no_args
>
(
"test_actor"
);
test_spawn
(
make_message
());
CAF_TEST_FIXTURE_SCOPE
(
add_actor_type_tests
,
fixture
)
}
CAF_TEST
(
class_one_arg_invalid
)
{
CAF_TEST
(
no_args
)
{
cfg
.
add_actor_type
<
test_actor_one_arg
,
const
int
&>
(
"test_actor"
);
CAF_CHECK_NOT_EQUAL
(
test_spawn
(
"no_args_1"
),
none
);
test_spawn
(
make_message
(),
true
);
CAF_CHECK_NOT_EQUAL
(
test_spawn
(
"no_args_2"
),
none
);
CAF_CHECK_NOT_EQUAL
(
test_spawn
(
"no_args_3"
),
none
);
CAF_CHECK_EQUAL
(
test_spawn
(
"no_args_1"
,
42
),
invalid_args
);
CAF_CHECK_EQUAL
(
test_spawn
(
"no_args_2"
,
42
),
invalid_args
);
CAF_CHECK_EQUAL
(
test_spawn
(
"no_args_3"
,
42
),
invalid_args
);
}
}
CAF_TEST
(
class_one_arg_valid
)
{
CAF_TEST
(
one_arg
)
{
cfg
.
add_actor_type
<
test_actor_one_arg
,
const
int
&>
(
"test_actor"
);
CAF_CHECK_NOT_EQUAL
(
test_spawn
(
"one_arg_1"
,
42
),
none
);
test_spawn
(
make_message
(
42
));
CAF_CHECK_NOT_EQUAL
(
test_spawn
(
"one_arg_2"
,
42
),
none
);
CAF_CHECK_NOT_EQUAL
(
test_spawn
(
"one_arg_3"
,
42
),
none
);
CAF_CHECK_EQUAL
(
test_spawn
(
"one_arg_1"
),
invalid_args
);
CAF_CHECK_EQUAL
(
test_spawn
(
"one_arg_2"
),
invalid_args
);
CAF_CHECK_EQUAL
(
test_spawn
(
"one_arg_3"
),
invalid_args
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
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