Modified re-factored version of hash.c

This commit is contained in:
Lew Rossman
2018-10-19 10:36:39 -04:00
parent 0041772aa0
commit f7346cef5f
3 changed files with 45 additions and 34 deletions

View File

@@ -1,4 +1,5 @@
// Test of ENsetid EPANET API Function
#define _CRT_SECURE_NO_DEPRECATE
/*
This is a test for the API functions that change a node or link ID name.
@@ -11,9 +12,9 @@ A node and link name are changed, the network is saved, reopened and the new nam
#include <string>
#include "epanet2.h"
#define DATA_PATH_INP "net1.inp"
#define DATA_PATH_RPT "test.rpt"
#define DATA_PATH_OUT ""
#define DATA_PATH_INP "./net1.inp"
#define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out"
using namespace std;
@@ -24,57 +25,63 @@ BOOST_AUTO_TEST_CASE(test_setid)
int error = 0;
int index;
string newid;
EN_ProjectHandle ph = NULL;
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 = ENopen(path_inp.c_str(), path_rpt.c_str(), "");
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Test of illegal node name change
newid = "Illegal; node name";
error = ENsetnodeid(3, (char *)newid.c_str());
error = EN_setnodeid(ph, 3, (char *)newid.c_str());
BOOST_REQUIRE(error > 0);
// Test of legal node name change
newid = "Node3";
error = ENsetnodeid(3, (char *)newid.c_str());
error = EN_setnodeid(ph, 3, (char *)newid.c_str());
BOOST_REQUIRE(error == 0);
// Test of illegal link name change
newid = "Illegal; link name";
error = ENsetlinkid(3, (char *)newid.c_str());
error = EN_setlinkid(ph, 3, (char *)newid.c_str());
BOOST_REQUIRE(error > 0);
// Test of legal link name change
newid = "Link3";
error = ENsetlinkid(3, (char *)newid.c_str());
error = EN_setlinkid(ph, 3, (char *)newid.c_str());
BOOST_REQUIRE(error == 0);
// Save the project
error = ENsaveinpfile("net1_setid.inp");
error = EN_saveinpfile(ph, "net1_setid.inp");
BOOST_REQUIRE(error == 0);
error = ENclose();
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
// Re-open the saved project
error = ENopen("net1_setid.inp", path_rpt.c_str(), "");
EN_createproject(&ph);
error = EN_open(ph, "net1_setid.inp", path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Check that 3rd node has its new name
error = ENgetnodeindex("Node3", &index);
error = EN_getnodeindex(ph, "Node3", &index);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(index == 3);
// Check that 3rd link has its new name
error = ENgetlinkindex("Link3", &index);
error = EN_getlinkindex(ph, "Link3", &index);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(index == 3);
error = ENclose();
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph);
}
BOOST_AUTO_TEST_SUITE_END()