Cleaning up tests
Fixing memory leak associated with using string objects to pass filepath arguments to toolkit
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
|
||||
|
||||
//#define BOOST_ALL_DYN_LINK
|
||||
|
||||
#include <string>
|
||||
#ifdef _WIN32
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
@@ -63,12 +70,8 @@ boost::test_tools::predicate_result check_string(std::string test, std::string r
|
||||
|
||||
struct FixtureOpenClose{
|
||||
FixtureOpenClose() {
|
||||
path_inp = std::string(DATA_PATH_NET1);
|
||||
path_rpt = std::string(DATA_PATH_RPT);
|
||||
path_out = std::string(DATA_PATH_OUT);
|
||||
|
||||
EN_createproject(&ph);
|
||||
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
|
||||
}
|
||||
|
||||
~FixtureOpenClose() {
|
||||
@@ -76,10 +79,6 @@ struct FixtureOpenClose{
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
|
||||
std::string path_inp;
|
||||
std::string path_rpt;
|
||||
std::string path_out;
|
||||
|
||||
int error;
|
||||
EN_Project ph;
|
||||
};
|
||||
@@ -90,12 +89,8 @@ struct FixtureAfterStep{
|
||||
flag = 0;
|
||||
tstop = 10800;
|
||||
|
||||
path_inp = std::string(DATA_PATH_NET1);
|
||||
path_rpt = std::string(DATA_PATH_RPT);
|
||||
path_out = std::string(DATA_PATH_OUT);
|
||||
|
||||
EN_createproject(&ph);
|
||||
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
|
||||
|
||||
error = EN_solveH(ph);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
@@ -124,10 +119,6 @@ struct FixtureAfterStep{
|
||||
EN_deleteproject(&ph);
|
||||
}
|
||||
|
||||
std::string path_inp;
|
||||
std::string path_rpt;
|
||||
std::string path_out;
|
||||
|
||||
int error, flag;
|
||||
long t, tstep, tstop;
|
||||
EN_Project ph;
|
||||
|
||||
@@ -16,13 +16,11 @@ BOOST_AUTO_TEST_SUITE (test_demands)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_categories_save)
|
||||
{
|
||||
std::string path_inp(DATA_PATH_NET1);
|
||||
std::string inp_save("net1_dem_cat.inp");
|
||||
std::string path_rpt(DATA_PATH_RPT);
|
||||
std::string path_out(DATA_PATH_OUT);
|
||||
//std::string path_inp(DATA_PATH_NET1);
|
||||
//std::string inp_save = "net1_dem_cat.inp";
|
||||
//std::string path_rpt(DATA_PATH_RPT);
|
||||
//std::string path_out(DATA_PATH_OUT);
|
||||
|
||||
char node_id[] = "12";
|
||||
char demand_category[] = "Demand category name";
|
||||
|
||||
int error = 0;
|
||||
int Nindex, ndem;
|
||||
@@ -30,17 +28,17 @@ BOOST_AUTO_TEST_CASE(test_categories_save)
|
||||
EN_Project ph = NULL;
|
||||
|
||||
error = EN_createproject(&ph);
|
||||
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
|
||||
|
||||
error = EN_getnodeindex(ph, node_id, &Nindex);
|
||||
error = EN_getnodeindex(ph, "12", &Nindex);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getnumdemands(ph, Nindex, &ndem);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(ndem == 1);
|
||||
|
||||
error = EN_setdemandname(ph, Nindex, ndem, demand_category);
|
||||
error = EN_setdemandname(ph, Nindex, ndem, "Demand category name");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_saveinpfile(ph, inp_save.c_str());
|
||||
error = EN_saveinpfile(ph, "net1_dem_cat.inp");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_close(ph);
|
||||
@@ -51,12 +49,10 @@ BOOST_AUTO_TEST_CASE(test_categories_save)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demands/test_categories_save"))
|
||||
{
|
||||
std::string inp_save("net1_dem_cat.inp");
|
||||
std::string path_rpt(DATA_PATH_RPT);
|
||||
std::string path_out(DATA_PATH_OUT);
|
||||
|
||||
char node_id[] = "12";
|
||||
char demand_category[] = "Demand category name";
|
||||
//std::string inp_save = "net1_dem_cat.inp";
|
||||
//std::string path_rpt(DATA_PATH_RPT);
|
||||
//std::string path_out(DATA_PATH_OUT);
|
||||
|
||||
char demname[80];
|
||||
|
||||
int error = 0;
|
||||
@@ -67,10 +63,10 @@ BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("tes
|
||||
BOOST_TEST_CHECKPOINT("Reopening saved input file");
|
||||
error = EN_createproject(&ph);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_open(ph, inp_save.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
error = EN_open(ph, "net1_dem_cat.inp", DATA_PATH_RPT, DATA_PATH_OUT);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_getnodeindex(ph, node_id, &Nindex);
|
||||
error = EN_getnodeindex(ph, "12", &Nindex);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
error = EN_getnumdemands(ph, Nindex, &ndem);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
@@ -78,7 +74,8 @@ BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("tes
|
||||
|
||||
error = EN_getdemandname(ph, Nindex, ndem, demname);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_CHECK(check_string(demname, demand_category));
|
||||
|
||||
BOOST_CHECK(check_string(demname, "Demand category name"));
|
||||
|
||||
error = EN_close(ph);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
@@ -8,15 +8,6 @@
|
||||
//
|
||||
|
||||
|
||||
//#ifdef _WIN32
|
||||
//#define _CRTDBG_MAP_ALLOC
|
||||
//#include <stdlib.h>
|
||||
//#include <crtdbg.h>
|
||||
//#else
|
||||
#include <stdlib.h>
|
||||
//#endif
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE hydrqual
|
||||
|
||||
#include "shared_test.hpp"
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -3,14 +3,6 @@
|
||||
// This is a test of the API functions EN_setjuncdata, EN_settankdata & EN_setpipedata
|
||||
//
|
||||
|
||||
#ifdef _WIN32
|
||||
#define _CRTDBG_MAP_ALLOC
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MODULE "net_builder"
|
||||
|
||||
#include "shared_test.hpp"
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
// US EPA - ORD/NRMRL
|
||||
//
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE "node"
|
||||
|
||||
#include "shared_test.hpp"
|
||||
@@ -137,17 +136,12 @@ BOOST_AUTO_TEST_SUITE(setid_save_reopen)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_setid_save)
|
||||
{
|
||||
std::string path_inp(DATA_PATH_NET1);
|
||||
std::string path_out(DATA_PATH_OUT);
|
||||
std::string path_rpt(DATA_PATH_RPT);
|
||||
std::string inp_save("net1_setid.inp");
|
||||
|
||||
int error = 0;
|
||||
|
||||
EN_Project ph = NULL;
|
||||
EN_createproject(&ph);
|
||||
|
||||
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);
|
||||
|
||||
// Test of illegal node name change
|
||||
@@ -161,7 +155,7 @@ BOOST_AUTO_TEST_CASE(test_setid_save)
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
// Save the project
|
||||
error = EN_saveinpfile(ph, inp_save.c_str());
|
||||
error = EN_saveinpfile(ph, "net1_setid.inp");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_close(ph);
|
||||
@@ -172,24 +166,18 @@ BOOST_AUTO_TEST_CASE(test_setid_save)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_setid_reopen, * boost::unit_test::depends_on("setid_save_reopen/test_setid_save"))
|
||||
{
|
||||
std::string inp_save("net1_setid.inp");
|
||||
std::string path_out(DATA_PATH_OUT);
|
||||
std::string path_rpt(DATA_PATH_RPT);
|
||||
|
||||
int error = 0;
|
||||
int index;
|
||||
|
||||
EN_Project ph = NULL;
|
||||
|
||||
char newid_2[] = "Node3";
|
||||
|
||||
// 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 node has its new name
|
||||
error = EN_getnodeindex(ph, newid_2, &index);
|
||||
error = EN_getnodeindex(ph, "Node3", &index);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
BOOST_REQUIRE(index == 3);
|
||||
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
// US EPA - ORD/NRMRL
|
||||
//
|
||||
|
||||
|
||||
//#ifdef _WIN32
|
||||
//#define _CRTDBG_MAP_ALLOC
|
||||
//#include <stdlib.h>
|
||||
//#include <crtdbg.h>
|
||||
//#else
|
||||
//#include <stdlib.h>
|
||||
//#endif
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE "project"
|
||||
|
||||
#include "shared_test.hpp"
|
||||
@@ -43,14 +33,13 @@ BOOST_AUTO_TEST_CASE (test_create_delete)
|
||||
|
||||
BOOST_AUTO_TEST_CASE (test_open_close)
|
||||
{
|
||||
std::string path_inp(DATA_PATH_NET1);
|
||||
std::string path_rpt(DATA_PATH_RPT);
|
||||
std::string path_out(DATA_PATH_OUT);
|
||||
int error;
|
||||
|
||||
EN_Project ph = NULL;
|
||||
|
||||
EN_createproject(&ph);
|
||||
|
||||
int error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
error = EN_open(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_close(ph);
|
||||
@@ -63,22 +52,16 @@ BOOST_AUTO_TEST_CASE(test_save)
|
||||
{
|
||||
int error;
|
||||
|
||||
std::string path_inp(DATA_PATH_NET1);
|
||||
std::string inp_save("test_reopen.inp");
|
||||
std::string path_rpt(DATA_PATH_RPT);
|
||||
std::string path_out(DATA_PATH_OUT);
|
||||
|
||||
EN_Project ph_save;
|
||||
|
||||
|
||||
EN_createproject(&ph_save);
|
||||
error = EN_open(ph_save, path_inp.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
error = EN_open(ph_save, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_saveinpfile(ph_save, inp_save.c_str());
|
||||
error = EN_saveinpfile(ph_save, "test_reopen.inp");
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
BOOST_CHECK(filesystem::exists(inp_save) == true);
|
||||
BOOST_CHECK(filesystem::exists("test_reopen.inp") == true);
|
||||
|
||||
error = EN_close(ph_save);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
@@ -89,15 +72,10 @@ BOOST_AUTO_TEST_CASE(test_reopen, * unit_test::depends_on("test_project/test_sav
|
||||
{
|
||||
int error;
|
||||
|
||||
std::string inp_save("test_reopen.inp");
|
||||
std::string path_rpt(DATA_PATH_RPT);
|
||||
std::string path_out(DATA_PATH_OUT);
|
||||
|
||||
EN_Project ph_reopen;
|
||||
|
||||
|
||||
EN_createproject(&ph_reopen);
|
||||
error = EN_open(ph_reopen, inp_save.c_str(), path_rpt.c_str(), path_out.c_str());
|
||||
error = EN_open(ph_reopen, "test_reopen.inp", DATA_PATH_RPT, DATA_PATH_OUT);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
error = EN_close(ph_reopen);
|
||||
@@ -107,15 +85,13 @@ BOOST_AUTO_TEST_CASE(test_reopen, * unit_test::depends_on("test_project/test_sav
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_run)
|
||||
{
|
||||
std::string path_inp(DATA_PATH_NET1);
|
||||
std::string path_rpt(DATA_PATH_RPT);
|
||||
std::string path_out(DATA_PATH_OUT);
|
||||
int error;
|
||||
|
||||
EN_Project ph;
|
||||
|
||||
EN_createproject(&ph);
|
||||
|
||||
int error = EN_runproject(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str(), NULL);
|
||||
error = EN_runproject(ph, DATA_PATH_NET1, DATA_PATH_RPT, DATA_PATH_OUT, NULL);
|
||||
BOOST_REQUIRE(error == 0);
|
||||
|
||||
EN_deleteproject(&ph);
|
||||
|
||||
@@ -7,17 +7,6 @@
|
||||
// US EPA - ORD/NRMRL
|
||||
//
|
||||
|
||||
//#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 hydqual
|
||||
|
||||
#include "shared_test.hpp"
|
||||
|
||||
Reference in New Issue
Block a user