Merge branch 'fix_bug_getdemandname' of https://github.com/Mariosmsk/EPANET into Mariosmsk-fix_bug_getdemandname

This commit is contained in:
Michael Tryby
2019-04-08 14:44:05 -04:00
4 changed files with 30 additions and 21 deletions

View File

@@ -1234,7 +1234,7 @@ int DLLEXPORT EN_setoption(EN_Project p, int option, double value)
if (demand->Pat == tmpPat)
{
demand->Pat = pat;
demand->Name = xstrcpy(&demand->Name, "", MAXMSG);
demand->Name = xstrcpy(&demand->Name, "", MAXID);
}
}
}
@@ -2758,7 +2758,9 @@ int DLLEXPORT EN_getdemandname(EN_Project p, int nodeIndex, int demandIndex,
for (d = p->network.Node[nodeIndex].D;
n < demandIndex && d->next != NULL; d = d->next) n++;
if (n != demandIndex) return 253;
strcpy(demandName, d->Name);
if (d->Name) strcpy(demandName, d->Name);
else demandName[0] = '\0';
return 0;
}
@@ -2781,11 +2783,14 @@ int DLLEXPORT EN_setdemandname(EN_Project p, int nodeIndex, int demandIndex,
if (!p->Openflag) return 102;
if (nodeIndex <= 0 || nodeIndex > p->network.Njuncs) return 203;
// Check that demandName is not too long
if (strlen(demandName) > MAXID) return 250;
// Locate demand category record and assign demandName to it
for (d = p->network.Node[nodeIndex].D;
n < demandIndex && d->next != NULL; d = d->next) n++;
if (n != demandIndex) return 253;
d->Name = xstrcpy(&d->Name, demandName, MAXMSG);
d->Name = xstrcpy(&d->Name, demandName, MAXID);
return 0;
}

View File

@@ -334,7 +334,7 @@ void adjustdata(Project *pr)
if (demand->Pat == 0)
{
demand->Pat = hyd->DefPat;
xstrcpy(&demand->Name, "", MAXMSG);
xstrcpy(&demand->Name, "", MAXID);
}
}
}

View File

@@ -742,7 +742,7 @@ int demanddata(Project *pr)
// with what is specified in this section
demand->Base = y;
demand->Pat = p;
demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXMSG);
demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXID);
hyd->NodeDemand[j] = MISSING; // marker - next iteration will append a new category.
}
@@ -755,7 +755,7 @@ int demanddata(Project *pr)
if (demand == NULL) return 101;
demand->Base = y;
demand->Pat = p;
demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXMSG);
demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXID);
demand->next = NULL;
cur_demand->next = demand;
}

View File

@@ -20,7 +20,7 @@ BOOST_AUTO_TEST_SUITE (test_demand)
BOOST_AUTO_TEST_CASE(test_categories_save)
{
int error = 0;
int error = 0;
int Nindex, ndem;
EN_Project ph = NULL;
@@ -34,15 +34,19 @@ BOOST_AUTO_TEST_CASE(test_categories_save)
BOOST_REQUIRE(error == 0);
BOOST_CHECK(ndem == 1);
error = EN_setdemandname(ph, Nindex, ndem, (char *)"Demand category name");
char demname[31];
error = EN_getdemandname(ph, Nindex, ndem, demname);
BOOST_REQUIRE(error == 0);
error = EN_setdemandname(ph, Nindex, ndem, (char *)"Demand category name");
BOOST_REQUIRE(error == 0);
error = EN_saveinpfile(ph, "net1_dem_cat.inp");
BOOST_REQUIRE(error == 0);
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
error = EN_deleteproject(&ph);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(error == 0);
error = EN_deleteproject(&ph);
BOOST_REQUIRE(error == 0);
}
BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demand/test_categories_save"))
@@ -52,11 +56,11 @@ BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("tes
EN_Project ph = NULL;
BOOST_TEST_CHECKPOINT("Reopening saved input file");
BOOST_TEST_CHECKPOINT("Reopening saved input file");
error = EN_createproject(&ph);
BOOST_REQUIRE(error == 0);
error = EN_open(ph, "net1_dem_cat.inp", DATA_PATH_RPT, DATA_PATH_OUT);
BOOST_REQUIRE(error == 0);
BOOST_REQUIRE(error == 0);
error = EN_open(ph, "net1_dem_cat.inp", DATA_PATH_RPT, DATA_PATH_OUT);
BOOST_REQUIRE(error == 0);
error = EN_getnodeindex(ph, (char *)"12", &Nindex);
BOOST_REQUIRE(error == 0);
@@ -64,16 +68,16 @@ BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("tes
BOOST_REQUIRE(error == 0);
BOOST_CHECK(ndem == 1);
char demname[80];
error = EN_getdemandname(ph, Nindex, ndem, demname);
char demname[31];
error = EN_getdemandname(ph, Nindex, ndem, demname);
BOOST_REQUIRE(error == 0);
BOOST_CHECK(check_string(demname, "Demand category name"));
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
error = EN_deleteproject(&ph);
BOOST_REQUIRE(error == 0);
error = EN_close(ph);
BOOST_REQUIRE(error == 0);
error = EN_deleteproject(&ph);
BOOST_REQUIRE(error == 0);
}
BOOST_AUTO_TEST_SUITE_END()