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
e87824c6
Commit
e87824c6
authored
May 12, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use fixtures in unit tests + cleanup
parent
ff54e90a
Changes
24
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
851 additions
and
1095 deletions
+851
-1095
libcaf_core/test/actor_pool.cpp
libcaf_core/test/actor_pool.cpp
+109
-124
libcaf_core/test/constructor_attach.cpp
libcaf_core/test/constructor_attach.cpp
+1
-1
libcaf_core/test/either.cpp
libcaf_core/test/either.cpp
+43
-25
libcaf_core/test/fixed_stack_actor.cpp
libcaf_core/test/fixed_stack_actor.cpp
+0
-125
libcaf_core/test/intrusive_ptr.cpp
libcaf_core/test/intrusive_ptr.cpp
+46
-55
libcaf_core/test/limited_vector.cpp
libcaf_core/test/limited_vector.cpp
+2
-2
libcaf_core/test/match.cpp
libcaf_core/test/match.cpp
+37
-42
libcaf_core/test/message.cpp
libcaf_core/test/message.cpp
+8
-8
libcaf_core/test/message_lifetime.cpp
libcaf_core/test/message_lifetime.cpp
+7
-7
libcaf_core/test/metaprogramming.cpp
libcaf_core/test/metaprogramming.cpp
+1
-2
libcaf_core/test/optional.cpp
libcaf_core/test/optional.cpp
+52
-41
libcaf_core/test/or_else.cpp
libcaf_core/test/or_else.cpp
+63
-46
libcaf_core/test/ripemd_160.cpp
libcaf_core/test/ripemd_160.cpp
+1
-1
libcaf_core/test/simple_reply_response.cpp
libcaf_core/test/simple_reply_response.cpp
+1
-1
libcaf_core/test/spawn.cpp
libcaf_core/test/spawn.cpp
+114
-163
libcaf_core/test/sync_send.cpp
libcaf_core/test/sync_send.cpp
+201
-195
libcaf_core/test/typed_spawn.cpp
libcaf_core/test/typed_spawn.cpp
+73
-76
libcaf_core/test/variant.cpp
libcaf_core/test/variant.cpp
+3
-3
libcaf_io/test/ping_pong.cpp
libcaf_io/test/ping_pong.cpp
+0
-89
libcaf_io/test/ping_pong.hpp
libcaf_io/test/ping_pong.hpp
+0
-38
libcaf_io/test/remote_actor.cpp
libcaf_io/test/remote_actor.cpp
+50
-2
libcaf_io/test/unpublish.cpp
libcaf_io/test/unpublish.cpp
+17
-18
libcaf_test/caf/test/unit_test.hpp
libcaf_test/caf/test/unit_test.hpp
+21
-20
libcaf_test/caf/test/unit_test_impl.hpp
libcaf_test/caf/test/unit_test_impl.hpp
+1
-11
No files found.
libcaf_core/test/actor_pool.cpp
View file @
e87824c6
...
@@ -60,6 +60,11 @@ struct fixture {
...
@@ -60,6 +60,11 @@ struct fixture {
fixture
()
{
fixture
()
{
announce
<
std
::
vector
<
int
>>
(
"vector<int>"
);
announce
<
std
::
vector
<
int
>>
(
"vector<int>"
);
}
}
~
fixture
()
{
await_all_actors_done
();
shutdown
();
CAF_CHECK_EQUAL
(
s_dtors
.
load
(),
s_ctors
.
load
());
}
};
};
}
// namespace <anonymous>
}
// namespace <anonymous>
...
@@ -67,131 +72,116 @@ struct fixture {
...
@@ -67,131 +72,116 @@ struct fixture {
CAF_TEST_FIXTURE_SCOPE
(
actor_pool_tests
,
fixture
)
CAF_TEST_FIXTURE_SCOPE
(
actor_pool_tests
,
fixture
)
CAF_TEST
(
round_robin_actor_pool
)
{
CAF_TEST
(
round_robin_actor_pool
)
{
{
// lifetime scope of self
scoped_actor
self
;
scoped_actor
self
;
auto
w
=
actor_pool
::
make
(
5
,
spawn_worker
,
actor_pool
::
round_robin
{});
auto
w
=
actor_pool
::
make
(
5
,
spawn_worker
,
actor_pool
::
round_robin
{});
self
->
monitor
(
w
);
self
->
monitor
(
w
);
self
->
send
(
w
,
sys_atom
::
value
,
put_atom
::
value
,
spawn_worker
());
self
->
send
(
w
,
sys_atom
::
value
,
put_atom
::
value
,
spawn_worker
());
std
::
vector
<
actor_addr
>
workers
;
std
::
vector
<
actor_addr
>
workers
;
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
self
->
sync_send
(
w
,
i
,
i
).
await
(
self
->
sync_send
(
w
,
i
,
i
).
await
(
[
&
](
int
res
)
{
[
&
](
int
res
)
{
CAF_CHECK_EQUAL
(
res
,
i
+
i
);
CAF_CHECK_EQUAL
(
res
,
i
+
i
);
auto
sender
=
self
->
current_sender
();
auto
sender
=
self
->
current_sender
();
self
->
monitor
(
sender
);
self
->
monitor
(
sender
);
workers
.
push_back
(
sender
);
workers
.
push_back
(
sender
);
}
);
}
CAF_CHECK
(
workers
.
size
()
==
6
);
CAF_CHECK
(
std
::
unique
(
workers
.
begin
(),
workers
.
end
())
==
workers
.
end
());
auto
is_invalid
=
[](
const
actor_addr
&
addr
)
{
return
addr
==
invalid_actor_addr
;
};
CAF_CHECK
(
std
::
none_of
(
workers
.
begin
(),
workers
.
end
(),
is_invalid
));
self
->
sync_send
(
w
,
sys_atom
::
value
,
get_atom
::
value
).
await
(
[
&
](
std
::
vector
<
actor
>&
ws
)
{
std
::
sort
(
workers
.
begin
(),
workers
.
end
());
std
::
sort
(
ws
.
begin
(),
ws
.
end
());
CAF_CHECK
(
workers
.
size
()
==
ws
.
size
()
&&
std
::
equal
(
workers
.
begin
(),
workers
.
end
(),
ws
.
begin
()));
}
);
anon_send_exit
(
workers
.
back
(),
exit_reason
::
user_shutdown
);
self
->
receive
(
after
(
std
::
chrono
::
milliseconds
(
25
))
>>
[]
{
// wait some time to give the pool time to remove the failed worker
}
);
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
CAF_CHECK
(
dm
.
source
==
workers
.
back
());
workers
.
pop_back
();
// check whether actor pool removed failed worker
self
->
sync_send
(
w
,
sys_atom
::
value
,
get_atom
::
value
).
await
(
[
&
](
std
::
vector
<
actor
>&
ws
)
{
std
::
sort
(
ws
.
begin
(),
ws
.
end
());
CAF_CHECK
(
workers
.
size
()
==
ws
.
size
()
&&
std
::
equal
(
workers
.
begin
(),
workers
.
end
(),
ws
.
begin
()));
}
}
);
);
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_TEST_ERROR
(
"didn't receive a down message"
);
}
}
CAF_CHECK
(
workers
.
size
()
==
6
);
);
CAF_CHECK
(
std
::
unique
(
workers
.
begin
(),
workers
.
end
())
==
workers
.
end
());
CAF_MESSAGE
(
"about to send exit to workers"
);
auto
is_invalid
=
[](
const
actor_addr
&
addr
)
{
self
->
send_exit
(
w
,
exit_reason
::
user_shutdown
);
return
addr
==
invalid_actor_addr
;
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
};
CAF_CHECK
(
std
::
none_of
(
workers
.
begin
(),
workers
.
end
(),
is_invalid
));
self
->
sync_send
(
w
,
sys_atom
::
value
,
get_atom
::
value
).
await
(
[
&
](
std
::
vector
<
actor
>&
ws
)
{
std
::
sort
(
workers
.
begin
(),
workers
.
end
());
std
::
sort
(
ws
.
begin
(),
ws
.
end
());
CAF_CHECK
(
workers
.
size
()
==
ws
.
size
()
&&
std
::
equal
(
workers
.
begin
(),
workers
.
end
(),
ws
.
begin
()));
}
);
anon_send_exit
(
workers
.
back
(),
exit_reason
::
user_shutdown
);
self
->
receive
(
after
(
std
::
chrono
::
milliseconds
(
25
))
>>
[]
{
// wait some time to give the pool time to remove the failed worker
}
);
self
->
receive
(
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
[
&
](
const
down_msg
&
dm
)
{
CAF_CHECK
(
dm
.
source
==
workers
.
back
());
auto
last
=
workers
.
end
();
workers
.
pop_back
();
auto
src
=
dm
.
source
;
// check whether actor pool removed failed worker
CAF_CHECK
(
src
!=
invalid_actor_addr
);
self
->
sync_send
(
w
,
sys_atom
::
value
,
get_atom
::
value
).
await
(
auto
pos
=
std
::
find
(
workers
.
begin
(),
last
,
src
);
[
&
](
std
::
vector
<
actor
>&
ws
)
{
//CAF_CHECK(pos != last || src == w); fail?
std
::
sort
(
ws
.
begin
(),
ws
.
end
());
if
(
pos
!=
last
)
{
CAF_CHECK
(
workers
.
size
()
==
ws
.
size
()
workers
.
erase
(
pos
);
&&
std
::
equal
(
workers
.
begin
(),
workers
.
end
(),
ws
.
begin
()));
}
}
);
},
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_TEST_ERROR
(
"didn't receive a down message"
);
CAF_TEST_ERROR
(
"didn't receive a down message"
);
}
}
);
);
CAF_MESSAGE
(
"about to send exit to workers"
);
self
->
send_exit
(
w
,
exit_reason
::
user_shutdown
);
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
auto
last
=
workers
.
end
();
auto
src
=
dm
.
source
;
CAF_CHECK
(
src
!=
invalid_actor_addr
);
auto
pos
=
std
::
find
(
workers
.
begin
(),
last
,
src
);
//CAF_CHECK(pos != last || src == w); fail?
if
(
pos
!=
last
)
{
workers
.
erase
(
pos
);
}
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_TEST_ERROR
(
"didn't receive a down message"
);
}
);
}
}
}
await_all_actors_done
();
shutdown
();
CAF_CHECK_EQUAL
(
s_dtors
.
load
(),
s_ctors
.
load
());
}
}
CAF_TEST
(
broadcast_actor_pool
)
{
CAF_TEST
(
broadcast_actor_pool
)
{
{
// lifetime scope of self
scoped_actor
self
;
scoped_actor
self
;
auto
spawn5
=
[]()
{
auto
spawn5
=
[]()
{
return
actor_pool
::
make
(
5
,
spawn_worker
,
actor_pool
::
broadcast
{});
return
actor_pool
::
make
(
5
,
spawn_worker
,
actor_pool
::
broadcast
{});
};
};
auto
w
=
actor_pool
::
make
(
5
,
spawn5
,
actor_pool
::
broadcast
{});
auto
w
=
actor_pool
::
make
(
5
,
spawn5
,
actor_pool
::
broadcast
{});
self
->
send
(
w
,
1
,
2
);
self
->
send
(
w
,
1
,
2
);
std
::
vector
<
int
>
results
;
std
::
vector
<
int
>
results
;
int
i
=
0
;
int
i
=
0
;
self
->
receive_for
(
i
,
25
)(
self
->
receive_for
(
i
,
25
)(
[
&
](
int
res
)
{
results
.
push_back
(
res
);
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_TEST_ERROR
(
"didn't receive a result"
);
}
);
CAF_CHECK_EQUAL
(
results
.
size
(),
25
);
CAF_CHECK
(
std
::
all_of
(
results
.
begin
(),
results
.
end
(),
[](
int
res
)
{
return
res
==
3
;
}));
self
->
send_exit
(
w
,
exit_reason
::
user_shutdown
);
}
CAF_TEST
(
random_actor_pool
)
{
scoped_actor
self
;
auto
w
=
actor_pool
::
make
(
5
,
spawn_worker
,
actor_pool
::
random
{});
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
self
->
sync_send
(
w
,
1
,
2
).
await
(
[
&
](
int
res
)
{
[
&
](
int
res
)
{
results
.
push_back
(
res
);
CAF_CHECK_EQUAL
(
res
,
3
);
},
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_TEST_ERROR
(
"didn't receive a
result
"
);
CAF_TEST_ERROR
(
"didn't receive a
down message
"
);
}
}
);
);
CAF_CHECK_EQUAL
(
results
.
size
(),
25
);
CAF_CHECK
(
std
::
all_of
(
results
.
begin
(),
results
.
end
(),
[](
int
res
)
{
return
res
==
3
;
}));
self
->
send_exit
(
w
,
exit_reason
::
user_shutdown
);
}
await_all_actors_done
();
shutdown
();
CAF_CHECK_EQUAL
(
s_dtors
.
load
(),
s_ctors
.
load
());
}
CAF_TEST
(
random_actor_pool
)
{
{
// lifetime scope of self
scoped_actor
self
;
auto
w
=
actor_pool
::
make
(
5
,
spawn_worker
,
actor_pool
::
random
{});
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
self
->
sync_send
(
w
,
1
,
2
).
await
(
[
&
](
int
res
)
{
CAF_CHECK_EQUAL
(
res
,
3
);
},
after
(
std
::
chrono
::
milliseconds
(
250
))
>>
[]
{
CAF_TEST_ERROR
(
"didn't receive a down message"
);
}
);
}
self
->
send_exit
(
w
,
exit_reason
::
user_shutdown
);
}
}
await_all_actors_done
();
self
->
send_exit
(
w
,
exit_reason
::
user_shutdown
);
shutdown
();
CAF_CHECK_EQUAL
(
s_dtors
.
load
(),
s_ctors
.
load
());
}
}
CAF_TEST
(
split_join_actor_pool
)
{
CAF_TEST
(
split_join_actor_pool
)
{
...
@@ -214,25 +204,20 @@ CAF_TEST(split_join_actor_pool) {
...
@@ -214,25 +204,20 @@ CAF_TEST(split_join_actor_pool) {
res
+=
x
;
res
+=
x
;
});
});
};
};
{
// lifetime scope of self
scoped_actor
self
;
scoped_actor
self
;
auto
w
=
actor_pool
::
make
(
5
,
spawn_split_worker
,
auto
w
=
actor_pool
::
make
(
5
,
spawn_split_worker
,
actor_pool
::
split_join
<
int
>
(
join_fun
,
split_fun
));
actor_pool
::
split_join
<
int
>
(
join_fun
,
split_fun
));
self
->
sync_send
(
w
,
std
::
vector
<
int
>
{
1
,
2
,
3
,
4
,
5
}).
await
(
self
->
sync_send
(
w
,
std
::
vector
<
int
>
{
1
,
2
,
3
,
4
,
5
}).
await
(
[
&
](
int
res
)
{
[
&
](
int
res
)
{
CAF_CHECK_EQUAL
(
res
,
15
);
CAF_CHECK_EQUAL
(
res
,
15
);
}
}
);
);
self
->
sync_send
(
w
,
std
::
vector
<
int
>
{
6
,
7
,
8
,
9
,
10
}).
await
(
self
->
sync_send
(
w
,
std
::
vector
<
int
>
{
6
,
7
,
8
,
9
,
10
}).
await
(
[
&
](
int
res
)
{
[
&
](
int
res
)
{
CAF_CHECK_EQUAL
(
res
,
40
);
CAF_CHECK_EQUAL
(
res
,
40
);
}
}
);
);
self
->
send_exit
(
w
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
w
,
exit_reason
::
user_shutdown
);
}
await_all_actors_done
();
shutdown
();
CAF_CHECK_EQUAL
(
s_dtors
.
load
(),
s_ctors
.
load
());
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/constructor_attach.cpp
View file @
e87824c6
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
using
namespace
caf
;
using
namespace
caf
;
CAF_TEST
(
test_
constructor_attach
)
{
CAF_TEST
(
constructor_attach
)
{
class
testee
:
public
event_based_actor
{
class
testee
:
public
event_based_actor
{
public:
public:
testee
(
actor
buddy
)
:
m_buddy
(
buddy
)
{
testee
(
actor
buddy
)
:
m_buddy
(
buddy
)
{
...
...
libcaf_core/test/either.cpp
View file @
e87824c6
...
@@ -24,6 +24,8 @@
...
@@ -24,6 +24,8 @@
using
namespace
caf
;
using
namespace
caf
;
namespace
{
using
foo
=
typed_actor
<
replies_to
<
int
>::
with_either
<
int
>::
or_else
<
float
>>
;
using
foo
=
typed_actor
<
replies_to
<
int
>::
with_either
<
int
>::
or_else
<
float
>>
;
foo
::
behavior_type
my_foo
()
{
foo
::
behavior_type
my_foo
()
{
...
@@ -37,7 +39,18 @@ foo::behavior_type my_foo() {
...
@@ -37,7 +39,18 @@ foo::behavior_type my_foo() {
};
};
}
}
CAF_TEST
(
either
)
{
struct
fixture
{
~
fixture
()
{
await_all_actors_done
();
shutdown
();
}
};
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
atom_tests
,
fixture
)
CAF_TEST
(
basic_usage
)
{
auto
f1
=
[]()
->
either
<
int
>::
or_else
<
float
>
{
auto
f1
=
[]()
->
either
<
int
>::
or_else
<
float
>
{
return
42
;
return
42
;
};
};
...
@@ -50,31 +63,36 @@ CAF_TEST(either) {
...
@@ -50,31 +63,36 @@ CAF_TEST(either) {
}
}
return
{
3.
f
,
4.
f
};
return
{
3.
f
,
4.
f
};
};
};
f1
(
);
CAF_CHECK
(
f1
().
value
==
make_message
(
42
)
);
f2
(
);
CAF_CHECK
(
f2
().
value
==
make_message
(
42.
f
)
);
f3
(
true
);
CAF_CHECK
(
f3
(
true
).
value
==
make_message
(
1
,
2
)
);
f3
(
false
);
CAF_CHECK
(
f3
(
false
).
value
==
make_message
(
3.
f
,
4.
f
)
);
either
<
int
>::
or_else
<
float
>
x1
{
4
};
either
<
int
>::
or_else
<
float
>
x1
{
4
};
CAF_CHECK
(
x1
.
value
==
make_message
(
4
));
either
<
int
>::
or_else
<
float
>
x2
{
4.
f
};
either
<
int
>::
or_else
<
float
>
x2
{
4.
f
};
CAF_CHECK
(
x2
.
value
==
make_message
(
4.
f
));
}
CAF_TEST
(
either_in_typed_interfaces
)
{
auto
mf
=
spawn_typed
(
my_foo
);
auto
mf
=
spawn_typed
(
my_foo
);
{
scoped_actor
self
;
scoped_actor
self
;
self
->
sync_send
(
mf
,
42
).
await
(
self
->
sync_send
(
mf
,
42
).
await
(
[](
int
val
)
{
[](
int
val
)
{
CAF_CHECK_EQUAL
(
val
,
42
);
CAF_CHECK_EQUAL
(
val
,
42
);
},
},
[](
float
)
{
[](
float
)
{
CAF_TEST_ERROR
(
"expected an integer"
);
CAF_TEST_ERROR
(
"expected an integer"
);
}
}
);
);
self
->
sync_send
(
mf
,
10
).
await
(
self
->
sync_send
(
mf
,
10
).
await
(
[](
int
)
{
[](
int
)
{
CAF_TEST_ERROR
(
"expected a float"
);
CAF_TEST_ERROR
(
"expected a float"
);
},
},
[](
float
val
)
{
[](
float
val
)
{
CAF_CHECK_EQUAL
(
val
,
10.
f
);
CAF_CHECK_EQUAL
(
val
,
10.
f
);
}
}
);
);
self
->
send_exit
(
mf
,
exit_reason
::
kill
);
}
shutdown
();
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/fixed_stack_actor.cpp
deleted
100644 → 0
View file @
ff54e90a
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#define CAF_SUITE fixed_stack_actor
#include "caf/test/unit_test.hpp"
#include <vector>
#include "caf/all.hpp"
using
namespace
caf
;
using
pop_atom
=
atom_constant
<
atom
(
"pop"
)
>
;
using
push_atom
=
atom_constant
<
atom
(
"push"
)
>
;
class
fixed_stack
:
public
sb_actor
<
fixed_stack
>
{
public:
friend
class
sb_actor
<
fixed_stack
>
;
fixed_stack
(
size_t
max
)
:
max_size
(
max
)
{
full
.
assign
(
[
=
](
push_atom
,
int
)
{
/* discard */
},
[
=
](
pop_atom
)
->
message
{
auto
result
=
data
.
back
();
data
.
pop_back
();
become
(
filled
);
return
make_message
(
ok_atom
::
value
,
result
);
}
);
filled
.
assign
(
[
=
](
push_atom
,
int
what
)
{
data
.
push_back
(
what
);
if
(
data
.
size
()
==
max_size
)
{
become
(
full
);
}
},
[
=
](
pop_atom
)
->
message
{
auto
result
=
data
.
back
();
data
.
pop_back
();
if
(
data
.
empty
())
{
become
(
empty
);
}
return
make_message
(
ok_atom
::
value
,
result
);
}
);
empty
.
assign
(
[
=
](
push_atom
,
int
what
)
{
data
.
push_back
(
what
);
become
(
filled
);
},
[
=
](
pop_atom
)
{
return
error_atom
::
value
;
}
);
}
~
fixed_stack
();
private:
size_t
max_size
=
10
;
std
::
vector
<
int
>
data
;
behavior
full
;
behavior
filled
;
behavior
empty
;
behavior
&
init_state
=
empty
;
};
fixed_stack
::~
fixed_stack
()
{
// avoid weak-vtables warning
}
CAF_TEST
(
test_fixed_stack_actor
)
{
{
scoped_actor
self
;
auto
st
=
spawn
<
fixed_stack
>
(
size_t
{
10
});
// push 20 values
for
(
int
i
=
0
;
i
<
20
;
++
i
)
self
->
send
(
st
,
push_atom
::
value
,
i
);
// pop 20 times
for
(
int
i
=
0
;
i
<
20
;
++
i
)
self
->
send
(
st
,
pop_atom
::
value
);
// expect 10 failure messages
{
int
i
=
0
;
self
->
receive_for
(
i
,
10
)
(
[](
error_atom
)
{
CAF_MESSAGE
(
"received `error_atom`"
);
}
);
CAF_MESSAGE
(
"received all messages"
);
}
// expect 10 {'ok', value} messages
{
std
::
vector
<
int
>
values
;
int
i
=
0
;
self
->
receive_for
(
i
,
10
)
(
[
&
](
ok_atom
,
int
value
)
{
values
.
push_back
(
value
);
}
);
std
::
vector
<
int
>
expected
{
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
,
0
};
CAF_CHECK_EQUAL
(
join
(
values
,
","
),
join
(
expected
,
","
));
}
// terminate st
self
->
send_exit
(
st
,
exit_reason
::
user_shutdown
);
self
->
await_all_other_actors_done
();
}
await_all_actors_done
();
shutdown
();
}
libcaf_core/test/intrusive_ptr.cpp
View file @
e87824c6
...
@@ -20,10 +20,10 @@
...
@@ -20,10 +20,10 @@
#define CAF_SUITE intrusive_ptr
#define CAF_SUITE intrusive_ptr
#include "caf/test/unit_test.hpp"
#include "caf/test/unit_test.hpp"
// this test dosn't
test
thread-safety of intrusive_ptr
// this test dosn't
verify
thread-safety of intrusive_ptr
// however, it is thread safe since it uses atomic operations only
// however, it is thread safe since it uses atomic operations only
#include <
list
>
#include <
vector
>
#include <cstddef>
#include <cstddef>
#include "caf/ref_counted.hpp"
#include "caf/ref_counted.hpp"
...
@@ -92,73 +92,64 @@ class0ptr get_test_ptr() {
...
@@ -92,73 +92,64 @@ class0ptr get_test_ptr() {
return
get_test_rc
();
return
get_test_rc
();
}
}
struct
fixture
{
~
fixture
()
{
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
0
);
}
};
}
// namespace <anonymous>
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
atom_tests
,
fixture
)
CAF_TEST
(
make_counted
)
{
CAF_TEST
(
make_counted
)
{
{
auto
p
=
make_counted
<
class0
>
();
auto
p
=
make_counted
<
class0
>
();
CAF_CHECK_EQUAL
(
class0_instances
,
1
);
CAF_CHECK_EQUAL
(
class0_instances
,
1
);
CAF_CHECK
(
p
->
unique
());
CAF_CHECK
(
p
->
unique
());
}
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
0
);
}
}
CAF_TEST
(
reset
)
{
CAF_TEST
(
reset
)
{
{
class0ptr
p
;
class0ptr
p
;
p
.
reset
(
new
class0
,
false
);
p
.
reset
(
new
class0
,
false
);
CAF_CHECK_EQUAL
(
class0_instances
,
1
);
CAF_CHECK_EQUAL
(
class0_instances
,
1
);
CAF_CHECK
(
p
->
unique
());
CAF_CHECK
(
p
->
unique
());
}
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
0
);
}
}
CAF_TEST
(
get_test_rc
)
{
CAF_TEST
(
get_test_rc
)
{
{
class0ptr
p1
;
class0ptr
p1
;
p1
=
get_test_rc
();
p1
=
get_test_rc
();
class0ptr
p2
=
p1
;
class0ptr
p2
=
p1
;
CAF_CHECK_EQUAL
(
class0_instances
,
1
);
CAF_CHECK_EQUAL
(
class0_instances
,
1
);
CAF_CHECK_EQUAL
(
p1
->
unique
(),
false
);
CAF_CHECK_EQUAL
(
p1
->
unique
(),
false
);
}
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
0
);
}
}
CAF_TEST
(
list
)
{
CAF_TEST
(
list
)
{
{
std
::
vector
<
class0ptr
>
pl
;
std
::
list
<
class0ptr
>
pl
;
pl
.
push_back
(
get_test_ptr
());
pl
.
push_back
(
get_test_ptr
());
pl
.
push_back
(
get_test_rc
());
pl
.
push_back
(
get_test_rc
());
pl
.
push_back
(
pl
.
front
()
->
create
());
pl
.
push_back
(
pl
.
front
()
->
create
());
CAF_CHECK
(
pl
.
front
()
->
unique
());
CAF_CHECK
(
pl
.
front
()
->
unique
());
CAF_CHECK_EQUAL
(
class0_instances
,
3
);
CAF_CHECK_EQUAL
(
class0_instances
,
3
);
}
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
0
);
}
}
CAF_TEST
(
full_test
)
{
CAF_TEST
(
full_test
)
{
{
auto
p1
=
make_counted
<
class0
>
();
auto
p1
=
make_counted
<
class0
>
();
CAF_CHECK_EQUAL
(
p1
->
is_subtype
(),
false
);
CAF_CHECK_EQUAL
(
p1
->
is_subtype
(),
false
);
CAF_CHECK_EQUAL
(
p1
->
unique
(),
true
);
CAF_CHECK_EQUAL
(
p1
->
unique
(),
true
);
CAF_CHECK_EQUAL
(
class0_instances
,
1
);
CAF_CHECK_EQUAL
(
class0_instances
,
1
);
CAF_CHECK_EQUAL
(
class1_instances
,
0
);
p1
.
reset
(
new
class1
,
false
);
CAF_CHECK_EQUAL
(
p1
->
is_subtype
(),
true
);
CAF_CHECK_EQUAL
(
p1
->
unique
(),
true
);
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
1
);
auto
p2
=
make_counted
<
class1
>
();
p1
=
p2
;
CAF_CHECK_EQUAL
(
p1
->
unique
(),
false
);
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
1
);
CAF_CHECK
(
p1
==
p2
);
}
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
0
);
p1
.
reset
(
new
class1
,
false
);
CAF_CHECK_EQUAL
(
p1
->
is_subtype
(),
true
);
CAF_CHECK_EQUAL
(
p1
->
unique
(),
true
);
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
1
);
auto
p2
=
make_counted
<
class1
>
();
p1
=
p2
;
CAF_CHECK_EQUAL
(
p1
->
unique
(),
false
);
CAF_CHECK_EQUAL
(
class0_instances
,
0
);
CAF_CHECK_EQUAL
(
class1_instances
,
1
);
CAF_CHECK
(
p1
==
p2
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/
fix
ed_vector.cpp
→
libcaf_core/test/
limit
ed_vector.cpp
View file @
e87824c6
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
* http://www.boost.org/LICENSE_1_0.txt. *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
******************************************************************************/
#define CAF_SUITE
fix
ed_vector
#define CAF_SUITE
limit
ed_vector
#include "caf/test/unit_test.hpp"
#include "caf/test/unit_test.hpp"
#include <algorithm>
#include <algorithm>
...
@@ -29,7 +29,7 @@ using std::endl;
...
@@ -29,7 +29,7 @@ using std::endl;
using
std
::
equal
;
using
std
::
equal
;
using
caf
::
detail
::
limited_vector
;
using
caf
::
detail
::
limited_vector
;
CAF_TEST
(
limited_vector
)
{
CAF_TEST
(
basics
)
{
int
arr1
[]
{
1
,
2
,
3
,
4
};
int
arr1
[]
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
4
>
vec1
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
4
>
vec1
{
1
,
2
,
3
,
4
};
limited_vector
<
int
,
5
>
vec2
{
4
,
3
,
2
,
1
};
limited_vector
<
int
,
5
>
vec2
{
4
,
3
,
2
,
1
};
...
...
libcaf_core/test/match.cpp
View file @
e87824c6
...
@@ -36,7 +36,6 @@ using ho_atom = atom_constant<atom("ho")>;
...
@@ -36,7 +36,6 @@ using ho_atom = atom_constant<atom("ho")>;
function
<
optional
<
string
>
(
const
string
&
)
>
starts_with
(
const
string
&
s
)
{
function
<
optional
<
string
>
(
const
string
&
)
>
starts_with
(
const
string
&
s
)
{
return
[
=
](
const
string
&
str
)
->
optional
<
string
>
{
return
[
=
](
const
string
&
str
)
->
optional
<
string
>
{
CAF_MESSAGE
(
"starts with guard called"
);
if
(
str
.
size
()
>
s
.
size
()
&&
str
.
compare
(
0
,
s
.
size
(),
s
)
==
0
)
{
if
(
str
.
size
()
>
s
.
size
()
&&
str
.
compare
(
0
,
s
.
size
(),
s
)
==
0
)
{
auto
res
=
str
.
substr
(
s
.
size
());
auto
res
=
str
.
substr
(
s
.
size
());
return
res
;
return
res
;
...
@@ -104,7 +103,7 @@ function<void()> f(int idx) {
...
@@ -104,7 +103,7 @@ function<void()> f(int idx) {
};
};
}
}
CAF_TEST
(
test_atom
s
)
{
CAF_TEST
(
atom_constant
s
)
{
auto
expr
=
on
(
hi_atom
::
value
)
>>
f
(
0
);
auto
expr
=
on
(
hi_atom
::
value
)
>>
f
(
0
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
hi_atom
::
value
),
0
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
hi_atom
::
value
),
0
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
ho_atom
::
value
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
ho_atom
::
value
),
-
1
);
...
@@ -122,44 +121,41 @@ CAF_TEST(test_atoms) {
...
@@ -122,44 +121,41 @@ CAF_TEST(test_atoms) {
CAF_CHECK_EQUAL
(
invoked
(
expr2
,
ho_atom
::
value
),
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr2
,
ho_atom
::
value
),
1
);
}
}
CAF_TEST
(
test_custom_projections
)
{
CAF_TEST
(
guards_called
)
{
// check whether projection is called
bool
guard_called
=
false
;
{
auto
guard
=
[
&
](
int
arg
)
->
optional
<
int
>
{
bool
guard_called
=
false
;
guard_called
=
true
;
auto
guard
=
[
&
](
int
arg
)
->
optional
<
int
>
{
return
arg
;
guard_called
=
true
;
};
return
arg
;
auto
expr
=
on
(
guard
)
>>
f
(
0
);
};
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
),
0
);
auto
expr
=
on
(
guard
)
>>
f
(
0
);
CAF_CHECK_EQUAL
(
guard_called
,
true
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
),
0
);
}
CAF_CHECK_EQUAL
(
guard_called
,
true
);
}
CAF_TEST
(
forwarding_optionals
)
{
// check forwarding optional<const string&> from guard
auto
expr
=
(
{
on
(
starts_with
(
"--"
))
>>
[](
const
string
&
str
)
{
auto
expr
=
(
CAF_CHECK_EQUAL
(
str
,
"help"
);
on
(
starts_with
(
"--"
))
>>
[](
const
string
&
str
)
{
s_invoked
[
0
]
=
true
;
CAF_CHECK_EQUAL
(
str
,
"help"
);
}
s_invoked
[
0
]
=
true
;
);
}
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"--help"
),
0
);
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"-help"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"--help"
),
0
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"--help"
,
"--help"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"-help"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"--help"
,
"--help"
),
-
1
);
}
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
),
-
1
);
}
CAF_TEST
(
projections
)
{
// check projection
auto
expr
=
(
{
on
(
toint
)
>>
[](
int
i
)
{
auto
expr
=
(
CAF_CHECK_EQUAL
(
i
,
42
);
on
(
toint
)
>>
[](
int
i
)
{
s_invoked
[
0
]
=
true
;
CAF_CHECK_EQUAL
(
i
,
42
);
}
s_invoked
[
0
]
=
true
;
);
}
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"42"
),
0
);
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"42f"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"42"
),
0
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"42"
,
"42"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"42f"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
"42"
,
"42"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
),
-
1
);
}
}
}
struct
wrapped_int
{
struct
wrapped_int
{
...
@@ -170,7 +166,7 @@ inline bool operator==(const wrapped_int& lhs, const wrapped_int& rhs) {
...
@@ -170,7 +166,7 @@ inline bool operator==(const wrapped_int& lhs, const wrapped_int& rhs) {
return
lhs
.
value
==
rhs
.
value
;
return
lhs
.
value
==
rhs
.
value
;
}
}
CAF_TEST
(
test_arg_match
)
{
CAF_TEST
(
arg_match_pattern
)
{
announce
<
wrapped_int
>
(
"wrapped_int"
,
&
wrapped_int
::
value
);
announce
<
wrapped_int
>
(
"wrapped_int"
,
&
wrapped_int
::
value
);
auto
expr
=
on
(
42
,
arg_match
)
>>
[](
int
i
)
{
auto
expr
=
on
(
42
,
arg_match
)
>>
[](
int
i
)
{
s_invoked
[
0
]
=
true
;
s_invoked
[
0
]
=
true
;
...
@@ -196,5 +192,4 @@ CAF_TEST(test_arg_match) {
...
@@ -196,5 +192,4 @@ CAF_TEST(test_arg_match) {
CAF_CHECK_EQUAL
(
invoked
(
expr3
,
wrapped_int
{
1
},
wrapped_int
{
42
}),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr3
,
wrapped_int
{
1
},
wrapped_int
{
42
}),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr3
,
42
,
1
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr3
,
42
,
1
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr3
,
wrapped_int
{
42
},
wrapped_int
{
1
}),
0
);
CAF_CHECK_EQUAL
(
invoked
(
expr3
,
wrapped_int
{
42
},
wrapped_int
{
1
}),
0
);
shutdown
();
}
}
libcaf_core/test/message.cpp
View file @
e87824c6
...
@@ -27,7 +27,7 @@ using std::cout;
...
@@ -27,7 +27,7 @@ using std::cout;
using
std
::
endl
;
using
std
::
endl
;
using
namespace
caf
;
using
namespace
caf
;
CAF_TEST
(
test_
drop
)
{
CAF_TEST
(
drop
)
{
auto
m1
=
make_message
(
1
,
2
,
3
,
4
,
5
);
auto
m1
=
make_message
(
1
,
2
,
3
,
4
,
5
);
std
::
vector
<
message
>
messages
{
std
::
vector
<
message
>
messages
{
m1
,
m1
,
...
@@ -42,13 +42,13 @@ CAF_TEST(test_drop) {
...
@@ -42,13 +42,13 @@ CAF_TEST(test_drop) {
}
}
}
}
CAF_TEST
(
test_
slice
)
{
CAF_TEST
(
slice
)
{
auto
m1
=
make_message
(
1
,
2
,
3
,
4
,
5
);
auto
m1
=
make_message
(
1
,
2
,
3
,
4
,
5
);
auto
m2
=
m1
.
slice
(
2
,
2
);
auto
m2
=
m1
.
slice
(
2
,
2
);
CAF_CHECK_EQUAL
(
to_string
(
m2
),
to_string
(
make_message
(
3
,
4
)));
CAF_CHECK_EQUAL
(
to_string
(
m2
),
to_string
(
make_message
(
3
,
4
)));
}
}
CAF_TEST
(
test_
extract1
)
{
CAF_TEST
(
extract1
)
{
auto
f
=
[](
int
lhs1
,
int
lhs2
,
int
lhs3
,
int
rhs1
,
int
rhs2
,
int
val
)
{
auto
f
=
[](
int
lhs1
,
int
lhs2
,
int
lhs3
,
int
rhs1
,
int
rhs2
,
int
val
)
{
auto
m1
=
make_message
(
lhs1
,
lhs2
,
lhs3
);
auto
m1
=
make_message
(
lhs1
,
lhs2
,
lhs3
);
auto
m2
=
make_message
(
rhs1
,
rhs2
);
auto
m2
=
make_message
(
rhs1
,
rhs2
);
...
@@ -60,7 +60,7 @@ CAF_TEST(test_extract1) {
...
@@ -60,7 +60,7 @@ CAF_TEST(test_extract1) {
f
(
1
,
2
,
3
,
1
,
2
,
3
);
f
(
1
,
2
,
3
,
1
,
2
,
3
);
}
}
CAF_TEST
(
test_
extract2
)
{
CAF_TEST
(
extract2
)
{
auto
m1
=
make_message
(
1.0
,
2.0
,
3.0
);
auto
m1
=
make_message
(
1.0
,
2.0
,
3.0
);
auto
m2
=
make_message
(
1
,
2
,
1.0
,
2.0
,
3.0
);
auto
m2
=
make_message
(
1
,
2
,
1.0
,
2.0
,
3.0
);
auto
m3
=
make_message
(
1.0
,
1
,
2
,
2.0
,
3.0
);
auto
m3
=
make_message
(
1.0
,
1
,
2
,
2.0
,
3.0
);
...
@@ -80,7 +80,7 @@ CAF_TEST(test_extract2) {
...
@@ -80,7 +80,7 @@ CAF_TEST(test_extract2) {
CAF_CHECK_EQUAL
(
to_string
(
m7
.
extract
(
f
)),
to_string
(
m1
));
CAF_CHECK_EQUAL
(
to_string
(
m7
.
extract
(
f
)),
to_string
(
m1
));
}
}
CAF_TEST
(
test_
extract3
)
{
CAF_TEST
(
extract3
)
{
auto
m1
=
make_message
(
1
);
auto
m1
=
make_message
(
1
);
CAF_CHECK_EQUAL
(
to_string
(
m1
.
extract
([](
int
)
{})),
to_string
(
message
{}));
CAF_CHECK_EQUAL
(
to_string
(
m1
.
extract
([](
int
)
{})),
to_string
(
message
{}));
auto
m2
=
make_message
(
1.0
,
2
,
3
,
4.0
);
auto
m2
=
make_message
(
1.0
,
2
,
3
,
4.0
);
...
@@ -92,7 +92,7 @@ CAF_TEST(test_extract3) {
...
@@ -92,7 +92,7 @@ CAF_TEST(test_extract3) {
CAF_CHECK_EQUAL
(
to_string
(
m3
),
to_string
(
make_message
(
1.0
,
4.0
)));
CAF_CHECK_EQUAL
(
to_string
(
m3
),
to_string
(
make_message
(
1.0
,
4.0
)));
}
}
CAF_TEST
(
test_
extract_opts
)
{
CAF_TEST
(
extract_opts
)
{
auto
f
=
[](
std
::
vector
<
std
::
string
>
xs
)
{
auto
f
=
[](
std
::
vector
<
std
::
string
>
xs
)
{
std
::
string
filename
;
std
::
string
filename
;
auto
res
=
message_builder
(
xs
.
begin
(),
xs
.
end
()).
extract_opts
({
auto
res
=
message_builder
(
xs
.
begin
(),
xs
.
end
()).
extract_opts
({
...
@@ -108,12 +108,12 @@ CAF_TEST(test_extract_opts) {
...
@@ -108,12 +108,12 @@ CAF_TEST(test_extract_opts) {
f
({
"-f"
,
"hello.txt"
});
f
({
"-f"
,
"hello.txt"
});
}
}
CAF_TEST
(
t
est_t
ype_token
)
{
CAF_TEST
(
type_token
)
{
auto
m1
=
make_message
(
get_atom
::
value
);
auto
m1
=
make_message
(
get_atom
::
value
);
CAF_CHECK_EQUAL
(
m1
.
type_token
(),
detail
::
make_type_token
<
get_atom
>
());
CAF_CHECK_EQUAL
(
m1
.
type_token
(),
detail
::
make_type_token
<
get_atom
>
());
}
}
CAF_TEST
(
test_
concat
)
{
CAF_TEST
(
concat
)
{
auto
m1
=
make_message
(
get_atom
::
value
);
auto
m1
=
make_message
(
get_atom
::
value
);
auto
m2
=
make_message
(
uint32_t
{
1
});
auto
m2
=
make_message
(
uint32_t
{
1
});
auto
m3
=
message
::
concat
(
m1
,
m2
);
auto
m3
=
message
::
concat
(
m1
,
m2
);
...
...
libcaf_core/test/message_lifetime.cpp
View file @
e87824c6
...
@@ -31,13 +31,6 @@ using namespace caf;
...
@@ -31,13 +31,6 @@ using namespace caf;
namespace
{
namespace
{
struct
fixture
{
~
fixture
()
{
await_all_actors_done
();
shutdown
();
}
};
class
testee
:
public
event_based_actor
{
class
testee
:
public
event_based_actor
{
public:
public:
testee
();
testee
();
...
@@ -111,6 +104,13 @@ void test_message_lifetime() {
...
@@ -111,6 +104,13 @@ void test_message_lifetime() {
}
}
}
}
struct
fixture
{
~
fixture
()
{
await_all_actors_done
();
shutdown
();
}
};
}
// namespace <anonymous>
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
message_lifetime_tests
,
fixture
)
CAF_TEST_FIXTURE_SCOPE
(
message_lifetime_tests
,
fixture
)
...
...
libcaf_core/test/metaprogramming.cpp
View file @
e87824c6
...
@@ -45,7 +45,7 @@ struct is_int : std::false_type {};
...
@@ -45,7 +45,7 @@ struct is_int : std::false_type {};
template
<
>
template
<
>
struct
is_int
<
int
>
:
std
::
true_type
{};
struct
is_int
<
int
>
:
std
::
true_type
{};
CAF_TEST
(
test_
metaprogramming
)
{
CAF_TEST
(
metaprogramming
)
{
using
if1
=
type_list
<
replies_to
<
int
,
double
>::
with
<
void
>
,
using
if1
=
type_list
<
replies_to
<
int
,
double
>::
with
<
void
>
,
replies_to
<
int
>::
with
<
int
>>
;
replies_to
<
int
>::
with
<
int
>>
;
using
if2
=
type_list
<
replies_to
<
int
>::
with
<
int
>
,
using
if2
=
type_list
<
replies_to
<
int
>::
with
<
int
>
,
...
@@ -93,5 +93,4 @@ CAF_TEST(test_metaprogramming) {
...
@@ -93,5 +93,4 @@ CAF_TEST(test_metaprogramming) {
CAF_CHECK
((
tl_is_strict_subset
<
list_a
,
list_a
>::
value
));
CAF_CHECK
((
tl_is_strict_subset
<
list_a
,
list_a
>::
value
));
CAF_CHECK
((
tl_is_strict_subset
<
list_b
,
list_b
>::
value
));
CAF_CHECK
((
tl_is_strict_subset
<
list_b
,
list_b
>::
value
));
}
}
shutdown
();
}
}
libcaf_core/test/optional.cpp
View file @
e87824c6
...
@@ -27,46 +27,57 @@
...
@@ -27,46 +27,57 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
caf
;
using
namespace
caf
;
CAF_TEST
(
test_optional
)
{
CAF_TEST
(
empties
)
{
{
optional
<
int
>
i
;
optional
<
int
>
i
,
j
;
optional
<
int
>
j
;
CAF_CHECK
(
i
==
j
);
CAF_CHECK
(
i
==
j
);
CAF_CHECK
(
!
(
i
!=
j
));
CAF_CHECK
(
!
(
i
!=
j
));
}
}
{
optional
<
int
>
i
=
5
;
CAF_TEST
(
unequal
)
{
optional
<
int
>
j
=
6
;
optional
<
int
>
i
=
5
;
CAF_CHECK
(
!
(
i
==
j
));
optional
<
int
>
j
=
6
;
CAF_CHECK
(
i
!=
j
);
CAF_CHECK
(
!
(
i
==
j
));
}
CAF_CHECK
(
i
!=
j
);
{
}
optional
<
int
>
i
;
optional
<
double
>
j
;
CAF_TEST
(
distinct_types
)
{
CAF_CHECK
(
i
==
j
);
optional
<
int
>
i
;
CAF_CHECK
(
!
(
i
!=
j
));
optional
<
double
>
j
;
}
CAF_CHECK
(
i
==
j
);
{
CAF_CHECK
(
!
(
i
!=
j
));
struct
qwertz
{
}
qwertz
(
int
i
,
int
j
)
:
m_i
(
i
),
m_j
(
j
)
{
CAF_MESSAGE
(
"called ctor of `qwertz`"
);
struct
qwertz
{
}
qwertz
(
int
i
,
int
j
)
:
m_i
(
i
),
m_j
(
j
)
{
int
m_i
;
// nop
int
m_j
;
};
{
optional
<
qwertz
>
i
;
CAF_CHECK
(
i
.
empty
());
}
{
qwertz
obj
(
1
,
2
);
optional
<
qwertz
>
j
(
obj
);
CAF_CHECK
(
!
j
.
empty
());
}
{
optional
<
qwertz
>
i
=
qwertz
(
1
,
2
);
CAF_CHECK
(
!
i
.
empty
());
optional
<
qwertz
>
j
=
{
{
1
,
2
}
};
CAF_CHECK
(
!
j
.
empty
());
}
}
}
int
m_i
;
int
m_j
;
};
inline
bool
operator
==
(
const
qwertz
&
lhs
,
const
qwertz
&
rhs
)
{
return
lhs
.
m_i
==
rhs
.
m_i
&&
lhs
.
m_j
==
rhs
.
m_j
;
}
CAF_TEST
(
custom_type_none
)
{
optional
<
qwertz
>
i
;
CAF_CHECK
(
i
==
none
);
}
CAF_TEST
(
custom_type_engaged
)
{
qwertz
obj
{
1
,
2
};
optional
<
qwertz
>
j
=
obj
;
CAF_CHECK
(
j
!=
none
);
CAF_CHECK
(
obj
==
j
);
CAF_CHECK
(
j
==
obj
);
CAF_CHECK
(
obj
==
*
j
);
CAF_CHECK
(
*
j
==
obj
);
}
CAF_TEST
(
test_optional
)
{
optional
<
qwertz
>
i
=
qwertz
(
1
,
2
);
CAF_CHECK
(
!
i
.
empty
());
optional
<
qwertz
>
j
=
{
{
1
,
2
}
};
CAF_CHECK
(
!
j
.
empty
());
}
}
libcaf_core/test/or_else.cpp
View file @
e87824c6
...
@@ -24,52 +24,69 @@
...
@@ -24,52 +24,69 @@
using
namespace
caf
;
using
namespace
caf
;
CAF_TEST
(
test_or_else
)
{
namespace
{
{
scoped_actor
self
;
message_handler
handle_a
{
on
(
"a"
)
>>
[]
{
return
1
;
}
};
message_handler
handle_b
{
on
(
"b"
)
>>
[]
{
return
2
;
}
};
message_handler
handle_c
{
on
(
"c"
)
>>
[]
{
return
3
;
}
};
auto
run_testee
([
&
](
actor
testee
)
{
self
->
sync_send
(
testee
,
"a"
).
await
([](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
1
);
});
self
->
sync_send
(
testee
,
"b"
).
await
([](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
2
);
});
self
->
sync_send
(
testee
,
"c"
).
await
([](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
3
);
});
self
->
send_exit
(
testee
,
exit_reason
::
user_shutdown
);
self
->
await_all_other_actors_done
();
});
message_handler
handle_a
()
{
CAF_MESSAGE
(
"run_testee: handle_a.or_else(handle_b).or_else(handle_c)"
);
return
on
(
"a"
)
>>
[]
{
return
1
;
};
run_testee
(
}
spawn
([
=
]
{
return
handle_a
.
or_else
(
handle_b
).
or_else
(
handle_c
);
message_handler
handle_b
()
{
})
return
on
(
"b"
)
>>
[]
{
return
2
;
};
);
}
CAF_MESSAGE
(
"run_testee: handle_a.or_else(handle_b), on(
\"
c
\"
) ..."
);
run_testee
(
message_handler
handle_c
()
{
spawn
([
=
]
{
return
on
(
"c"
)
>>
[]
{
return
3
;
};
return
handle_a
.
or_else
(
handle_b
).
or_else
(
on
(
"c"
)
>>
[]
{
return
3
;
});
}
})
);
void
run_testee
(
actor
testee
)
{
CAF_MESSAGE
(
"run_testee: on(
\"
a
\"
) ..., handle_b.or_else(handle_c)"
);
scoped_actor
self
;
run_testee
(
self
->
sync_send
(
testee
,
"a"
).
await
([](
int
i
)
{
spawn
([
=
]
{
CAF_CHECK_EQUAL
(
i
,
1
);
return
message_handler
{
on
(
"a"
)
>>
[]
{
return
1
;
}}.
});
or_else
(
handle_b
).
or_else
(
handle_c
);
self
->
sync_send
(
testee
,
"b"
).
await
([](
int
i
)
{
})
CAF_CHECK_EQUAL
(
i
,
2
);
);
});
self
->
sync_send
(
testee
,
"c"
).
await
([](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
3
);
});
self
->
send_exit
(
testee
,
exit_reason
::
user_shutdown
);
self
->
await_all_other_actors_done
();
}
struct
fixture
{
~
fixture
()
{
await_all_actors_done
();
shutdown
();
}
}
await_all_actors_done
();
};
shutdown
();
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
atom_tests
,
fixture
)
CAF_TEST
(
composition1
)
{
run_testee
(
spawn
([
=
]
{
return
handle_a
().
or_else
(
handle_b
()).
or_else
(
handle_c
());
})
);
}
CAF_TEST
(
composition2
)
{
run_testee
(
spawn
([
=
]
{
return
handle_a
().
or_else
(
handle_b
()).
or_else
(
on
(
"c"
)
>>
[]
{
return
3
;
});
})
);
}
CAF_TEST
(
composition3
)
{
run_testee
(
spawn
([
=
]
{
return
message_handler
{
on
(
"a"
)
>>
[]
{
return
1
;
}}.
or_else
(
handle_b
()).
or_else
(
handle_c
());
})
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/ripemd_160.cpp
View file @
e87824c6
...
@@ -44,7 +44,7 @@ std::string str_hash(const std::string& what) {
...
@@ -44,7 +44,7 @@ std::string str_hash(const std::string& what) {
// verify ripemd implementation with example hash results from
// verify ripemd implementation with example hash results from
// http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
// http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
CAF_TEST
(
test_ripemd_160
)
{
CAF_TEST
(
hash_results
)
{
CAF_CHECK_EQUAL
(
"9c1185a5c5e9fc54612808977ee8f548b2258d31"
,
str_hash
(
""
));
CAF_CHECK_EQUAL
(
"9c1185a5c5e9fc54612808977ee8f548b2258d31"
,
str_hash
(
""
));
CAF_CHECK_EQUAL
(
"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"
,
str_hash
(
"a"
));
CAF_CHECK_EQUAL
(
"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"
,
str_hash
(
"a"
));
CAF_CHECK_EQUAL
(
"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"
,
str_hash
(
"abc"
));
CAF_CHECK_EQUAL
(
"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"
,
str_hash
(
"abc"
));
...
...
libcaf_core/test/simple_reply_response.cpp
View file @
e87824c6
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
using
namespace
caf
;
using
namespace
caf
;
CAF_TEST
(
test_
simple_reply_response
)
{
CAF_TEST
(
simple_reply_response
)
{
auto
s
=
spawn
([](
event_based_actor
*
self
)
->
behavior
{
auto
s
=
spawn
([](
event_based_actor
*
self
)
->
behavior
{
return
(
return
(
others
>>
[
=
]()
->
message
{
others
>>
[
=
]()
->
message
{
...
...
libcaf_core/test/spawn.cpp
View file @
e87824c6
...
@@ -386,33 +386,41 @@ behavior counting_actor::make_behavior() {
...
@@ -386,33 +386,41 @@ behavior counting_actor::make_behavior() {
return
{};
return
{};
}
}
CAF_TEST
(
test_counting_actor
)
{
struct
fixture
{
{
// lifetime scope of temporary counting_actor handle
~
fixture
()
{
spawn
<
counting_actor
>
();
await_all_actors_done
();
await_all_actors_done
();
shutdown
();
CAF_CHECK_EQUAL
(
s_actor_instances
.
load
(),
0
);
CAF_MESSAGE
(
"max. # of actor instances: "
<<
s_max_actor_instances
.
load
());
}
}
};
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
atom_tests
,
fixture
)
CAF_TEST
(
count_mailbox
)
{
spawn
<
counting_actor
>
();
}
}
CAF_TEST
(
test_send
)
{
CAF_TEST
(
send_to_self
)
{
scoped_actor
self
;
scoped_actor
self
;
self
->
send
(
self
,
1
,
2
,
3
,
true
);
self
->
send
(
self
,
1
,
2
,
3
,
true
);
self
->
receive
(
on
(
1
,
2
,
3
,
true
)
>>
[]
{
});
self
->
receive
(
on
(
1
,
2
,
3
,
true
)
>>
[]
{
});
self
->
send
(
self
,
message
{});
self
->
send
(
self
,
message
{});
self
->
receive
(
on
()
>>
[]
{
});
self
->
receive
(
on
()
>>
[]
{
});
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_
detached_actors_and_schedulued_actors
)
{
CAF_TEST
(
detached_actors_and_schedulued_actors
)
{
scoped_actor
self
;
scoped_actor
self
;
// check whether detached actors and scheduled actors interact w/o errors
// check whether detached actors and scheduled actors interact w/o errors
auto
m
=
spawn
<
master
,
detached
>
();
auto
m
=
spawn
<
master
,
detached
>
();
spawn
<
slave
>
(
m
);
spawn
<
slave
>
(
m
);
spawn
<
slave
>
(
m
);
spawn
<
slave
>
(
m
);
self
->
send
(
m
,
atom
(
"done"
));
self
->
send
(
m
,
atom
(
"done"
));
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_
self_receive_with_zero_timeout
)
{
CAF_TEST
(
self_receive_with_zero_timeout
)
{
scoped_actor
self
;
scoped_actor
self
;
self
->
receive
(
self
->
receive
(
others
>>
[
&
]
{
others
>>
[
&
]
{
...
@@ -421,112 +429,102 @@ CAF_TEST(test_self_receive_with_zero_timeout) {
...
@@ -421,112 +429,102 @@ CAF_TEST(test_self_receive_with_zero_timeout) {
},
},
after
(
chrono
::
seconds
(
0
))
>>
[]
{
/* mailbox empty */
}
after
(
chrono
::
seconds
(
0
))
>>
[]
{
/* mailbox empty */
}
);
);
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_mirror
)
{
CAF_TEST
(
mirror
)
{
{
scoped_actor
self
;
scoped_actor
self
;
auto
mirror
=
self
->
spawn
<
simple_mirror
,
monitored
>
();
auto
mirror
=
self
->
spawn
<
simple_mirror
,
monitored
>
();
self
->
send
(
mirror
,
"hello mirror"
);
self
->
send
(
mirror
,
"hello mirror"
);
self
->
receive
(
self
->
receive
(
on
(
"hello mirror"
)
>>
[]
{
on
(
"hello mirror"
)
>>
[]
{
CAF_MESSAGE
(
"received
\"
hello mirror
\"
"
);
CAF_MESSAGE
(
"received
\"
hello mirror
\"
"
);
},
},
others
>>
[
&
]
{
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
<<
to_string
(
self
->
current_message
()));
}
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CAF_MESSAGE
(
"received `down_msg`"
);
}
}
);
else
{
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
CAF_TEST_ERROR
(
"Unexpected message: "
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CAF_MESSAGE
(
"received `down_msg`"
);
}
else
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message"
<<
to_string
(
self
->
current_message
()));
<<
to_string
(
self
->
current_message
()));
}
}
);
},
self
->
await_all_other_actors_done
();
others
>>
[
&
]
{
}
CAF_TEST_ERROR
(
"Unexpected message"
<<
to_string
(
self
->
current_message
()));
}
);
}
}
CAF_TEST
(
test_detached_mirror
)
{
CAF_TEST
(
detached_mirror
)
{
{
scoped_actor
self
;
scoped_actor
self
;
auto
mirror
=
self
->
spawn
<
simple_mirror
,
monitored
+
detached
>
();
auto
mirror
=
self
->
spawn
<
simple_mirror
,
monitored
+
detached
>
();
self
->
send
(
mirror
,
"hello mirror"
);
self
->
send
(
mirror
,
"hello mirror"
);
self
->
receive
(
self
->
receive
(
on
(
"hello mirror"
)
>>
[]
{
on
(
"hello mirror"
)
>>
[]
{
CAF_MESSAGE
(
"received
\"
hello mirror
\"
"
);
CAF_MESSAGE
(
"received
\"
hello mirror
\"
"
);
},
},
others
>>
[
&
]
{
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
<<
to_string
(
self
->
current_message
()));
}
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CAF_MESSAGE
(
"received `down_msg`"
);
}
}
);
else
{
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CAF_MESSAGE
(
"received `down_msg`"
);
}
else
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
<<
to_string
(
self
->
current_message
()));
}
}
);
},
self
->
await_all_other_actors_done
();
others
>>
[
&
]
{
}
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
);
}
}
CAF_TEST
(
test_priority_aware_mirror
)
{
CAF_TEST
(
priority_aware_mirror
)
{
{
scoped_actor
self
;
scoped_actor
self
;
auto
mirror
=
self
->
spawn
<
simple_mirror
,
monitored
+
priority_aware
>
();
auto
mirror
=
self
->
spawn
<
simple_mirror
,
monitored
+
priority_aware
>
();
CAF_MESSAGE
(
"spawned mirror"
);
CAF_MESSAGE
(
"spawned mirror"
);
self
->
send
(
mirror
,
"hello mirror"
);
self
->
send
(
mirror
,
"hello mirror"
);
self
->
receive
(
self
->
receive
(
on
(
"hello mirror"
)
>>
[]
{
on
(
"hello mirror"
)
>>
[]
{
CAF_MESSAGE
(
"received
\"
hello mirror
\"
"
);
CAF_MESSAGE
(
"received
\"
hello mirror
\"
"
);
},
},
others
>>
[
&
]
{
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CAF_MESSAGE
(
"received `down_msg`"
);
}
}
);
else
{
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
if
(
dm
.
reason
==
exit_reason
::
user_shutdown
)
{
CAF_MESSAGE
(
"received `down_msg`"
);
}
else
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
<<
to_string
(
self
->
current_message
()));
}
}
);
},
self
->
await_all_other_actors_done
();
others
>>
[
&
]
{
}
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
);
}
}
CAF_TEST
(
test_
echo_actor
)
{
CAF_TEST
(
echo_actor
)
{
scoped_actor
self
;
scoped_actor
self
;
auto
mecho
=
spawn
<
echo_actor
>
();
auto
mecho
=
spawn
<
echo_actor
>
();
self
->
send
(
mecho
,
"hello echo"
);
self
->
send
(
mecho
,
"hello echo"
);
...
@@ -536,33 +534,31 @@ CAF_TEST(test_echo_actor) {
...
@@ -536,33 +534,31 @@ CAF_TEST(test_echo_actor) {
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
}
);
);
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_
delayed_send
)
{
CAF_TEST
(
delayed_send
)
{
scoped_actor
self
;
scoped_actor
self
;
self
->
delayed_send
(
self
,
chrono
::
milliseconds
(
1
),
1
,
2
,
3
);
self
->
delayed_send
(
self
,
chrono
::
milliseconds
(
1
),
1
,
2
,
3
);
self
->
receive
(
on
(
1
,
2
,
3
)
>>
[]
{
});
self
->
receive
(
on
(
1
,
2
,
3
)
>>
[]
{
});
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_timeout
)
{
CAF_TEST
(
delayed_spawn
)
{
scoped_actor
self
;
scoped_actor
self
;
self
->
receive
(
after
(
chrono
::
milliseconds
(
1
))
>>
[]
{
});
self
->
receive
(
after
(
chrono
::
milliseconds
(
1
))
>>
[]
{
});
spawn
<
testee1
>
();
spawn
<
testee1
>
();
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_
spawn_event_testee2
)
{
CAF_TEST
(
spawn_event_testee2
)
{
scoped_actor
self
;
scoped_actor
self
;
spawn_event_testee2
(
self
);
spawn_event_testee2
(
self
);
self
->
receive
(
on
(
atom
(
"t2done"
))
>>
[]
{
self
->
receive
(
CAF_MESSAGE
(
"Received
\"
t2done
\"
"
);
on
(
atom
(
"t2done"
))
>>
[]
{
});
CAF_MESSAGE
(
"Received
\"
t2done
\"
"
);
self
->
await_all_other_actors_done
();
}
);
}
}
CAF_TEST
(
test_chopstick
)
{
CAF_TEST
(
chopsticks
)
{
scoped_actor
self
;
scoped_actor
self
;
auto
cstk
=
spawn
<
chopstick
>
();
auto
cstk
=
spawn
<
chopstick
>
();
self
->
send
(
cstk
,
atom
(
"take"
),
self
);
self
->
send
(
cstk
,
atom
(
"take"
),
self
);
...
@@ -576,10 +572,9 @@ CAF_TEST(test_chopstick) {
...
@@ -576,10 +572,9 @@ CAF_TEST(test_chopstick) {
to_string
(
self
->
current_message
()));
to_string
(
self
->
current_message
()));
}
}
);
);
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_sync_send
)
{
CAF_TEST
(
sync_sends
)
{
scoped_actor
self
;
scoped_actor
self
;
auto
sync_testee
=
spawn
<
blocking_api
>
([](
blocking_actor
*
s
)
{
auto
sync_testee
=
spawn
<
blocking_api
>
([](
blocking_actor
*
s
)
{
s
->
receive
(
s
->
receive
(
...
@@ -637,7 +632,7 @@ CAF_TEST(test_sync_send) {
...
@@ -637,7 +632,7 @@ CAF_TEST(test_sync_send) {
);
);
}
}
CAF_TEST
(
test_
inflater
)
{
CAF_TEST
(
inflater
)
{
scoped_actor
self
;
scoped_actor
self
;
struct
inflater
:
public
event_based_actor
{
struct
inflater
:
public
event_based_actor
{
public:
public:
...
@@ -679,10 +674,9 @@ CAF_TEST(test_inflater) {
...
@@ -679,10 +674,9 @@ CAF_TEST(test_inflater) {
auto
poison_pill
=
make_message
(
atom
(
"done"
));
auto
poison_pill
=
make_message
(
atom
(
"done"
));
anon_send
(
joe
,
poison_pill
);
anon_send
(
joe
,
poison_pill
);
anon_send
(
bob
,
poison_pill
);
anon_send
(
bob
,
poison_pill
);
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_
kr34t0r
)
{
CAF_TEST
(
kr34t0r
)
{
class
kr34t0r
:
public
event_based_actor
{
class
kr34t0r
:
public
event_based_actor
{
public:
public:
kr34t0r
(
string
name
,
actor
pal
)
kr34t0r
(
string
name
,
actor
pal
)
...
@@ -716,10 +710,9 @@ CAF_TEST(test_kr34t0r) {
...
@@ -716,10 +710,9 @@ CAF_TEST(test_kr34t0r) {
scoped_actor
self
;
scoped_actor
self
;
auto
joe_the_second
=
spawn
<
kr34t0r
>
(
"Joe"
,
invalid_actor
);
auto
joe_the_second
=
spawn
<
kr34t0r
>
(
"Joe"
,
invalid_actor
);
self
->
send
(
joe_the_second
,
atom
(
"done"
));
self
->
send
(
joe_the_second
,
atom
(
"done"
));
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
test_
function_spawn
)
{
CAF_TEST
(
function_spawn
)
{
scoped_actor
self
;
scoped_actor
self
;
auto
f
=
[](
const
string
&
name
)
->
behavior
{
auto
f
=
[](
const
string
&
name
)
->
behavior
{
return
(
return
(
...
@@ -744,7 +737,6 @@ CAF_TEST(test_function_spawn) {
...
@@ -744,7 +737,6 @@ CAF_TEST(test_function_spawn) {
);
);
self
->
send_exit
(
a1
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
a1
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
a2
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
a2
,
exit_reason
::
user_shutdown
);
self
->
await_all_other_actors_done
();
}
}
using
abc_atom
=
atom_constant
<
atom
(
"abc"
)
>
;
using
abc_atom
=
atom_constant
<
atom
(
"abc"
)
>
;
...
@@ -760,7 +752,7 @@ typed_testee::behavior_type testee() {
...
@@ -760,7 +752,7 @@ typed_testee::behavior_type testee() {
};
};
}
}
CAF_TEST
(
t
est_typed_testee
)
{
CAF_TEST
(
t
yped_await
)
{
scoped_actor
self
;
scoped_actor
self
;
auto
x
=
spawn_typed
(
testee
);
auto
x
=
spawn_typed
(
testee
);
self
->
sync_send
(
x
,
abc_atom
()).
await
(
self
->
sync_send
(
x
,
abc_atom
()).
await
(
...
@@ -769,11 +761,10 @@ CAF_TEST(test_typed_testee) {
...
@@ -769,11 +761,10 @@ CAF_TEST(test_typed_testee) {
}
}
);
);
self
->
send_exit
(
x
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
x
,
exit_reason
::
user_shutdown
);
self
->
await_all_other_actors_done
();
}
}
// tests attach_functor() inside of an actor's constructor
// tests attach_functor() inside of an actor's constructor
CAF_TEST
(
test_
constructor_attach
)
{
CAF_TEST
(
constructor_attach
)
{
class
testee
:
public
event_based_actor
{
class
testee
:
public
event_based_actor
{
public:
public:
testee
(
actor
buddy
)
:
m_buddy
(
buddy
)
{
testee
(
actor
buddy
)
:
m_buddy
(
buddy
)
{
...
@@ -850,7 +841,7 @@ class exception_testee : public event_based_actor {
...
@@ -850,7 +841,7 @@ class exception_testee : public event_based_actor {
}
}
};
};
CAF_TEST
(
test_
custom_exception_handler
)
{
CAF_TEST
(
custom_exception_handler
)
{
auto
handler
=
[](
const
std
::
exception_ptr
&
eptr
)
->
optional
<
uint32_t
>
{
auto
handler
=
[](
const
std
::
exception_ptr
&
eptr
)
->
optional
<
uint32_t
>
{
try
{
try
{
std
::
rethrow_exception
(
eptr
);
std
::
rethrow_exception
(
eptr
);
...
@@ -894,7 +885,7 @@ CAF_TEST(test_custom_exception_handler) {
...
@@ -894,7 +885,7 @@ CAF_TEST(test_custom_exception_handler) {
);
);
}
}
CAF_TEST
(
test_kil
l
)
{
CAF_TEST
(
kill_the_immorta
l
)
{
auto
wannabe_immortal
=
spawn
([](
event_based_actor
*
self
)
->
behavior
{
auto
wannabe_immortal
=
spawn
([](
event_based_actor
*
self
)
->
behavior
{
self
->
trap_exit
(
true
);
self
->
trap_exit
(
true
);
return
{
return
{
...
@@ -914,50 +905,10 @@ CAF_TEST(test_kill) {
...
@@ -914,50 +905,10 @@ CAF_TEST(test_kill) {
);
);
}
}
CAF_TEST
(
test_exit_reason_scoped_actor
)
{
CAF_TEST
(
exit_reason_in_scoped_actor
)
{
// test setting exit reasons for scoped actors
{
// lifetime scope of self
scoped_actor
self
;
self
->
spawn
<
linked
>
([]()
->
behavior
{
return
others
>>
[]
{};
});
self
->
planned_exit_reason
(
exit_reason
::
user_defined
);
}
await_all_actors_done
();
shutdown
();
}
CAF_TEST
(
test_spawn_fun
)
{
class
my_actor
:
public
event_based_actor
{
public:
behavior
make_behavior
()
override
{
return
{
[
=
](
sys_atom
,
std
::
function
<
behavior
(
my_actor
*
)
>&
fun
)
{
become
(
fun
(
this
));
}
};
}
};
auto
ma
=
spawn
<
my_actor
>
();
std
::
function
<
behavior
(
my_actor
*
)
>
fun
=
[](
my_actor
*
)
->
behavior
{
return
{
[](
int
x
,
int
y
)
{
return
x
+
y
;
}
};
};
scoped_actor
self
;
scoped_actor
self
;
self
->
send
(
ma
,
sys_atom
::
value
,
fun
);
self
->
spawn
<
linked
>
([]()
->
behavior
{
return
others
>>
[]
{};
});
self
->
sync_send
(
ma
,
10
,
20
).
await
(
self
->
planned_exit_reason
(
exit_reason
::
user_defined
);
[](
int
res
)
{
CAF_CHECK_EQUAL
(
res
,
10
+
20
);
}
);
self
->
send_exit
(
ma
,
exit_reason
::
kill
);
self
->
await_all_other_actors_done
();
}
CAF_TEST
(
test_number_of_instances
)
{
CAF_CHECK_EQUAL
(
s_actor_instances
.
load
(),
0
);
CAF_MESSAGE
(
"max. nr. of actor instances: "
<<
s_max_actor_instances
.
load
());
}
}
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/sync_send.cpp
View file @
e87824c6
...
@@ -235,8 +235,17 @@ class server : public event_based_actor {
...
@@ -235,8 +235,17 @@ class server : public event_based_actor {
}
}
};
};
struct
fixture
{
~
fixture
()
{
await_all_actors_done
();
shutdown
();
}
};
}
// namespace <anonymous>
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
atom_tests
,
fixture
)
CAF_TEST
(
test_void_res
)
{
CAF_TEST
(
test_void_res
)
{
using
testee_a
=
typed_actor
<
replies_to
<
int
,
int
>::
with
<
void
>>
;
using
testee_a
=
typed_actor
<
replies_to
<
int
,
int
>::
with
<
void
>>
;
auto
buddy
=
spawn_typed
([]()
->
testee_a
::
behavior_type
{
auto
buddy
=
spawn_typed
([]()
->
testee_a
::
behavior_type
{
...
@@ -249,229 +258,226 @@ CAF_TEST(test_void_res) {
...
@@ -249,229 +258,226 @@ CAF_TEST(test_void_res) {
CAF_MESSAGE
(
"received void res"
);
CAF_MESSAGE
(
"received void res"
);
});
});
self
->
send_exit
(
buddy
,
exit_reason
::
kill
);
self
->
send_exit
(
buddy
,
exit_reason
::
kill
);
self
->
await_all_other_actors_done
();
}
}
CAF_TEST
(
sync_send
)
{
CAF_TEST
(
sync_send
)
{
{
scoped_actor
self
;
scoped_actor
self
;
self
->
on_sync_failure
([
&
]
{
self
->
on_sync_failure
([
&
]
{
CAF_TEST_ERROR
(
"received: "
<<
to_string
(
self
->
current_message
()));
CAF_TEST_ERROR
(
"received: "
<<
to_string
(
self
->
current_message
()));
});
});
self
->
spawn
<
monitored
+
blocking_api
>
([](
blocking_actor
*
s
)
{
self
->
spawn
<
monitored
+
blocking_api
>
([](
blocking_actor
*
s
)
{
int
invocations
=
0
;
int
invocations
=
0
;
auto
foi
=
s
->
spawn
<
float_or_int
,
linked
>
();
auto
foi
=
s
->
spawn
<
float_or_int
,
linked
>
();
s
->
send
(
foi
,
i_atom
::
value
);
s
->
send
(
foi
,
i_atom
::
value
);
s
->
receive
(
s
->
receive
(
[](
int
i
)
{
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
0
);
CAF_CHECK_EQUAL
(
i
,
0
);
}
);
s
->
on_sync_failure
([
=
]
{
CAF_TEST_ERROR
(
"received: "
<<
to_string
(
s
->
current_message
()));
});
s
->
sync_send
(
foi
,
i_atom
::
value
).
await
(
[
&
](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
0
);
++
invocations
;
},
[
&
](
float
)
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
s
->
current_message
()));
}
);
s
->
sync_send
(
foi
,
f_atom
::
value
).
await
(
[
&
](
int
)
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
s
->
current_message
()));
},
[
&
](
float
f
)
{
CAF_CHECK_EQUAL
(
f
,
0.
f
);
++
invocations
;
}
);
CAF_CHECK_EQUAL
(
invocations
,
2
);
CAF_MESSAGE
(
"trigger sync failure"
);
// provoke invocation of s->handle_sync_failure()
bool
sync_failure_called
=
false
;
bool
int_handler_called
=
false
;
s
->
on_sync_failure
([
&
]
{
sync_failure_called
=
true
;
});
s
->
sync_send
(
foi
,
f_atom
::
value
).
await
(
[
&
](
int
)
{
int_handler_called
=
true
;
}
);
CAF_CHECK_EQUAL
(
sync_failure_called
,
true
);
CAF_CHECK_EQUAL
(
int_handler_called
,
false
);
s
->
quit
(
exit_reason
::
user_shutdown
);
});
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
CAF_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
);
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
}
);
);
auto
mirror
=
spawn
<
sync_mirror
>
();
s
->
on_sync_failure
([
=
]
{
bool
continuation_called
=
false
;
CAF_TEST_ERROR
(
"received: "
<<
to_string
(
s
->
current_message
()));
self
->
sync_send
(
mirror
,
42
).
await
([
&
](
int
value
)
{
continuation_called
=
true
;
CAF_CHECK_EQUAL
(
value
,
42
);
});
});
CAF_CHECK_EQUAL
(
continuation_called
,
true
);
s
->
sync_send
(
foi
,
i_atom
::
value
).
await
(
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
[
&
](
int
i
)
{
CAF_MESSAGE
(
"block on `await_all_other_actors_done"
);
CAF_CHECK_EQUAL
(
i
,
0
);
self
->
await_all_other_actors_done
();
++
invocations
;
CAF_MESSAGE
(
"`await_all_other_actors_done` finished"
);
auto
non_normal_down_msg
=
[](
down_msg
dm
)
->
optional
<
down_msg
>
{
if
(
dm
.
reason
!=
exit_reason
::
normal
)
{
return
dm
;
}
return
none
;
};
auto
await_ok_message
=
[
&
]
{
self
->
receive
(
[](
ok_atom
)
{
CAF_MESSAGE
(
"received `ok_atom`"
);
},
[](
error_atom
)
{
CAF_TEST_ERROR
(
"A didn't receive sync response"
);
},
on
(
non_normal_down_msg
)
>>
[
&
](
const
down_msg
&
dm
)
{
CAF_TEST_ERROR
(
"A exited for reason "
<<
dm
.
reason
);
}
);
};
self
->
send
(
self
->
spawn
<
A
,
monitored
>
(
self
),
go_atom
::
value
,
spawn
<
B
>
(
spawn
<
C
>
()));
CAF_MESSAGE
(
"block on `await_ok_message`"
);
await_ok_message
();
CAF_MESSAGE
(
"`await_ok_message` finished"
);
self
->
await_all_other_actors_done
();
self
->
send
(
self
->
spawn
<
A
,
monitored
>
(
self
),
go_atom
::
value
,
spawn
<
D
>
(
spawn
<
C
>
()));
CAF_MESSAGE
(
"block on `await_ok_message`"
);
await_ok_message
();
CAF_MESSAGE
(
"`await_ok_message` finished"
);
CAF_MESSAGE
(
"block on `await_all_other_actors_done`"
);
self
->
await_all_other_actors_done
();
CAF_MESSAGE
(
"`await_all_other_actors_done` finished"
);
self
->
timed_sync_send
(
self
,
milliseconds
(
50
),
no_way_atom
::
value
).
await
(
on
<
sync_timeout_msg
>
()
>>
[]
{
CAF_MESSAGE
(
"Got timeout"
);
},
},
others
>>
[
&
]
{
[
&
](
float
)
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
s
elf
->
current_message
()));
<<
to_string
(
s
->
current_message
()));
}
}
);
);
// we should have received two DOWN messages with normal exit reason
s
->
sync_send
(
foi
,
f_atom
::
value
).
await
(
// plus 'NoWay'
[
&
](
int
)
{
int
i
=
0
;
self
->
receive_for
(
i
,
3
)(
[
&
](
const
down_msg
&
dm
)
{
CAF_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
normal
);
},
[](
no_way_atom
)
{
CAF_MESSAGE
(
"trigger
\"
actor did not reply to a "
"synchronous request message
\"
"
);
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
s
elf
->
current_message
()));
<<
to_string
(
s
->
current_message
()));
},
},
after
(
milliseconds
(
0
))
>>
[]
{
[
&
](
float
f
)
{
CAF_TEST_ERROR
(
"Unexpected timeout"
);
CAF_CHECK_EQUAL
(
f
,
0.
f
);
++
invocations
;
}
}
);
);
// mailbox should be empty now
CAF_CHECK_EQUAL
(
invocations
,
2
);
self
->
receive
(
CAF_MESSAGE
(
"trigger sync failure"
);
others
>>
[]
{
// provoke invocation of s->handle_sync_failure()
CAF_TEST_ERROR
(
"Unexpected message"
);
bool
sync_failure_called
=
false
;
},
bool
int_handler_called
=
false
;
after
(
milliseconds
(
0
))
>>
[]
{
s
->
on_sync_failure
([
&
]
{
sync_failure_called
=
true
;
});
CAF_MESSAGE
(
"Mailbox is empty, all good"
);
s
->
sync_send
(
foi
,
f_atom
::
value
).
await
(
[
&
](
int
)
{
int_handler_called
=
true
;
}
}
);
);
// check wheter continuations are invoked correctly
CAF_CHECK_EQUAL
(
sync_failure_called
,
true
);
auto
c
=
spawn
<
C
>
();
// replies only to 'gogo' messages
CAF_CHECK_EQUAL
(
int_handler_called
,
false
);
// first test: sync error must occur, continuation must not be called
s
->
quit
(
exit_reason
::
user_shutdown
);
bool
timeout_occured
=
false
;
})
;
self
->
on_sync_timeout
([
&
]
{
self
->
receive
(
CAF_MESSAGE
(
"timeout occured"
);
[
&
](
const
down_msg
&
dm
)
{
timeout_occured
=
true
;
CAF_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
)
;
}
);
}
,
self
->
on_sync_failure
(
[
&
]
{
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
<<
to_string
(
self
->
current_message
()));
});
}
self
->
timed_sync_send
(
c
,
milliseconds
(
500
),
hi_there_atom
::
value
).
await
(
);
on
(
val
<
atom_value
>
)
>>
[
&
]
{
auto
mirror
=
spawn
<
sync_mirror
>
();
cout
<<
"C did reply to 'HiThere'"
<<
endl
;
bool
continuation_called
=
false
;
self
->
sync_send
(
mirror
,
42
).
await
([
&
](
int
value
)
{
continuation_called
=
true
;
CAF_CHECK_EQUAL
(
value
,
42
);
});
CAF_CHECK_EQUAL
(
continuation_called
,
true
);
self
->
send_exit
(
mirror
,
exit_reason
::
user_shutdown
);
CAF_MESSAGE
(
"block on `await_all_other_actors_done"
);
self
->
await_all_other_actors_done
();
CAF_MESSAGE
(
"`await_all_other_actors_done` finished"
);
auto
non_normal_down_msg
=
[](
down_msg
dm
)
->
optional
<
down_msg
>
{
if
(
dm
.
reason
!=
exit_reason
::
normal
)
{
return
dm
;
}
return
none
;
};
auto
await_ok_message
=
[
&
]
{
self
->
receive
(
[](
ok_atom
)
{
CAF_MESSAGE
(
"received `ok_atom`"
);
},
[](
error_atom
)
{
CAF_TEST_ERROR
(
"A didn't receive sync response"
);
},
on
(
non_normal_down_msg
)
>>
[
&
](
const
down_msg
&
dm
)
{
CAF_TEST_ERROR
(
"A exited for reason "
<<
dm
.
reason
);
}
}
);
);
CAF_CHECK_EQUAL
(
timeout_occured
,
true
);
};
self
->
on_sync_failure
([
&
]
{
self
->
send
(
self
->
spawn
<
A
,
monitored
>
(
self
),
go_atom
::
value
,
spawn
<
B
>
(
spawn
<
C
>
()));
CAF_MESSAGE
(
"block on `await_ok_message`"
);
await_ok_message
();
CAF_MESSAGE
(
"`await_ok_message` finished"
);
self
->
await_all_other_actors_done
();
self
->
send
(
self
->
spawn
<
A
,
monitored
>
(
self
),
go_atom
::
value
,
spawn
<
D
>
(
spawn
<
C
>
()));
CAF_MESSAGE
(
"block on `await_ok_message`"
);
await_ok_message
();
CAF_MESSAGE
(
"`await_ok_message` finished"
);
CAF_MESSAGE
(
"block on `await_all_other_actors_done`"
);
self
->
await_all_other_actors_done
();
CAF_MESSAGE
(
"`await_all_other_actors_done` finished"
);
self
->
timed_sync_send
(
self
,
milliseconds
(
50
),
no_way_atom
::
value
).
await
(
on
<
sync_timeout_msg
>
()
>>
[]
{
CAF_MESSAGE
(
"Got timeout"
);
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
);
// we should have received two DOWN messages with normal exit reason
// plus 'NoWay'
int
i
=
0
;
self
->
receive_for
(
i
,
3
)(
[
&
](
const
down_msg
&
dm
)
{
CAF_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
normal
);
},
[](
no_way_atom
)
{
CAF_MESSAGE
(
"trigger
\"
actor did not reply to a "
"synchronous request message
\"
"
);
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
<<
to_string
(
self
->
current_message
()));
},
after
(
milliseconds
(
0
))
>>
[]
{
CAF_TEST_ERROR
(
"Unexpected timeout"
);
}
);
// mailbox should be empty now
self
->
receive
(
others
>>
[]
{
CAF_TEST_ERROR
(
"Unexpected message"
);
},
after
(
milliseconds
(
0
))
>>
[]
{
CAF_MESSAGE
(
"Mailbox is empty, all good"
);
}
);
// check wheter continuations are invoked correctly
auto
c
=
spawn
<
C
>
();
// replies only to 'gogo' messages
// first test: sync error must occur, continuation must not be called
bool
timeout_occured
=
false
;
self
->
on_sync_timeout
([
&
]
{
CAF_MESSAGE
(
"timeout occured"
);
timeout_occured
=
true
;
});
self
->
on_sync_failure
([
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
});
self
->
timed_sync_send
(
c
,
milliseconds
(
500
),
hi_there_atom
::
value
).
await
(
on
(
val
<
atom_value
>
)
>>
[
&
]
{
cout
<<
"C did reply to 'HiThere'"
<<
endl
;
}
);
CAF_CHECK_EQUAL
(
timeout_occured
,
true
);
self
->
on_sync_failure
([
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
});
self
->
sync_send
(
c
,
gogo_atom
::
value
).
await
(
[](
gogogo_atom
)
{
CAF_MESSAGE
(
"received `gogogo_atom`"
);
}
);
self
->
send_exit
(
c
,
exit_reason
::
user_shutdown
);
CAF_MESSAGE
(
"block on `await_all_other_actors_done`"
);
self
->
await_all_other_actors_done
();
CAF_MESSAGE
(
"`await_all_other_actors_done` finished"
);
// test use case 3
self
->
spawn
<
monitored
+
blocking_api
>
([](
blocking_actor
*
s
)
{
// client
auto
serv
=
s
->
spawn
<
server
,
linked
>
();
// server
auto
work
=
s
->
spawn
<
linked
>
([]()
->
behavior
{
// worker
return
{
[](
request_atom
)
{
return
response_atom
::
value
;
}
};
});
});
self
->
sync_send
(
c
,
gogo_atom
::
value
).
await
(
// first 'idle', then 'request'
[](
gogogo_atom
)
{
anon_send
(
serv
,
idle_atom
::
value
,
work
);
CAF_MESSAGE
(
"received `gogogo_atom`"
);
s
->
sync_send
(
serv
,
request_atom
::
value
).
await
(
[
=
](
response_atom
)
{
CAF_MESSAGE
(
"received `response_atom`"
);
CAF_CHECK_EQUAL
(
s
->
current_sender
(),
work
);
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
s
->
current_message
()));
}
}
);
);
self
->
send_exit
(
c
,
exit_reason
::
user_shutdown
);
// first 'request', then 'idle'
CAF_MESSAGE
(
"block on `await_all_other_actors_done`"
);
auto
handle
=
s
->
sync_send
(
serv
,
request_atom
::
value
);
self
->
await_all_other_actors_done
();
send_as
(
work
,
serv
,
idle_atom
::
value
,
work
);
CAF_MESSAGE
(
"`await_all_other_actors_done` finished"
);
handle
.
await
(
// test use case 3
[
=
](
response_atom
)
{
self
->
spawn
<
monitored
+
blocking_api
>
([](
blocking_actor
*
s
)
{
// client
CAF_CHECK_EQUAL
(
s
->
current_sender
(),
work
);
auto
serv
=
s
->
spawn
<
server
,
linked
>
();
// server
auto
work
=
s
->
spawn
<
linked
>
([]()
->
behavior
{
// worker
return
{
[](
request_atom
)
{
return
response_atom
::
value
;
}
};
});
// first 'idle', then 'request'
anon_send
(
serv
,
idle_atom
::
value
,
work
);
s
->
sync_send
(
serv
,
request_atom
::
value
).
await
(
[
=
](
response_atom
)
{
CAF_MESSAGE
(
"received `response_atom`"
);
CAF_CHECK_EQUAL
(
s
->
current_sender
(),
work
);
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
s
->
current_message
()));
}
);
// first 'request', then 'idle'
auto
handle
=
s
->
sync_send
(
serv
,
request_atom
::
value
);
send_as
(
work
,
serv
,
idle_atom
::
value
,
work
);
handle
.
await
(
[
=
](
response_atom
)
{
CAF_CHECK_EQUAL
(
s
->
current_sender
(),
work
);
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
s
->
current_message
()));
}
);
s
->
quit
(
exit_reason
::
user_shutdown
);
});
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
CAF_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
);
},
},
others
>>
[
&
]
{
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
s
elf
->
current_message
()));
<<
to_string
(
s
->
current_message
()));
}
}
);
);
}
s
->
quit
(
exit_reason
::
user_shutdown
);
await_all_actors_done
();
});
shutdown
();
self
->
receive
(
[
&
](
const
down_msg
&
dm
)
{
CAF_CHECK_EQUAL
(
dm
.
reason
,
exit_reason
::
user_shutdown
);
},
others
>>
[
&
]
{
CAF_TEST_ERROR
(
"Unexpected message: "
<<
to_string
(
self
->
current_message
()));
}
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/typed_spawn.cpp
View file @
e87824c6
...
@@ -244,18 +244,28 @@ behavior foo2(event_based_actor* self) {
...
@@ -244,18 +244,28 @@ behavior foo2(event_based_actor* self) {
};
};
}
}
struct
fixture
{
fixture
()
{
announce
<
get_state_msg
>
(
"get_state_msg"
);
announce
<
int_actor
>
(
"int_actor"
);
announce
<
my_request
>
(
"my_request"
,
&
my_request
::
a
,
&
my_request
::
b
);
}
~
fixture
()
{
await_all_actors_done
();
shutdown
();
}
};
}
// namespace <anonymous>
}
// namespace <anonymous>
CAF_TEST_FIXTURE_SCOPE
(
typed_spawn_tests
,
fixture
)
/******************************************************************************
/******************************************************************************
* put it all together *
* put it all together *
******************************************************************************/
******************************************************************************/
CAF_TEST
(
test_typed_spawns
)
{
CAF_TEST
(
typed_spawns
)
{
// announce stuff
announce
<
get_state_msg
>
(
"get_state_msg"
);
announce
<
int_actor
>
(
"int_actor"
);
announce
<
my_request
>
(
"my_request"
,
&
my_request
::
a
,
&
my_request
::
b
);
// run test series with typed_server(1|2)
// run test series with typed_server(1|2)
test_typed_spawn
(
spawn_typed
(
typed_server1
));
test_typed_spawn
(
spawn_typed
(
typed_server1
));
await_all_actors_done
();
await_all_actors_done
();
...
@@ -271,88 +281,75 @@ CAF_TEST(test_typed_spawns) {
...
@@ -271,88 +281,75 @@ CAF_TEST(test_typed_spawns) {
CAF_MESSAGE
(
"received
\"
hi there
\"
"
);
CAF_MESSAGE
(
"received
\"
hi there
\"
"
);
});
});
}
}
await_all_actors_done
();
CAF_MESSAGE
(
"finished test series with `typed_server3`"
);
}
}
CAF_TEST
(
test_event_testee
)
{
CAF_TEST
(
test_event_testee
)
{
// run test series with event_testee
// run test series with event_testee
{
scoped_actor
self
;
scoped_actor
self
;
auto
et
=
self
->
spawn_typed
<
event_testee
>
();
auto
et
=
self
->
spawn_typed
<
event_testee
>
();
string
result
;
string
result
;
self
->
send
(
et
,
1
);
self
->
send
(
et
,
1
);
self
->
send
(
et
,
2
);
self
->
send
(
et
,
2
);
self
->
send
(
et
,
3
);
self
->
send
(
et
,
3
);
self
->
send
(
et
,
.1
f
);
self
->
send
(
et
,
.1
f
);
self
->
send
(
et
,
"hello event testee!"
);
self
->
send
(
et
,
"hello event testee!"
);
self
->
send
(
et
,
.2
f
);
self
->
send
(
et
,
.2
f
);
self
->
send
(
et
,
.3
f
);
self
->
send
(
et
,
.3
f
);
self
->
send
(
et
,
"hello again event testee!"
);
self
->
send
(
et
,
"hello again event testee!"
);
self
->
send
(
et
,
"goodbye event testee!"
);
self
->
send
(
et
,
"goodbye event testee!"
);
typed_actor
<
replies_to
<
get_state_msg
>::
with
<
string
>>
sub_et
=
et
;
typed_actor
<
replies_to
<
get_state_msg
>::
with
<
string
>>
sub_et
=
et
;
// $:: is the anonymous namespace
// $:: is the anonymous namespace
set
<
string
>
iface
{
"caf::replies_to<get_state_msg>::with<@str>"
,
set
<
string
>
iface
{
"caf::replies_to<get_state_msg>::with<@str>"
,
"caf::replies_to<@str>::with<void>"
,
"caf::replies_to<@str>::with<void>"
,
"caf::replies_to<float>::with<void>"
,
"caf::replies_to<float>::with<void>"
,
"caf::replies_to<@i32>::with<@i32>"
};
"caf::replies_to<@i32>::with<@i32>"
};
CAF_CHECK_EQUAL
(
join
(
sub_et
->
message_types
(),
","
),
join
(
iface
,
","
));
CAF_CHECK_EQUAL
(
join
(
sub_et
->
message_types
(),
","
),
join
(
iface
,
","
));
self
->
send
(
sub_et
,
get_state_msg
{});
self
->
send
(
sub_et
,
get_state_msg
{});
// we expect three 42s
// we expect three 42s
int
i
=
0
;
int
i
=
0
;
self
->
receive_for
(
i
,
3
)([](
int
value
)
{
CAF_CHECK_EQUAL
(
value
,
42
);
});
self
->
receive_for
(
i
,
3
)([](
int
value
)
{
CAF_CHECK_EQUAL
(
value
,
42
);
});
self
->
receive
(
self
->
receive
(
[
&
](
const
string
&
str
)
{
[
&
](
const
string
&
str
)
{
result
=
str
;
result
=
str
;
},
},
after
(
chrono
::
minutes
(
1
))
>>
[
&
]
{
after
(
chrono
::
minutes
(
1
))
>>
[
&
]
{
CAF_TEST_ERROR
(
"event_testee does not reply"
);
CAF_TEST_ERROR
(
"event_testee does not reply"
);
throw
runtime_error
(
"event_testee does not reply"
);
throw
runtime_error
(
"event_testee does not reply"
);
}
}
);
);
self
->
send_exit
(
et
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
et
,
exit_reason
::
user_shutdown
);
self
->
await_all_other_actors_done
();
self
->
await_all_other_actors_done
();
CAF_CHECK_EQUAL
(
result
,
"wait4int"
);
CAF_CHECK_EQUAL
(
result
,
"wait4int"
);
self
->
await_all_other_actors_done
();
}
}
}
CAF_TEST
(
test_simple_string_reverter
)
{
CAF_TEST
(
test_simple_string_reverter
)
{
// run test series with string reverter
// run test series with string reverter
{
scoped_actor
self
;
scoped_actor
self
;
// actor-under-test
// actor-under-test
auto
aut
=
self
->
spawn_typed
<
monitored
>
(
simple_relay
,
auto
aut
=
self
->
spawn_typed
<
monitored
>
(
simple_relay
,
spawn_typed
(
simple_string_reverter
),
spawn_typed
(
simple_string_reverter
),
true
);
true
);
set
<
string
>
iface
{
"caf::replies_to<@str>::with<@str>"
};
set
<
string
>
iface
{
"caf::replies_to<@str>::with<@str>"
};
CAF_CHECK
(
aut
->
message_types
()
==
iface
);
CAF_CHECK
(
aut
->
message_types
()
==
iface
);
self
->
sync_send
(
aut
,
"Hello World!"
).
await
([](
const
string
&
answer
)
{
self
->
sync_send
(
aut
,
"Hello World!"
).
await
([](
const
string
&
answer
)
{
CAF_CHECK_EQUAL
(
answer
,
"!dlroW olleH"
);
CAF_CHECK_EQUAL
(
answer
,
"!dlroW olleH"
);
});
});
anon_send_exit
(
aut
,
exit_reason
::
user_shutdown
);
anon_send_exit
(
aut
,
exit_reason
::
user_shutdown
);
self
->
await_all_other_actors_done
();
}
}
}
CAF_TEST
(
test_sending_typed_actors
)
{
CAF_TEST
(
test_sending_typed_actors
)
{
{
scoped_actor
self
;
scoped_actor
self
;
auto
aut
=
spawn_typed
(
int_fun
);
auto
aut
=
spawn_typed
(
int_fun
);
self
->
send
(
spawn
(
foo
),
10
,
aut
);
self
->
send
(
spawn
(
foo
),
10
,
aut
);
self
->
receive
(
on_arg_match
>>
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
100
);
});
self
->
receive
(
on_arg_match
>>
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
100
);
});
self
->
send_exit
(
aut
,
exit_reason
::
user_shutdown
);
self
->
send_exit
(
aut
,
exit_reason
::
user_shutdown
);
self
->
await_all_other_actors_done
();
}
}
}
CAF_TEST
(
test_sending_typed_actors_and_down_msg
)
{
CAF_TEST
(
test_sending_typed_actors_and_down_msg
)
{
{
scoped_actor
self
;
scoped_actor
self
;
auto
aut
=
spawn_typed
(
int_fun2
);
auto
aut
=
spawn_typed
(
int_fun2
);
self
->
send
(
spawn
(
foo2
),
10
,
aut
);
self
->
send
(
spawn
(
foo2
),
10
,
aut
);
self
->
receive
([](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
100
);
});
self
->
receive
([](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
100
);
});
self
->
await_all_other_actors_done
();
}
shutdown
();
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
libcaf_core/test/variant.cpp
View file @
e87824c6
...
@@ -34,12 +34,12 @@ struct tostring_visitor : static_visitor<string> {
...
@@ -34,12 +34,12 @@ struct tostring_visitor : static_visitor<string> {
}
}
};
};
CAF_TEST
(
variant
)
{
CAF_TEST
(
string_convertible
)
{
tostring_visitor
tv
;
tostring_visitor
tv
;
// test never-empty guarantee, i.e., expect default-constucted first arg
// test never-empty guarantee, i.e., expect default-constucted first arg
variant
<
int
,
float
>
v1
;
variant
<
int
,
float
>
v1
;
CAF_CHECK_EQUAL
(
apply_visitor
(
tv
,
v1
),
"0"
);
CAF_CHECK_EQUAL
(
apply_visitor
(
tv
,
v1
),
"0"
);
variant
<
int
,
float
>
v2
=
42
;
variant
<
int
,
float
>
v2
=
42
;
CAF_CHECK_EQUAL
(
apply_visitor
(
tv
,
v2
),
"42"
);
CAF_CHECK_EQUAL
(
apply_visitor
(
tv
,
v2
),
"42"
);
v2
=
0.2
f
;
v2
=
0.2
f
;
CAF_CHECK_EQUAL
(
apply_visitor
(
tv
,
v2
),
to_string
(
0.2
f
));
CAF_CHECK_EQUAL
(
apply_visitor
(
tv
,
v2
),
to_string
(
0.2
f
));
...
...
libcaf_io/test/ping_pong.cpp
deleted
100644 → 0
View file @
ff54e90a
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include <iostream>
#include "ping_pong.hpp"
#include "caf/all.hpp"
#include "caf/detail/logging.hpp"
#include "caf/test/unit_test.hpp"
using
std
::
cout
;
using
std
::
endl
;
using
namespace
caf
;
using
namespace
caf
;
namespace
{
size_t
s_pongs
=
0
;
behavior
ping_behavior
(
local_actor
*
self
,
size_t
num_pings
)
{
return
{
on
(
atom
(
"pong"
),
arg_match
)
>>
[
=
](
int
value
)
->
message
{
if
(
!
self
->
current_sender
())
{
CAF_TEST_ERROR
(
"current_sender() invalid!"
);
}
CAF_TEST_INFO
(
"received {'pong', "
<<
value
<<
"}"
);
// cout << to_string(self->current_message()) << endl;
if
(
++
s_pongs
>=
num_pings
)
{
CAF_TEST_INFO
(
"reached maximum, send {'EXIT', user_defined} "
<<
"to last sender and quit with normal reason"
);
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
self
->
quit
();
}
return
make_message
(
atom
(
"ping"
),
value
);
},
others
()
>>
[
=
]
{
self
->
quit
(
exit_reason
::
user_shutdown
);
}
};
}
behavior
pong_behavior
(
local_actor
*
self
)
{
return
{
on
(
atom
(
"ping"
),
arg_match
)
>>
[](
int
value
)
->
message
{
return
make_message
(
atom
(
"pong"
),
value
+
1
);
},
others
()
>>
[
=
]
{
self
->
quit
(
exit_reason
::
user_shutdown
);
}
};
}
}
// namespace <anonymous>
size_t
pongs
()
{
return
s_pongs
;
}
void
ping
(
blocking_actor
*
self
,
size_t
num_pings
)
{
s_pongs
=
0
;
self
->
receive_loop
(
ping_behavior
(
self
,
num_pings
));
}
void
event_based_ping
(
event_based_actor
*
self
,
size_t
num_pings
)
{
s_pongs
=
0
;
self
->
become
(
ping_behavior
(
self
,
num_pings
));
}
void
pong
(
blocking_actor
*
self
,
actor
ping_actor
)
{
self
->
send
(
ping_actor
,
atom
(
"pong"
),
0
);
// kickoff
self
->
receive_loop
(
pong_behavior
(
self
));
}
libcaf_io/test/ping_pong.hpp
deleted
100644 → 0
View file @
ff54e90a
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef PING_PONG_HPP
#define PING_PONG_HPP
//#include "caf/actor.hpp"
#include <cstddef>
#include "caf/fwd.hpp"
void
ping
(
caf
::
blocking_actor
*
,
size_t
num_pings
);
void
event_based_ping
(
caf
::
event_based_actor
*
,
size_t
num_pings
);
void
pong
(
caf
::
blocking_actor
*
,
caf
::
actor
ping_actor
);
// returns the number of messages ping received
size_t
pongs
();
#endif // PING_PONG_HPP
libcaf_io/test/remote_actor.cpp
View file @
e87824c6
...
@@ -34,8 +34,6 @@
...
@@ -34,8 +34,6 @@
#include "caf/detail/singletons.hpp"
#include "caf/detail/singletons.hpp"
#include "caf/detail/run_program.hpp"
#include "caf/detail/run_program.hpp"
#include "../libcaf_io/test/ping_pong.hpp"
using
namespace
std
;
using
namespace
std
;
using
namespace
caf
;
using
namespace
caf
;
...
@@ -56,6 +54,56 @@ atomic<long> s_on_exit_called;
...
@@ -56,6 +54,56 @@ atomic<long> s_on_exit_called;
constexpr
size_t
num_pings
=
10
;
constexpr
size_t
num_pings
=
10
;
size_t
s_pongs
=
0
;
behavior
ping_behavior
(
local_actor
*
self
,
size_t
num_pings
)
{
return
{
on
(
atom
(
"pong"
),
arg_match
)
>>
[
=
](
int
value
)
->
message
{
if
(
!
self
->
current_sender
())
{
CAF_TEST_ERROR
(
"current_sender() invalid!"
);
}
CAF_TEST_INFO
(
"received {'pong', "
<<
value
<<
"}"
);
// cout << to_string(self->current_message()) << endl;
if
(
++
s_pongs
>=
num_pings
)
{
CAF_TEST_INFO
(
"reached maximum, send {'EXIT', user_defined} "
<<
"to last sender and quit with normal reason"
);
self
->
send_exit
(
self
->
current_sender
(),
exit_reason
::
user_shutdown
);
self
->
quit
();
}
return
make_message
(
atom
(
"ping"
),
value
);
},
others
()
>>
[
=
]
{
self
->
quit
(
exit_reason
::
user_shutdown
);
}
};
}
behavior
pong_behavior
(
local_actor
*
self
)
{
return
{
on
(
atom
(
"ping"
),
arg_match
)
>>
[](
int
value
)
->
message
{
return
make_message
(
atom
(
"pong"
),
value
+
1
);
},
others
()
>>
[
=
]
{
self
->
quit
(
exit_reason
::
user_shutdown
);
}
};
}
size_t
pongs
()
{
return
s_pongs
;
}
void
event_based_ping
(
event_based_actor
*
self
,
size_t
num_pings
)
{
s_pongs
=
0
;
self
->
become
(
ping_behavior
(
self
,
num_pings
));
}
void
pong
(
blocking_actor
*
self
,
actor
ping_actor
)
{
self
->
send
(
ping_actor
,
atom
(
"pong"
),
0
);
// kickoff
self
->
receive_loop
(
pong_behavior
(
self
));
}
using
string_pair
=
std
::
pair
<
std
::
string
,
std
::
string
>
;
using
string_pair
=
std
::
pair
<
std
::
string
,
std
::
string
>
;
using
actor_vector
=
vector
<
actor
>
;
using
actor_vector
=
vector
<
actor
>
;
...
...
libcaf_io/test/unpublish.cpp
View file @
e87824c6
...
@@ -55,25 +55,24 @@ void test_invalid_unpublish(const actor& published, uint16_t port) {
...
@@ -55,25 +55,24 @@ void test_invalid_unpublish(const actor& published, uint16_t port) {
anon_send_exit
(
d
,
exit_reason
::
user_shutdown
);
anon_send_exit
(
d
,
exit_reason
::
user_shutdown
);
}
}
CAF_TEST
(
test_unpublish
)
{
CAF_TEST
(
unpublishing
)
{
auto
d
=
spawn
<
dummy
>
();
{
// scope for local variables
auto
port
=
io
::
publish
(
d
,
0
);
auto
d
=
spawn
<
dummy
>
();
CAF_MESSAGE
(
"published actor on port "
<<
port
);
auto
port
=
io
::
publish
(
d
,
0
);
test_invalid_unpublish
(
d
,
port
);
CAF_MESSAGE
(
"published actor on port "
<<
port
);
CAF_MESSAGE
(
"finished `invalid_unpublish`"
);
test_invalid_unpublish
(
d
,
port
);
io
::
unpublish
(
d
,
port
);
CAF_MESSAGE
(
"finished `invalid_unpublish`"
);
// must fail now
io
::
unpublish
(
d
,
port
);
try
{
// must fail now
CAF_MESSAGE
(
"expect exception..."
);
try
{
io
::
remote_actor
(
"127.0.0.1"
,
port
);
CAF_MESSAGE
(
"expect exception..."
);
CAF_TEST_ERROR
(
"unexpected: remote actor succeeded!"
);
io
::
remote_actor
(
"127.0.0.1"
,
port
);
}
catch
(
network_error
&
)
{
CAF_TEST_ERROR
(
"unexpected: remote actor succeeded!"
);
CAF_MESSAGE
(
"unpublish succeeded"
);
}
catch
(
network_error
&
)
{
CAF_MESSAGE
(
"unpublish succeeded"
);
}
anon_send_exit
(
d
,
exit_reason
::
user_shutdown
);
}
}
anon_send_exit
(
d
,
exit_reason
::
user_shutdown
);
}
CAF_TEST
(
test_dtor_called
)
{
await_all_actors_done
();
await_all_actors_done
();
shutdown
();
shutdown
();
CAF_CHECK_EQUAL
(
s_dtor_called
.
load
(),
2
);
CAF_CHECK_EQUAL
(
s_dtor_called
.
load
(),
2
);
...
...
libcaf_test/caf/test/unit_test.hpp
View file @
e87824c6
...
@@ -36,14 +36,6 @@ namespace caf {
...
@@ -36,14 +36,6 @@ namespace caf {
class
message
;
class
message
;
namespace
test
{
namespace
test
{
/**
* A sequence of *checks*.
*/
class
check_sequence
{
virtual
~
check_sequence
();
virtual
void
run
()
=
0
;
};
/**
/**
* A sequence of *checks*.
* A sequence of *checks*.
*/
*/
...
@@ -69,9 +61,7 @@ class test {
...
@@ -69,9 +61,7 @@ class test {
return
m_bad
;
return
m_bad
;
}
}
void
run
();
virtual
void
run
()
=
0
;
virtual
std
::
unique_ptr
<
check_sequence
>
make_sequence
()
=
0
;
private:
private:
size_t
m_expected_failures
;
size_t
m_expected_failures
;
...
@@ -82,6 +72,19 @@ class test {
...
@@ -82,6 +72,19 @@ class test {
struct
dummy_fixture
{
};
struct
dummy_fixture
{
};
template
<
class
T
>
class
test_impl
:
public
test
{
public:
test_impl
(
std
::
string
name
)
:
test
(
std
::
move
(
name
))
{
// nop
}
virtual
void
run
()
override
{
T
impl
;
impl
.
run
();
}
};
namespace
detail
{
namespace
detail
{
// thrown when a required check fails
// thrown when a required check fails
...
@@ -311,8 +314,8 @@ namespace detail {
...
@@ -311,8 +314,8 @@ namespace detail {
template
<
class
T
>
template
<
class
T
>
struct
adder
{
struct
adder
{
adder
(
c
har
const
*
name
)
{
adder
(
c
onst
char
*
suite_name
,
const
char
*
test_
name
)
{
engine
::
add
(
name
,
[]
{
return
std
::
unique_ptr
<
T
>
{
new
T
};
});
engine
::
add
(
suite_name
,
std
::
unique_ptr
<
T
>
{
new
T
(
test_name
)
});
}
}
};
};
...
@@ -606,13 +609,11 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
...
@@ -606,13 +609,11 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
#define CAF_TEST(name) \
#define CAF_TEST(name) \
namespace { \
namespace { \
struct CAF_UNIQUE(test) : public ::caf::test::test { \
struct CAF_UNIQUE(test) : caf_test_case_auto_fixture { \
CAF_UNIQUE(test)() : test{CAF_XSTR(name)} { } \
void run(); \
void run() final; \
}; \
::caf::test::detail::adder<CAF_UNIQUE(test)> CAF_UNIQUE(a) { \
CAF_XSTR(CAF_SUITE) \
}; \
}; \
::caf::test::detail::adder<::caf::test::test_impl<CAF_UNIQUE(test)>> \
CAF_UNIQUE(a) {CAF_XSTR(CAF_SUITE), CAF_XSTR(name)}; \
}
/* namespace <anonymous> */
\
}
/* namespace <anonymous> */
\
void CAF_UNIQUE(test)::run()
void CAF_UNIQUE(test)::run()
...
@@ -620,7 +621,7 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
...
@@ -620,7 +621,7 @@ using caf_test_case_auto_fixture = caf::test::dummy_fixture;
namespace scope_name { using caf_test_case_auto_fixture = fixture_name ;
namespace scope_name { using caf_test_case_auto_fixture = fixture_name ;
#define CAF_TEST_FIXTURE_SCOPE_END() \
#define CAF_TEST_FIXTURE_SCOPE_END() \
} //
close namespace
} //
namespace <scope_name>
// Boost Test compatibility macro
// Boost Test compatibility macro
#define CAF_CHECK_EQUAL(x, y) CAF_CHECK(x == y)
#define CAF_CHECK_EQUAL(x, y) CAF_CHECK(x == y)
...
...
libcaf_test/caf/test/unit_test_impl.hpp
View file @
e87824c6
...
@@ -81,10 +81,6 @@ void watchdog::stop() {
...
@@ -81,10 +81,6 @@ void watchdog::stop() {
delete
s_watchdog
;
delete
s_watchdog
;
}
}
check_sequence
::~
check_sequence
()
{
// nop
}
test
::
test
(
std
::
string
test_name
)
test
::
test
(
std
::
string
test_name
)
:
m_expected_failures
(
0
),
:
m_expected_failures
(
0
),
m_name
(
std
::
move
(
test_name
)),
m_name
(
std
::
move
(
test_name
)),
...
@@ -118,11 +114,6 @@ const std::string& test::name() const {
...
@@ -118,11 +114,6 @@ const std::string& test::name() const {
return
m_name
;
return
m_name
;
}
}
void
test
::
run
()
{
auto
runner
=
make_sequence
();
runner
->
run
();
}
namespace
detail
{
namespace
detail
{
require_error
::
require_error
(
const
std
::
string
&
msg
)
:
std
::
logic_error
(
msg
)
{
require_error
::
require_error
(
const
std
::
string
&
msg
)
:
std
::
logic_error
(
msg
)
{
...
@@ -359,8 +350,7 @@ bool engine::run(bool colorize,
...
@@ -359,8 +350,7 @@ bool engine::run(bool colorize,
auto
pad
=
std
::
string
((
bar
.
size
()
-
suite_name
.
size
())
/
2
,
' '
);
auto
pad
=
std
::
string
((
bar
.
size
()
-
suite_name
.
size
())
/
2
,
' '
);
bool
displayed_header
=
false
;
bool
displayed_header
=
false
;
size_t
tests_ran
=
0
;
size_t
tests_ran
=
0
;
for
(
auto
&
generator
:
p
.
second
)
{
for
(
auto
&
t
:
p
.
second
)
{
auto
t
=
generator
();
if
(
!
enabled
(
tests
,
not_tests
,
t
->
name
()))
{
if
(
!
enabled
(
tests
,
not_tests
,
t
->
name
()))
{
continue
;
continue
;
}
}
...
...
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