Adding test_save_reopen, minor refactoring.

This commit is contained in:
Michael Tryby
2018-11-16 13:49:45 -05:00
parent db3f2f1818
commit a4c9973d47
3 changed files with 115 additions and 70 deletions

View File

@@ -20,53 +20,72 @@ A demand category name is set, the network is saved, reopened and the new demand
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_CASE(test_demand_categories)
{
int error = 0;
int Nindex, ndem;
char demname[80];
EN_ProjectHandle ph = NULL;
string path_inp(DATA_PATH_INP);
string inp_save("net1_dem_cat.inp");
string path_rpt(DATA_PATH_RPT);
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);
std::string path_rpt = std::string(DATA_PATH_RPT);
std::string path_out = std::string(DATA_PATH_OUT);
int error = 0;
int Nindex, ndem;
EN_ProjectHandle 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);
error = EN_getnodeindex(ph, (char *)"12", &Nindex);
error = EN_getnodeindex(ph, node_id, &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_CHECK(ndem == 1);
error = EN_setdemandname(ph, Nindex, ndem, demand_category);
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);
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_TEST_CHECKPOINT("Reopening saved input file");
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_open(ph, inp_save.c_str(), path_rpt.c_str(), path_out.c_str());
BOOST_REQUIRE(error == 0);
error = EN_getnodeindex(ph, node_id, &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_CHECK(ndem == 1);
error = EN_getdemandname(ph, Nindex, ndem, demname);
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()