Fixed bug in hash.c

A bug in the delete function in hash.c was preventing the unit test of the new set ID API functions from running properly. In fixing this bug the entire hash table code was refactored to make it look more like the mempool service routines. Also the need to copy the string passed into the table's insert function was eliminated.
This commit is contained in:
Lew Rossman
2018-10-18 10:03:09 -04:00
parent b3e84e0c42
commit 60a79de4a9
7 changed files with 212 additions and 222 deletions

View File

@@ -1,6 +1,4 @@
//
// test_setid.cpp
//
// Test of ENsetid EPANET API Function
/*
This is a test for the API functions that change a node or link ID name.
@@ -10,77 +8,76 @@ A node and link name are changed, the network is saved, reopened and the new nam
#define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp>
#include <string.h>
#include <string>
#include "epanet2.h"
// NOTE: Project Home needs to be updated to run unit test
#define DATA_PATH_INP "./net1.inp"
#define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out"
#define DATA_PATH_INP "net1.inp"
#define DATA_PATH_RPT "test.rpt"
#define DATA_PATH_OUT ""
using namespace std;
BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE(test_setid)
{
int main(int argc, char *argv[])
{
int error = 0;
int index;
char errmsg[256];
char id[80];
char newid[80];
string newid;
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(), path_out.c_str());
error = ENopen(path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Test of illegal node name change
error = ENgetnodeid(3, id);
BOOST_REQUIRE(error == 0);
strncpy(newid, "Illegal; node name", 79);
error = ENsetnodeid(3, newid);
newid = "Illegal; node name";
error = ENsetnodeid(3, (char *)newid.c_str());
BOOST_REQUIRE(error > 0);
// Test of legal node name change
strncpy(newid, "Node3", 79);
error = ENsetnodeid(3, newid);
newid = "Node3";
error = ENsetnodeid(3, (char *)newid.c_str());
BOOST_REQUIRE(error == 0);
// Test of illegal link name change
error = ENgetlinkid(3, id);
BOOST_REQUIRE(error == 0);
strncpy(newid, "Illegal; link name", 79);
error = ENsetlinkid(3, newid);
newid = "Illegal; link name";
error = ENsetlinkid(3, (char *)newid.c_str());
BOOST_REQUIRE(error > 0);
// Test of legal link name change
strncpy(newid, "Link3", 79);
error = ENsetlinkid(3, newid);
newid = "Link3";
error = ENsetlinkid(3, (char *)newid.c_str());
BOOST_REQUIRE(error == 0);
// Save the project
error = ENsaveinpfile("net1_setid.inp");
BOOST_REQUIRE(error == 0);
error = ENclose();
BOOST_REQUIRE(error == 0);
// Re-open the saved project
error = ENopen("net1_setid.inp", path_rpt.c_str(), path_out.c_str());
error = ENopen("net1_setid.inp", path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0);
// Check that 3rd node has its new name
error = ENgetnodeindex((char *)"Node3", &index);
error = ENgetnodeindex("Node3", &index);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(index == 3);
// Check that 3rd link has its new name
error = ENgetlinkindex((char *)"Link3", &index);
error = ENgetlinkindex("Link3", &index);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(index == 3);
ENclose();
error = ENclose();
BOOST_REQUIRE(error == 0);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()