From 0cfb5a4e1edbc164fc674a98ee8d788c821fbc39 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Wed, 4 Feb 2015 22:00:43 +0100 Subject: got annotation parsing to work with the comments domain. detected a bug, though (or better said: A conceptual problem) --- test/plugins/xml/XmlParserTest.cpp | 62 +++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp index 2d0cb6f..6619199 100644 --- a/test/plugins/xml/XmlParserTest.cpp +++ b/test/plugins/xml/XmlParserTest.cpp @@ -89,6 +89,7 @@ static void checkStructuredClass( ASSERT_EQ(cardinality, sc->getCardinality()); ASSERT_EQ(transparent, sc->isTransparent()); ASSERT_EQ(root, sc->hasRootPermission()); + ASSERT_EQ(attributesDescriptor, sc->getAttributesDescriptor()); } static Rooted checkStructuredClass( @@ -108,6 +109,31 @@ static Rooted checkStructuredClass( return sc; } +static void checkAnnotationClass( + Handle n, const std::string &name, Handle domain, + Handle attributesDescriptor = nullptr) +{ + ASSERT_FALSE(n == nullptr); + Handle ac = n.cast(); + ASSERT_FALSE(ac == nullptr); + ASSERT_EQ(name, ac->getName()); + ASSERT_EQ(domain, ac->getParent()); + ASSERT_EQ(attributesDescriptor, ac->getAttributesDescriptor()); +} + +static Rooted checkAnnotationClass( + const std::string &resolve, const std::string &name, Handle domain, + Handle attributesDescriptor = nullptr) +{ + auto res = domain->resolve(RttiTypes::AnnotationClass, resolve); + if (res.size() != 1) { + throw OusiaException("resolution error!"); + } + Handle ac = res[0].node.cast(); + checkAnnotationClass(ac, name, domain, attributesDescriptor); + return ac; +} + static void checkFieldDescriptor( Handle n, const std::string &name, Handle parent, NodeVector children, @@ -180,7 +206,7 @@ TEST(XmlParser, domainParsing) text, {}, "content", FieldDescriptor::FieldType::PRIMITIVE, env.project->getSystemTypesystem()->getStringType(), false); - // check parent handling. + // check parent handling using the headings domain. Rooted headings_domain_node = env.parse("headings_domain.oxm", "", "", RttiSet{&RttiTypes::Domain}); ASSERT_FALSE(headings_domain_node == nullptr); @@ -204,6 +230,40 @@ TEST(XmlParser, domainParsing) FieldDescriptor::FieldType::SUBTREE, nullptr, true); checkFieldDescriptor(paragraph, {heading}, "heading", FieldDescriptor::FieldType::SUBTREE, nullptr, true); + + // check annotation handling using the comments domain. + Rooted comments_domain_node = + env.parse("comments_domain.oxm", "", "", RttiSet{&RttiTypes::Domain}); + ASSERT_FALSE(comments_domain_node == nullptr); + ASSERT_FALSE(logger.hasError()); + Rooted comments_domain = comments_domain_node.cast(); + // now we should be able to find a comment annotation. + Rooted comment_anno = + checkAnnotationClass("comment", "comment", comments_domain); + // as well as a comment struct + Rooted comment = + checkStructuredClass("comment", "comment", comments_domain); + // and a reply struct + Rooted reply = + checkStructuredClass("reply", "reply", comments_domain); + // check the fields for each of them. + { + std::vector> descs{comment_anno, comment, reply}; + for (auto &d : descs) { + checkFieldDescriptor(d, {paragraph}, "content", + FieldDescriptor::FieldType::SUBTREE, nullptr, + false); + checkFieldDescriptor(d, {reply}, "replies", + FieldDescriptor::FieldType::SUBTREE, nullptr, + false); + } + } + // paragraph should have comment as child now as well. + checkFieldDescriptor(paragraph, {text, comment}); + // as should heading, because it references the paragraph default field. + // TODO: This does not work as of now, because in fact fields get copied, + // not referenced. Should we reference fields, though? + //checkFieldDescriptor(heading, {text, comment}); } } -- cgit v1.2.3