diff --git a/CMakeLists.txt b/CMakeLists.txt index 499b1e4..4bf4748 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,12 +28,12 @@ cmake_minimum_required (VERSION 2.8.8) project(EPANET) +include(CTest) # Append local dir to module search path list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -option(BUILD_TESTS "Build unit tests (requires Boost test)" OFF) option(BUILD_PY_LIB "Build library for Python wrapper" OFF) option(BUILD_COVERAGE "Build library for coverage" OFF) @@ -43,10 +43,12 @@ IF (NOT BUILD_PY_LIB) ENDIF (NOT BUILD_PY_LIB) add_subdirectory(src/outfile) -IF (BUILD_TESTS) +IF (BUILD_TESTING) + enable_testing() add_subdirectory(tests) add_subdirectory(tests/outfile) -ENDIF (BUILD_TESTS) + add_subdirectory(tests/util) +ENDIF (BUILD_TESTING) # Sets for output directory for executables and libraries. diff --git a/appveyor.yml b/appveyor.yml index 7db9355..c02546e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,6 +21,7 @@ environment: GENERATOR: "Visual Studio 15 2017" GROUP: "SUPPORTED" BOOST_ROOT: "C:/Libraries/boost_1_67_0" + PLATFORM: "win32" REF_BUILD_ID: "220dev5" # New build on Visual Studio 15 2017 @@ -37,6 +38,7 @@ init: - set EPANET_HOME=%APPVEYOR_BUILD_FOLDER% - set BUILD_HOME=buildprod - set TEST_HOME=nrtestsuite + - set PATH=%PATH%;%BOOST_ROOT%/ # See values set - echo %APPVEYOR_BUILD_WORKER_IMAGE% diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 375561c..12807c1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,6 @@ #Setup CMake to run tests enable_testing() - # Sets for output directory for executables and libraries. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) @@ -25,6 +24,7 @@ IF(MSVC) set(Boost_DEBUG OFF) set(Boost_DETAILED_FAILURE_MSG OFF) set(Boost_USE_STATIC_LIBS OFF) + add_definitions(-DBOOST_ALL_DYN_LINK) ENDIF(MSVC) set(Boost_THREAD_FOUND OFF) diff --git a/tests/outfile/CMakeLists.txt b/tests/outfile/CMakeLists.txt index e7c2de7..b14bb84 100644 --- a/tests/outfile/CMakeLists.txt +++ b/tests/outfile/CMakeLists.txt @@ -9,11 +9,19 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set (Boost_USE_STATIC_LIBS OFF) +if (MSVC) + set (Boost_USE_STATIC_LIBS OFF) + add_definitions(-DBOOST_ALL_DYN_LINK) +endif(MSVC) + find_package(Boost COMPONENTS unit_test_framework) include_directories (${Boost_INCLUDE_DIRS} ../../src/outfile/include) -add_executable(test_errormanager test_output.cpp) +add_executable(test_output test_output.cpp) -target_link_libraries(test_errormanager ${Boost_LIBRARIES} epanet-output) +target_link_libraries(test_output ${Boost_LIBRARIES} epanet-output) + +add_test(NAME test_output + COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_output + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data) diff --git a/tests/outfile/data/example1.out b/tests/outfile/data/example1.out new file mode 100644 index 0000000..416c98b Binary files /dev/null and b/tests/outfile/data/example1.out differ diff --git a/tests/outfile/test_output.cpp b/tests/outfile/test_output.cpp index eb381b2..bcae21d 100644 --- a/tests/outfile/test_output.cpp +++ b/tests/outfile/test_output.cpp @@ -8,13 +8,7 @@ * Unit testing for EPANET Output API. */ -// NOTE: Travis installs libboost test version 1.5.4 -// NOTE: Can not dyn link boost using Visual Studio 10 2010 -//#define BOOST_TEST_DYN_LINK - - #define BOOST_TEST_MODULE "output" -#define BOOST_TEST_DYN_LINK #include #include diff --git a/tests/test_analysis.cpp b/tests/test_analysis.cpp index 2b1e367..f7120f1 100644 --- a/tests/test_analysis.cpp +++ b/tests/test_analysis.cpp @@ -11,7 +11,7 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK +//#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_control.cpp b/tests/test_control.cpp index 8a3f309..32b3f5f 100644 --- a/tests/test_control.cpp +++ b/tests/test_control.cpp @@ -17,8 +17,6 @@ nodes and links from a project. Deletion can be conditional on node or link appearing in any simple or rule-based controls. */ - -#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_demand.cpp b/tests/test_demand.cpp index 5ad8272..3a7d38f 100644 --- a/tests/test_demand.cpp +++ b/tests/test_demand.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_hydraulics.cpp b/tests/test_hydraulics.cpp index 0da7e50..8fe81a0 100644 --- a/tests/test_hydraulics.cpp +++ b/tests/test_hydraulics.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK #include #include diff --git a/tests/test_link.cpp b/tests/test_link.cpp index aaa5b4e..0b9a25a 100644 --- a/tests/test_link.cpp +++ b/tests/test_link.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_net_builder.cpp b/tests/test_net_builder.cpp index daaa2b6..5c6f274 100644 --- a/tests/test_net_builder.cpp +++ b/tests/test_net_builder.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_node.cpp b/tests/test_node.cpp index a15793b..68376fd 100644 --- a/tests/test_node.cpp +++ b/tests/test_node.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_pattern.cpp b/tests/test_pattern.cpp index b3b6542..a13cab6 100644 --- a/tests/test_pattern.cpp +++ b/tests/test_pattern.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_project.cpp b/tests/test_project.cpp index 351f695..6f0b68c 100644 --- a/tests/test_project.cpp +++ b/tests/test_project.cpp @@ -11,8 +11,6 @@ ****************************************************************************** */ - -#define BOOST_ALL_DYN_LINK #include #include diff --git a/tests/test_quality.cpp b/tests/test_quality.cpp index e2eeaef..973732a 100644 --- a/tests/test_quality.cpp +++ b/tests/test_quality.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_reent.cpp b/tests/test_reent.cpp index f296117..14cf154 100644 --- a/tests/test_reent.cpp +++ b/tests/test_reent.cpp @@ -11,13 +11,12 @@ ****************************************************************************** */ +#include + #include #include #include -#define BOOST_ALL_DYN_LINK -#include - #include "epanet2_2.h" #define NUM_THREADS 2 diff --git a/tests/test_report.cpp b/tests/test_report.cpp index 8f9e82c..f1268a3 100644 --- a/tests/test_report.cpp +++ b/tests/test_report.cpp @@ -11,7 +11,6 @@ ****************************************************************************** */ -#define BOOST_ALL_DYN_LINK #include #include "test_toolkit.hpp" diff --git a/tests/test_toolkit.cpp b/tests/test_toolkit.cpp index 8c4b191..33945c8 100644 --- a/tests/test_toolkit.cpp +++ b/tests/test_toolkit.cpp @@ -11,9 +11,7 @@ ****************************************************************************** */ - #define BOOST_TEST_MODULE toolkit -#define BOOST_ALL_DYN_LINK #include diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt index df2f743..2c380ff 100644 --- a/tests/util/CMakeLists.txt +++ b/tests/util/CMakeLists.txt @@ -1,10 +1,20 @@ -cmake_minimum_required(VERSION 3.12) enable_testing() -set (Boost_USE_STATIC_LIBS OFF) +# Sets for output directory for executables and libraries +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + + +IF(MSVC) + set (Boost_USE_STATIC_LIBS OFF) + add_definitions(-DBOOST_ALL_DYN_LINK) +ENDIF(MSVC) + + find_package(Boost COMPONENTS unit_test_framework) include_directories (${Boost_INCLUDE_DIRS} ../../src/) @@ -16,3 +26,6 @@ set (test_source add_executable(test_errormanager ${test_source}) target_link_libraries(test_errormanager ${Boost_LIBRARIES}) + +add_test(NAME test_errormanager + COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_errormanager) diff --git a/tests/util/test_errormanager.cpp b/tests/util/test_errormanager.cpp index 7d270ae..0003ee2 100644 --- a/tests/util/test_errormanager.cpp +++ b/tests/util/test_errormanager.cpp @@ -1,7 +1,7 @@ #define BOOST_TEST_MODULE errormanager -#define BOOST_TEST_DYN_LINK +//#define BOOST_TEST_DYN_LINK #include #include "util/errormanager.h" @@ -37,19 +37,19 @@ BOOST_AUTO_TEST_SUITE(test_errormanager) BOOST_AUTO_TEST_CASE (test_create_destroy) { error_handle_t *error_handle = NULL; - error_handle = error_new_manager(&mock_lookup); + error_handle = create_error_manager(&mock_lookup); - error_dst_manager(error_handle); + delete_error_manager(error_handle); } struct Fixture{ Fixture() { error_message = NULL; - error_handle = error_new_manager(&mock_lookup); + error_handle = create_error_manager(&mock_lookup); } ~Fixture() { - error_dst_manager(error_handle); + delete_error_manager(error_handle); free(error_message); } int error; @@ -60,21 +60,21 @@ struct Fixture{ BOOST_FIXTURE_TEST_CASE (test_set_clear, Fixture) { - error = error_set(error_handle, 100); + error = set_error(error_handle, 100); BOOST_CHECK(error == 100); - error_clear(error_handle); - error = error_check(error_handle, &error_message); + clear_error(error_handle); + error = check_error(error_handle, &error_message); BOOST_CHECK(error == 0); BOOST_CHECK(error_message == NULL); } BOOST_FIXTURE_TEST_CASE(test_set_check, Fixture) { - error = error_set(error_handle, 100); + error = set_error(error_handle, 100); BOOST_CHECK(error == 100); - error = error_check(error_handle, &error_message); + error = check_error(error_handle, &error_message); BOOST_CHECK(check_string(error_message, MESSAGE_STRING)); }