8000 Return object index from EN_addnode and EN_addlink (issue #432) by LRossman · Pull Request #461 · OpenWaterAnalytics/EPANET · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Return object index from EN_addnode and EN_addlink (issue #432) #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 19, 2019

Conversation

LRossman
Copy link
Collaborator

Adds an output argument to EN_addnode and EN_addlink that returns the index of the newly added object.
Also refactors the validity check on object ID names.

Lew Rossman added 3 commits April 18, 2019 07:00
Adds an output argument to EN_addnode and EN_addlink that returns the index of the newly added object.
Also refactors the validity check on object ID names.
@codecov-io
Copy link
codecov-io commented Apr 18, 2019

Codecov Report

Merging #461 into dev will increase coverage by 0.06%.
The diff coverage is 70.58%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #461      +/-   ##
==========================================
+ Coverage   70.32%   70.39%   +0.06%     
==========================================
  Files          23       22       -1     
  Lines        9907     9889      -18     
==========================================
- Hits         6967     6961       -6     
+ Misses       2940     2928      -12
Impacted Files Coverage Δ
src/report.c 73.78% <ø> (ø) ⬆️
src/epanet2.c 5.71% <0%> (ø) ⬆️
src/project.c 90.19% <100%> (+0.08%) ⬆️
src/epanet.c 59.08% <76.92%> (-0.11%) ⬇️
src/util/cstr_helper.c
src/smatrix.c 98.81% <0%> (+0.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4494db8...a4ac34d. Read the comment docs.

BOOST_REQUIRE(error == 252);

error = EN_addnode(ph, (char *)"N\"3", EN_JUNCTION);
error = EN_addnode(ph, (char *)"N\"3", EN_JUNCTION, &index);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This is ok with EPANET UI.
image

8000

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This observation about the UI accepting N\"3 as a valid ID raises a number of points:

  1. Not only will the UI accept the ID but so will the EN_open API function that reads in an input file.
  2. The new update to the UI will not allow a space, semi-colon, or double quote to be entered into an ID field in the Property Editor (which is a good thing).
  3. The engine code's input file reader does not do any checking of ID names. If they exceed 31 characters they are truncated. If the ID in the original input line had a pair of double quotes for the ID name field, the name will be truncated at the first quote and the characters within the quotes will be treated as a separate token. This behavior may (or may not) trigger an input error.

It's my opionion that we stick with the current restriction on valid ID names used with the EN_add functions but also extend it to the names processed through an .INP file, even if this might affect backward compatibility.

@LRossman
Copy link
Collaborator Author

This is an update on the question of not allowing double quotes in an object ID name. A closer inspection of EPANET's input file parsing routine shows that a double quote in an ID name is only a problem if it is the first character in the name. So N\"3 should be allowed, as should abc"def"efg, but not "abc. This PR will be updated to reflect this.

@@ -57,7 +57,7 @@ BOOST_FIXTURE_TEST_CASE(test_node_validate_id, FixtureInitClose)
error = EN_addnode(ph, (char *)"N 3", EN_JUNCTION, &index);
BOOST_REQUIRE(error == 252);

8000
error = EN_addnode(ph, (char *)"N\"3", EN_JUNCTION, &index);
error = EN_addnode(ph, (char *)"\"N3", EN_JUNCTION, &index);
BOOST_REQUIRE(error == 252);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with matlab test:
image

Returns of this function with this node ID is zero, not 252.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In C/C++ code, a double quote in a string literal needs to be preceeded by an escape character (the backslash) so it is not interpreted as the end of string marker. So in the C code for test_node.cpp, the literal "\"N3" is read as "N3 by the compiler and fails to be a valid ID name. In Matlab, I'm guessing that '\"N3' is interpreted as \"N3 which is valid since it doesn't begin with a double quote.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LRossman , Thanks! Then this PR looks ok.

@LRossman LRossman merged commit ebb271c into dev Apr 19, 2019
@LRossman LRossman deleted the lrossman-dev branch April 19, 2019 15:03
@rjanke20 rjanke20 mentioned this pull request Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0