Fixed refactoring bug in EN_setlinkid

This commit is contained in:
Lew Rossman
2018-11-27 19:25:01 -05:00
parent b7a7cdc5ee
commit d3a50dc490
2 changed files with 18 additions and 6 deletions

View File

@@ -3455,7 +3455,7 @@ int DLLEXPORT EN_setlinkid(EN_Project p, int index, char *newid)
if (index <= 0 || index > net->Nlinks) return 204; if (index <= 0 || index > net->Nlinks) return 204;
n = strlen(newid); n = strlen(newid);
if (n < 1 || n > MAXID) return 211; if (n < 1 || n > MAXID) return 211;
if (strcspn(newid, " ;") < n) 211; if (strcspn(newid, " ;") < n) return 211;
// Check if another link with same name exists // Check if another link with same name exists
if (hashtable_find(net->LinkHashTable, newid) > 0) return 215; if (hashtable_find(net->LinkHashTable, newid) > 0) return 215;

View File

@@ -5,10 +5,14 @@
This is a test for the API functions that change a node or link ID name. This is a test for the API functions that change a node or link ID name.
A node and link name are changed, the network is saved, reopened and the new names are checked. A node and link name are changed, the network is saved, reopened and the new names are checked.
*/ */
//#define NO_BOOST
#ifndef NO_BOOST
#define BOOST_TEST_MODULE "toolkit" #define BOOST_TEST_MODULE "toolkit"
#include <boost/test/included/unit_test.hpp> #include <boost/test/included/unit_test.hpp>
#endif
#include <iostream>
#include <string> #include <string>
#include "epanet2.h" #include "epanet2.h"
@@ -16,11 +20,18 @@ A node and link name are changed, the network is saved, reopened and the new nam
#define DATA_PATH_RPT "./test.rpt" #define DATA_PATH_RPT "./test.rpt"
#define DATA_PATH_OUT "./test.out" #define DATA_PATH_OUT "./test.out"
#ifdef NO_BOOST
#define BOOST_REQUIRE(x) (((x)) ? cout << "\nPassed at line " << __LINE__ : cout << "\nFailed at line " << __LINE__ )
#endif
using namespace std; using namespace std;
#ifndef NO_BOOST
BOOST_AUTO_TEST_SUITE (test_toolkit) BOOST_AUTO_TEST_SUITE (test_toolkit)
BOOST_AUTO_TEST_CASE(test_setid) BOOST_AUTO_TEST_CASE(test_setid)
#else
int main(int argc, char *argv[])
#endif
{ {
string path_inp(DATA_PATH_INP); string path_inp(DATA_PATH_INP);
string path_rpt(DATA_PATH_RPT); string path_rpt(DATA_PATH_RPT);
@@ -33,7 +44,7 @@ BOOST_AUTO_TEST_CASE(test_setid)
EN_Project ph = NULL; EN_Project ph = NULL;
EN_createproject(&ph); EN_createproject(&ph);
error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), path_out.c_str()); error = EN_open(ph, path_inp.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
// Test of illegal node name change // Test of illegal node name change
@@ -64,10 +75,9 @@ BOOST_AUTO_TEST_CASE(test_setid)
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
EN_deleteproject(&ph); EN_deleteproject(&ph);
// Re-open the saved project // Re-open the saved project
EN_createproject(&ph); EN_createproject(&ph);
error = EN_open(ph, inp_save.c_str(), path_rpt.c_str(), path_out.c_str()); error = EN_open(ph, inp_save.c_str(), path_rpt.c_str(), "");
BOOST_REQUIRE(error == 0); BOOST_REQUIRE(error == 0);
// Check that 3rd node has its new name // Check that 3rd node has its new name
@@ -85,4 +95,6 @@ BOOST_AUTO_TEST_CASE(test_setid)
EN_deleteproject(&ph); EN_deleteproject(&ph);
} }
#ifndef NO_BOOST
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()
#endif