diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2b285f1..d48dac1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,41 +24,62 @@ endif(UNIX) IF(MSVC) set(Boost_DEBUG OFF) set(Boost_DETAILED_FAILURE_MSG OFF) - set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_STATIC_LIBS OFF) ENDIF(MSVC) set(Boost_THREAD_FOUND OFF) -find_package(Boost COMPONENTS unit_test_framework system thread filesystem) +find_package(Boost COMPONENTS unit_test_framework filesystem) include_directories (${Boost_INCLUDE_DIRS}) -#I like to keep test files in a separate source directory called test -file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test_*.cpp) +set(toolkit_test_srcs + test_toolkit.cpp + test_project.cpp + test_hydraulics.cpp + test_quality.cpp + test_report.cpp + test_analysis.cpp + test_node.cpp + test_demand.cpp + test_link.cpp +# test_pump.cpp + test_pattern.cpp +# test_curve.cpp + test_control.cpp) -add_library(shared_test OBJECT shared_test.cpp) +add_executable(test_toolkit ${toolkit_test_srcs}) + +target_link_libraries(test_toolkit ${Boost_LIBRARIES} epanet2) + + + +#I like to keep test files in a separate source directory called test +#file(GLOB TEST_SRCS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} test_*.cpp) + +#add_library(shared_test OBJECT shared_test.cpp) #Run through each source -foreach(testSrc ${TEST_SRCS}) - #Extract the filename without an extension (NAME_WE) - get_filename_component(testName ${testSrc} NAME_WE) - - #Add compile target - IF(${testName} MATCHES "test_reent") - add_executable(${testName} ${testSrc}) - ELSE (TRUE) - add_executable(${testName} ${testSrc} $) - ENDIF(${testName} MATCHES "test_reent") - - #link to Boost libraries AND your targets and dependencies - IF(MSVC) - target_link_libraries(${testName} ${Boost_LIBRARIES} epanet2 epanet-output) - ELSE(TRUE) - target_link_libraries(${testName} ${Boost_LIBRARIES} pthread epanet2 epanet-output) - ENDIF(MSVC) - - #Finally add it to test execution - #Notice the WORKING_DIRECTORY and COMMAND - add_test(NAME ${testName} - COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testName} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data) -endforeach(testSrc) +#foreach(testSrc ${TEST_SRCS}) +# #Extract the filename without an extension (NAME_WE) +# get_filename_component(testName ${testSrc} NAME_WE) +# +# #Add compile target +# IF(${testName} MATCHES "test_reent") +# add_executable(${testName} ${testSrc}) +# ELSE (TRUE) +# add_executable(${testName} ${testSrc} $) +# ENDIF(${testName} MATCHES "test_reent") +# +# #link to Boost libraries AND your targets and dependencies +# IF(MSVC) +# target_link_libraries(${testName} ${Boost_LIBRARIES} epanet2 epanet-output) +# ELSE(TRUE) +# target_link_libraries(${testName} ${Boost_LIBRARIES} pthread epanet2 epanet-output) +# ENDIF(MSVC) +# +# #Finally add it to test execution +# #Notice the WORKING_DIRECTORY and COMMAND +# add_test(NAME ${testName} +# COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testName} +# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data) +#endforeach(testSrc) diff --git a/tests/shared_test.cpp b/tests/shared_test.cpp deleted file mode 100644 index 97387a1..0000000 --- a/tests/shared_test.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Hack to get boost unit test to compile faster -// - -#include diff --git a/tests/test_rprtanlys.cpp b/tests/test_analysis.cpp similarity index 57% rename from tests/test_rprtanlys.cpp rename to tests/test_analysis.cpp index 01e452c..2b1e367 100644 --- a/tests/test_rprtanlys.cpp +++ b/tests/test_analysis.cpp @@ -1,49 +1,23 @@ -// -// test_rprtanlys.cpp -// -// Date Created: February 28, 2019 -// -// Author: Michael E. Tryby -// US EPA - ORD/NRMRL -// +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_analysis.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ -#define BOOST_TEST_MODULE hydqual +#define BOOST_ALL_DYN_LINK +#include -#include "shared_test.hpp" - -using namespace boost; +#include "test_toolkit.hpp" -BOOST_AUTO_TEST_SUITE (test_rprtanlys) - -BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose) -{ - int i; - double array[5]; - - std::vector test; - std::vector ref = {3.0, 7.0799498320679432e-06, 1.6680242187483429e-08, - 0.0089173150106518495, 0.99999998187144024}; - - error = EN_solveH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_solveQ(ph); - BOOST_REQUIRE(error == 0); - - - for (i=EN_ITERATIONS; i<=EN_MASSBALANCE; i++) { - error = EN_getstatistic(ph, i, &array[i]); - BOOST_REQUIRE(error == 0); - } - - test.assign(array, array + 5); -// BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end()); - BOOST_CHECK(check_cdd_double(test, ref, 3)); - - error = EN_getstatistic(ph, 8, &array[0]); - BOOST_CHECK(error == 251); -} +BOOST_AUTO_TEST_SUITE (test_analysis) BOOST_FIXTURE_TEST_CASE(test_anlys_getoption, FixtureOpenClose) { diff --git a/tests/test_addrule.cpp b/tests/test_control.cpp similarity index 81% rename from tests/test_addrule.cpp rename to tests/test_control.cpp index bbc6172..8a3f309 100644 --- a/tests/test_addrule.cpp +++ b/tests/test_control.cpp @@ -1,5 +1,15 @@ -// Test of EN_addrule, EN_deletenode & EN_deletelink EPANET API Functions -#define _CRT_SECURE_NO_DEPRECATE +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_control.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ /* This is a test for the API functions that adds rules and deletes @@ -8,9 +18,10 @@ node or link appearing in any simple or rule-based controls. */ -#define BOOST_TEST_MODULE "rules" +#define BOOST_ALL_DYN_LINK +#include -#include "shared_test.hpp" +#include "test_toolkit.hpp" char R1[] = "RULE 1 \n IF NODE 2 LEVEL < 100 \n THEN LINK 9 STATUS = OPEN"; @@ -19,7 +30,7 @@ char R3[] = "RULE 3\nIF NODE 23 PRESSURE ABOVE 140\nAND NODE 2 LEVEL > 120\n" "THEN LINK 113 STATUS = CLOSED\nELSE LINK 22 STATUS = CLOSED"; -BOOST_AUTO_TEST_SUITE (test_addrule) +BOOST_AUTO_TEST_SUITE (test_controls) BOOST_FIXTURE_TEST_CASE(test_add_get_rule, FixtureOpenClose) { diff --git a/tests/test_demand_categories.cpp b/tests/test_demand.cpp similarity index 73% rename from tests/test_demand_categories.cpp rename to tests/test_demand.cpp index f4ee864..5ad8272 100644 --- a/tests/test_demand_categories.cpp +++ b/tests/test_demand.cpp @@ -1,18 +1,23 @@ -// -// test_demand_categories.cpp -// - /* -This is a test for the demand categories names get\set APIs -A demand category name is set, the network is saved, reopened and the new demand category name is checked. + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_analysis.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** */ -#define BOOST_TEST_MODULE "demands" +#define BOOST_ALL_DYN_LINK +#include -#include "shared_test.hpp" +#include "test_toolkit.hpp" -BOOST_AUTO_TEST_SUITE (test_demands) +BOOST_AUTO_TEST_SUITE (test_demand) BOOST_AUTO_TEST_CASE(test_categories_save) { @@ -41,7 +46,7 @@ BOOST_AUTO_TEST_CASE(test_categories_save) BOOST_REQUIRE(error == 0); } -BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demands/test_categories_save")) +BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demand/test_categories_save")) { int error = 0; int Nindex, ndem; @@ -59,11 +64,11 @@ BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("tes error = EN_getnumdemands(ph, Nindex, &ndem); BOOST_REQUIRE(error == 0); BOOST_CHECK(ndem == 1); - + char demname[80]; error = EN_getdemandname(ph, Nindex, ndem, demname); BOOST_REQUIRE(error == 0); - + BOOST_CHECK(check_string(demname, "Demand category name")); error = EN_close(ph); diff --git a/tests/test_hydraulics.cpp b/tests/test_hydraulics.cpp new file mode 100644 index 0000000..0da7e50 --- /dev/null +++ b/tests/test_hydraulics.cpp @@ -0,0 +1,85 @@ +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_hydraulics.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ + +#define BOOST_ALL_DYN_LINK +#include +#include + +#include "test_toolkit.hpp" + + +BOOST_AUTO_TEST_SUITE (test_hydraulics) + +BOOST_FIXTURE_TEST_CASE(test_solveH, FixtureOpenClose) +{ + error = EN_solveH(ph); + BOOST_REQUIRE(error == 0); +} + +BOOST_FIXTURE_TEST_CASE(test_hyd_step, FixtureOpenClose) +{ + int flag = 00; + long t, tstep; + + error = EN_openH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_initH(ph, flag); + BOOST_REQUIRE(error == 0); + + do { + error = EN_runH(ph, &t); + BOOST_REQUIRE(error == 0); + + error = EN_nextH(ph, &tstep); + BOOST_REQUIRE(error == 0); + + } while (tstep > 0); + + error = EN_closeH(ph); + BOOST_REQUIRE(error == 0); +} + +BOOST_FIXTURE_TEST_CASE(test_hydr_save, FixtureOpenClose) +{ + error = EN_solveH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_saveH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_report(ph); + BOOST_REQUIRE(error == 0); +} + +BOOST_FIXTURE_TEST_CASE(test_hydr_savefile, FixtureOpenClose) +{ + error = EN_solveH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_savehydfile(ph, "test_savefile.hyd"); + BOOST_REQUIRE(error == 0); + + BOOST_CHECK(boost::filesystem::exists("test_savefile.hyd") == true); +} + +BOOST_FIXTURE_TEST_CASE(test_hydr_usefile, FixtureOpenClose, * boost::unit_test::depends_on("test_hydraulics/test_hydr_savefile")) +{ + error = EN_usehydfile(ph, "test_savefile.hyd"); + BOOST_REQUIRE(error == 0); + + error = EN_solveQ(ph); + BOOST_REQUIRE(error == 0); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_hydrqual.cpp b/tests/test_hydrqual.cpp deleted file mode 100644 index 4364545..0000000 --- a/tests/test_hydrqual.cpp +++ /dev/null @@ -1,163 +0,0 @@ -// -// test_hydrqual.cpp -// -// Date Created: February 28, 2019 -// -// Author: Michael E. Tryby -// US EPA - ORD/NRMRL -// - - -#define BOOST_TEST_MODULE hydrqual - -#include "shared_test.hpp" - - -using namespace std; -using namespace boost; - - -BOOST_AUTO_TEST_SUITE (test_hydrqual) - -BOOST_FIXTURE_TEST_CASE(test_solveH_solveQ, FixtureOpenClose) -{ - error = EN_solveH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_solveQ(ph); - BOOST_REQUIRE(error == 0); - - error = EN_report(ph); - BOOST_REQUIRE(error == 0); -} - -BOOST_FIXTURE_TEST_CASE(test_hyd_step, FixtureOpenClose) -{ - int flag = 00; - long t, tstep; - - error = EN_openH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_initH(ph, flag); - BOOST_REQUIRE(error == 0); - - do { - error = EN_runH(ph, &t); - BOOST_REQUIRE(error == 0); - - error = EN_nextH(ph, &tstep); - BOOST_REQUIRE(error == 0); - - } while (tstep > 0); - - error = EN_closeH(ph); - BOOST_REQUIRE(error == 0); -} - -BOOST_FIXTURE_TEST_CASE(test_qual_step, FixtureOpenClose) -{ - int flag = 0; - long t, tstep; - - error = EN_solveH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_openQ(ph); - BOOST_REQUIRE(error == 0); - - error = EN_initQ(ph, flag); - BOOST_REQUIRE(error == 0); - - do { - error = EN_runQ(ph, &t); - BOOST_REQUIRE(error == 0); - - error = EN_stepQ(ph, &tstep); - BOOST_REQUIRE(error == 0); - - } while (tstep > 0); - - error = EN_closeQ(ph); - BOOST_REQUIRE(error == 0); -} - -BOOST_FIXTURE_TEST_CASE(test_progressive_step, FixtureOpenClose) -{ - int flag = EN_NOSAVE; - long t, tstep_h, tstep_q; - - error = EN_openH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_initH(ph, flag); - BOOST_REQUIRE(error == 0); - - error = EN_openQ(ph); - BOOST_REQUIRE(error == 0); - - error = EN_initQ(ph, flag); - BOOST_REQUIRE(error == 0); - - do { - error = EN_runH(ph, &t); - BOOST_REQUIRE(error == 0); - - error = EN_runQ(ph, &t); - BOOST_REQUIRE(error == 0); - - error = EN_nextH(ph, &tstep_h); - BOOST_REQUIRE(error == 0); - - error = EN_nextQ(ph, &tstep_q); - BOOST_REQUIRE(error == 0); - - } while (tstep_h > 0); - - error = EN_closeH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_closeQ(ph); - BOOST_REQUIRE(error == 0); - -} - -BOOST_FIXTURE_TEST_CASE(test_hydr_save, FixtureOpenClose) -{ - error = EN_solveH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_saveH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_report(ph); - BOOST_REQUIRE(error == 0); -} - -BOOST_FIXTURE_TEST_CASE(test_hydr_savefile, FixtureOpenClose) -{ - string hyd_file("test_savefile.hyd"); - - error = EN_solveH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_savehydfile(ph, hyd_file.c_str()); - BOOST_REQUIRE(error == 0); - - BOOST_CHECK(filesystem::exists(hyd_file) == true); -} - -BOOST_FIXTURE_TEST_CASE(test_hydr_usefile, FixtureOpenClose, * unit_test::depends_on("test_hydrqual/test_hydr_savefile")) -{ - string hyd_file("test_savefile.hyd"); - - error = EN_usehydfile(ph, hyd_file.c_str()); - BOOST_REQUIRE(error == 0); - - error = EN_solveQ(ph); - BOOST_REQUIRE(error == 0); -} - - - -BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_link.cpp b/tests/test_link.cpp index a712b0f..aaa5b4e 100644 --- a/tests/test_link.cpp +++ b/tests/test_link.cpp @@ -1,17 +1,20 @@ -// Test of ENsetlinktype EPANET API Function -#define _CRT_SECURE_NO_DEPRECATE - /* -This is a test for the API function that changes a link's type. -Two links in Net1.inp are changed: Pipe 113 is reversed with a CV added -and Pipe 121 is changed to a 100 psi PRV. After running the revised model, -at hour 0 the flow in Pipe 113 should be zero and the pressure at node 31 -of the PRV 121 should be 100. + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_link.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** */ -#define BOOST_TEST_MODULE "link" +#define BOOST_ALL_DYN_LINK +#include -#include "shared_test.hpp" +#include "test_toolkit.hpp" BOOST_AUTO_TEST_SUITE (test_link) @@ -86,12 +89,8 @@ BOOST_AUTO_TEST_CASE(test_setlinktype) EN_deleteproject(&ph); } -BOOST_AUTO_TEST_SUITE_END() - -BOOST_AUTO_TEST_SUITE(setid_save_reopen) - -BOOST_AUTO_TEST_CASE(test_setid_save) +BOOST_AUTO_TEST_CASE(test_link_setid_save) { int error = 0; @@ -120,7 +119,7 @@ BOOST_AUTO_TEST_CASE(test_setid_save) EN_deleteproject(&ph); } -BOOST_AUTO_TEST_CASE(test_setid_reopen, * boost::unit_test::depends_on("setid_save_reopen/test_setid_save")) +BOOST_AUTO_TEST_CASE(test_link_setid_reopen, * boost::unit_test::depends_on("test_link/test_link_setid_save")) { int error = 0; int index; diff --git a/tests/test_net_builder.cpp b/tests/test_net_builder.cpp index 056e4e6..d6ae6a7 100644 --- a/tests/test_net_builder.cpp +++ b/tests/test_net_builder.cpp @@ -1,7 +1,15 @@ -// Test of EPANET's Network Building Functions -// -// This is a test of the API functions EN_setjuncdata, EN_settankdata & EN_setpipedata -// +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_net_builder.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ #define BOOST_TEST_MODULE "net_builder" @@ -246,7 +254,7 @@ BOOST_AUTO_TEST_CASE(test_open_net1, * boost::unit_test::depends_on("test_net_bu EN_createproject(&ph); error = EN_open(ph, "net_builder.inp", DATA_PATH_RPT, DATA_PATH_OUT); BOOST_REQUIRE(error == 0); - + error = EN_getnodeindex(ph, (char *)"2", &Nindex); BOOST_REQUIRE(error == 0); @@ -351,7 +359,7 @@ BOOST_FIXTURE_TEST_CASE(test_save_net2, FixtureInitClose) BOOST_AUTO_TEST_CASE(test_reopen_net2, *boost::unit_test::depends_on("test_net_builder/test_save_net2")) { int error, index; - + double p1_2, p2_2; double q1_2, q2_2; diff --git a/tests/test_node.cpp b/tests/test_node.cpp index 21ca9df..a15793b 100644 --- a/tests/test_node.cpp +++ b/tests/test_node.cpp @@ -1,18 +1,23 @@ -// -// test_node.cpp -// -// Date Created: February 8, 2019 -// -// Author: Michael E. Tryby -// US EPA - ORD/NRMRL -// +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_node.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ -#define BOOST_TEST_MODULE "node" +#define BOOST_ALL_DYN_LINK +#include -#include "shared_test.hpp" +#include "test_toolkit.hpp" -BOOST_AUTO_TEST_SUITE (node_props_after_open) +BOOST_AUTO_TEST_SUITE (test_node) BOOST_FIXTURE_TEST_CASE(test_junc_props, FixtureOpenClose) { diff --git a/tests/test_pattern_curve_funcs.cpp b/tests/test_pattern.cpp similarity index 87% rename from tests/test_pattern_curve_funcs.cpp rename to tests/test_pattern.cpp index a3e90e9..b3b6542 100644 --- a/tests/test_pattern_curve_funcs.cpp +++ b/tests/test_pattern.cpp @@ -1,9 +1,20 @@ -// Test of the EN_setpatternid, EN_setcurveid, EN_deletepattern & EN_deletecurve -// EPANET 2.2 API functions +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_pattern.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ -#define BOOST_TEST_MODULE "pattern_curve" +#define BOOST_ALL_DYN_LINK +#include -#include "shared_test.hpp" +#include "test_toolkit.hpp" BOOST_AUTO_TEST_SUITE (pattern) diff --git a/tests/test_proj.cpp b/tests/test_project.cpp similarity index 90% rename from tests/test_proj.cpp rename to tests/test_project.cpp index 1fa9258..351f695 100644 --- a/tests/test_proj.cpp +++ b/tests/test_project.cpp @@ -1,17 +1,23 @@ -// -// test_project.cpp -// -// Date Created: January 24, 2018 -// -// Author: Michael E. Tryby -// US EPA - ORD/NRMRL -// +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_project.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ -#define BOOST_TEST_MODULE "project" -#include "shared_test.hpp" +#define BOOST_ALL_DYN_LINK +#include +#include + +#include "test_toolkit.hpp" -using namespace boost; BOOST_AUTO_TEST_SUITE (test_project) @@ -61,14 +67,14 @@ BOOST_AUTO_TEST_CASE(test_save) error = EN_saveinpfile(ph_save, "test_reopen.inp"); BOOST_REQUIRE(error == 0); - BOOST_CHECK(filesystem::exists("test_reopen.inp") == true); + BOOST_CHECK(boost::filesystem::exists("test_reopen.inp") == true); error = EN_close(ph_save); BOOST_REQUIRE(error == 0); EN_deleteproject(&ph_save); } -BOOST_AUTO_TEST_CASE(test_reopen, * unit_test::depends_on("test_project/test_save")) +BOOST_AUTO_TEST_CASE(test_reopen, * boost::unit_test::depends_on("test_project/test_save")) { int error; @@ -100,7 +106,6 @@ BOOST_AUTO_TEST_CASE(test_run) BOOST_AUTO_TEST_SUITE_END() - BOOST_AUTO_TEST_SUITE(test_proj_fixture) BOOST_FIXTURE_TEST_CASE(test_title, FixtureOpenClose) diff --git a/tests/test_quality.cpp b/tests/test_quality.cpp new file mode 100644 index 0000000..e2eeaef --- /dev/null +++ b/tests/test_quality.cpp @@ -0,0 +1,101 @@ +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_quality.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ + +#define BOOST_ALL_DYN_LINK +#include + +#include "test_toolkit.hpp" + + +BOOST_AUTO_TEST_SUITE (test_quality) + +BOOST_FIXTURE_TEST_CASE(test_solveQ, FixtureOpenClose) +{ + error = EN_solveH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_solveQ(ph); + BOOST_REQUIRE(error == 0); + + error = EN_report(ph); + BOOST_REQUIRE(error == 0); +} + +BOOST_FIXTURE_TEST_CASE(test_qual_step, FixtureOpenClose) +{ + int flag = 0; + long t, tstep; + + error = EN_solveH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_openQ(ph); + BOOST_REQUIRE(error == 0); + + error = EN_initQ(ph, flag); + BOOST_REQUIRE(error == 0); + + do { + error = EN_runQ(ph, &t); + BOOST_REQUIRE(error == 0); + + error = EN_stepQ(ph, &tstep); + BOOST_REQUIRE(error == 0); + + } while (tstep > 0); + + error = EN_closeQ(ph); + BOOST_REQUIRE(error == 0); +} + +BOOST_FIXTURE_TEST_CASE(test_progressive_step, FixtureOpenClose) +{ + int flag = EN_NOSAVE; + long t, tstep_h, tstep_q; + + error = EN_openH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_initH(ph, flag); + BOOST_REQUIRE(error == 0); + + error = EN_openQ(ph); + BOOST_REQUIRE(error == 0); + + error = EN_initQ(ph, flag); + BOOST_REQUIRE(error == 0); + + do { + error = EN_runH(ph, &t); + BOOST_REQUIRE(error == 0); + + error = EN_runQ(ph, &t); + BOOST_REQUIRE(error == 0); + + error = EN_nextH(ph, &tstep_h); + BOOST_REQUIRE(error == 0); + + error = EN_nextQ(ph, &tstep_q); + BOOST_REQUIRE(error == 0); + + } while (tstep_h > 0); + + error = EN_closeH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_closeQ(ph); + BOOST_REQUIRE(error == 0); + +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_reent.cpp b/tests/test_reent.cpp index 3a59425..875ad49 100644 --- a/tests/test_reent.cpp +++ b/tests/test_reent.cpp @@ -1,11 +1,14 @@ /* - * test_reent.cpp - * - * Created: 8/30/2018 - * Author: Michael E. Tryby - * US EPA - ORD/NRMRL - * - * Multi-threading / reentrancy test for EPANET Toolkit API. + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_reent.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** */ #include diff --git a/tests/test_report.cpp b/tests/test_report.cpp new file mode 100644 index 0000000..8f9e82c --- /dev/null +++ b/tests/test_report.cpp @@ -0,0 +1,51 @@ +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_report.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ + +#define BOOST_ALL_DYN_LINK +#include + +#include "test_toolkit.hpp" + + +BOOST_AUTO_TEST_SUITE (test_report) + +BOOST_FIXTURE_TEST_CASE(test_rprt_anlysstats, FixtureOpenClose) +{ + int i; + double array[5]; + + std::vector test; + std::vector ref = {3.0, 7.0799498320679432e-06, 1.6680242187483429e-08, + 0.0089173150106518495, 0.99999998187144024}; + + error = EN_solveH(ph); + BOOST_REQUIRE(error == 0); + + error = EN_solveQ(ph); + BOOST_REQUIRE(error == 0); + + + for (i=EN_ITERATIONS; i<=EN_MASSBALANCE; i++) { + error = EN_getstatistic(ph, i, &array[i]); + BOOST_REQUIRE(error == 0); + } + + test.assign(array, array + 5); +// BOOST_CHECK_EQUAL_COLLECTIONS(ref.begin(), ref.end(), test.begin(), test.end()); + BOOST_CHECK(check_cdd_double(test, ref, 3)); + + error = EN_getstatistic(ph, 8, &array[0]); + BOOST_CHECK(error == 251); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_toolkit.cpp b/tests/test_toolkit.cpp new file mode 100644 index 0000000..8c4b191 --- /dev/null +++ b/tests/test_toolkit.cpp @@ -0,0 +1,65 @@ +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_toolkit.cpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ + + +#define BOOST_TEST_MODULE toolkit +#define BOOST_ALL_DYN_LINK + +#include + +#include "test_toolkit.hpp" + + +// Custom test to check the minimum number of correct decimal digits between +// the test and the ref vectors. +boost::test_tools::predicate_result check_cdd_double(std::vector& test, + std::vector& ref, long cdd_tol){ + double tmp, min_cdd = 10.0; + + // TODO: What if the vectors aren't the same length? + + std::vector::iterator test_it; + std::vector::iterator ref_it; + + for (test_it = test.begin(), ref_it = ref.begin(); + (test_it < test.end()) && (ref_it < ref.end()); + ++test_it, ++ref_it) + { + if (*test_it != *ref_it) { + // Compute log absolute error + tmp = abs(*test_it - *ref_it); + if (tmp < 1.0e-7) + tmp = 1.0e-7; + + else if (tmp > 2.0) + tmp = 1.0; + + tmp = -log10(tmp); + if (tmp < 0.0) + tmp = 0.0; + + if (tmp < min_cdd) + min_cdd = tmp; + } + } + + return floor(min_cdd) >= cdd_tol; +} + +boost::test_tools::predicate_result check_string(std::string test, std::string ref) +{ + if (ref.compare(test) == 0) + return true; + else + return false; +} diff --git a/tests/shared_test.hpp b/tests/test_toolkit.hpp similarity index 58% rename from tests/shared_test.hpp rename to tests/test_toolkit.hpp index 19fe8b7..1aa7400 100644 --- a/tests/shared_test.hpp +++ b/tests/test_toolkit.hpp @@ -1,4 +1,18 @@ +/* + ****************************************************************************** + Project: OWA EPANET + Version: 2.2 + Module: test_toolkit.hpp + Description: Tests EPANET toolkit api functions + Authors: see AUTHORS + Copyright: see AUTHORS + License: see LICENSE + Last Updated: 03/21/2019 + ****************************************************************************** +*/ +#ifndef TEST_TOOLKIT_HPP +#define TEST_TOOLKIT_HPP #ifdef _WIN32 @@ -12,58 +26,9 @@ #include -#include -#include - #include "epanet2_2.h" - -// Custom test to check the minimum number of correct decimal digits between -// the test and the ref vectors. -boost::test_tools::predicate_result check_cdd_double(std::vector& test, - std::vector& ref, long cdd_tol){ - double tmp, min_cdd = 10.0; - - // TODO: What if the vectors aren't the same length? - - std::vector::iterator test_it; - std::vector::iterator ref_it; - - for (test_it = test.begin(), ref_it = ref.begin(); - (test_it < test.end()) && (ref_it < ref.end()); - ++test_it, ++ref_it) - { - if (*test_it != *ref_it) { - // Compute log absolute error - tmp = abs(*test_it - *ref_it); - if (tmp < 1.0e-7) - tmp = 1.0e-7; - - else if (tmp > 2.0) - tmp = 1.0; - - tmp = -log10(tmp); - if (tmp < 0.0) - tmp = 0.0; - - if (tmp < min_cdd) - min_cdd = tmp; - } - } - - return floor(min_cdd) >= cdd_tol; -} - -boost::test_tools::predicate_result check_string(std::string test, std::string ref) -{ - if (ref.compare(test) == 0) - return true; - else - return false; -} - - #define DATA_PATH_NET1 "./net1.inp" #define DATA_PATH_RPT "./test.rpt" #define DATA_PATH_OUT "./test.out" @@ -123,3 +88,10 @@ struct FixtureAfterStep{ long t, tstep, tstop; EN_Project ph; }; + +boost::test_tools::predicate_result check_cdd_double(std::vector& test, + std::vector& ref, long cdd_tol); +boost::test_tools::predicate_result check_string(std::string test, std::string ref); + + +#endif //TEST_TOOLKIT_HPP