Merge pull request #431 from Mariosmsk/fix_bug_getdemandname
try to fix bug in EN_getdemandname
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ BOOST_AUTO_TEST_CASE(test_categories_save)
|
|||||||
BOOST_REQUIRE(error == 0);
|
BOOST_REQUIRE(error == 0);
|
||||||
BOOST_CHECK(ndem == 1);
|
BOOST_CHECK(ndem == 1);
|
||||||
|
|
||||||
|
char demname[31];
|
||||||
|
error = EN_getdemandname(ph, Nindex, ndem, demname);
|
||||||
|
BOOST_REQUIRE(error == 0);
|
||||||
|
|
||||||
error = EN_setdemandname(ph, Nindex, ndem, (char *)"Demand category name");
|
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");
|
||||||
@@ -64,7 +68,7 @@ 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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user