Skip to content

Commit 5ebc7fe

Browse files
authored
Merge pull request #194 from sigiesec/add-initial-tests
Add some initial tests, add some build/version CI variants
2 parents 7db13d3 + cc5f405 commit 5ebc7fe

File tree

10 files changed

+117
-20
lines changed

10 files changed

+117
-20
lines changed

.travis.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ env:
1919
matrix:
2020
# - BUILD_TYPE=cmake DRAFT=enabled
2121
- BUILD_TYPE=cmake ZMQ_VERSION=4.2.5
22+
- BUILD_TYPE=cmake ZMQ_VERSION=4.2.0
2223

2324
matrix:
2425
include:
@@ -30,15 +31,25 @@ matrix:
3031
# - llvm-toolchain-trusty-5.0
3132
# packages:
3233
# - clang-5.0
34+
- os: linux
35+
addons:
36+
apt:
37+
sources:
38+
- ubuntu-toolchain-r-test
39+
packages:
40+
- g++-7
41+
env:
42+
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" BUILD_TYPE=cmake ZMQ_VERSION=4.2.5 DRAFT=1
3343

3444
sudo: required
3545

3646
before_install:
3747
- pip install --user cpp-coveralls
3848

3949
# Build and check this project according to the BUILD_TYPE
40-
script:
50+
script:
51+
- eval "${MATRIX_EVAL}"
4152
- ./ci_build.sh
4253

4354
after_success:
44-
- coveralls --root . -E ".*external.*" -E ".*CMakeFiles.*" -E ".*tests/" -E ".*libzmq/"
55+
- coveralls --root . -E ".*external.*" -E ".*CMakeFiles.*" -E ".*tests/" -E ".*demo/" -E ".*libzmq/"

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static))
1919
message(FATAL_ERROR "ZeroMQ version not supported!")
2020
endif()
2121

22+
if (EXISTS "${SOURCE_DIR}/.git")
23+
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON)
24+
else ()
25+
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" OFF)
26+
endif ()
27+
IF (ENABLE_DRAFTS)
28+
ADD_DEFINITIONS (-DZMQ_BUILD_DRAFT_API)
29+
set (pkg_config_defines "-DZMQ_BUILD_DRAFT_API=1")
30+
ELSE (ENABLE_DRAFTS)
31+
set (pkg_config_defines "")
32+
ENDIF (ENABLE_DRAFTS)
33+
2234
message(STATUS "cppzmq v${CPPZMQ_VERSION}")
2335

2436
set(CPPZMQ_HEADERS
@@ -63,3 +75,6 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
6375
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
6476
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake
6577
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}/libzmq-pkg-config)
78+
79+
enable_testing()
80+
add_subdirectory(tests)

ci_build.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/usr/bin/env bash
22

33
set -x
4+
set -e
5+
6+
if [ "$DRAFT" = "1" ] ; then
7+
# if we enable drafts during the libzmq cmake build, the pkgconfig
8+
# data should set ZMQ_BUILD_DRAFT_API in dependent builds, but this
9+
# does not appear to work (TODO)
10+
export ZEROMQ_CMAKE_FLAGS="-DENABLE_DRAFTS=ON"
11+
fi
412

513
install_zeromq() {
614
pushd .
@@ -13,7 +21,7 @@ install_zeromq() {
1321

1422
mkdir build
1523
cd build
16-
cmake ..
24+
cmake .. ${ZEROMQ_CMAKE_FLAGS}
1725
sudo make -j4 install
1826

1927
popd
@@ -28,12 +36,14 @@ if [ "${ZMQ_VERSION}" != "" ] ; then install_zeromq ; fi
2836
pushd .
2937
mkdir build
3038
cd build
31-
cmake ..
39+
cmake .. ${ZEROMQ_CMAKE_FLAGS}
40+
cmake --build .
3241
sudo make -j4 install
42+
make test ARGS="-V"
3343
popd
3444

35-
# build cppzmq tests
36-
cd tests
45+
# build cppzmq demo
46+
cd demo
3747
mkdir build
3848
cd build
3949
cmake ..

demo/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
2+
3+
project(cppzmq-demo CXX)
4+
5+
find_package(cppzmq)
6+
7+
enable_testing()
8+
add_executable(
9+
demo
10+
main.cpp
11+
)
12+
13+
target_link_libraries(
14+
demo
15+
libzmq
16+
)
17+
18+
add_test(
19+
NAME
20+
demo
21+
COMMAND
22+
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/demo
23+
)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#include "gtest/gtest.h"
21
#include <zmq.hpp>
32

4-
TEST(create_context, add)
3+
int main(int argc, char** argv)
54
{
65
zmq::context_t context;
76

8-
7+
return 0;
98
}

libzmq-pkg-config/FindZeroMQ.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pkg_check_modules(PC_LIBZMQ QUIET libzmq)
44
set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION})
55
find_library(ZeroMQ_LIBRARY NAMES libzmq.so libzmq.dylib libzmq.dll
66
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})
7-
find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq.a libzmq.dll.a
7+
find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq-static.a libzmq.a libzmq.dll.a
88
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})
99

1010
if(ZeroMQ_LIBRARY AND ZeroMQ_STATIC_LIBRARY)

tests/CMakeLists.txt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
33
project(cppzmq-test CXX)
44

55
# place binaries and libraries according to GNU standards
6-
# TODO check if we should do this
76

8-
# include(GNUInstallDirs)
9-
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
10-
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
11-
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
7+
include(GNUInstallDirs)
8+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
9+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
10+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
1211

1312
# we use this to get code coverage
1413
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
@@ -20,14 +19,12 @@ fetch_googletest(
2019
${PROJECT_SOURCE_DIR}/cmake
2120
${PROJECT_BINARY_DIR}/googletest
2221
)
23-
24-
find_package(cppzmq)
25-
26-
enable_testing()
2722

2823
add_executable(
2924
unit_tests
30-
example_add.cpp
25+
context.cpp
26+
socket.cpp
27+
poller.cpp
3128
)
3229

3330
target_link_libraries(
@@ -36,6 +33,8 @@ target_link_libraries(
3633
libzmq
3734
)
3835

36+
target_include_directories(unit_tests PRIVATE ..)
37+
3938
add_test(
4039
NAME
4140
unit

tests/context.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <gtest/gtest.h>
2+
#include <zmq.hpp>
3+
4+
TEST(context, create_default_destroy)
5+
{
6+
zmq::context_t context;
7+
}
8+
9+
TEST(context, create_close)
10+
{
11+
zmq::context_t context;
12+
context.close();
13+
14+
ASSERT_EQ(NULL, (void*)context);
15+
}

tests/poller.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <gtest/gtest.h>
2+
#include <zmq.hpp>
3+
4+
#if defined(ZMQ_CPP11) && defined(ZMQ_BUILD_DRAFT_API)
5+
TEST(poller, create_destroy)
6+
{
7+
zmq::poller_t context;
8+
}
9+
#endif

tests/socket.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <gtest/gtest.h>
2+
#include <zmq.hpp>
3+
4+
TEST(socket, create_destroy)
5+
{
6+
zmq::context_t context;
7+
zmq::socket_t socket(context, ZMQ_ROUTER);
8+
}
9+
10+
#ifdef ZMQ_CPP11
11+
TEST(socket, create_by_enum_destroy)
12+
{
13+
zmq::context_t context;
14+
zmq::socket_t socket(context, zmq::socket_type::router);
15+
}
16+
#endif

0 commit comments

Comments
 (0)