diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-03-03 20:38:32 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2015-03-03 20:38:32 +0100 |
commit | e9f726d2f8108104d86e967dd27bba1fbe493b19 (patch) | |
tree | e0bf6412eecfe43b883b253748664e60c76f2cee | |
parent | ec758436a01903ded6ec5951fa1fc5d2fe062239 (diff) |
added more complex tests and prevented endless loops in DocumentChildHandler::startAnnotation
-rw-r--r-- | src/core/parser/stack/DocumentHandler.cpp | 10 | ||||
-rw-r--r-- | test/formats/osml/OsmlParserTest.cpp | 25 | ||||
-rw-r--r-- | testdata/osmlparser/error_annotation_boundaries.osml | 20 | ||||
-rw-r--r-- | testdata/osmlparser/overlapping_annotations.osml | 18 |
4 files changed, 73 insertions, 0 deletions
diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index 486ce81..c239583 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -302,6 +302,16 @@ bool DocumentChildHandler::startAnnotation(Variant::mapType &args) // pop the implicit element. scope().pop(logger()); continue; + } else { + logger().error( + "Cannot start or end annotation within the primitive field \"" + + parent->getDescriptor() + ->getFieldDescriptors()[fieldIdx] + ->getNameOrDefaultName() + + "\" of descriptor \"" + parent->getDescriptor()->getName() + + "\".", + location()); + return false; } } diff --git a/test/formats/osml/OsmlParserTest.cpp b/test/formats/osml/OsmlParserTest.cpp index 1c8894d..cc711b4 100644 --- a/test/formats/osml/OsmlParserTest.cpp +++ b/test/formats/osml/OsmlParserTest.cpp @@ -212,6 +212,31 @@ TEST(OsmlParser, simpleAnnotation) ASSERT_TRUE(node->isa(&RttiTypes::Document)); } +TEST(OsmlParser, overlappingAnnotations) +{ + OsmlStandaloneEnvironment env(logger); + logger.reset(); + + Rooted<Node> node = env.parse("overlapping_annotations.osml", "", "", + RttiSet{&RttiTypes::Node}); + ASSERT_FALSE(logger.hasError()); + + ASSERT_TRUE(node != nullptr); + ASSERT_TRUE(node->isa(&RttiTypes::Document)); +} + +TEST(OsmlParser, errorAnnotationBoundaries) +{ + OsmlStandaloneEnvironment env(logger); + logger.reset(); + + Rooted<Node> node = env.parse("error_annotation_boundaries.osml", "", "", + RttiSet{&RttiTypes::Node}); + ASSERT_TRUE(logger.hasError()); + + ASSERT_TRUE(node != nullptr); + ASSERT_TRUE(node->isa(&RttiTypes::Document)); +} } diff --git a/testdata/osmlparser/error_annotation_boundaries.osml b/testdata/osmlparser/error_annotation_boundaries.osml new file mode 100644 index 0000000..fb8e43b --- /dev/null +++ b/testdata/osmlparser/error_annotation_boundaries.osml @@ -0,0 +1,20 @@ +\begin{document} + +\ontology#testOntology + \struct#test[root=true] + \field + \childRef[ref=a] + \struct#a[transparent=true] + \primitive[type=string] + \annotation#comment + \field + \childRef[ref=a] + +\begin{test} +This boundary is a <\comment#c1{This is a stupid Cloud Atlas reference, isn't it?} +convention <\comment#c2{Change this to: "for overlapping annotations!"\comment#c1>} +for annotations\comment#c2>. +\end{test} + +\end{document} + diff --git a/testdata/osmlparser/overlapping_annotations.osml b/testdata/osmlparser/overlapping_annotations.osml new file mode 100644 index 0000000..be28070 --- /dev/null +++ b/testdata/osmlparser/overlapping_annotations.osml @@ -0,0 +1,18 @@ +\begin{document} + +\ontology#testOntology + \struct#test[root=true] + \field + \childRef[ref=a] + \struct#a[transparent=true] + \primitive[type=string] + \annotation#comment + \primitive[type=string] + +\begin{test} +This is a <\comment#c1{Not a nice test!}test <\comment#c2{Change this to: +"for overlapping annotations!"}for\comment#c1> annotations\comment#c2>. +\end{test} + +\end{document} + |