mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-01-31 14:39:56 +01:00
Merge pull request #194 from sigiesec/add-initial-tests
Add some initial tests, add some build/version CI variants
This commit is contained in:
commit
5ebc7fe32f
15
.travis.yml
15
.travis.yml
@ -19,6 +19,7 @@ env:
|
||||
matrix:
|
||||
# - BUILD_TYPE=cmake DRAFT=enabled
|
||||
- BUILD_TYPE=cmake ZMQ_VERSION=4.2.5
|
||||
- BUILD_TYPE=cmake ZMQ_VERSION=4.2.0
|
||||
|
||||
matrix:
|
||||
include:
|
||||
@ -30,6 +31,15 @@ matrix:
|
||||
# - llvm-toolchain-trusty-5.0
|
||||
# packages:
|
||||
# - clang-5.0
|
||||
- os: linux
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-7
|
||||
env:
|
||||
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" BUILD_TYPE=cmake ZMQ_VERSION=4.2.5 DRAFT=1
|
||||
|
||||
sudo: required
|
||||
|
||||
@ -37,8 +47,9 @@ before_install:
|
||||
- pip install --user cpp-coveralls
|
||||
|
||||
# Build and check this project according to the BUILD_TYPE
|
||||
script:
|
||||
script:
|
||||
- eval "${MATRIX_EVAL}"
|
||||
- ./ci_build.sh
|
||||
|
||||
after_success:
|
||||
- coveralls --root . -E ".*external.*" -E ".*CMakeFiles.*" -E ".*tests/" -E ".*libzmq/"
|
||||
- coveralls --root . -E ".*external.*" -E ".*CMakeFiles.*" -E ".*tests/" -E ".*demo/" -E ".*libzmq/"
|
||||
|
@ -19,6 +19,18 @@ if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static))
|
||||
message(FATAL_ERROR "ZeroMQ version not supported!")
|
||||
endif()
|
||||
|
||||
if (EXISTS "${SOURCE_DIR}/.git")
|
||||
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON)
|
||||
else ()
|
||||
OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" OFF)
|
||||
endif ()
|
||||
IF (ENABLE_DRAFTS)
|
||||
ADD_DEFINITIONS (-DZMQ_BUILD_DRAFT_API)
|
||||
set (pkg_config_defines "-DZMQ_BUILD_DRAFT_API=1")
|
||||
ELSE (ENABLE_DRAFTS)
|
||||
set (pkg_config_defines "")
|
||||
ENDIF (ENABLE_DRAFTS)
|
||||
|
||||
message(STATUS "cppzmq v${CPPZMQ_VERSION}")
|
||||
|
||||
set(CPPZMQ_HEADERS
|
||||
@ -63,3 +75,6 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
|
||||
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake
|
||||
DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}/libzmq-pkg-config)
|
||||
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
|
18
ci_build.sh
18
ci_build.sh
@ -1,6 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
if [ "$DRAFT" = "1" ] ; then
|
||||
# if we enable drafts during the libzmq cmake build, the pkgconfig
|
||||
# data should set ZMQ_BUILD_DRAFT_API in dependent builds, but this
|
||||
# does not appear to work (TODO)
|
||||
export ZEROMQ_CMAKE_FLAGS="-DENABLE_DRAFTS=ON"
|
||||
fi
|
||||
|
||||
install_zeromq() {
|
||||
pushd .
|
||||
@ -13,7 +21,7 @@ install_zeromq() {
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake .. ${ZEROMQ_CMAKE_FLAGS}
|
||||
sudo make -j4 install
|
||||
|
||||
popd
|
||||
@ -28,12 +36,14 @@ if [ "${ZMQ_VERSION}" != "" ] ; then install_zeromq ; fi
|
||||
pushd .
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake .. ${ZEROMQ_CMAKE_FLAGS}
|
||||
cmake --build .
|
||||
sudo make -j4 install
|
||||
make test ARGS="-V"
|
||||
popd
|
||||
|
||||
# build cppzmq tests
|
||||
cd tests
|
||||
# build cppzmq demo
|
||||
cd demo
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
|
23
demo/CMakeLists.txt
Normal file
23
demo/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
|
||||
|
||||
project(cppzmq-demo CXX)
|
||||
|
||||
find_package(cppzmq)
|
||||
|
||||
enable_testing()
|
||||
add_executable(
|
||||
demo
|
||||
main.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
demo
|
||||
libzmq
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME
|
||||
demo
|
||||
COMMAND
|
||||
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/demo
|
||||
)
|
@ -1,9 +1,8 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include <zmq.hpp>
|
||||
|
||||
TEST(create_context, add)
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
zmq::context_t context;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
@ -4,7 +4,7 @@ pkg_check_modules(PC_LIBZMQ QUIET libzmq)
|
||||
set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION})
|
||||
find_library(ZeroMQ_LIBRARY NAMES libzmq.so libzmq.dylib libzmq.dll
|
||||
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})
|
||||
find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq.a libzmq.dll.a
|
||||
find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq-static.a libzmq.a libzmq.dll.a
|
||||
PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})
|
||||
|
||||
if(ZeroMQ_LIBRARY AND ZeroMQ_STATIC_LIBRARY)
|
||||
|
@ -3,12 +3,11 @@ cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
|
||||
project(cppzmq-test CXX)
|
||||
|
||||
# place binaries and libraries according to GNU standards
|
||||
# TODO check if we should do this
|
||||
|
||||
# include(GNUInstallDirs)
|
||||
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
|
||||
include(GNUInstallDirs)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
# we use this to get code coverage
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
||||
@ -20,14 +19,12 @@ fetch_googletest(
|
||||
${PROJECT_SOURCE_DIR}/cmake
|
||||
${PROJECT_BINARY_DIR}/googletest
|
||||
)
|
||||
|
||||
find_package(cppzmq)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_executable(
|
||||
unit_tests
|
||||
example_add.cpp
|
||||
context.cpp
|
||||
socket.cpp
|
||||
poller.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
@ -36,6 +33,8 @@ target_link_libraries(
|
||||
libzmq
|
||||
)
|
||||
|
||||
target_include_directories(unit_tests PRIVATE ..)
|
||||
|
||||
add_test(
|
||||
NAME
|
||||
unit
|
||||
|
15
tests/context.cpp
Normal file
15
tests/context.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <zmq.hpp>
|
||||
|
||||
TEST(context, create_default_destroy)
|
||||
{
|
||||
zmq::context_t context;
|
||||
}
|
||||
|
||||
TEST(context, create_close)
|
||||
{
|
||||
zmq::context_t context;
|
||||
context.close();
|
||||
|
||||
ASSERT_EQ(NULL, (void*)context);
|
||||
}
|
9
tests/poller.cpp
Normal file
9
tests/poller.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <zmq.hpp>
|
||||
|
||||
#if defined(ZMQ_CPP11) && defined(ZMQ_BUILD_DRAFT_API)
|
||||
TEST(poller, create_destroy)
|
||||
{
|
||||
zmq::poller_t context;
|
||||
}
|
||||
#endif
|
16
tests/socket.cpp
Normal file
16
tests/socket.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <zmq.hpp>
|
||||
|
||||
TEST(socket, create_destroy)
|
||||
{
|
||||
zmq::context_t context;
|
||||
zmq::socket_t socket(context, ZMQ_ROUTER);
|
||||
}
|
||||
|
||||
#ifdef ZMQ_CPP11
|
||||
TEST(socket, create_by_enum_destroy)
|
||||
{
|
||||
zmq::context_t context;
|
||||
zmq::socket_t socket(context, zmq::socket_type::router);
|
||||
}
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user