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
b01685ea
Commit
b01685ea
authored
Feb 03, 2020
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: no unittests for curve_encoding_t
Solution: add initial tests
parent
78b94a4f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
165 additions
and
1 deletion
+165
-1
Makefile.am
Makefile.am
+11
-1
CMakeLists.txt
unittests/CMakeLists.txt
+1
-0
unittest_curve_encoding.cpp
unittests/unittest_curve_encoding.cpp
+153
-0
No files found.
Makefile.am
View file @
b01685ea
...
...
@@ -1085,7 +1085,8 @@ test_apps += \
unittests/unittest_mtrie
\
unittests/unittest_ip_resolver
\
unittests/unittest_udp_address
\
unittests/unittest_radix_tree
unittests/unittest_radix_tree
\
unittests/unittest_curve_encoding
unittests_unittest_poller_SOURCES
=
unittests/unittest_poller.cpp
unittests_unittest_poller_CPPFLAGS
=
-I
$(top_srcdir)
/src
${
TESTUTIL_CPPFLAGS
}
$(CODE_COVERAGE_CPPFLAGS)
...
...
@@ -1140,6 +1141,15 @@ unittests_unittest_radix_tree_LDADD = \
$(top_builddir)
/src/.libs/libzmq.a
\
${
src_libzmq_la_LIBADD
}
\
$(CODE_COVERAGE_LDFLAGS)
unittests_unittest_curve_encoding_SOURCES
=
unittests/unittest_curve_encoding.cpp
unittests_unittest_curve_encoding_CPPFLAGS
=
-I
$(top_srcdir)
/src
${
TESTUTIL_CPPFLAGS
}
$(CODE_COVERAGE_CPPFLAGS)
unittests_unittest_curve_encoding_CXXFLAGS
=
$(CODE_COVERAGE_CXXFLAGS)
unittests_unittest_curve_encoding_LDADD
=
\
${
TESTUTIL_LIBS
}
\
$(top_builddir)
/src/.libs/libzmq.a
\
${
src_libzmq_la_LIBADD
}
\
$(CODE_COVERAGE_LDFLAGS)
endif
check_PROGRAMS
=
${
test_apps
}
...
...
unittests/CMakeLists.txt
View file @
b01685ea
...
...
@@ -8,6 +8,7 @@ set(unittests
unittest_ip_resolver
unittest_udp_address
unittest_radix_tree
unittest_curve_encoding
)
#if(ENABLE_DRAFTS)
...
...
unittests/unittest_curve_encoding.cpp
0 → 100644
View file @
b01685ea
/*
Copyright (c) 2018 Contributors as noted in the AUTHORS file
This file is part of 0MQ.
0MQ is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
0MQ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../tests/testutil_unity.hpp"
// TODO: remove this ugly hack
#ifdef close
#undef close
#endif
#include <curve_mechanism_base.hpp>
#include <msg.hpp>
#include <random.hpp>
#include <unity.h>
#include <vector>
void
setUp
()
{
}
void
tearDown
()
{
}
void
test_roundtrip
(
zmq
::
msg_t
*
msg_
)
{
#ifdef ZMQ_HAVE_CURVE
const
std
::
vector
<
uint8_t
>
original
(
static_cast
<
uint8_t
*>
(
msg_
->
data
()),
static_cast
<
uint8_t
*>
(
msg_
->
data
())
+
msg_
->
size
());
zmq
::
curve_encoding_t
encoding_client
(
"CurveZMQMESSAGEC"
,
"CurveZMQMESSAGES"
);
zmq
::
curve_encoding_t
encoding_server
(
"CurveZMQMESSAGES"
,
"CurveZMQMESSAGEC"
);
uint8_t
client_public
[
32
];
uint8_t
client_secret
[
32
];
TEST_ASSERT_SUCCESS_ERRNO
(
crypto_box_keypair
(
client_public
,
client_secret
));
uint8_t
server_public
[
32
];
uint8_t
server_secret
[
32
];
TEST_ASSERT_SUCCESS_ERRNO
(
crypto_box_keypair
(
server_public
,
server_secret
));
TEST_ASSERT_SUCCESS_ERRNO
(
crypto_box_beforenm
(
encoding_client
.
get_writable_precom_buffer
(),
server_public
,
client_secret
));
TEST_ASSERT_SUCCESS_ERRNO
(
crypto_box_beforenm
(
encoding_server
.
get_writable_precom_buffer
(),
client_public
,
server_secret
));
TEST_ASSERT_SUCCESS_ERRNO
(
encoding_client
.
encode
(
msg_
));
// TODO: This is hacky...
encoding_server
.
set_peer_nonce
(
0
);
int
error_event_code
;
TEST_ASSERT_SUCCESS_ERRNO
(
encoding_server
.
decode
(
msg_
,
&
error_event_code
));
TEST_ASSERT_EQUAL_INT
(
original
.
size
(),
msg_
->
size
());
if
(
!
original
.
empty
())
{
TEST_ASSERT_EQUAL_UINT8_ARRAY
(
&
original
[
0
],
msg_
->
data
(),
original
.
size
());
}
#else
TEST_IGNORE_MESSAGE
(
"CURVE support is disabled"
);
#endif
}
void
test_roundtrip_empty
()
{
zmq
::
msg_t
msg
;
msg
.
init
();
test_roundtrip
(
&
msg
);
msg
.
close
();
}
void
test_roundtrip_small
()
{
zmq
::
msg_t
msg
;
msg
.
init_size
(
32
);
memcpy
(
msg
.
data
(),
"0123456789ABCDEF0123456789ABCDEF"
,
32
);
test_roundtrip
(
&
msg
);
msg
.
close
();
}
void
test_roundtrip_large
()
{
zmq
::
msg_t
msg
;
msg
.
init_size
(
2048
);
for
(
size_t
pos
=
0
;
pos
<
2048
;
pos
+=
32
)
{
memcpy
(
static_cast
<
char
*>
(
msg
.
data
())
+
pos
,
"0123456789ABCDEF0123456789ABCDEF"
,
32
);
}
test_roundtrip
(
&
msg
);
msg
.
close
();
}
void
test_roundtrip_empty_more
()
{
zmq
::
msg_t
msg
;
msg
.
init
();
msg
.
set_flags
(
zmq
::
msg_t
::
more
);
test_roundtrip
(
&
msg
);
TEST_ASSERT_TRUE
(
msg
.
flags
()
&
zmq
::
msg_t
::
more
);
msg
.
close
();
}
int
main
()
{
setup_test_environment
();
zmq
::
random_open
();
UNITY_BEGIN
();
RUN_TEST
(
test_roundtrip_empty
);
RUN_TEST
(
test_roundtrip_small
);
RUN_TEST
(
test_roundtrip_large
);
RUN_TEST
(
test_roundtrip_empty_more
);
zmq
::
random_close
();
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