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
8bb055ec
Commit
8bb055ec
authored
Feb 20, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: insufficient unit tests for mtrie
Solution: added test case, reduced code duplication in tests
parent
0e34d130
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
29 deletions
+62
-29
unittest_mtrie.cpp
unittests/unittest_mtrie.cpp
+62
-29
No files found.
unittests/unittest_mtrie.cpp
View file @
8bb055ec
...
...
@@ -36,7 +36,7 @@ void tearDown ()
int
getlen
(
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
&
data
)
{
return
strlen
(
reinterpret_cast
<
const
char
*>
(
data
));
return
(
int
)
strlen
(
reinterpret_cast
<
const
char
*>
(
data
));
}
void
test_create
()
...
...
@@ -213,7 +213,7 @@ void test_rm_nonexistent_nonempty_prefixed ()
void
add_indexed_expect_unique
(
zmq
::
generic_mtrie_t
<
int
>
&
mtrie
,
int
*
pipes
,
const
char
**
names
,
in
t
i
)
size_
t
i
)
{
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
name_data
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
names
[
i
]);
...
...
@@ -225,7 +225,7 @@ void add_indexed_expect_unique (zmq::generic_mtrie_t<int> &mtrie,
void
test_rm_nonexistent_between
()
{
int
pipes
[
3
];
const
char
*
names
[
3
]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
const
char
*
names
[]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
0
);
...
...
@@ -238,17 +238,25 @@ void test_rm_nonexistent_between ()
TEST_ASSERT_FALSE
(
res
);
}
template
<
size_t
N
>
void
add_entries
(
zmq
::
generic_mtrie_t
<
int
>
&
mtrie
,
int
(
&
pipes
)[
N
],
const
char
*
(
&
names
)[
N
])
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
i
);
}
}
void
test_add_multiple
()
{
int
pipes
[
3
];
const
char
*
names
[
3
]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
const
char
*
names
[]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
i
);
}
add_entries
(
mtrie
,
pipes
,
names
);
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
sizeof
(
names
)
/
sizeof
(
names
[
0
])
;
++
i
)
{
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
name_data
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
names
[
i
]);
int
count
=
0
;
...
...
@@ -260,14 +268,14 @@ void test_add_multiple ()
void
test_add_multiple_reverse
()
{
int
pipes
[
3
];
const
char
*
names
[
3
]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
const
char
*
names
[]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
for
(
int
i
=
2
;
i
>=
0
;
--
i
)
{
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
i
);
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
(
size_t
)
i
);
}
for
(
in
t
i
=
0
;
i
<
3
;
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
3
;
++
i
)
{
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
name_data
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
names
[
i
]);
int
count
=
0
;
...
...
@@ -276,17 +284,13 @@ void test_add_multiple_reverse ()
}
}
void
test_rm_multiple_in_order
(
)
template
<
size_t
N
>
void
add_and_rm_entries
(
const
char
*
(
&
names
)[
N
]
)
{
int
pipes
[
3
];
const
char
*
names
[
3
]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
int
pipes
[
N
];
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
i
);
}
add_entries
(
mtrie
,
pipes
,
names
);
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
name_data
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
names
[
i
]);
...
...
@@ -295,23 +299,49 @@ void test_rm_multiple_in_order ()
}
}
void
test_rm_multiple_in_order
()
{
const
char
*
names
[]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
add_and_rm_entries
(
names
);
}
void
test_rm_multiple_reverse_order
()
{
int
pipes
[
3
];
const
char
*
names
[
3
]
=
{
"foo1"
,
"foo2"
,
"foo3"
};
const
char
*
names
[]
=
{
"foo3"
,
"foo2"
,
"foo1"
};
add_and_rm_entries
(
names
);
}
void
check_name
(
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
data_
,
size_t
len_
,
void
*
void_name_
)
{
TEST_ASSERT_EQUAL_UINT
(
strlen
((
char
*
)
void_name_
),
len_
);
TEST_ASSERT_EQUAL_STRING_LEN
(
void_name_
,
data_
,
len_
);
}
template
<
size_t
N
>
void
add_entries_rm_pipes_unique
(
const
char
*
(
&
names
)[
N
])
{
int
pipes
[
N
];
zmq
::
generic_mtrie_t
<
int
>
mtrie
;
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
add_indexed_expect_unique
(
mtrie
,
pipes
,
names
,
i
);
add_entries
(
mtrie
,
pipes
,
names
);
for
(
size_t
i
=
0
;
i
<
N
;
++
i
)
{
mtrie
.
rm
(
&
pipes
[
i
],
check_name
,
const_cast
<
char
*>
(
names
[
i
]),
false
);
}
}
for
(
int
i
=
2
;
i
>=
0
;
--
i
)
{
const
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
name_data
=
reinterpret_cast
<
zmq
::
generic_mtrie_t
<
int
>::
prefix_t
>
(
names
[
i
])
;
void
test_rm_with_callback_multiple_in_order
()
{
const
char
*
names
[]
=
{
"foo1"
,
"foo2"
,
"foo3"
}
;
bool
res
=
mtrie
.
rm
(
name_data
,
getlen
(
name_data
),
&
pipes
[
i
]);
TEST_ASSERT_TRUE
(
res
);
}
add_entries_rm_pipes_unique
(
names
);
}
void
test_rm_with_callback_multiple_reverse_order
()
{
const
char
*
names
[]
=
{
"foo3"
,
"foo2"
,
"foo1"
};
add_entries_rm_pipes_unique
(
names
);
}
int
main
(
void
)
...
...
@@ -343,5 +373,8 @@ int main (void)
RUN_TEST
(
test_rm_multiple_in_order
);
RUN_TEST
(
test_rm_multiple_reverse_order
);
RUN_TEST
(
test_rm_with_callback_multiple_in_order
);
RUN_TEST
(
test_rm_with_callback_multiple_reverse_order
);
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