diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-10 20:57:16 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2015-02-10 20:57:16 +0100 |
commit | 928d989aef13e72064f31e3d6cad64f46c56bfdc (patch) | |
tree | 65babd36f9b071fb8736a8a6f8ed30afbc9b04e8 | |
parent | 76ab539306d98dfedb759731f6ea3808d3f5f9c0 (diff) |
added a document parsing test.
-rw-r--r-- | test/plugins/xml/XmlParserTest.cpp | 91 |
1 files changed, 89 insertions, 2 deletions
diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp index af1ef56..067214c 100644 --- a/test/plugins/xml/XmlParserTest.cpp +++ b/test/plugins/xml/XmlParserTest.cpp @@ -22,6 +22,7 @@ #include <core/common/CharReader.hpp> #include <core/common/SourceContextReader.hpp> +#include <core/model/Document.hpp> #include <core/model/Domain.hpp> #include <core/model/Node.hpp> #include <core/model/Project.hpp> @@ -303,12 +304,98 @@ TEST(XmlParser, domainParsing) checkFieldDescriptor(heading, paragraph, {text, comment}); } +static void checkStructuredEntity( + Handle<Node> s, Handle<Node> expectedParent, Handle<StructuredClass> strct, + const Variant::mapType &expectedAttributes = Variant::mapType{}, + const std::string &expectedName = "") +{ + ASSERT_FALSE(s == nullptr); + ASSERT_TRUE(s->isa(&RttiTypes::StructuredEntity)); + Rooted<StructuredEntity> entity = s.cast<StructuredEntity>(); + ASSERT_EQ(expectedParent, entity->getParent()); + ASSERT_EQ(strct, entity->getDescriptor()); + ASSERT_EQ(expectedAttributes, entity->getAttributes()); + ASSERT_EQ(expectedName, entity->getName()); +} + +static void checkStructuredEntity( + Handle<Node> s, Handle<Node> expectedParent, Handle<Document> doc, + const std::string &className, + const Variant::mapType &expectedAttributes = Variant::mapType{}, + const std::string &expectedName = "") +{ + auto res = doc->resolve(&RttiTypes::StructuredClass, className); + if (res.size() != 1) { + throw OusiaException("resolution error!"); + } + Handle<StructuredClass> sc = res[0].node.cast<StructuredClass>(); + checkStructuredEntity(s, expectedParent, sc, expectedAttributes, + expectedName); +} + +static void checkText(Handle<Node> p, Handle<Node> expectedParent, + Handle<Document> doc, Variant expected) +{ + checkStructuredEntity(p, expectedParent, doc, "paragraph"); + Rooted<StructuredEntity> par = p.cast<StructuredEntity>(); + ASSERT_EQ(1, par->getField().size()); + checkStructuredEntity(par->getField()[0], par, doc, "text"); + Rooted<StructuredEntity> text = par->getField()[0].cast<StructuredEntity>(); + ASSERT_EQ(1, text->getField().size()); + + Handle<StructureNode> d = text->getField()[0]; + ASSERT_FALSE(d == nullptr); + ASSERT_TRUE(d->isa(&RttiTypes::DocumentPrimitive)); + Rooted<DocumentPrimitive> prim = d.cast<DocumentPrimitive>(); + ASSERT_EQ(text, prim->getParent()); + ASSERT_EQ(expected, prim->getContent()); +} + TEST(XmlParser, documentParsing) { XmlStandaloneEnvironment env(logger); - Rooted<Node> book_domain_node = + Rooted<Node> book_document_node = env.parse("simple_book.oxd", "", "", RttiSet{&RttiTypes::Document}); - //TODO: Check result + ASSERT_FALSE(book_document_node == nullptr); + ASSERT_TRUE(book_document_node->isa(&RttiTypes::Document)); + Rooted<Document> doc = book_document_node.cast<Document>(); + ASSERT_TRUE(doc->validate(logger)); + checkStructuredEntity(doc->getRoot(), doc, doc, "book"); + { + Rooted<StructuredEntity> book = doc->getRoot(); + ASSERT_EQ(2, book->getField().size()); + checkText(book->getField()[0], book, doc, + "This might be some introductory text or a dedication."); + checkStructuredEntity(book->getField()[1], book, doc, "chapter", + Variant::mapType{}, "myFirstChapter"); + { + Rooted<StructuredEntity> chapter = + book->getField()[1].cast<StructuredEntity>(); + ASSERT_EQ(3, chapter->getField().size()); + checkText(chapter->getField()[0], chapter, doc, + "Here we might have an introduction to the chapter."); + checkStructuredEntity(chapter->getField()[1], chapter, doc, + "section", Variant::mapType{}, + "myFirstSection"); + { + Rooted<StructuredEntity> section = + chapter->getField()[1].cast<StructuredEntity>(); + ASSERT_EQ(1, section->getField().size()); + checkText(section->getField()[0], section, doc, + "Here we might find the actual section content."); + } + checkStructuredEntity(chapter->getField()[2], chapter, doc, + "section", Variant::mapType{}, + "mySndSection"); + { + Rooted<StructuredEntity> section = + chapter->getField()[2].cast<StructuredEntity>(); + ASSERT_EQ(1, section->getField().size()); + checkText(section->getField()[0], section, doc, + "Here we might find the actual section content."); + } + } + } } } |