Cleaning up tests

Fixing memory leak associated with using string objects to pass filepath arguments to toolkit
This commit is contained in:
Michael Tryby
2019-03-19 13:27:07 -04:00
parent ed9a89763b
commit 29cfe43e5a
8 changed files with 75 additions and 148 deletions

View File

@@ -25,11 +25,7 @@ BOOST_AUTO_TEST_CASE(test_setlinktype)
EN_Project ph = NULL;
EN_createproject(&ph);
std::string path_inp = std::string(DATA_PATH_NET1);
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, DATA_PATH_NET1, DATA_PATH_RPT, "");
BOOST_REQUIRE(error == 0);
// Change duration to 0
@@ -90,47 +86,54 @@ BOOST_AUTO_TEST_CASE(test_setlinktype)
EN_deleteproject(&ph);
}
BOOST_AUTO_TEST_CASE(test_setid)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(setid_save_reopen)
BOOST_AUTO_TEST_CASE(test_setid_save)
{
std::string path_inp(DATA_PATH_NET1);
std::string path_rpt(DATA_PATH_RPT);
std::string path_out(DATA_PATH_OUT);
std::string inp_save("net1_setid.inp");
int error = 0;
int error = 0;
int index;
EN_Project ph = NULL;
EN_createproject(&ph);
EN_Project ph = NULL;
EN_createproject(&ph);
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, "");
BOOST_REQUIRE(error == 0);
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Test of illegal link name change
char newid_3[] = "Illegal; link name";
error = EN_setlinkid(ph, 3, newid_3);
BOOST_REQUIRE(error > 0);
// Test of illegal link name change
char newid_3[] = "Illegal; link name";
error = EN_setlinkid(ph, 3, newid_3);
BOOST_REQUIRE(error > 0);
// Test of legal link name change
char newid_4[] = "Link3";
error = EN_setlinkid(ph, 3, newid_4);
BOOST_REQUIRE(error == 0);
// Test of legal link name change
char newid_4[] = "Link3";
error = EN_setlinkid(ph, 3, newid_4);
BOOST_REQUIRE(error == 0);
// Save the project
error = EN_saveinpfile(ph, "net1_setid.inp");
BOOST_REQUIRE(error == 0);
// Save the project
error = EN_saveinpfile(ph, inp_save.c_str());
BOOST_REQUIRE(error == 0);
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
}
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
BOOST_AUTO_TEST_CASE(test_setid_reopen, * boost::unit_test::depends_on("setid_save_reopen/test_setid_save"))
{
int error = 0;
int index;
EN_Project ph = NULL;
// Re-open the saved project
EN_createproject(&ph);
error = EN_open(ph, inp_save.c_str(), path_rpt.c_str(), "");
error = EN_open(ph, "net1_setid.inp", DATA_PATH_RPT, "");
BOOST_REQUIRE(error == 0);
// Check that 3rd link has its new name
error = EN_getlinkindex(ph, newid_4, &index);
error = EN_getlinkindex(ph, "Link3", &index);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(index == 3);