Merge pull request #431 from Mariosmsk/fix_bug_getdemandname
try to fix bug in EN_getdemandname
This commit is contained in:
17
src/epanet.c
17
src/epanet.c
@@ -2812,7 +2812,9 @@ int DLLEXPORT EN_getdemandname(EN_Project p, int nodeIndex, int demandIndex,
|
|||||||
for (d = p->network.Node[nodeIndex].D;
|
for (d = p->network.Node[nodeIndex].D;
|
||||||
n < demandIndex && d->next != NULL; d = d->next) n++;
|
n < demandIndex && d->next != NULL; d = d->next) n++;
|
||||||
if (n != demandIndex) return 253;
|
if (n != demandIndex) return 253;
|
||||||
strcpy(demandName, d->Name);
|
|
||||||
|
if (d->Name) strcpy(demandName, d->Name);
|
||||||
|
else demandName[0] = '\0';
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2835,11 +2837,14 @@ int DLLEXPORT EN_setdemandname(EN_Project p, int nodeIndex, int demandIndex,
|
|||||||
if (!p->Openflag) return 102;
|
if (!p->Openflag) return 102;
|
||||||
if (nodeIndex <= 0 || nodeIndex > p->network.Njuncs) return 203;
|
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
|
// Locate demand category record and assign demandName to it
|
||||||
for (d = p->network.Node[nodeIndex].D;
|
for (d = p->network.Node[nodeIndex].D;
|
||||||
n < demandIndex && d->next != NULL; d = d->next) n++;
|
n < demandIndex && d->next != NULL; d = d->next) n++;
|
||||||
if (n != demandIndex) return 253;
|
if (n != demandIndex) return 253;
|
||||||
d->Name = xstrcpy(&d->Name, demandName, MAXMSG);
|
d->Name = xstrcpy(&d->Name, demandName, MAXID);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4417,26 +4422,26 @@ int DLLEXPORT EN_setcurvevalue(EN_Project p, int curveIndex, int pointIndex,
|
|||||||
if (curveIndex <= 0 || curveIndex > net->Ncurves) return 206;
|
if (curveIndex <= 0 || curveIndex > net->Ncurves) return 206;
|
||||||
curve = &net->Curve[curveIndex];
|
curve = &net->Curve[curveIndex];
|
||||||
if (pointIndex <= 0) return 251;
|
if (pointIndex <= 0) return 251;
|
||||||
|
|
||||||
// Check that new point maintains increasing x values
|
// Check that new point maintains increasing x values
|
||||||
if (n - 1 >= 0) x1 = curve->X[n-1];
|
if (n - 1 >= 0) x1 = curve->X[n-1];
|
||||||
if (n + 1 < curve->Npts) x2 = curve->X[n+1];
|
if (n + 1 < curve->Npts) x2 = curve->X[n+1];
|
||||||
if (x <= x1 || x >= x2) return 230;
|
if (x <= x1 || x >= x2) return 230;
|
||||||
|
|
||||||
// Expand curve if need be
|
// Expand curve if need be
|
||||||
if (pointIndex > curve->Npts) pointIndex = curve->Npts + 1;
|
if (pointIndex > curve->Npts) pointIndex = curve->Npts + 1;
|
||||||
if (pointIndex >= curve->Capacity)
|
if (pointIndex >= curve->Capacity)
|
||||||
{
|
{
|
||||||
if (resizecurve(curve, curve->Capacity + 10) > 0) return 101;
|
if (resizecurve(curve, curve->Capacity + 10) > 0) return 101;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increase curve's number of points if need be
|
// Increase curve's number of points if need be
|
||||||
if (pointIndex > curve->Npts)
|
if (pointIndex > curve->Npts)
|
||||||
{
|
{
|
||||||
curve->Npts++;
|
curve->Npts++;
|
||||||
n = curve->Npts - 1;
|
n = curve->Npts - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert new point into curve
|
// Insert new point into curve
|
||||||
curve->X[n] = x;
|
curve->X[n] = x;
|
||||||
curve->Y[n] = y;
|
curve->Y[n] = y;
|
||||||
|
|||||||
@@ -762,7 +762,7 @@ int demanddata(Project *pr)
|
|||||||
if (parser->Comment[0])
|
if (parser->Comment[0])
|
||||||
{
|
{
|
||||||
demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXID);
|
demand->Name = xstrcpy(&demand->Name, parser->Comment, MAXID);
|
||||||
}
|
}
|
||||||
demand->next = NULL;
|
demand->next = NULL;
|
||||||
cur_demand->next = demand;
|
cur_demand->next = demand;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ BOOST_AUTO_TEST_SUITE (test_demand)
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_categories_save)
|
BOOST_AUTO_TEST_CASE(test_categories_save)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
int Nindex, ndem;
|
int Nindex, ndem;
|
||||||
|
|
||||||
EN_Project ph = NULL;
|
EN_Project ph = NULL;
|
||||||
@@ -34,15 +34,19 @@ BOOST_AUTO_TEST_CASE(test_categories_save)
|
|||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_CHECK(ndem == 1);
|
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);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_saveinpfile(ph, "net1_dem_cat.inp");
|
error = EN_saveinpfile(ph, "net1_dem_cat.inp");
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
error = EN_close(ph);
|
error = EN_close(ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_deleteproject(&ph);
|
error = EN_deleteproject(&ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(test_categories_reopen, * boost::unit_test::depends_on("test_demand/test_categories_save"))
|
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;
|
EN_Project ph = NULL;
|
||||||
|
|
||||||
BOOST_TEST_CHECKPOINT("Reopening saved input file");
|
BOOST_TEST_CHECKPOINT("Reopening saved input file");
|
||||||
error = EN_createproject(&ph);
|
error = EN_createproject(&ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_open(ph, "net1_dem_cat.inp", DATA_PATH_RPT, DATA_PATH_OUT);
|
error = EN_open(ph, "net1_dem_cat.inp", DATA_PATH_RPT, DATA_PATH_OUT);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
error = EN_getnodeindex(ph, (char *)"12", &Nindex);
|
error = EN_getnodeindex(ph, (char *)"12", &Nindex);
|
||||||
BOOST_REQUIRE(error == 0);
|
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_REQUIRE(error == 0);
|
||||||
BOOST_CHECK(ndem == 1);
|
BOOST_CHECK(ndem == 1);
|
||||||
|
|
||||||
char demname[80];
|
char demname[31];
|
||||||
error = EN_getdemandname(ph, Nindex, ndem, demname);
|
error = EN_getdemandname(ph, Nindex, ndem, demname);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
BOOST_CHECK(check_string(demname, "Demand category name"));
|
BOOST_CHECK(check_string(demname, "Demand category name"));
|
||||||
|
|
||||||
error = EN_close(ph);
|
error = EN_close(ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
error = EN_deleteproject(&ph);
|
error = EN_deleteproject(&ph);
|
||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|||||||
Reference in New Issue
Block a user