Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
dbbc10e0
Commit
dbbc10e0
authored
Feb 16, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: incomplete test coverage of mtrie
Solution: add some more test cases
parent
a9712c0b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
6 deletions
+53
-6
unittest_mtrie.cpp
unittests/unittest_mtrie.cpp
+53
-6
No files found.
unittests/unittest_mtrie.cpp
View file @
dbbc10e0
...
...
@@ -34,6 +34,11 @@ void tearDown ()
{
}
int
getlen
(
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
&
data
)
{
return
strlen
(
reinterpret_cast
<
const
char
*>
(
data
));
}
void
test_create
()
{
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
...
...
@@ -53,7 +58,7 @@ void test_check_empty_match_nonempty_data ()
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
"foo"
);
int
count
=
0
;
mtrie
.
match
(
test_name
,
3
,
mtrie_count
,
&
count
);
mtrie
.
match
(
test_name
,
getlen
(
test_name
)
,
mtrie_count
,
&
count
);
TEST_ASSERT_EQUAL_INT
(
0
,
count
);
}
...
...
@@ -74,14 +79,54 @@ void test_add_single_entry_match_exact ()
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
test_name
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
"foo"
);
bool
res
=
mtrie
.
add
(
test_name
,
3
,
&
pipe
);
bool
res
=
mtrie
.
add
(
test_name
,
getlen
(
test_name
)
,
&
pipe
);
TEST_ASSERT_TRUE
(
res
);
int
count
=
0
;
mtrie
.
match
(
test_name
,
3
,
mtrie_count
,
&
count
);
mtrie
.
match
(
test_name
,
getlen
(
test_name
)
,
mtrie_count
,
&
count
);
TEST_ASSERT_EQUAL_INT
(
1
,
count
);
}
void
test_add_two_entries_with_same_name_match_exact
()
{
int
pipe_1
,
pipe_2
;
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
test_name
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
"foo"
);
bool
res
=
mtrie
.
add
(
test_name
,
getlen
(
test_name
),
&
pipe_1
);
TEST_ASSERT_TRUE
(
res
);
res
=
mtrie
.
add
(
test_name
,
getlen
(
test_name
),
&
pipe_2
);
TEST_ASSERT_FALSE
(
res
);
int
count
=
0
;
mtrie
.
match
(
test_name
,
getlen
(
test_name
),
mtrie_count
,
&
count
);
TEST_ASSERT_EQUAL_INT
(
2
,
count
);
}
void
test_add_two_entries_match_prefix_and_exact
()
{
int
pipe_1
,
pipe_2
;
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
test_name_prefix
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
"foo"
);
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
test_name_full
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
"foobar"
);
bool
res
=
mtrie
.
add
(
test_name_prefix
,
getlen
(
test_name_prefix
),
&
pipe_1
);
TEST_ASSERT_TRUE
(
res
);
res
=
mtrie
.
add
(
test_name_full
,
getlen
(
test_name_full
),
&
pipe_2
);
TEST_ASSERT_TRUE
(
res
);
int
count
=
0
;
mtrie
.
match
(
test_name_full
,
getlen
(
test_name_full
),
mtrie_count
,
&
count
);
TEST_ASSERT_EQUAL_INT
(
2
,
count
);
}
void
test_add_rm_single_entry_match_exact
()
{
int
pipe
;
...
...
@@ -89,12 +134,12 @@ void test_add_rm_single_entry_match_exact ()
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
test_name
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
"foo"
);
mtrie
.
add
(
test_name
,
3
,
&
pipe
);
bool
res
=
mtrie
.
rm
(
test_name
,
3
,
&
pipe
);
mtrie
.
add
(
test_name
,
getlen
(
test_name
)
,
&
pipe
);
bool
res
=
mtrie
.
rm
(
test_name
,
getlen
(
test_name
)
,
&
pipe
);
TEST_ASSERT_TRUE
(
res
);
int
count
=
0
;
mtrie
.
match
(
test_name
,
3
,
mtrie_count
,
&
count
);
mtrie
.
match
(
test_name
,
getlen
(
test_name
)
,
mtrie_count
,
&
count
);
TEST_ASSERT_EQUAL_INT
(
0
,
count
);
}
...
...
@@ -108,6 +153,8 @@ int main (void)
RUN_TEST
(
test_check_empty_match_empty_data
);
RUN_TEST
(
test_add_single_entry_match_exact
);
RUN_TEST
(
test_add_rm_single_entry_match_exact
);
RUN_TEST
(
test_add_two_entries_match_prefix_and_exact
);
RUN_TEST
(
test_add_two_entries_with_same_name_match_exact
);
return
UNITY_END
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment