From 0b5c5a3b7e40308c7db2f1e784f666c6e749e66a Mon Sep 17 00:00:00 2001 From: Elad Salomons Date: Wed, 26 Sep 2018 12:13:49 +0300 Subject: [PATCH] Test for set\get demand categories --- tests/test_demand_categories.cpp | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/test_demand_categories.cpp diff --git a/tests/test_demand_categories.cpp b/tests/test_demand_categories.cpp new file mode 100644 index 0000000..a910500 --- /dev/null +++ b/tests/test_demand_categories.cpp @@ -0,0 +1,72 @@ +// +// 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. +*/ + +#define BOOST_TEST_MODULE "toolkit" +#include + +#include +#include "epanet2.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" + +using namespace std; + +BOOST_AUTO_TEST_SUITE (test_toolkit) + +BOOST_AUTO_TEST_CASE(test_demand_categories) +{ + int error = 0; + int Nindex, ndem; + char demname[80]; + EN_ProjectHandle ph = NULL; + + 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); + + 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); + error = EN_getnodeindex(ph, (char *)"12", &Nindex); + BOOST_REQUIRE(error == 0); + error = EN_getnumdemands(ph, Nindex, &ndem); + BOOST_REQUIRE(error == 0); + BOOST_REQUIRE(ndem == 1); + error = EN_setdemandname(ph, Nindex, ndem, (char *)"Demand category name"); + BOOST_REQUIRE(error == 0); + error = EN_saveinpfile(ph, "net1_dem_cat.inp"); + BOOST_REQUIRE(error == 0); + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + error = EN_deleteproject(&ph); + BOOST_REQUIRE(error == 0); + + error = EN_createproject(&ph); + BOOST_REQUIRE(error == 0); + error = EN_open(ph, "net1_dem_cat.inp", path_rpt.c_str(), path_out.c_str()); + BOOST_REQUIRE(error == 0); + error = EN_getnodeindex(ph, (char *)"12", &Nindex); + BOOST_REQUIRE(error == 0); + error = EN_getnumdemands(ph, Nindex, &ndem); + BOOST_REQUIRE(error == 0); + BOOST_REQUIRE(ndem == 1); + error = EN_getdemandname(ph, Nindex, ndem, demname); + BOOST_REQUIRE(error == 0); + BOOST_REQUIRE(strcmp(demname, "Demand category name")==0); + error = EN_close(ph); + BOOST_REQUIRE(error == 0); + error = EN_deleteproject(&ph); + BOOST_REQUIRE(error == 0); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file