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

@@ -9,6 +9,10 @@
//#define BOOST_TEST_DYN_LINK
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
@@ -43,12 +47,12 @@ BOOST_AUTO_TEST_CASE (test_alloc_free)
BOOST_AUTO_TEST_CASE (test_open_close)
{
EN_ProjectHandle ph = NULL;
EN_createproject(&ph);
string path_inp(DATA_PATH_INP);
string path_rpt(DATA_PATH_RPT);
string path_out(DATA_PATH_OUT);
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);
EN_ProjectHandle ph = NULL;
EN_createproject(&ph);
int error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
BOOST_REQUIRE(error == 0);
@@ -59,11 +63,37 @@ BOOST_AUTO_TEST_CASE (test_open_close)
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)
{
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);
string path_inp(DATA_PATH_INP);
string path_rpt(DATA_PATH_RPT);
string path_out(DATA_PATH_OUT);
int error = ENepanet(path_inp.c_str(), path_rpt.c_str(), path_out.c_str(), NULL);
BOOST_REQUIRE(error == 0);
@@ -74,13 +104,12 @@ BOOST_AUTO_TEST_SUITE_END()
struct Fixture{
Fixture() {
path_inp = std::string(DATA_PATH_INP);
path_rpt = std::string(DATA_PATH_RPT);
path_out = std::string(DATA_PATH_OUT);
path_inp = string(DATA_PATH_INP);
path_rpt = string(DATA_PATH_RPT);
path_out = string(DATA_PATH_OUT);
EN_createproject(&ph);
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
}
~Fixture() {
@@ -88,13 +117,12 @@ struct Fixture{
EN_deleteproject(&ph);
}
std::string path_inp;
std::string path_rpt;
std::string path_out;
string path_inp;
string path_rpt;
string path_out;
int error;
EN_ProjectHandle ph;
};
BOOST_AUTO_TEST_SUITE(test_epanet_fixture)
@@ -180,8 +208,6 @@ BOOST_FIXTURE_TEST_CASE(test_progressive_stepping, Fixture)
BOOST_REQUIRE(error == 0);
do {
error = EN_runH(ph, &t);
BOOST_REQUIRE(error == 0);
@@ -233,7 +259,7 @@ BOOST_FIXTURE_TEST_CASE(test_setdemandpattern, Fixture)
// get demand patterns should be the same with set
error = EN_getdemandpattern(ph, i, j, &pat_index_2);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(pat_index == pat_index_2);
BOOST_CHECK(pat_index == pat_index_2);
}
}
}
@@ -253,11 +279,11 @@ BOOST_FIXTURE_TEST_CASE(test_addpattern, Fixture)
// get the new patterns count, shoul dbe the old one + 1
error = EN_getcount(ph, EN_PATCOUNT, &n_patterns_2);
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
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)
@@ -293,10 +319,10 @@ BOOST_FIXTURE_TEST_CASE(test_add_control, Fixture)
// add new controls
error = EN_addcontrol(ph, &Cindex, 0, 13, 1, 11, 110);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(Cindex == 3);
BOOST_CHECK(Cindex == 3);
error = EN_addcontrol(ph, &Cindex, 1, 13, 0, 11, 140);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(Cindex == 4);
BOOST_CHECK(Cindex == 4);
// run with new controls
error = EN_openH(ph);
@@ -315,7 +341,7 @@ BOOST_FIXTURE_TEST_CASE(test_add_control, Fixture)
error = EN_closeH(ph);
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()