aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml4
-rw-r--r--CMakeLists.txt4
-rw-r--r--tests/CMakeLists.txt25
-rw-r--r--tests/cplusplus_pair.cc66
4 files changed, 95 insertions, 4 deletions
diff --git a/.travis.yml b/.travis.yml
index 2c46dab3..3fa094f9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -46,7 +46,6 @@ matrix:
packages:
- gcc-7
env: CC=gcc-7
-
# clang v4 build
- os: linux
dist: trusty
@@ -78,7 +77,8 @@ matrix:
- ubuntu-toolchain-r-test
packages:
- gcc-7
- env: CC=gcc-7 COVERAGE=ON GCOV=gcov-7
+ - g++-7
+ env: CC=gcc-7 CXX=g++-7 COVERAGE=ON GCOV=gcov-7
# One MacOS X build
- os: osx
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 06009b28..d95206c5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -102,8 +102,8 @@ if (NNG_ENABLE_COVERAGE)
# is older than that, you will need to find something newer. For
# correct reporting, we always turn off all optimizations.
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- set(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
- set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
+ set(CMAKE_C_FLAGS "-g -O0 --coverage")
+ set(CMAKE_CXX_FLAGS "-g -O0 --coverage")
elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index c6f6872c..0c0973b2 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -76,9 +76,32 @@ if (NNG_TESTS)
math (EXPR TEST_PORT "${TEST_PORT}+10")
endmacro (add_nng_compat_test)
+ macro (add_nng_cpp_test NAME TIMEOUT)
+ if (NOT NNG_ENABLE_COVERAGE)
+ enable_language (CXX)
+ list (APPEND all_tests ${NAME})
+ add_executable (${NAME} ${NAME}.cc)
+ target_link_libraries (${NAME} ${PROJECT_NAME}_static)
+ target_link_libraries (${NAME} ${NNG_REQUIRED_LIBRARIES})
+ target_compile_definitions(${NAME} PUBLIC -DNNG_STATIC_LIB)
+ if (CMAKE_THREAD_LIBS_INIT)
+ target_link_libraries (${NAME} "${CMAKE_THREAD_LIBS_INIT}")
+ endif()
+
+ add_test (NAME ${NAME} COMMAND ${NAME} ${TEST_PORT})
+ set_tests_properties (${NAME} PROPERTIES TIMEOUT ${TIMEOUT})
+ math (EXPR TEST_PORT "${TEST_PORT}+10")
+ endif()
+ endmacro (add_nng_cpp_test)
+
+
else ()
macro (add_nng_test NAME TIMEOUT)
endmacro (add_nng_test)
+ macro (add_nng_compat_test NAME TIMEOUT)
+ endmacro (add_nng_compat_test)
+ macro (add_nng_cpp_test NAME TIMEOUT)
+ endmacro (add_nng_cpp_test)
endif ()
add_nng_test(bus 5)
@@ -120,3 +143,5 @@ add_nng_compat_test(compat_survey 5)
add_nng_compat_test(compat_reqttl 5)
add_nng_compat_test(compat_shutdown 5)
+# c++ tests
+add_nng_cpp_test(cplusplus_pair 5)
diff --git a/tests/cplusplus_pair.cc b/tests/cplusplus_pair.cc
new file mode 100644
index 00000000..54a99737
--- /dev/null
+++ b/tests/cplusplus_pair.cc
@@ -0,0 +1,66 @@
+//
+// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+//
+// This software is supplied under the terms of the MIT License, a
+// copy of which should be located in the distribution where this
+// file was obtained (LICENSE.txt). A copy of the license may also be
+// found online at https://opensource.org/licenses/MIT.
+//
+
+#include "nng.h"
+
+#include <cstring>
+
+#define SOCKET_ADDRESS "inproc://c++"
+
+int
+main(int argc, char **argv)
+{
+ nng_socket s1;
+ nng_socket s2;
+ int rv;
+ size_t sz;
+ char buf[8];
+
+ if ((rv = nng_pair0_open(&s1)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_pair0_open(&s2)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_send(s2, (void *)"ABC", 4, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ sz = sizeof (buf);
+ if ((rv = nng_recv(s1, buf, &sz, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((sz != 4) || (memcmp(buf, "ABC", 4) != 0)) {
+ throw "Contents did not match";
+ }
+ if ((rv = nng_send(s1, (void *)"DEF", 4, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ sz = sizeof (buf);
+ if ((rv = nng_recv(s2, buf, &sz, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((sz != 4) || (memcmp(buf, "DEF", 4) != 0)) {
+ throw "Contents did not match";
+ }
+ if ((rv = nng_close(s1)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_close(s2)) != 0) {
+ throw nng_strerror(rv);
+ }
+
+ return (0);
+}
+