Merge pull request #341 from michaeltryby/dev
Adding test_save_reopen, minor refactoring.
This commit is contained in:
@@ -20,53 +20,72 @@ A demand category name is set, the network is saved, reopened and the new demand
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
boost::test_tools::predicate_result check_string(std::string test, std::string ref)
|
||||||
|
{
|
||||||
|
if (ref.compare(test) == 0)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE (test_toolkit)
|
BOOST_AUTO_TEST_SUITE (test_toolkit)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_demand_categories)
|
BOOST_AUTO_TEST_CASE(test_demand_categories)
|
||||||
{
|
{
|
||||||
int error = 0;
|
string path_inp(DATA_PATH_INP);
|
||||||
int Nindex, ndem;
|
string inp_save("net1_dem_cat.inp");
|
||||||
char demname[80];
|
string path_rpt(DATA_PATH_RPT);
|
||||||
EN_ProjectHandle ph = NULL;
|
string path_out(DATA_PATH_OUT);
|
||||||
|
|
||||||
|
char node_id[] = "12";
|
||||||
|
char demand_category[] = "Demand category name";
|
||||||
|
char demname[80];
|
||||||
|
|
||||||
|
|
||||||
std::string path_inp = std::string(DATA_PATH_INP);
|
int error = 0;
|
||||||
std::string path_rpt = std::string(DATA_PATH_RPT);
|
int Nindex, ndem;
|
||||||
std::string path_out = std::string(DATA_PATH_OUT);
|
|
||||||
|
|
||||||
|
EN_ProjectHandle ph = NULL;
|
||||||
|
|
||||||
error = EN_createproject(&ph);
|
error = EN_createproject(&ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
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);
|
error = EN_getnodeindex(ph, node_id, &Nindex);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_getnumdemands(ph, Nindex, &ndem);
|
error = EN_getnumdemands(ph, Nindex, &ndem);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_REQUIRE(ndem == 1);
|
BOOST_CHECK(ndem == 1);
|
||||||
error = EN_setdemandname(ph, Nindex, ndem, (char *)"Demand category name");
|
|
||||||
|
error = EN_setdemandname(ph, Nindex, ndem, demand_category);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_saveinpfile(ph, "net1_dem_cat.inp");
|
error = EN_saveinpfile(ph, inp_save.c_str());
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
error = EN_close(ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
|
||||||
error = EN_deleteproject(&ph);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
error = EN_close(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
error = EN_deleteproject(&ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
|
BOOST_TEST_CHECKPOINT("Reopening saved input file");
|
||||||
error = EN_createproject(&ph);
|
error = EN_createproject(&ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_open(ph, "net1_dem_cat.inp", path_rpt.c_str(), path_out.c_str());
|
error = EN_open(ph, inp_save.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_getnodeindex(ph, (char *)"12", &Nindex);
|
|
||||||
|
error = EN_getnodeindex(ph, node_id, &Nindex);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_getnumdemands(ph, Nindex, &ndem);
|
error = EN_getnumdemands(ph, Nindex, &ndem);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_REQUIRE(ndem == 1);
|
BOOST_CHECK(ndem == 1);
|
||||||
error = EN_getdemandname(ph, Nindex, ndem, demname);
|
|
||||||
BOOST_REQUIRE(error == 0);
|
error = EN_getdemandname(ph, Nindex, ndem, demname);
|
||||||
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_REQUIRE(error == 0);
|
||||||
|
BOOST_CHECK(check_string(demname, demand_category));
|
||||||
|
|
||||||
|
error = EN_close(ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
error = EN_deleteproject(&ph);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
@@ -22,38 +22,37 @@ BOOST_AUTO_TEST_SUITE (test_toolkit)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_setid)
|
BOOST_AUTO_TEST_CASE(test_setid)
|
||||||
{
|
{
|
||||||
|
string path_inp(DATA_PATH_INP);
|
||||||
|
string path_rpt(DATA_PATH_RPT);
|
||||||
|
string path_out(DATA_PATH_OUT);
|
||||||
|
|
||||||
int error = 0;
|
int error = 0;
|
||||||
int index;
|
int index;
|
||||||
string newid;
|
|
||||||
|
|
||||||
EN_ProjectHandle ph = NULL;
|
EN_ProjectHandle ph = NULL;
|
||||||
EN_createproject(&ph);
|
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);
|
|
||||||
|
|
||||||
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
|
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
// Test of illegal node name change
|
// Test of illegal node name change
|
||||||
newid = "Illegal; node name";
|
char newid_1[] = "Illegal; node name";
|
||||||
error = EN_setnodeid(ph, 3, (char *)newid.c_str());
|
error = EN_setnodeid(ph, 3, newid_1);
|
||||||
BOOST_REQUIRE(error > 0);
|
BOOST_REQUIRE(error > 0);
|
||||||
|
|
||||||
// Test of legal node name change
|
// Test of legal node name change
|
||||||
newid = "Node3";
|
char newid_2[] = "Node3";
|
||||||
error = EN_setnodeid(ph, 3, (char *)newid.c_str());
|
error = EN_setnodeid(ph, 3, newid_2);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
// Test of illegal link name change
|
// Test of illegal link name change
|
||||||
newid = "Illegal; link name";
|
char newid_3[] = "Illegal; link name";
|
||||||
error = EN_setlinkid(ph, 3, (char *)newid.c_str());
|
error = EN_setlinkid(ph, 3, newid_3);
|
||||||
BOOST_REQUIRE(error > 0);
|
BOOST_REQUIRE(error > 0);
|
||||||
|
|
||||||
// Test of legal link name change
|
// Test of legal link name change
|
||||||
newid = "Link3";
|
char newid_4[] = "Link3";
|
||||||
error = EN_setlinkid(ph, 3, (char *)newid.c_str());
|
error = EN_setlinkid(ph, 3, newid_4);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
// Save the project
|
// Save the project
|
||||||
@@ -64,20 +63,21 @@ BOOST_AUTO_TEST_CASE(test_setid)
|
|||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
EN_deleteproject(&ph);
|
EN_deleteproject(&ph);
|
||||||
|
|
||||||
// Re-open the saved project
|
|
||||||
|
// Re-open the saved project
|
||||||
EN_createproject(&ph);
|
EN_createproject(&ph);
|
||||||
error = EN_open(ph, "net1_setid.inp", path_rpt.c_str(), "");
|
error = EN_open(ph, "net1_setid.inp", path_rpt.c_str(), "");
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
// Check that 3rd node has its new name
|
// Check that 3rd node has its new name
|
||||||
error = EN_getnodeindex(ph, "Node3", &index);
|
error = EN_getnodeindex(ph, newid_2, &index);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_REQUIRE(index == 3);
|
BOOST_CHECK(index == 3);
|
||||||
|
|
||||||
// Check that 3rd link has its new name
|
// Check that 3rd link has its new name
|
||||||
error = EN_getlinkindex(ph, "Link3", &index);
|
error = EN_getlinkindex(ph, newid_4, &index);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_REQUIRE(index == 3);
|
BOOST_CHECK(index == 3);
|
||||||
|
|
||||||
error = EN_close(ph);
|
error = EN_close(ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|||||||
@@ -9,6 +9,14 @@
|
|||||||
|
|
||||||
//#define BOOST_TEST_DYN_LINK
|
//#define BOOST_TEST_DYN_LINK
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define _CRTDBG_MAP_ALLOC
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <crtdbg.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define BOOST_TEST_MODULE "toolkit"
|
#define BOOST_TEST_MODULE "toolkit"
|
||||||
#include <boost/test/included/unit_test.hpp>
|
#include <boost/test/included/unit_test.hpp>
|
||||||
|
|
||||||
@@ -43,12 +51,12 @@ BOOST_AUTO_TEST_CASE (test_alloc_free)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE (test_open_close)
|
BOOST_AUTO_TEST_CASE (test_open_close)
|
||||||
{
|
{
|
||||||
EN_ProjectHandle ph = NULL;
|
string path_inp(DATA_PATH_INP);
|
||||||
EN_createproject(&ph);
|
string path_rpt(DATA_PATH_RPT);
|
||||||
|
string path_out(DATA_PATH_OUT);
|
||||||
|
|
||||||
std::string path_inp = std::string(DATA_PATH_INP);
|
EN_ProjectHandle ph = NULL;
|
||||||
std::string path_rpt = std::string(DATA_PATH_RPT);
|
EN_createproject(&ph);
|
||||||
std::string path_out = std::string(DATA_PATH_OUT);
|
|
||||||
|
|
||||||
int error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
int error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
@@ -59,11 +67,37 @@ BOOST_AUTO_TEST_CASE (test_open_close)
|
|||||||
EN_deleteproject(&ph);
|
EN_deleteproject(&ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(test_save_reopen)
|
||||||
|
{
|
||||||
|
string path_inp(DATA_PATH_INP);
|
||||||
|
string inp_save("test_reopen.inp");
|
||||||
|
string path_rpt(DATA_PATH_RPT);
|
||||||
|
string path_out(DATA_PATH_OUT);
|
||||||
|
|
||||||
|
EN_ProjectHandle ph_save, ph_reopen;
|
||||||
|
|
||||||
|
EN_createproject(&ph_save);
|
||||||
|
|
||||||
|
EN_open(ph_save, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||||
|
EN_saveinpfile(ph_save, inp_save.c_str());
|
||||||
|
EN_close(ph_save);
|
||||||
|
|
||||||
|
EN_deleteproject(&ph_save);
|
||||||
|
BOOST_TEST_CHECKPOINT("Saved input file");
|
||||||
|
|
||||||
|
EN_createproject(&ph_reopen);
|
||||||
|
|
||||||
|
EN_open(ph_reopen, inp_save.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||||
|
EN_close(ph_reopen);
|
||||||
|
|
||||||
|
EN_deleteproject(&ph_reopen);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_epanet)
|
BOOST_AUTO_TEST_CASE(test_epanet)
|
||||||
{
|
{
|
||||||
std::string path_inp = std::string(DATA_PATH_INP);
|
string path_inp(DATA_PATH_INP);
|
||||||
std::string path_rpt = std::string(DATA_PATH_RPT);
|
string path_rpt(DATA_PATH_RPT);
|
||||||
std::string path_out = std::string(DATA_PATH_OUT);
|
string path_out(DATA_PATH_OUT);
|
||||||
|
|
||||||
int error = ENepanet(path_inp.c_str(), path_rpt.c_str(), path_out.c_str(), NULL);
|
int error = ENepanet(path_inp.c_str(), path_rpt.c_str(), path_out.c_str(), NULL);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
@@ -74,13 +108,12 @@ BOOST_AUTO_TEST_SUITE_END()
|
|||||||
|
|
||||||
struct Fixture{
|
struct Fixture{
|
||||||
Fixture() {
|
Fixture() {
|
||||||
path_inp = std::string(DATA_PATH_INP);
|
path_inp = string(DATA_PATH_INP);
|
||||||
path_rpt = std::string(DATA_PATH_RPT);
|
path_rpt = string(DATA_PATH_RPT);
|
||||||
path_out = std::string(DATA_PATH_OUT);
|
path_out = string(DATA_PATH_OUT);
|
||||||
|
|
||||||
EN_createproject(&ph);
|
EN_createproject(&ph);
|
||||||
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Fixture() {
|
~Fixture() {
|
||||||
@@ -88,13 +121,12 @@ struct Fixture{
|
|||||||
EN_deleteproject(&ph);
|
EN_deleteproject(&ph);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string path_inp;
|
string path_inp;
|
||||||
std::string path_rpt;
|
string path_rpt;
|
||||||
std::string path_out;
|
string path_out;
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
EN_ProjectHandle ph;
|
EN_ProjectHandle ph;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(test_epanet_fixture)
|
BOOST_AUTO_TEST_SUITE(test_epanet_fixture)
|
||||||
@@ -180,8 +212,6 @@ BOOST_FIXTURE_TEST_CASE(test_progressive_stepping, Fixture)
|
|||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
|
|
||||||
error = EN_runH(ph, &t);
|
error = EN_runH(ph, &t);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
@@ -233,7 +263,7 @@ BOOST_FIXTURE_TEST_CASE(test_setdemandpattern, Fixture)
|
|||||||
// get demand patterns should be the same with set
|
// get demand patterns should be the same with set
|
||||||
error = EN_getdemandpattern(ph, i, j, &pat_index_2);
|
error = EN_getdemandpattern(ph, i, j, &pat_index_2);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_REQUIRE(pat_index == pat_index_2);
|
BOOST_CHECK(pat_index == pat_index_2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,11 +283,11 @@ BOOST_FIXTURE_TEST_CASE(test_addpattern, Fixture)
|
|||||||
// get the new patterns count, shoul dbe the old one + 1
|
// get the new patterns count, shoul dbe the old one + 1
|
||||||
error = EN_getcount(ph, EN_PATCOUNT, &n_patterns_2);
|
error = EN_getcount(ph, EN_PATCOUNT, &n_patterns_2);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_REQUIRE(n_patterns_1 + 1 == n_patterns_2);
|
BOOST_CHECK(n_patterns_1 + 1 == n_patterns_2);
|
||||||
|
|
||||||
// gwt the new patterns index, should be as the number of patterns
|
// gwt the new patterns index, should be as the number of patterns
|
||||||
error = EN_getpatternindex(ph, newpat, &pat_index);
|
error = EN_getpatternindex(ph, newpat, &pat_index);
|
||||||
BOOST_REQUIRE(pat_index == n_patterns_2);
|
BOOST_CHECK(pat_index == n_patterns_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE(test_add_control, Fixture)
|
BOOST_FIXTURE_TEST_CASE(test_add_control, Fixture)
|
||||||
@@ -293,10 +323,10 @@ BOOST_FIXTURE_TEST_CASE(test_add_control, Fixture)
|
|||||||
// add new controls
|
// add new controls
|
||||||
error = EN_addcontrol(ph, &Cindex, 0, 13, 1, 11, 110);
|
error = EN_addcontrol(ph, &Cindex, 0, 13, 1, 11, 110);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_REQUIRE(Cindex == 3);
|
BOOST_CHECK(Cindex == 3);
|
||||||
error = EN_addcontrol(ph, &Cindex, 1, 13, 0, 11, 140);
|
error = EN_addcontrol(ph, &Cindex, 1, 13, 0, 11, 140);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_REQUIRE(Cindex == 4);
|
BOOST_CHECK(Cindex == 4);
|
||||||
|
|
||||||
// run with new controls
|
// run with new controls
|
||||||
error = EN_openH(ph);
|
error = EN_openH(ph);
|
||||||
@@ -315,7 +345,7 @@ BOOST_FIXTURE_TEST_CASE(test_add_control, Fixture)
|
|||||||
error = EN_closeH(ph);
|
error = EN_closeH(ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
BOOST_REQUIRE(h1 == h2); // end head should be the same with new controls
|
BOOST_CHECK(h1 == h2); // end head should be the same with new controls
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|||||||
Reference in New Issue
Block a user