Unverified Commit df03bf48 authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #2987 from sigiesec/migrate-to-unity

Migrate further tests (test_hwm, test_router_mandatory) to unity
parents c9437ab7 c6023618
......@@ -462,8 +462,9 @@ tests_test_reqrep_tcp_SOURCES = \
tests/testutil.hpp
tests_test_reqrep_tcp_LDADD = src/libzmq.la
tests_test_hwm_SOURCES = tests/test_hwm.cpp
tests_test_hwm_LDADD = src/libzmq.la
tests_test_hwm_SOURCES = tests/test_hwm.cpp tests/testutil_unity.hpp
tests_test_hwm_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_hwm_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_hwm_pubsub_SOURCES = tests/test_hwm_pubsub.cpp
tests_test_hwm_pubsub_LDADD = src/libzmq.la
......@@ -501,8 +502,9 @@ tests_test_srcfd_LDADD = src/libzmq.la
tests_test_monitor_SOURCES = tests/test_monitor.cpp
tests_test_monitor_LDADD = src/libzmq.la
tests_test_router_mandatory_SOURCES = tests/test_router_mandatory.cpp
tests_test_router_mandatory_LDADD = src/libzmq.la
tests_test_router_mandatory_SOURCES = tests/test_router_mandatory.cpp tests/testutil_unity.hpp
tests_test_router_mandatory_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_router_mandatory_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_router_mandatory_hwm_SOURCES = tests/test_router_mandatory_hwm.cpp
tests_test_router_mandatory_hwm_LDADD = src/libzmq.la
......
......@@ -177,7 +177,7 @@ foreach(test ${tests})
add_executable(${test} ${test}.cpp
"testutil_security.hpp")
else ()
add_executable(${test} ${test}.cpp)
add_executable(${test} ${test}.cpp "testutil.hpp" "testutil_unity.hpp")
endif ()
if(WIN32)
# This is the output for Debug dynamic builds on Visual Studio 6.0
......
......@@ -2,27 +2,23 @@
Write your test case as if you were writing clean application code. It should be safe to compile on all platforms.
The only include file you should use is `testutil.hpp`. Do not include files from src. Do not use the internal libzmq API or your test case is fair game to be deleted.
Normally, you should only include the header files from the tests directory, e.g. `testutil.hpp`. Do not include files from src. Do not use the internal libzmq API. Tests for these should be placed in unittests instead.
If you must write non-portable code, wrap it in #ifdefs to ensure it will compile and run on all systems.
Note that testutil.hpp includes platform.h. Do not include it yourself as it changes location depending on the build system and OS.
All sources must contain the correct header. Please copy from test_system.cpp if you're not certain.
All sources must contain the correct copyright header. Please copy from test_system.cpp if you're not certain.
Write new tests using the unity test framework. For an example, see test_sockopt_hwm.
Please use only ANSI C99 in test cases, no C++. This is to make the code more reusable.
On many slower environments, like embedded systems, VMs or CI systems, test might
On many slower environments, like embedded systems, VMs or CI systems, tests might
fail because it takes time for sockets to settle after a connect. If you need
to add a sleep, please be consistent with all the other tests and use:
msleep (SETTLE_TIME);
# Building tests in Windows
According to the version of your compiler, you should adapt the path `libzmq.lib` in the file `tests/CMakeLists.txt`.
Install CMAKE
CMD> CMAKE libzmq/tests
CMD> tests.sln
CMD> # build all projects in the solution
# Building tests in Windows
The tests are only built via cmake, not when using the checked-in Visual Studio .sln files.
This diff is collapsed.
This diff is collapsed.
#pragma once
/*
Copyright (c) 2018 Contributors as noted in the AUTHORS file
This file is part of libzmq, the ZeroMQ core engine in C++.
libzmq is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
As a special exception, the Contributors give you permission to link
this library with independent modules to produce an executable,
regardless of the license terms of these independent modules, and to
copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the
terms and conditions of the license of that module. An independent
module is a module which is not derived from or based on this library.
If you modify this library, you must extend this exception to your
version of the library.
libzmq 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 "../include/zmq.h"
#include <unity.h>
#include <string.h>
#include <stdio.h>
#if defined(_MSC_VER) && _MSC_VER <= 1800
#define snprintf _snprintf
#endif
int test_assert_success_message_errno_helper (int rc,
const char *msg,
const char *expr)
{
if (rc == -1) {
char buffer[512];
buffer[sizeof (buffer) - 1] =
0; // to ensure defined behavior with VC++ <= 2013
snprintf (buffer, sizeof (buffer) - 1,
"%s failed%s%s%s, errno = %i (%s)", expr,
msg ? " (additional info: " : "", msg ? msg : "",
msg ? ")" : "", zmq_errno (), zmq_strerror (zmq_errno ()));
TEST_FAIL_MESSAGE (buffer);
}
return rc;
}
#define TEST_ASSERT_SUCCESS_MESSAGE_ERRNO(expr, msg) \
test_assert_success_message_errno_helper (expr, msg, #expr)
#define TEST_ASSERT_SUCCESS_ERRNO(expr) \
test_assert_success_message_errno_helper (expr, NULL, #expr)
void send_string_expect_success (void *socket, const char *str, int flags)
{
const size_t len = str ? strlen (str) : 0;
const int rc = zmq_send (socket, str, len, flags);
TEST_ASSERT_EQUAL_INT ((int) len, rc);
}
void recv_string_expect_success (void *socket, const char *str, int flags)
{
const size_t len = str ? strlen (str) : 0;
char buffer[255];
TEST_ASSERT_LESS_OR_EQUAL_MESSAGE (sizeof (buffer), len,
"recv_string_expect_success cannot be "
"used for strings longer than 255 "
"characters");
const int rc =
TEST_ASSERT_SUCCESS_ERRNO (zmq_recv (socket, buffer, sizeof (buffer), 0));
TEST_ASSERT_EQUAL_INT ((int) len, rc);
if (str)
TEST_ASSERT_EQUAL_STRING_LEN (str, buffer, len);
}
......@@ -48,7 +48,6 @@ foreach(test ${unittests})
# TODO prevent libzmq (non-static) being in the list of link libraries at all
get_target_property(LIBS ${test} LINK_LIBRARIES)
list(REMOVE_ITEM LIBS libzmq)
message("Link libraries of ${test}: ${LIBS}")
set_target_properties(${test} PROPERTIES LINK_LIBRARIES "${LIBS}")
endforeach()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment