From d3a50dc49085f948473315b27470578bd9928369 Mon Sep 17 00:00:00 2001 From: Lew Rossman Date: Tue, 27 Nov 2018 19:25:01 -0500 Subject: [PATCH] Fixed refactoring bug in EN_setlinkid --- src/epanet.c | 2 +- tests/test_setid.cpp | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/epanet.c b/src/epanet.c index 4f637ec..8bd45e9 100644 --- a/src/epanet.c +++ b/src/epanet.c @@ -3455,7 +3455,7 @@ int DLLEXPORT EN_setlinkid(EN_Project p, int index, char *newid) if (index <= 0 || index > net->Nlinks) return 204; n = strlen(newid); 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 if (hashtable_find(net->LinkHashTable, newid) > 0) return 215; diff --git a/tests/test_setid.cpp b/tests/test_setid.cpp index c801a68..70f0579 100644 --- a/tests/test_setid.cpp +++ b/tests/test_setid.cpp @@ -5,10 +5,14 @@ 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. */ +//#define NO_BOOST +#ifndef NO_BOOST #define BOOST_TEST_MODULE "toolkit" #include +#endif +#include #include #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_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; +#ifndef NO_BOOST BOOST_AUTO_TEST_SUITE (test_toolkit) - BOOST_AUTO_TEST_CASE(test_setid) +#else +int main(int argc, char *argv[]) +#endif { string path_inp(DATA_PATH_INP); string path_rpt(DATA_PATH_RPT); @@ -33,7 +44,7 @@ BOOST_AUTO_TEST_CASE(test_setid) EN_Project ph = NULL; 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); // Test of illegal node name change @@ -63,11 +74,10 @@ BOOST_AUTO_TEST_CASE(test_setid) error = EN_close(ph); BOOST_REQUIRE(error == 0); EN_deleteproject(&ph); - - // Re-open the saved project + // Re-open the saved project 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); // Check that 3rd node has its new name @@ -85,4 +95,6 @@ BOOST_AUTO_TEST_CASE(test_setid) EN_deleteproject(&ph); } +#ifndef NO_BOOST BOOST_AUTO_TEST_SUITE_END() +#endif