Skip to content

Commit

Permalink
Also support Boost 1.65 and fix tester
Browse files Browse the repository at this point in the history
Somehow the runner was segfaulting with the CMake steps. Didn't want to
find out why, instead used the default runner main with auto test
suites/cases.
  • Loading branch information
sehe committed Feb 9, 2021
1 parent c9caec0 commit b650a6b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ FIND_PACKAGE(Threads REQUIRED)
SET(Boost_USE_MULTITHREAD ON)
SET(Boost_USE_STATIC_LIBS OFF)

FIND_PACKAGE(Boost 1.70.0
FIND_PACKAGE(Boost 1.65.0
COMPONENTS system thread unit_test_framework test_exec_monitor
REQUIRED)

#LINK_LIBRARIES(${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
11 changes: 11 additions & 0 deletions containers/issue1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN \
apt update; \
apt -qqyy install build-essential git cmake libboost-all-dev

RUN git clone https://github.com/sehe/msghub --depth 1 -b cmake
WORKDIR /msghub
RUN cmake . && make

CMD ["/bin/bash", "-c", "(./examples/server & ./examples/client ; kill %1; wait)"]
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SET(MSGHUB_SRC
ADD_LIBRARY(msghub STATIC ${MSGHUB_SRC})
TARGET_COMPILE_DEFINITIONS(msghub PUBLIC "-DBOOST_BIND_NO_PLACEHOLDERS=1")
TARGET_INCLUDE_DIRECTORIES(msghub SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
TARGET_LINK_DIRECTORIES(msghub PUBLIC ${Boost_LIBRARY_DIRS})
TARGET_LINK_LIBRARIES(msghub Threads::Threads)
TARGET_LINK_LIBRARIES(msghub ${Boost_SYSTEM_LIBRARY})
TARGET_LINK_LIBRARIES(msghub ${Boost_THREAD_LIBRARY})
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
ADD_EXECUTABLE(tester
client_onserverfailure.cpp
connect.cpp
Expand Down
10 changes: 6 additions & 4 deletions test/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <string>

#include <boost/asio.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>

void test_connect()
{
BOOST_AUTO_TEST_SUITE(message_hub)
BOOST_AUTO_TEST_CASE(test_connect) {
{
boost::asio::io_service io_service;

Expand All @@ -17,4 +17,6 @@ void test_connect()
BOOST_CHECK(msghub1.connect("localhost", 0xBEE));
io_service.stop();
}
}
}

BOOST_AUTO_TEST_SUITE_END()
10 changes: 7 additions & 3 deletions test/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
#include <string>

#include <boost/asio.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>

void test_create()
BOOST_AUTO_TEST_SUITE(message_hub)

BOOST_AUTO_TEST_CASE(test_create)
{
// Create 2 instances with same address and port, second shoul fail
{
Expand All @@ -28,4 +30,6 @@ void test_create()
//io_service2.stop();
}

}
}

BOOST_AUTO_TEST_SUITE_END()
34 changes: 3 additions & 31 deletions test/main.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
#include <boost/test/unit_test.hpp>

using namespace boost;
using namespace unit_test;

void test_create();
void test_connect();

void test_subscribe();
void test_unsubscribe();

void test_client_onserverfailure();
void test_server_oncleintfailure();
#define BOOST_TEST_MAIN [0/18287]
#define BOOST_TEST_MODULE msghub

void test_toobigmsg();
void test_emptymsg();

test_suite* init_unit_test_suite(int, char**)
{
test_suite *test = BOOST_TEST_SUITE("messagehub test");

test->add(BOOST_TEST_CASE(&test_create));
test->add(BOOST_TEST_CASE(&test_connect));
test->add(BOOST_TEST_CASE(&test_subscribe));
//test->add(BOOST_TEST_CASE(&test_unsubscribe));
//test->add(BOOST_TEST_CASE(&test_client_onserverfailure));
//test->add(BOOST_TEST_CASE(&test_server_oncleintfailure));
//test->add(BOOST_TEST_CASE(&test_toobigmsg));
//test->add(BOOST_TEST_CASE(&test_emptymsg));

return test;
}
#include <boost/test/unit_test.hpp>
14 changes: 10 additions & 4 deletions test/subscribe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/test/unit_test_suite.hpp>
#include <boost/test/unit_test_monitor.hpp>
#include <boost/test/test_tools.hpp>

std::mutex mutant;
std::condition_variable newmessage;
bool goodmessage = false;
BOOST_AUTO_TEST_SUITE(message_hub)

static std::mutex mutant;
static std::condition_variable newmessage;
static bool goodmessage = false;

using namespace boost::unit_test;

void test_create_on_message(const std::string& topic, std::vector<char> const& message)
{
std::unique_lock<std::mutex> lock(mutant);
Expand All @@ -32,7 +36,7 @@ bool publish_message(msghub& msghub)
return true;
}

void test_subscribe()
BOOST_AUTO_TEST_CASE(test_subscribe)
{
boost::asio::io_service io_service;
msghub msghub(io_service);
Expand All @@ -46,3 +50,5 @@ void test_subscribe()
io_service.stop();
//io_service1.stop();
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit b650a6b

Please sign in to comment.