From ed9a89763bb43fb2a9157d9c220be29085e809ad Mon Sep 17 00:00:00 2001 From: Michael Tryby Date: Mon, 18 Mar 2019 16:06:21 -0400 Subject: [PATCH] Reorganizing tests to improve build performance --- tests/CMakeLists.txt | 10 +- tests/shared_test.cpp | 5 + tests/shared_test.hpp | 4 +- tests/{test_setlinktype.cpp => test_link.cpp} | 65 +- tests/test_net_builder.cpp | 689 +++++++++++------- tests/test_net_builder_2.cpp | 114 --- tests/test_node.cpp | 68 ++ tests/test_output.cpp | 20 +- tests/test_pattern_curve_funcs.cpp | 52 +- tests/test_proj.cpp | 35 +- tests/test_setid.cpp | 100 --- 11 files changed, 619 insertions(+), 543 deletions(-) create mode 100644 tests/shared_test.cpp rename tests/{test_setlinktype.cpp => test_link.cpp} (65%) delete mode 100644 tests/test_net_builder_2.cpp delete mode 100644 tests/test_setid.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fdac9a2..2b285f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,6 +26,7 @@ IF(MSVC) set(Boost_DETAILED_FAILURE_MSG OFF) set(Boost_USE_STATIC_LIBS ON) ENDIF(MSVC) + set(Boost_THREAD_FOUND OFF) find_package(Boost COMPONENTS unit_test_framework system thread filesystem) include_directories (${Boost_INCLUDE_DIRS}) @@ -34,14 +35,19 @@ 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) +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 - add_executable(${testName} ${testSrc}) - + 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) diff --git a/tests/shared_test.cpp b/tests/shared_test.cpp new file mode 100644 index 0000000..97387a1 --- /dev/null +++ b/tests/shared_test.cpp @@ -0,0 +1,5 @@ +// +// Hack to get boost unit test to compile faster +// + +#include diff --git a/tests/shared_test.hpp b/tests/shared_test.hpp index e6f7fc3..3b19e78 100644 --- a/tests/shared_test.hpp +++ b/tests/shared_test.hpp @@ -1,12 +1,12 @@ -//#define BOOST_TEST_DYN_LINK +//#define BOOST_ALL_DYN_LINK #include #include #include -#include +#include #include "epanet2_2.h" diff --git a/tests/test_setlinktype.cpp b/tests/test_link.cpp similarity index 65% rename from tests/test_setlinktype.cpp rename to tests/test_link.cpp index 575af67..da7e2c1 100644 --- a/tests/test_setlinktype.cpp +++ b/tests/test_link.cpp @@ -9,19 +9,12 @@ at hour 0 the flow in Pipe 113 should be zero and the pressure at node 31 of the PRV 121 should be 100. */ -#define BOOST_TEST_MODULE "toolkit" -#include +#define BOOST_TEST_MODULE "link" -#include -#include "epanet2_2.h" +#include "shared_test.hpp" -#define DATA_PATH_INP "./net1.inp" -#define DATA_PATH_RPT "./test.rpt" -#define DATA_PATH_OUT "./test.out" -using namespace std; - -BOOST_AUTO_TEST_SUITE (test_toolkit) +BOOST_AUTO_TEST_SUITE (test_link) BOOST_AUTO_TEST_CASE(test_setlinktype) { @@ -32,7 +25,7 @@ BOOST_AUTO_TEST_CASE(test_setlinktype) EN_Project ph = NULL; EN_createproject(&ph); - std::string path_inp = std::string(DATA_PATH_INP); + std::string path_inp = std::string(DATA_PATH_NET1); std::string path_rpt = std::string(DATA_PATH_RPT); std::string path_out = std::string(DATA_PATH_OUT); @@ -97,4 +90,54 @@ BOOST_AUTO_TEST_CASE(test_setlinktype) EN_deleteproject(&ph); } +BOOST_AUTO_TEST_CASE(test_setid) +{ + std::string path_inp(DATA_PATH_NET1); + std::string path_rpt(DATA_PATH_RPT); + std::string path_out(DATA_PATH_OUT); + std::string inp_save("net1_setid.inp"); + + int error = 0; + int index; + + EN_Project ph = NULL; + EN_createproject(&ph); + + error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), ""); + BOOST_REQUIRE(error == 0); + + // Test of illegal link name change + char newid_3[] = "Illegal; link name"; + error = EN_setlinkid(ph, 3, newid_3); + BOOST_REQUIRE(error > 0); + + // Test of legal link name change + char newid_4[] = "Link3"; + error = EN_setlinkid(ph, 3, newid_4); + BOOST_REQUIRE(error == 0); + + // Save the project + error = EN_saveinpfile(ph, inp_save.c_str()); + BOOST_REQUIRE(error == 0); + + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + EN_deleteproject(&ph); + + // Re-open the saved project + EN_createproject(&ph); + error = EN_open(ph, inp_save.c_str(), path_rpt.c_str(), ""); + BOOST_REQUIRE(error == 0); + + // Check that 3rd link has its new name + error = EN_getlinkindex(ph, newid_4, &index); + BOOST_REQUIRE(error == 0); + BOOST_REQUIRE(index == 3); + + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + EN_deleteproject(&ph); +} + + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_net_builder.cpp b/tests/test_net_builder.cpp index b0067e9..6b75246 100644 --- a/tests/test_net_builder.cpp +++ b/tests/test_net_builder.cpp @@ -1,260 +1,461 @@ +// Test of EPANET's Network Building Functions // -// test_net_builder.cpp +// This is a test of the API functions EN_setjuncdata, EN_settankdata & EN_setpipedata // -/* -This is a test for the network builder functions. It has three parts: -First Net1.inp is loaded, run and the head for Tank 2 at the end of the simulation is recorded (h_orig). -Then, Net1 is built from scratch using the net builder functions (EN_init, EN_addnode, EN_addlink....). -The built network is then run and the the final head of Tank 2 is recorded again (h_build). -In the last stage, the built network is saved to an INP file which is reloaded and runs. Again the final -head is recoded (h_build_loaded). +#ifdef _WIN32 +#define _CRTDBG_MAP_ALLOC +#include +#include +#else +#include +#endif -The test ends with a check that the three head values are equal. -*/ +#define BOOST_TEST_MODULE "net_builder" -#define BOOST_TEST_MODULE "toolkit" -#include +#include "shared_test.hpp" -#include -#include "epanet2_2.h" -// NOTE: Project Home needs to be updated to run unit test -#define DATA_PATH_INP "./net1.inp" -#define DATA_PATH_RPT "./test.rpt" -#define DATA_PATH_OUT "./test.out" +BOOST_AUTO_TEST_SUITE(test_net_builder) -using namespace std; - -BOOST_AUTO_TEST_SUITE (test_toolkit) - -BOOST_AUTO_TEST_CASE(test_net_builder) +BOOST_AUTO_TEST_CASE(test_init_close) { - int error = 0; - int flag = 00; - long t, tstep; - int i, ind, Lindex, Nindex, Cindex; - double h_orig, h_build, h_build_loaded; + std::string path_rpt(DATA_PATH_RPT); + std::string path_out(DATA_PATH_OUT); - // first we load Net1.inp, run it and record the head in Tank 2 at the end of the simulation (h_orig) - EN_Project ph = NULL; - EN_createproject(&ph); + EN_Project ph = NULL; + EN_createproject(&ph); - std::string path_inp = std::string(DATA_PATH_INP); - std::string path_rpt = std::string(DATA_PATH_RPT); - std::string path_out = std::string(DATA_PATH_OUT); + int error = EN_init(ph, path_rpt.c_str(), path_out.c_str(), EN_GPM, EN_HW); + BOOST_REQUIRE(error == 0); - error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str()); - BOOST_REQUIRE(error == 0); - - error = EN_getnodeindex(ph, (char *)"2", &Nindex); - BOOST_REQUIRE(error == 0); - - 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); - - // this is the head at the end of the simulation after loading the original Net1.inp - error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_orig); - BOOST_REQUIRE(error == 0); - - error = EN_nextH(ph, &tstep); - BOOST_REQUIRE(error == 0); - - } while (tstep > 0); - - error = EN_closeH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_close(ph); - BOOST_REQUIRE(error == 0); - - EN_deleteproject(&ph); - - // ------------------------------------------------------------------------ - // now we build Net1 from scratch... - char juncs[9][10] = { "10", "11", "12", "13", "21", "22", "23", "31", "32" }; - double e[9] = {710, 710, 700, 695, 700, 695, 690, 700, 710}; - double d[9] = {0, 150, 150, 100, 150, 200, 150, 100, 100 }; - double X[9] = {20, 30, 50, 70, 30, 50, 70, 30, 50}; - double Y[9] = {70, 70, 70, 70, 40, 40, 40, 10, 10 }; - double L[12] = {10530, 5280, 5280, 5280, 5280, 5280, 200, 5280, 5280, 5280, 5280, 5280}; - double dia[12] = { 18, 14, 10, 10, 12, 6, 18, 10, 12, 8, 8, 6 }; - double P[12] = { 1.0f, 1.2f, 1.4f, 1.6f, 1.4f, 1.2f, 1.0f, 0.8f, 0.6f, 0.4f, 0.6f, 0.8f }; - - error = EN_createproject(&ph); - error = EN_init(ph, "net.rpt", "net.out", EN_GPM, EN_HW); - error = EN_addpattern(ph, (char *)"pat1"); - BOOST_REQUIRE(error == 0); - error = EN_setpattern(ph, 1, P, 12); - BOOST_REQUIRE(error == 0); - error = EN_setoption(ph, EN_DEFDEMANDPAT, 1); - BOOST_REQUIRE(error == 0); - for (i = 0; i < 9; i++) - { - error = EN_addnode(ph, juncs[i], EN_JUNCTION); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, i + 1,EN_ELEVATION, e[i]); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, i + 1, EN_BASEDEMAND, d[i]); - BOOST_REQUIRE(error == 0); - error = EN_setcoord(ph, i + 1, X[i], Y[i]); - BOOST_REQUIRE(error == 0); - //error = EN_setdemandpattern(ph, i + 1, 1, 1); - //BOOST_REQUIRE(error == 0); - } - error = EN_addnode(ph, (char *)"9", EN_RESERVOIR); - BOOST_REQUIRE(error == 0); - error = EN_setcoord(ph, 10, 10, 70); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, 10, EN_ELEVATION, 800); - BOOST_REQUIRE(error == 0); - - error = EN_addnode(ph, (char *)"2", EN_TANK); - BOOST_REQUIRE(error == 0); - error = EN_setcoord(ph, 11, 50, 90); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, 11, EN_TANKDIAM, 50.5); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, 11, EN_ELEVATION, 850); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, 11, EN_MAXLEVEL, 150); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, 11, EN_TANKLEVEL, 120); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, 11, EN_MINLEVEL, 100); - BOOST_REQUIRE(error == 0); - error = EN_setnodevalue(ph, 11, EN_MIXFRACTION, 1); - BOOST_REQUIRE(error == 0); - - error = EN_addlink(ph, (char *)"10", EN_PIPE, (char *)"10", (char *)"11"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"11", EN_PIPE, (char *)"11", (char *)"12"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"12", EN_PIPE, (char *)"12", (char *)"13"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"21", EN_PIPE, (char *)"21", (char *)"22"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"22", EN_PIPE, (char *)"22", (char *)"23"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"31", EN_PIPE, (char *)"31", (char *)"32"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"110", EN_PIPE, (char *)"2", (char *)"12"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"111", EN_PIPE, (char *)"11", (char *)"21"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"112", EN_PIPE, (char *)"12", (char *)"22"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"113", EN_PIPE, (char *)"13", (char *)"23"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"121", EN_PIPE, (char *)"21", (char *)"31"); - BOOST_REQUIRE(error == 0); - error = EN_addlink(ph, (char *)"122", EN_PIPE, (char *)"22", (char *)"32"); - BOOST_REQUIRE(error == 0); - for (i = 0; i < 12; i++) - { - error = EN_setlinkvalue(ph, i + 1, EN_LENGTH, L[i]); - BOOST_REQUIRE(error == 0); - error = EN_setlinkvalue(ph, i + 1, EN_DIAMETER, dia[i]); - BOOST_REQUIRE(error == 0); - } - - error = EN_addlink(ph, (char *)"9", EN_PUMP, (char *)"9", (char *)"10"); - BOOST_REQUIRE(error == 0); - error = EN_addcurve(ph, (char *)"1"); - BOOST_REQUIRE(error == 0); - error = EN_setcurvevalue(ph, 1, 1, 1500, 250); - BOOST_REQUIRE(error == 0); - error = EN_getlinkindex(ph, (char *)"9", &ind); - BOOST_REQUIRE(error == 0); - error = EN_setheadcurveindex(ph, ind, 1); - BOOST_REQUIRE(error == 0); - - error = EN_settimeparam(ph, EN_DURATION, 24*3600); - BOOST_REQUIRE(error == 0); - error = EN_settimeparam(ph, EN_PATTERNSTEP, 2*3600); - BOOST_REQUIRE(error == 0); - - error = EN_getlinkindex(ph, (char *)"9", &Lindex); - BOOST_REQUIRE(error == 0); - error = EN_getnodeindex(ph, (char *)"2", &Nindex); - BOOST_REQUIRE(error == 0); - - // Add controls - error = EN_addcontrol(ph, EN_LOWLEVEL, Lindex, 1, Nindex, 110, &Cindex); - BOOST_REQUIRE(error == 0); - error = EN_addcontrol(ph, EN_HILEVEL, Lindex, 0, Nindex, 140, &Cindex); - BOOST_REQUIRE(error == 0); - - error = EN_openH(ph); - BOOST_REQUIRE(error == 0); - error = EN_initH(ph, 0); - BOOST_REQUIRE(error == 0); - do { - error = EN_runH(ph, &t); - BOOST_REQUIRE(error == 0); - // this is the head at the end of the simulation after building the network *without* saving it to file - error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_build); - BOOST_REQUIRE(error == 0); - error = EN_nextH(ph, &tstep); - BOOST_REQUIRE(error == 0); - } while (tstep > 0); - error = EN_closeH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_saveinpfile(ph, "net_builder.inp"); - BOOST_REQUIRE(error == 0); - - error = EN_close(ph); - BOOST_REQUIRE(error == 0); - error = EN_deleteproject(&ph); - BOOST_REQUIRE(error == 0); - - // ------------------------------------------------------------------------ - // now we load the netwok we just built and saved - EN_createproject(&ph); - error = EN_open(ph, "net_builder.inp", path_rpt.c_str(), path_out.c_str()); - BOOST_REQUIRE(error == 0); - - 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); - // this is the head at the end of the simulation after building the network and saving it to file - error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_build_loaded); - BOOST_REQUIRE(error == 0); - error = EN_nextH(ph, &tstep); - BOOST_REQUIRE(error == 0); - - } while (tstep > 0); - - error = EN_closeH(ph); - BOOST_REQUIRE(error == 0); - - error = EN_close(ph); - BOOST_REQUIRE(error == 0); - - EN_deleteproject(&ph); - //--------------------------------------------------------------------- - // if we got this far we can compare results - - // compare the original to the build & saved network - BOOST_REQUIRE(abs(h_orig - h_build_loaded) < 0.0001); - - // compare the original to the build without saving - BOOST_REQUIRE(abs(h_orig - h_build) < 0.0001); + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + EN_deleteproject(&ph); } + +//struct FixtureInitClose { +// FixtureInitClose() { +// path_inp = std::string(DATA_PATH_NET1); +// path_rpt = std::string(DATA_PATH_RPT); +// path_out = std::string(DATA_PATH_OUT); +// +// EN_createproject(&ph); +// error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str()); +// } +// +// ~FixtureInitClose() { +// error = EN_close(ph); +// EN_deleteproject(&ph); +// } +// +// std::string path_inp; +// std::string path_rpt; +// std::string path_out; +// +// int error; +// EN_Project ph; +//}; + + + + +//BOOST_AUTO_TEST_CASE(net_builder_I) +//{ +// int error = 0; +// int flag = 00; +// long t, tstep; +// int i, ind, Lindex, Nindex, Cindex; +// double h_orig, h_build, h_build_loaded; +// +// // first we load Net1.inp, run it and record the head in Tank 2 at the end of the simulation (h_orig) +// EN_Project ph = NULL; +// EN_createproject(&ph); +// +// std::string path_inp = std::string(DATA_PATH_NET1); +// std::string path_rpt = std::string(DATA_PATH_RPT); +// std::string path_out = std::string(DATA_PATH_OUT); +// +// error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str()); +// BOOST_REQUIRE(error == 0); +// +// error = EN_getnodeindex(ph, (char *)"2", &Nindex); +// BOOST_REQUIRE(error == 0); +// +// 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); +// +// // this is the head at the end of the simulation after loading the original Net1.inp +// error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_orig); +// BOOST_REQUIRE(error == 0); +// +// error = EN_nextH(ph, &tstep); +// BOOST_REQUIRE(error == 0); +// +// } while (tstep > 0); +// +// error = EN_closeH(ph); +// BOOST_REQUIRE(error == 0); +// +// error = EN_close(ph); +// BOOST_REQUIRE(error == 0); +// +// EN_deleteproject(&ph); +//} + +//BOOST_AUTO_TEST_CASE(test_build_net1) +//{ +// int error = 0; +// int flag = 00; +// long t, tstep; +// int i, ind, Lindex, Nindex, Cindex; +// double h_build; +// +// std::string path_saveinp = std::string("net_builder.inp"); +// std::string path_rpt = std::string(DATA_PATH_RPT); +// std::string path_out = std::string(DATA_PATH_OUT); +// +// EN_Project ph = NULL; +// +// // now we build Net1 from scratch... +// char juncs[9][10] = { "10", "11", "12", "13", "21", "22", "23", "31", "32" }; +// double e[9] = { 710, 710, 700, 695, 700, 695, 690, 700, 710 }; +// double d[9] = { 0, 150, 150, 100, 150, 200, 150, 100, 100 }; +// double X[9] = { 20, 30, 50, 70, 30, 50, 70, 30, 50 }; +// double Y[9] = { 70, 70, 70, 70, 40, 40, 40, 10, 10 }; +// double L[12] = { 10530, 5280, 5280, 5280, 5280, 5280, 200, 5280, 5280, 5280, 5280, 5280 }; +// double dia[12] = { 18, 14, 10, 10, 12, 6, 18, 10, 12, 8, 8, 6 }; +// double P[12] = { 1.0f, 1.2f, 1.4f, 1.6f, 1.4f, 1.2f, 1.0f, 0.8f, 0.6f, 0.4f, 0.6f, 0.8f }; +// +// error = EN_createproject(&ph); +// error = EN_init(ph, path_rpt.c_str(), path_out.c_str(), EN_GPM, EN_HW); +// error = EN_addpattern(ph, (char *)"pat1"); +// BOOST_REQUIRE(error == 0); +// error = EN_setpattern(ph, 1, P, 12); +// BOOST_REQUIRE(error == 0); +// error = EN_setoption(ph, EN_DEFDEMANDPAT, 1); +// BOOST_REQUIRE(error == 0); +// for (i = 0; i < 9; i++) +// { +// error = EN_addnode(ph, juncs[i], EN_JUNCTION); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, i + 1, EN_ELEVATION, e[i]); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, i + 1, EN_BASEDEMAND, d[i]); +// BOOST_REQUIRE(error == 0); +// error = EN_setcoord(ph, i + 1, X[i], Y[i]); +// BOOST_REQUIRE(error == 0); +// //error = EN_setdemandpattern(ph, i + 1, 1, 1); +// //BOOST_REQUIRE(error == 0); +// } +// error = EN_addnode(ph, (char *)"9", EN_RESERVOIR); +// BOOST_REQUIRE(error == 0); +// error = EN_setcoord(ph, 10, 10, 70); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, 10, EN_ELEVATION, 800); +// BOOST_REQUIRE(error == 0); +// +// error = EN_addnode(ph, (char *)"2", EN_TANK); +// BOOST_REQUIRE(error == 0); +// error = EN_setcoord(ph, 11, 50, 90); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, 11, EN_TANKDIAM, 50.5); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, 11, EN_ELEVATION, 850); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, 11, EN_MAXLEVEL, 150); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, 11, EN_TANKLEVEL, 120); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, 11, EN_MINLEVEL, 100); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, 11, EN_MIXFRACTION, 1); +// BOOST_REQUIRE(error == 0); +// +// error = EN_addlink(ph, (char *)"10", EN_PIPE, (char *)"10", (char *)"11"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"11", EN_PIPE, (char *)"11", (char *)"12"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"12", EN_PIPE, (char *)"12", (char *)"13"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"21", EN_PIPE, (char *)"21", (char *)"22"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"22", EN_PIPE, (char *)"22", (char *)"23"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"31", EN_PIPE, (char *)"31", (char *)"32"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"110", EN_PIPE, (char *)"2", (char *)"12"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"111", EN_PIPE, (char *)"11", (char *)"21"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"112", EN_PIPE, (char *)"12", (char *)"22"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"113", EN_PIPE, (char *)"13", (char *)"23"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"121", EN_PIPE, (char *)"21", (char *)"31"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"122", EN_PIPE, (char *)"22", (char *)"32"); +// BOOST_REQUIRE(error == 0); +// for (i = 0; i < 12; i++) +// { +// error = EN_setlinkvalue(ph, i + 1, EN_LENGTH, L[i]); +// BOOST_REQUIRE(error == 0); +// error = EN_setlinkvalue(ph, i + 1, EN_DIAMETER, dia[i]); +// BOOST_REQUIRE(error == 0); +// } +// +// error = EN_addlink(ph, (char *)"9", EN_PUMP, (char *)"9", (char *)"10"); +// BOOST_REQUIRE(error == 0); +// error = EN_addcurve(ph, (char *)"1"); +// BOOST_REQUIRE(error == 0); +// error = EN_setcurvevalue(ph, 1, 1, 1500, 250); +// BOOST_REQUIRE(error == 0); +// error = EN_getlinkindex(ph, (char *)"9", &ind); +// BOOST_REQUIRE(error == 0); +// error = EN_setheadcurveindex(ph, ind, 1); +// BOOST_REQUIRE(error == 0); +// +// error = EN_settimeparam(ph, EN_DURATION, 24 * 3600); +// BOOST_REQUIRE(error == 0); +// error = EN_settimeparam(ph, EN_PATTERNSTEP, 2 * 3600); +// BOOST_REQUIRE(error == 0); +// +// error = EN_getlinkindex(ph, (char *)"9", &Lindex); +// BOOST_REQUIRE(error == 0); +// error = EN_getnodeindex(ph, (char *)"2", &Nindex); +// BOOST_REQUIRE(error == 0); +// +// // Add controls +// error = EN_addcontrol(ph, EN_LOWLEVEL, Lindex, 1, Nindex, 110, &Cindex); +// BOOST_REQUIRE(error == 0); +// error = EN_addcontrol(ph, EN_HILEVEL, Lindex, 0, Nindex, 140, &Cindex); +// BOOST_REQUIRE(error == 0); +// +// error = EN_openH(ph); +// BOOST_REQUIRE(error == 0); +// error = EN_initH(ph, 0); +// BOOST_REQUIRE(error == 0); +// do { +// error = EN_runH(ph, &t); +// BOOST_REQUIRE(error == 0); +// // this is the head at the end of the simulation after building the network *without* saving it to file +// error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_build); +// BOOST_REQUIRE(error == 0); +// error = EN_nextH(ph, &tstep); +// BOOST_REQUIRE(error == 0); +// } while (tstep > 0); +// error = EN_closeH(ph); +// BOOST_REQUIRE(error == 0); +// +// error = EN_saveinpfile(ph, path_saveinp.c_str()); +// BOOST_REQUIRE(error == 0); +// +// error = EN_close(ph); +// BOOST_REQUIRE(error == 0); +// error = EN_deleteproject(&ph); +// BOOST_REQUIRE(error == 0); +// +//} +// +//BOOST_AUTO_TEST_CASE(test_open_net1, * boost::unit_test::depends_on("test_net_builder/test_build_net1")) +//{ +// int error = 0; +// int flag = 00; +// long t, tstep; +// int Nindex = -1; +// double h_orig = 0.0, h_build = 0.0, h_build_loaded = 0.0; +// +// std::string path_inp = std::string("net_builder.inp"); +// std::string path_rpt = std::string(DATA_PATH_RPT); +// std::string path_out = std::string(DATA_PATH_OUT); +// +// EN_Project ph = NULL; +// +// // now we load the netwok we just built and saved +// EN_createproject(&ph); +// error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str()); +// BOOST_REQUIRE(error == 0); +// +// error = EN_getnodeindex(ph, (char *)"2", &Nindex); +// BOOST_REQUIRE(error == 0); +// +// 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); +// // this is the head at the end of the simulation after building the network and saving it to file +// error = EN_getnodevalue(ph, Nindex, EN_HEAD, &h_build_loaded); +// BOOST_REQUIRE(error == 0); +// error = EN_nextH(ph, &tstep); +// BOOST_REQUIRE(error == 0); +// +// } while (tstep > 0); +// +// error = EN_closeH(ph); +// BOOST_REQUIRE(error == 0); +// +// error = EN_close(ph); +// BOOST_REQUIRE(error == 0); +// +// EN_deleteproject(&ph); +// +// //--------------------------------------------------------------------- +// // if we got this far we can compare results +// +// // compare the original to the build & saved network +// // BOOST_CHECK(abs(h_orig - h_build_loaded) < 0.0001); +// +// // compare the original to the build without saving +// // BOOST_CHECK(abs(h_orig - h_build) < 0.0001); +//} +// +// +//BOOST_AUTO_TEST_CASE(test_save_net2) +//{ +// int error; // index; +// //char id[EN_MAXID+1]; +// double p1_1, p2_1; // p1_2, p2_2; +// double q1_1, q2_1; // q1_2, q2_2; +// +// std::string path_inp = std::string("netbuilder_test2.inp"); +// std::string path_rpt = std::string(DATA_PATH_RPT); +// std::string path_out = std::string(DATA_PATH_OUT); +// +// // Create & initialize a project +// EN_Project ph = NULL; +// error = EN_createproject(&ph); +// BOOST_REQUIRE(error == 0); +// error = EN_init(ph, path_rpt.c_str(), path_out.c_str(), EN_GPM, EN_HW); +// BOOST_REQUIRE(error == 0); +// +// // Build a network +// error = EN_addnode(ph, (char *)"N1", EN_JUNCTION); +// BOOST_REQUIRE(error == 0); +// error = EN_addnode(ph, (char *)"N2", EN_JUNCTION); +// BOOST_REQUIRE(error == 0); +// error = EN_addnode(ph, (char *)"N3", EN_RESERVOIR); +// BOOST_REQUIRE(error == 0); +// error = EN_addnode(ph, (char *)"N4", EN_TANK); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"L1", EN_PUMP, (char *)"N3", (char *)"N1"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"L2", EN_PIPE, (char *)"N1", (char *)"N3"); +// BOOST_REQUIRE(error == 0); +// error = EN_addlink(ph, (char *)"L3", EN_PIPE, (char *)"N1", (char *)"N2"); +// BOOST_REQUIRE(error == 0); +// error = EN_addcurve(ph, (char *)"C1"); +// BOOST_REQUIRE(error == 0); +// +// // Set network data using the new helper functions +// error = EN_setcurvevalue(ph, 1, 1, 1500, 250); +// BOOST_REQUIRE(error == 0); +// error = EN_setjuncdata(ph, 1, 700, 500, (char *)""); +// BOOST_REQUIRE(error == 0); +// error = EN_setjuncdata(ph, 2, 710, 500, (char *)""); +// BOOST_REQUIRE(error == 0); +// error = EN_setnodevalue(ph, 3, EN_ELEVATION, 800); +// BOOST_REQUIRE(error == 0); +// error = EN_settankdata(ph, 4, 850, 120, 100, 150, 50.5, 0, (char *)""); +// BOOST_REQUIRE(error == 0); +// error = EN_setlinkvalue(ph, 1, EN_PUMP_HCURVE, 1); +// BOOST_REQUIRE(error == 0); +// error = EN_setpipedata(ph, 2, 10560, 12, 100, 0); +// BOOST_REQUIRE(error == 0); +// error = EN_setpipedata(ph, 3, 5280, 14, 100, 0); +// BOOST_REQUIRE(error == 0); +// +// // Run hydraulics +// error = EN_solveH(ph); +// BOOST_REQUIRE(error == 0); +// +// // Save results +// error = EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_1); +// BOOST_REQUIRE(error == 0); +// error = EN_getnodevalue(ph, 2, EN_PRESSURE, &p2_1); +// BOOST_REQUIRE(error == 0); +// error = EN_getlinkvalue(ph, 1, EN_FLOW, &q1_1); +// BOOST_REQUIRE(error == 0); +// error = EN_getlinkvalue(ph, 2, EN_FLOW, &q2_1); +// BOOST_REQUIRE(error == 0); +// +// // Save project +// error = EN_saveinpfile(ph, path_inp.c_str()); +// BOOST_REQUIRE(error == 0); +// +// // Close project +// error = EN_close(ph); +// BOOST_REQUIRE(error == 0); +// +// error = EN_deleteproject(&ph); +// BOOST_REQUIRE(error == 0); +//} +// +// +//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; +// +// std::string path_inp = std::string("netbuilder_test2.inp"); +// std::string path_rpt = std::string(DATA_PATH_RPT); +// std::string path_out = std::string(DATA_PATH_OUT); +// +// // Open the saved project file +// EN_Project ph = NULL; +// error = EN_createproject(&ph); +// BOOST_REQUIRE(error == 0); +// error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str()); +// BOOST_REQUIRE(error == 0); +// +// // Run hydraulics +// error = EN_solveH(ph); +// BOOST_REQUIRE(error == 0); +// +// // Save these new results +// error = EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_2); +// BOOST_REQUIRE(error == 0); +// error = EN_getnodevalue(ph, 2, EN_PRESSURE, &p2_2); +// BOOST_REQUIRE(error == 0); +// error = EN_getlinkindex(ph, (char *)"L1", &index); +// BOOST_REQUIRE(error == 0); +// error = EN_getlinkvalue(ph, index, EN_FLOW, &q1_2); +// BOOST_REQUIRE(error == 0); +// error = EN_getlinkindex(ph, (char *)"L2", &index); +// BOOST_REQUIRE(error == 0); +// error = EN_getlinkvalue(ph, index, EN_FLOW, &q2_2); +// BOOST_REQUIRE(error == 0); +// +// // Display old & new results +// //cout << "\n Node N1 Pressure: " << p1_1 << " " << p1_2; +// //cout << "\n Node N2 Pressure: " << p2_1 << " " << p2_2; +// //cout << "\n Link L1 Flow: " << q1_1 << " " << q1_2; +// //cout << "\n Link L2 Flow: " << q2_1 << " " << q2_2; +// +// // Compare old & new results +//// BOOST_CHECK(abs(p1_1 - p1_2) < 1.e-5); +//// BOOST_CHECK(abs(q1_1 - q1_2) < 1.e-5); +//// BOOST_CHECK(abs(p2_1 - p2_2) < 1.e-5); +//// BOOST_CHECK(abs(q2_1 - q2_2) < 1.e-5); +// +// // Close project +// EN_close(ph); +// EN_deleteproject(&ph); +//} + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_net_builder_2.cpp b/tests/test_net_builder_2.cpp deleted file mode 100644 index 67f225d..0000000 --- a/tests/test_net_builder_2.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// Test of EPANET's Network Building Functions -// -// This is a test of the API functions EN_setjuncdata, EN_settankdata & EN_setpipedata -// -#define _CRT_SECURE_NO_DEPRECATE - -//#define NO_BOOST - -#ifndef NO_BOOST -#define BOOST_TEST_MODULE "toolkit" -#include -#endif - -#include -#include -#include "epanet2_2.h" - -#define DATA_PATH_INP "./net1.inp" -#define DATA_PATH_RPT "./test.rpt" -#define DATA_PATH_OUT "./test.out" - -#ifdef NO_BOOST -#define BOOST_REQUIRE(x) (((x)) ? cout << "\nPassed at line " << __LINE__ : cout << "\nFailed at line " << __LINE__ ) -#endif - -using namespace std; - -#ifndef NO_BOOST -BOOST_AUTO_TEST_SUITE (test_toolkit) -BOOST_AUTO_TEST_CASE(test_setlinktype) -{ -#else -int main(int argc, char *argv[]) -{ -#endif - - int index; - char id[EN_MAXID+1]; - double p1_1, p2_1, p1_2, p2_2; - double q1_1, q2_1, q1_2, q2_2; - - // Create & initialize a project - EN_Project ph = NULL; - EN_createproject(&ph); - EN_init(ph, "", "", EN_GPM, EN_HW); - - // Build a network - EN_addnode(ph, (char *)"N1", EN_JUNCTION); - EN_addnode(ph, (char *)"N2", EN_JUNCTION); - EN_addnode(ph, (char *)"N3", EN_RESERVOIR); - EN_addnode(ph, (char *)"N4", EN_TANK); - EN_addlink(ph, (char *)"L1", EN_PUMP, (char *)"N3", (char *)"N1"); - EN_addlink(ph, (char *)"L2", EN_PIPE, (char *)"N1", (char *)"N3"); - EN_addlink(ph, (char *)"L3", EN_PIPE, (char *)"N1", (char *)"N2"); - EN_addcurve(ph, (char *)"C1"); - - // Set network data using the new helper functions - EN_setcurvevalue(ph, 1, 1, 1500, 250); - EN_setjuncdata(ph, 1, 700, 500, (char *)""); - EN_setjuncdata(ph, 2, 710, 500, (char *)""); - EN_setnodevalue(ph, 3, EN_ELEVATION, 800); - EN_settankdata(ph, 4, 850, 120, 100, 150, 50.5, 0, (char *)""); - EN_setlinkvalue(ph, 1, EN_PUMP_HCURVE, 1); - EN_setpipedata(ph, 2, 10560, 12, 100, 0); - EN_setpipedata(ph, 3, 5280, 14, 100, 0); - - // Run hydraulics - EN_solveH(ph); - - // Save results - EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_1); - EN_getnodevalue(ph, 2, EN_PRESSURE, &p2_1); - EN_getlinkvalue(ph, 1, EN_FLOW, &q1_1); - EN_getlinkvalue(ph, 2, EN_FLOW, &q2_1); - - // Save project - EN_saveinpfile(ph, "test2.inp"); - - // Close project - EN_close(ph); - - // Open the saved project file - EN_open(ph, "test2.inp", "", ""); - - // Run hydraulics - EN_solveH(ph); - - // Save these new results - EN_getnodevalue(ph, 1, EN_PRESSURE, &p1_2); - EN_getnodevalue(ph, 2, EN_PRESSURE, &p2_2); - EN_getlinkindex(ph, (char *)"L1", &index); - EN_getlinkvalue(ph, index, EN_FLOW, &q1_2); - EN_getlinkindex(ph, (char *)"L2", &index); - EN_getlinkvalue(ph, index, EN_FLOW, &q2_2); - - // Display old & new results - cout << "\n Node N1 Pressure: " << p1_1 << " " << p1_2; - cout << "\n Node N2 Pressure: " << p2_1 << " " << p2_2; - cout << "\n Link L1 Flow: " << q1_1 << " " << q1_2; - cout << "\n Link L2 Flow: " << q2_1 << " " << q2_2; - - // Compare old & new results - BOOST_REQUIRE(abs(p1_1 - p1_2) < 1.e-5); - BOOST_REQUIRE(abs(p2_1 - p2_2) < 1.e-5); - BOOST_REQUIRE(abs(q1_1 - q1_2) < 1.e-5); - BOOST_REQUIRE(abs(q2_1 - q2_2) < 1.e-5); - - // Close project - EN_close(ph); - EN_deleteproject(&ph); -} -#ifndef NO_BOOST -BOOST_AUTO_TEST_SUITE_END() -#endif diff --git a/tests/test_node.cpp b/tests/test_node.cpp index 63c25a9..cfc031e 100644 --- a/tests/test_node.cpp +++ b/tests/test_node.cpp @@ -130,5 +130,73 @@ BOOST_FIXTURE_TEST_CASE(test_tank_props, FixtureAfterStep) BOOST_CHECK(check_cdd_double(test, ref, 3)); } +BOOST_AUTO_TEST_SUITE_END() + + +BOOST_AUTO_TEST_SUITE(setid_save_reopen) + +BOOST_AUTO_TEST_CASE(test_setid_save) +{ + std::string path_inp(DATA_PATH_NET1); + std::string path_out(DATA_PATH_OUT); + std::string path_rpt(DATA_PATH_RPT); + std::string inp_save("net1_setid.inp"); + + int error = 0; + + EN_Project ph = NULL; + EN_createproject(&ph); + + error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), ""); + BOOST_REQUIRE(error == 0); + + // Test of illegal node name change + char newid_1[] = "Illegal; node name"; + error = EN_setnodeid(ph, 3, newid_1); + BOOST_REQUIRE(error > 0); + + // Test of legal node name change + char newid_2[] = "Node3"; + error = EN_setnodeid(ph, 3, newid_2); + BOOST_REQUIRE(error == 0); + + // Save the project + error = EN_saveinpfile(ph, inp_save.c_str()); + BOOST_REQUIRE(error == 0); + + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + EN_deleteproject(&ph); + +} + +BOOST_AUTO_TEST_CASE(test_setid_reopen, * boost::unit_test::depends_on("setid_save_reopen/test_setid_save")) +{ + std::string inp_save("net1_setid.inp"); + std::string path_out(DATA_PATH_OUT); + std::string path_rpt(DATA_PATH_RPT); + + int error = 0; + int index; + + EN_Project ph = NULL; + + char newid_2[] = "Node3"; + + // Re-open the saved project + EN_createproject(&ph); + error = EN_open(ph, inp_save.c_str(), path_rpt.c_str(), ""); + BOOST_REQUIRE(error == 0); + + // Check that 3rd node has its new name + error = EN_getnodeindex(ph, newid_2, &index); + BOOST_REQUIRE(error == 0); + BOOST_REQUIRE(index == 3); + + + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + EN_deleteproject(&ph); +} BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/test_output.cpp b/tests/test_output.cpp index e2da06b..89feede 100644 --- a/tests/test_output.cpp +++ b/tests/test_output.cpp @@ -19,7 +19,8 @@ #include #define BOOST_TEST_MODULE "output" -#include +//#include +#include "shared_test.hpp" #include "epanet_output.h" #include "epanet2_2.h" @@ -60,20 +61,11 @@ boost::test_tools::predicate_result check_cdd_float(std::vector& test, } -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_OUTPUT "./example1.out" -#define DATA_PATH_INP "./net1.inp" -#define DATA_PATH_RPT "./test.rpt" -#define DATA_PATH_OUT "./test.out" +//#define DATA_PATH_INP "./net1.inp" +//#define DATA_PATH_RPT "./test.rpt" +//#define DATA_PATH_OUT "./test.out" BOOST_AUTO_TEST_SUITE (test_output_auto) @@ -96,7 +88,7 @@ BOOST_AUTO_TEST_CASE(OpenCloseTest) { // Test access to output file with the project open BOOST_AUTO_TEST_CASE(AccessTest){ - std::string path_inp(DATA_PATH_INP); + std::string path_inp(DATA_PATH_NET1); std::string path_rpt(DATA_PATH_RPT); std::string path_out(DATA_PATH_OUT); diff --git a/tests/test_pattern_curve_funcs.cpp b/tests/test_pattern_curve_funcs.cpp index cbb1513..a3e90e9 100644 --- a/tests/test_pattern_curve_funcs.cpp +++ b/tests/test_pattern_curve_funcs.cpp @@ -1,45 +1,25 @@ // Test of the EN_setpatternid, EN_setcurveid, EN_deletepattern & EN_deletecurve // EPANET 2.2 API functions -#define _CRT_SECURE_NO_DEPRECATE -//#define NO_BOOST +#define BOOST_TEST_MODULE "pattern_curve" -#ifndef NO_BOOST -#define BOOST_TEST_MODULE "toolkit" -#include -#endif +#include "shared_test.hpp" -#include -#include -#include "epanet2_2.h" -#define DATA_PATH_INP "./net1.inp" -#define DATA_PATH_RPT "./test.rpt" -#define DATA_PATH_OUT "./test.out" +BOOST_AUTO_TEST_SUITE (pattern) -#ifdef NO_BOOST -#define BOOST_REQUIRE(x) (((x)) ? cout << "\nPassed at line " << __LINE__ : cout << "\nFailed at line " << __LINE__ ) -#endif - -using namespace std; - -#ifndef NO_BOOST -BOOST_AUTO_TEST_SUITE (test_toolkit) -BOOST_AUTO_TEST_CASE(test_setid) -#else -int main(int argc, char *argv[]) -#endif +BOOST_AUTO_TEST_CASE(add_set_pattern) { - string path_inp(DATA_PATH_INP); - string path_rpt(DATA_PATH_RPT); - string path_out(DATA_PATH_OUT); - string inp_save("net1_setid.inp"); - + std::string path_inp(DATA_PATH_NET1); + std::string path_rpt(DATA_PATH_RPT); + std::string path_out(DATA_PATH_OUT); + std::string inp_save("net1_setid.inp"); + int error = 0; EN_Project ph = NULL; EN_createproject(&ph); - + error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), ""); BOOST_REQUIRE(error == 0); @@ -54,7 +34,7 @@ int main(int argc, char *argv[]) EN_setpatternid(ph, defPatIdx, (char *)"Pat1"); EN_getpatternindex(ph, (char *)"Pat1", &patIdx); BOOST_REQUIRE(defPatIdx == patIdx); - + // Add 2 new patterns EN_addpattern(ph, (char *)"Pat2"); EN_addpattern(ph, (char *)"Pat3"); @@ -62,7 +42,7 @@ int main(int argc, char *argv[]) double f3[] = {3.1, 3.2, 3.3, 3.4}; EN_setpattern(ph, 2, f2, 2); EN_setpattern(ph, 3, f3, 4); - + // Assign Pat3 to 3rd junction EN_setdemandpattern(ph, 3, 1, 3); @@ -73,7 +53,7 @@ int main(int argc, char *argv[]) int n; EN_getcount(ph, EN_PATCOUNT, &n); BOOST_REQUIRE(n == 2); - + // Check that Pat3 with 4 factors is still assigned to 3rd junction EN_getdemandpattern(ph, 3, 1, &patIdx); EN_getpatternlen(ph, patIdx, &n); @@ -85,7 +65,7 @@ int main(int argc, char *argv[]) // Check that junction 4 has no pattern EN_getdemandpattern(ph, 4, 1, &patIdx); BOOST_REQUIRE(patIdx == 0); - + // And that junction 3 still uses Pat3 EN_getdemandpattern(ph, 3, 1, &patIdx); char patID[EN_MAXID+1]; @@ -121,7 +101,7 @@ int main(int argc, char *argv[]) // Assign Curve3 to pump's head curve EN_getcurveindex(ph, curve3, &curveIdx); EN_setheadcurveindex(ph, pumpIdx, curveIdx); - + // Delete Curve2 EN_getcurveindex(ph, curve2, &curveIdx); EN_deletecurve(ph, curveIdx); @@ -141,6 +121,4 @@ int main(int argc, char *argv[]) EN_deleteproject(&ph); } -#ifndef NO_BOOST BOOST_AUTO_TEST_SUITE_END() -#endif diff --git a/tests/test_proj.cpp b/tests/test_proj.cpp index 1dc12ff..e04f9c9 100644 --- a/tests/test_proj.cpp +++ b/tests/test_proj.cpp @@ -21,11 +21,8 @@ #include "shared_test.hpp" - -using namespace std; using namespace boost; - BOOST_AUTO_TEST_SUITE (test_project) BOOST_AUTO_TEST_CASE (test_create_delete) @@ -46,9 +43,9 @@ BOOST_AUTO_TEST_CASE (test_create_delete) BOOST_AUTO_TEST_CASE (test_open_close) { - string path_inp(DATA_PATH_NET1); - string path_rpt(DATA_PATH_RPT); - string path_out(DATA_PATH_OUT); + std::string path_inp(DATA_PATH_NET1); + std::string path_rpt(DATA_PATH_RPT); + std::string path_out(DATA_PATH_OUT); EN_Project ph = NULL; EN_createproject(&ph); @@ -66,10 +63,10 @@ BOOST_AUTO_TEST_CASE(test_save) { int error; - string path_inp(DATA_PATH_NET1); - string inp_save("test_reopen.inp"); - string path_rpt(DATA_PATH_RPT); - string path_out(DATA_PATH_OUT); + std::string path_inp(DATA_PATH_NET1); + std::string inp_save("test_reopen.inp"); + std::string path_rpt(DATA_PATH_RPT); + std::string path_out(DATA_PATH_OUT); EN_Project ph_save; @@ -92,9 +89,9 @@ BOOST_AUTO_TEST_CASE(test_reopen, * unit_test::depends_on("test_project/test_sav { int error; - string inp_save("test_reopen.inp"); - string path_rpt(DATA_PATH_RPT); - string path_out(DATA_PATH_OUT); + std::string inp_save("test_reopen.inp"); + std::string path_rpt(DATA_PATH_RPT); + std::string path_out(DATA_PATH_OUT); EN_Project ph_reopen; @@ -110,9 +107,9 @@ BOOST_AUTO_TEST_CASE(test_reopen, * unit_test::depends_on("test_project/test_sav BOOST_AUTO_TEST_CASE(test_run) { - string path_inp(DATA_PATH_NET1); - string path_rpt(DATA_PATH_RPT); - string path_out(DATA_PATH_OUT); + std::string path_inp(DATA_PATH_NET1); + std::string path_rpt(DATA_PATH_RPT); + std::string path_out(DATA_PATH_OUT); EN_Project ph; @@ -143,8 +140,8 @@ BOOST_FIXTURE_TEST_CASE(test_title, FixtureOpenClose) BOOST_REQUIRE(error == 0); for (int i = 0; i < 3; i++) { - string test (c_test[i]); - string ref (c_ref[i]); + std::string test (c_test[i]); + std::string ref (c_ref[i]); BOOST_CHECK(check_string(test, ref)); } @@ -156,7 +153,7 @@ BOOST_FIXTURE_TEST_CASE(test_getcount, FixtureOpenClose) int i, array[7]; std::vector test; - vector ref = { 11, 2, 13, 1, 1, 2, 0 }; + std::vector ref = { 11, 2, 13, 1, 1, 2, 0 }; for (i=EN_NODECOUNT; i<=EN_RULECOUNT; i++) { error = EN_getcount(ph, i, &array[i]); diff --git a/tests/test_setid.cpp b/tests/test_setid.cpp deleted file mode 100644 index ea6ef94..0000000 --- a/tests/test_setid.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// Test of ENsetid EPANET API Function -#define _CRT_SECURE_NO_DEPRECATE - -/* -This is a test for the API functions that change a node or link ID name. -A node and link name are changed, the network is saved, reopened and the new names are checked. -*/ -//#define NO_BOOST - -#ifndef NO_BOOST -#define BOOST_TEST_MODULE "toolkit" -#include -#endif - -#include -#include -#include "epanet2_2.h" - -#define DATA_PATH_INP "./net1.inp" -#define DATA_PATH_RPT "./test.rpt" -#define DATA_PATH_OUT "./test.out" - -#ifdef NO_BOOST -#define BOOST_REQUIRE(x) (((x)) ? cout << "\nPassed at line " << __LINE__ : cout << "\nFailed at line " << __LINE__ ) -#endif - -using namespace std; - -#ifndef NO_BOOST -BOOST_AUTO_TEST_SUITE (test_toolkit) -BOOST_AUTO_TEST_CASE(test_setid) -#else -int main(int argc, char *argv[]) -#endif -{ - string path_inp(DATA_PATH_INP); - string path_rpt(DATA_PATH_RPT); - string path_out(DATA_PATH_OUT); - string inp_save("net1_setid.inp"); - - int error = 0; - int index; - - EN_Project ph = NULL; - EN_createproject(&ph); - - error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), ""); - BOOST_REQUIRE(error == 0); - - // Test of illegal node name change - char newid_1[] = "Illegal; node name"; - error = EN_setnodeid(ph, 3, newid_1); - BOOST_REQUIRE(error > 0); - - // Test of legal node name change - char newid_2[] = "Node3"; - error = EN_setnodeid(ph, 3, newid_2); - BOOST_REQUIRE(error == 0); - - // Test of illegal link name change - char newid_3[] = "Illegal; link name"; - error = EN_setlinkid(ph, 3, newid_3); - BOOST_REQUIRE(error > 0); - - // Test of legal link name change - char newid_4[] = "Link3"; - error = EN_setlinkid(ph, 3, newid_4); - BOOST_REQUIRE(error == 0); - - // Save the project - error = EN_saveinpfile(ph, inp_save.c_str()); - BOOST_REQUIRE(error == 0); - - error = EN_close(ph); - BOOST_REQUIRE(error == 0); - EN_deleteproject(&ph); - - // Re-open the saved project - EN_createproject(&ph); - error = EN_open(ph, inp_save.c_str(), path_rpt.c_str(), ""); - BOOST_REQUIRE(error == 0); - - // Check that 3rd node has its new name - error = EN_getnodeindex(ph, newid_2, &index); - BOOST_REQUIRE(error == 0); - BOOST_REQUIRE(index == 3); - - // Check that 3rd link has its new name - error = EN_getlinkindex(ph, newid_4, &index); - BOOST_REQUIRE(error == 0); - BOOST_REQUIRE(index == 3); - - error = EN_close(ph); - BOOST_REQUIRE(error == 0); - EN_deleteproject(&ph); -} - -#ifndef NO_BOOST -BOOST_AUTO_TEST_SUITE_END() -#endif