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
d162ba49
Commit
d162ba49
authored
Jan 29, 2015
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend match unit test
parent
38e87948
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
28 deletions
+90
-28
unit_testing/test_match.cpp
unit_testing/test_match.cpp
+90
-28
No files found.
unit_testing/test_match.cpp
View file @
d162ba49
...
@@ -62,24 +62,38 @@ void reset() {
...
@@ -62,24 +62,38 @@ void reset() {
fill
(
begin
(
s_invoked
),
end
(
s_invoked
),
false
);
fill
(
begin
(
s_invoked
),
end
(
s_invoked
),
false
);
}
}
template
<
class
Expr
,
class
...
Ts
>
void
fill_mb
(
message_builder
&
)
{
bool
invoked
(
int
idx
,
Expr
&
expr
,
Ts
&&
...
args
)
{
// end of recursion
expr
(
make_message
(
forward
<
Ts
>
(
args
)...));
}
auto
res
=
s_invoked
[
idx
];
s_invoked
[
idx
]
=
false
;
template
<
class
T
,
class
...
Ts
>
auto
e
=
end
(
s_invoked
);
void
fill_mb
(
message_builder
&
mb
,
const
T
&
v
,
const
Ts
&
...
vs
)
{
res
=
res
&&
find
(
begin
(
s_invoked
),
e
,
true
)
==
e
;
fill_mb
(
mb
.
append
(
v
),
vs
...);
reset
();
return
res
;
}
}
template
<
class
Expr
,
class
...
Ts
>
template
<
class
Expr
,
class
...
Ts
>
bool
not_invoked
(
Expr
&
expr
,
Ts
&&
...
args
)
{
ptrdiff_t
invoked
(
Expr
&
expr
,
const
Ts
&
...
args
)
{
expr
(
make_message
(
forward
<
Ts
>
(
args
)...));
vector
<
message
>
msgs
;
auto
e
=
end
(
s_invoked
);
msgs
.
push_back
(
make_message
(
args
...));
auto
res
=
find
(
begin
(
s_invoked
),
e
,
true
)
==
e
;
message_builder
mb
;
fill
(
begin
(
s_invoked
),
end
(
s_invoked
),
false
);
fill_mb
(
mb
,
args
...);
return
res
;
msgs
.
push_back
(
mb
.
to_message
());
set
<
ptrdiff_t
>
results
;
for
(
auto
&
msg
:
msgs
)
{
expr
(
msg
);
auto
first
=
begin
(
s_invoked
);
auto
last
=
end
(
s_invoked
);
auto
i
=
find
(
begin
(
s_invoked
),
last
,
true
);
results
.
insert
(
i
!=
last
&&
count
(
i
,
last
,
true
)
==
1
?
distance
(
first
,
i
)
:
-
1
);
reset
();
}
if
(
results
.
size
()
>
1
)
{
CAF_FAILURE
(
"make_message() yielded a different result than "
"message_builder(...).to_message()"
);
return
-
2
;
}
return
*
results
.
begin
();
}
}
function
<
void
()
>
f
(
int
idx
)
{
function
<
void
()
>
f
(
int
idx
)
{
...
@@ -90,9 +104,20 @@ function<void()> f(int idx) {
...
@@ -90,9 +104,20 @@ function<void()> f(int idx) {
void
test_atoms
()
{
void
test_atoms
()
{
auto
expr
=
on
(
hi_atom
::
value
)
>>
f
(
0
);
auto
expr
=
on
(
hi_atom
::
value
)
>>
f
(
0
);
CAF_CHECK
(
invoked
(
0
,
expr
,
hi_atom
::
value
));
CAF_CHECK_EQUAL
(
invoked
(
expr
,
hi_atom
::
value
),
0
);
CAF_CHECK
(
not_invoked
(
expr
,
ho_atom
::
value
));
CAF_CHECK_EQUAL
(
invoked
(
expr
,
ho_atom
::
value
),
-
1
);
CAF_CHECK
(
not_invoked
(
expr
,
hi_atom
::
value
,
hi_atom
::
value
));
CAF_CHECK_EQUAL
(
invoked
(
expr
,
hi_atom
::
value
,
hi_atom
::
value
),
-
1
);
message_handler
expr2
{
[](
hi_atom
)
{
s_invoked
[
0
]
=
true
;
},
[](
ho_atom
)
{
s_invoked
[
1
]
=
true
;
}
};
CAF_CHECK_EQUAL
(
invoked
(
expr2
,
ok_atom
::
value
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr2
,
hi_atom
::
value
),
0
);
CAF_CHECK_EQUAL
(
invoked
(
expr2
,
ho_atom
::
value
),
1
);
}
}
void
test_custom_projections
()
{
void
test_custom_projections
()
{
...
@@ -106,8 +131,8 @@ void test_custom_projections() {
...
@@ -106,8 +131,8 @@ void test_custom_projections() {
auto
expr
=
(
auto
expr
=
(
on
(
guard
)
>>
f
(
0
)
on
(
guard
)
>>
f
(
0
)
);
);
CAF_CHECK
(
invoked
(
0
,
expr
,
42
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
42
),
0
);
CAF_CHECK
(
guard_called
);
CAF_CHECK
_EQUAL
(
guard_called
,
true
);
}
}
// check forwarding optional<const string&> from guard
// check forwarding optional<const string&> from guard
{
{
...
@@ -117,10 +142,10 @@ void test_custom_projections() {
...
@@ -117,10 +142,10 @@ void test_custom_projections() {
s_invoked
[
0
]
=
true
;
s_invoked
[
0
]
=
true
;
}
}
);
);
CAF_CHECK
(
invoked
(
0
,
expr
,
"--help"
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
"--help"
),
0
);
CAF_CHECK
(
not_invoked
(
expr
,
"-help"
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
"-help"
),
-
1
);
CAF_CHECK
(
not_invoked
(
expr
,
"--help"
,
"--help"
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
"--help"
,
"--help"
),
-
1
);
CAF_CHECK
(
not_invoked
(
expr
,
42
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
42
),
-
1
);
}
}
// check projection
// check projection
{
{
...
@@ -130,16 +155,53 @@ void test_custom_projections() {
...
@@ -130,16 +155,53 @@ void test_custom_projections() {
s_invoked
[
0
]
=
true
;
s_invoked
[
0
]
=
true
;
}
}
);
);
CAF_CHECK
(
invoked
(
0
,
expr
,
"42"
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
"42"
),
0
);
CAF_CHECK
(
not_invoked
(
expr
,
"42f"
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
"42f"
),
-
1
);
CAF_CHECK
(
not_invoked
(
expr
,
"42"
,
"42"
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
"42"
,
"42"
),
-
1
);
CAF_CHECK
(
not_invoked
(
expr
,
42
)
);
CAF_CHECK
_EQUAL
(
invoked
(
expr
,
42
),
-
1
);
}
}
}
}
struct
wrapped_int
{
int
value
;
};
inline
bool
operator
==
(
const
wrapped_int
&
lhs
,
const
wrapped_int
&
rhs
)
{
return
lhs
.
value
==
rhs
.
value
;
}
void
test_arg_match
()
{
announce
<
wrapped_int
>
(
"wrapped_int"
,
&
wrapped_int
::
value
);
auto
expr
=
on
(
42
,
arg_match
)
>>
[](
int
i
)
{
s_invoked
[
0
]
=
true
;
CAF_CHECK_EQUAL
(
i
,
1
);
};
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
,
1.
f
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
1
,
42
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr
,
42
,
1
),
0
);
auto
expr2
=
on
(
"-a"
,
arg_match
)
>>
[](
const
string
&
value
)
{
s_invoked
[
0
]
=
true
;
CAF_CHECK_EQUAL
(
value
,
"b"
);
};
CAF_CHECK_EQUAL
(
invoked
(
expr2
,
"b"
,
"-a"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr2
,
"-a"
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr2
,
"-a"
,
"b"
),
0
);
auto
expr3
=
on
(
wrapped_int
{
42
},
arg_match
)
>>
[](
wrapped_int
i
)
{
s_invoked
[
0
]
=
true
;
CAF_CHECK_EQUAL
(
i
.
value
,
1
);
};
CAF_CHECK_EQUAL
(
invoked
(
expr3
,
wrapped_int
{
42
},
1.
f
),
-
1
);
CAF_CHECK_EQUAL
(
invoked
(
expr3
,
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
,
wrapped_int
{
42
},
wrapped_int
{
1
}),
0
);
}
int
main
()
{
int
main
()
{
CAF_TEST
(
test_match
);
CAF_TEST
(
test_match
);
test_atoms
();
test_atoms
();
test_custom_projections
();
test_custom_projections
();
test_arg_match
();
return
CAF_TEST_RESULT
();
return
CAF_TEST_RESULT
();
}
}
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