RA-Consulting-GmbH / openscenario.api.test

Apache License 2.0
39 stars 12 forks source link

XmlSequenceParser::ParseSubElementsInternal does not increment _occuredElementList #209

Open rgourova opened 3 months ago

rgourova commented 3 months ago

Describe the bug _occuredElementList in XmlSequenceParser does not increment correctly the numbers of occurrences of a given parser. The emplace() method is used every time irrespective if the map element already exists or not. This leads to the element being placed in the map when created for the first time, however any consecutive encounter of the same element is discarded as the parser for it already exists. When there are two required elements which have min occurrence larger than 1, the second element will fail checks in XmlSequenceParser::GetNextIndex and the parsing of the scenario will fail with: "Required element is missing before XYZtag" .

To Reproduce Steps to reproduce the behavior:

  1. Create a scenario which includes two required elements that have >2 occurrence, for example one that contains a FollowTrajectoryAction with Nurbs shape
    <RoutingAction>
    <FollowTrajectoryAction>
    <TrajectoryRef>
      <Trajectory name="trajectory1" closed="false">
        <Shape>
          <Nurbs order="3">
            <ControlPoint time="0.0" weight="1.0">
              <Position>
                <WorldPosition x="0.0" y="0.0" z="0.0"/>
              </Position>
            </ControlPoint>
            ...
            <Knot value="0.0"/>
             ...
          </Nurbs>
        </Shape>
      </Trajectory>
    </TrajectoryRef>
    <TimeReference>
      <Timing domainAbsoluteRelative="absolute" scale="1" offset="0"/>
    </TimeReference>
    <TrajectoryFollowingMode followingMode="position"/>
    </FollowTrajectoryAction>
    </RoutingAction>
  2. Run the OpenScenarioReader on the created scenario
  3. Check the output of the OpenScenarioReader
  4. See error

Expected behavior The parser should be able to parse correctly all scenarios irrespective of the number of min required occurrence of elements contained in a tag.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop:

Additional context My proposed solution is to replace:

https://github.com/RA-Consulting-GmbH/openscenario.api.test/blob/6c6d6c43764029033b35987d1b8d69cea3a873f0/cpp/openScenarioLib/src/parser/modelgroup/XmlSequenceParser.cpp#L73

by:

auto it = _occuredElementList.find(parser);
if (it != _occuredElementList.end())
{
    it->second = currentOccurs + 1;
}
else
{
     _occuredElementList.emplace(parser, currentOccurs + 1);
 }
rgourova commented 3 months ago

PR #210 contains a test scenario (cpp/applications/openScenarioTester/res/exampleFilesVersion1_2/FollowTrajectory_Nurbs.xosc) which can be used for reproducing the reported issue. In that case the steps for reproducing the behavior will change to:

  1. Copy/download cpp/applications/openScenarioTester/res/exampleFilesVersion1_2/FollowTrajectory_Nurbs.xosc from https://github.com/rgourova/openscenario.api.test to your local openscenario.api.test repository (which does not contain the proposed changes)
  2. In your local openscenario.api.test repository cd into cpp/build/cgReleaseMakeShared/applications/OpenScenarioReader
  3. Run ./OpenScenarioReader -i <YOUR_PATH_TO>/cpp/applications/openScenarioTester/res/exampleFilesVersion1_2/FollowTrajectory_Nurbs.xosc -v1_2
  4. Check the output and observe the error: Required element is missing before