From a4b2e53768aa5275c655b397a775bc9d5ef8824e Mon Sep 17 00:00:00 2001 From: Michael Tryby Date: Thu, 28 Feb 2019 11:14:15 -0500 Subject: [PATCH] Adding tests for save and use hydraulics file --- include/epanet2_2.h | 6 +++--- src/epanet.c | 12 ++++++------ tests/test_hydqual.cpp | 29 ++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/include/epanet2_2.h b/include/epanet2_2.h index 924bb1a..3e6fbff 100644 --- a/include/epanet2_2.h +++ b/include/epanet2_2.h @@ -220,7 +220,7 @@ typedef struct Project *EN_Project; Do not call this function while the hydraulics solver is open. */ - int DLLEXPORT EN_usehydfile(EN_Project ph, char *filename); + int DLLEXPORT EN_usehydfile(EN_Project ph, const char *filename); /** @brief Opens a project's hydraulic solver. @@ -343,7 +343,7 @@ typedef struct Project *EN_Project; called ::EN_solveH or the ::EN_initH - ::EN_runH - ::EN_nextH sequence with the initflag argument of ::EN_initH set to `EN_SAVE` or `EN_SAVE_AND_INIT`. */ - int DLLEXPORT EN_savehydfile(EN_Project ph, char *filename); + int DLLEXPORT EN_savehydfile(EN_Project ph, const char *filename); /** @brief Closes the hydraulic solver freeing all of its allocated memory. @@ -617,7 +617,7 @@ typedef struct Project *EN_Project; @return an error code */ int DLLEXPORT EN_getstatistic(EN_Project ph, int type, double* value); - + /******************************************************************** Analysis Options Functions diff --git a/src/epanet.c b/src/epanet.c index 8a829ae..d00499a 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -583,7 +583,7 @@ int DLLEXPORT EN_closeH(EN_Project p) return 0; } -int DLLEXPORT EN_savehydfile(EN_Project p, char *filename) +int DLLEXPORT EN_savehydfile(EN_Project p, const char *filename) /*---------------------------------------------------------------- ** Input: filename = name of file to which hydraulic results are saved ** Output: none @@ -611,7 +611,7 @@ int DLLEXPORT EN_savehydfile(EN_Project p, char *filename) return 0; } -int DLLEXPORT EN_usehydfile(EN_Project p, char *filename) +int DLLEXPORT EN_usehydfile(EN_Project p, const char *filename) /*---------------------------------------------------------------- ** Input: filename = name of previously saved hydraulics file ** Output: none @@ -2484,7 +2484,7 @@ int DLLEXPORT EN_settankdata(EN_Project p, int index, double elev, if (initlvl < 0.0 || minlvl < 0.0 || maxlvl < 0.0) return 209; if (minlvl > initlvl || minlvl > maxlvl || initlvl > maxlvl) return 225; if (diam < 0.0 || minvol < 0.0) return 209; - + // volume curve supplied if (strlen(volcurve) > 0) { @@ -3459,13 +3459,13 @@ int DLLEXPORT EN_getlinkvalue(EN_Project p, int index, int property, double *val v = (double)Pump[findpump(&p->network, index)].Ecurve; } break; - + case EN_PUMP_ECOST: if (Link[index].Type == PUMP) { v = (double)Pump[findpump(&p->network, index)].Ecost; } - break; + break; case EN_PUMP_EPAT: if (Link[index].Type == PUMP) @@ -4392,7 +4392,7 @@ int DLLEXPORT EN_setcurve(EN_Project p, int index, double *xValues, if (!p->Openflag) return 102; if (index <= 0 || index > net->Ncurves) return 206; if (nPoints <= 0) return 202; - + // Check that x values are increasing for (j = 1; j < nPoints; j++) if (xValues[j-1] >= xValues[j]) return 230; diff --git a/tests/test_hydqual.cpp b/tests/test_hydqual.cpp index 942a702..219a017 100644 --- a/tests/test_hydqual.cpp +++ b/tests/test_hydqual.cpp @@ -19,6 +19,7 @@ #define BOOST_TEST_MODULE "hydqual" #include +#include #include "test_fixtures.hpp" @@ -26,7 +27,7 @@ using namespace std; using namespace boost; -BOOST_AUTO_TEST_SUITE (test_hydraulics_quality) +BOOST_AUTO_TEST_SUITE (test_hyd_qual) BOOST_FIXTURE_TEST_CASE(test_solveH_solveQ, FixtureOpenClose) { @@ -131,4 +132,30 @@ BOOST_FIXTURE_TEST_CASE(test_progressive_step, FixtureOpenClose) } +// saveH + +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_hyd_qual/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()