From 3883e6df939ad1ecb9a788153e087fefd9f0e838 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Fri, 6 Feb 2015 16:47:49 +0100 Subject: corrected attributes descriptor handling. --- test/plugins/xml/XmlParserTest.cpp | 41 +++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'test/plugins/xml/XmlParserTest.cpp') diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp index 0512fd0..647fc6d 100644 --- a/test/plugins/xml/XmlParserTest.cpp +++ b/test/plugins/xml/XmlParserTest.cpp @@ -74,6 +74,27 @@ TEST(XmlParser, generic) #endif } +static void checkAttributes(Handle expected, + Handle desc) +{ + if (expected == nullptr) { + ASSERT_TRUE(desc->getAttributesDescriptor()->getAttributes().empty()); + } else { + ASSERT_EQ(expected->getName(), + desc->getAttributesDescriptor()->getName()); + auto &attrs_exp = expected->getAttributes(); + auto &attrs = desc->getAttributesDescriptor()->getAttributes(); + ASSERT_EQ(attrs_exp.size(), attrs.size()); + for (size_t i = 0; i < attrs_exp.size(); i++) { + ASSERT_EQ(attrs_exp[i]->getName(), attrs[i]->getName()); + ASSERT_EQ(attrs_exp[i]->getType(), attrs[i]->getType()); + ASSERT_EQ(attrs_exp[i]->isOptional(), attrs[i]->isOptional()); + ASSERT_EQ(attrs_exp[i]->getDefaultValue(), + attrs[i]->getDefaultValue()); + } + } +} + static void checkStructuredClass( Handle n, const std::string &name, Handle domain, Variant cardinality = AnyCardinality, @@ -89,7 +110,7 @@ static void checkStructuredClass( ASSERT_EQ(cardinality, sc->getCardinality()); ASSERT_EQ(transparent, sc->isTransparent()); ASSERT_EQ(root, sc->hasRootPermission()); - ASSERT_EQ(attributesDescriptor, sc->getAttributesDescriptor()); + checkAttributes(attributesDescriptor, sc); } static Rooted checkStructuredClass( @@ -118,7 +139,7 @@ static void checkAnnotationClass( ASSERT_FALSE(ac == nullptr); ASSERT_EQ(name, ac->getName()); ASSERT_EQ(domain, ac->getParent()); - ASSERT_EQ(attributesDescriptor, ac->getAttributesDescriptor()); + checkAttributes(attributesDescriptor, ac); } static Rooted checkAnnotationClass( @@ -191,8 +212,15 @@ TEST(XmlParser, domainParsing) // get the book struct node. Cardinality single; single.merge({1}); + Rooted bookAuthor{ + new StructType(book_domain->getManager(), "", nullptr)}; + bookAuthor->addAttribute( + {new Attribute(book_domain->getManager(), "author", + env.project->getSystemTypesystem()->getStringType(), + "")}, + logger); Rooted book = checkStructuredClass( - "book", "book", book_domain, single, nullptr, nullptr, false, true); + "book", "book", book_domain, single, bookAuthor, nullptr, false, true); // get the chapter struct node. Rooted chapter = checkStructuredClass("chapter", "chapter", book_domain); @@ -274,5 +302,12 @@ TEST(XmlParser, domainParsing) // as should heading, because it references the paragraph default field. checkFieldDescriptor(heading, paragraph, {text, comment}); } + +TEST(XmlParser, documentParsing) +{ + XmlStandaloneEnvironment env(logger); + Rooted book_domain_node = + env.parse("simple_book.oxd", "", "", RttiSet{&RttiTypes::Document}); +} } -- cgit v1.2.3