From 7b6c47dca58a1aceb8fea2b66c3e0aa302ade67a Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sat, 17 Jan 2015 15:59:13 +0100 Subject: Added additional unit test for the setParentStructure function --- test/core/model/TypesystemTest.cpp | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/core') diff --git a/test/core/model/TypesystemTest.cpp b/test/core/model/TypesystemTest.cpp index 5871092..5a2efdd 100644 --- a/test/core/model/TypesystemTest.cpp +++ b/test/core/model/TypesystemTest.cpp @@ -611,6 +611,51 @@ TEST(StructType, createValidated) } } +TEST(StructType, setParentStructure) +{ + Manager mgr; + Rooted sys{new SystemTypesystem(mgr)}; + Rooted sa{new StructType(mgr, "a", sys)}; + Rooted sb{new StructType(mgr, "b", sys)}; + Rooted sc{new StructType(mgr, "c", sys)}; + + sa->addAttribute(new Attribute{mgr, "a", sys->getBoolType()}, logger); + sb->addAttribute(new Attribute{mgr, "b", sys->getStringType()}, logger); + sc->addAttribute(new Attribute{mgr, "a", sys->getIntType()}, logger); + sc->addAttribute(new Attribute{mgr, "b", sys->getIntType()}, logger); + + ASSERT_TRUE(sa->validate(logger)); + ASSERT_TRUE(sb->validate(logger)); + ASSERT_TRUE(sc->validate(logger)); + + logger.reset(); + sb->setParentStructure(sa, logger); + ASSERT_EQ(2U, sb->getAttributes().size()); + ASSERT_EQ("a", sb->getAttributes()[0]->getName()); + ASSERT_EQ("b", sb->getAttributes()[1]->getName()); + ASSERT_EQ(sys->getBoolType(), sb->getAttributes()[0]->getType()); + ASSERT_EQ(sys->getStringType(), sb->getAttributes()[1]->getType()); + ASSERT_FALSE(logger.hasError()); + + logger.reset(); + sc->setParentStructure(sb, logger); + ASSERT_EQ(4U, sc->getAttributes().size()); + ASSERT_EQ("a", sc->getAttributes()[0]->getName()); + ASSERT_EQ("b", sc->getAttributes()[1]->getName()); + ASSERT_EQ(sys->getBoolType(), sc->getAttributes()[0]->getType()); + ASSERT_EQ(sys->getStringType(), sc->getAttributes()[1]->getType()); + ASSERT_TRUE(logger.hasError()); + + logger.reset(); + sc->setParentStructure(nullptr, logger); + ASSERT_EQ(2U, sc->getAttributes().size()); + ASSERT_EQ("a", sc->getAttributes()[0]->getName()); + ASSERT_EQ("b", sc->getAttributes()[1]->getName()); + ASSERT_EQ(sys->getIntType(), sc->getAttributes()[0]->getType()); + ASSERT_EQ(sys->getIntType(), sc->getAttributes()[1]->getType()); + ASSERT_FALSE(logger.hasError()); +} + TEST(StructType, cast) { Manager mgr; -- cgit v1.2.3 From 77ae5cbb14aa375ffe33d41921d84028a453b121 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 18 Jan 2015 00:37:51 +0100 Subject: Fixed order in which elements in StandaloneParserContext are created/freed (to prevent Manager empty assertion to fail) --- test/core/parser/StandaloneParserContext.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/core') diff --git a/test/core/parser/StandaloneParserContext.hpp b/test/core/parser/StandaloneParserContext.hpp index 64a245f..78d148d 100644 --- a/test/core/parser/StandaloneParserContext.hpp +++ b/test/core/parser/StandaloneParserContext.hpp @@ -26,10 +26,10 @@ namespace parser { struct StandaloneParserContext : public ParserContext { private: + Manager manager; Logger logger; Scope scope; Registry registry; - Manager manager; public: StandaloneParserContext() -- cgit v1.2.3 From d935bf07d15ddd117d07d83bb3818b6abc23cc0b Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 18 Jan 2015 00:39:21 +0100 Subject: Renamed continueResolve to doResolve for more consistency with other virtual protected methods --- src/core/model/Document.cpp | 2 +- src/core/model/Document.hpp | 2 +- src/core/model/Domain.cpp | 4 ++-- src/core/model/Domain.hpp | 4 ++-- src/core/model/Node.cpp | 4 ++-- src/core/model/Node.hpp | 2 +- test/core/model/NodeTest.cpp | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) (limited to 'test/core') diff --git a/src/core/model/Document.cpp b/src/core/model/Document.cpp index 0de750f..ee15e31 100644 --- a/src/core/model/Document.cpp +++ b/src/core/model/Document.cpp @@ -292,7 +292,7 @@ bool AnnotationEntity::doValidate(Logger &logger) const /* Class Document */ -void Document::continueResolve(ResolutionState &state) +void Document::doResolve(ResolutionState &state) { continueResolveComposita(annotations, annotations.getIndex(), state); if (root != nullptr) { diff --git a/src/core/model/Document.hpp b/src/core/model/Document.hpp index 5af3ce2..cb7f394 100644 --- a/src/core/model/Document.hpp +++ b/src/core/model/Document.hpp @@ -567,7 +567,7 @@ private: NodeVector annotations; NodeVector domains; - void continueResolve(ResolutionState &state) override; + void doResolve(ResolutionState &state) override; public: Document(Manager &mgr, std::string name) diff --git a/src/core/model/Domain.cpp b/src/core/model/Domain.cpp index 2ac2d8d..bae0f4f 100644 --- a/src/core/model/Domain.cpp +++ b/src/core/model/Domain.cpp @@ -70,7 +70,7 @@ FieldDescriptor::FieldDescriptor(Manager &mgr, Handle parent, /* Class Descriptor */ -void Descriptor::continueResolve(ResolutionState &state) +void Descriptor::doResolve(ResolutionState &state) { if (attributesDescriptor != nullptr) { const NodeVector &attributes = @@ -244,7 +244,7 @@ AnnotationClass::AnnotationClass( /* Class Domain */ -void Domain::continueResolve(ResolutionState &state) +void Domain::doResolve(ResolutionState &state) { if (!continueResolveComposita(structuredClasses, structuredClasses.getIndex(), state) | diff --git a/src/core/model/Domain.hpp b/src/core/model/Domain.hpp index ac02ec7..a8d4a9e 100644 --- a/src/core/model/Domain.hpp +++ b/src/core/model/Domain.hpp @@ -394,7 +394,7 @@ private: bool exploreSubclasses = true) const; protected: - void continueResolve(ResolutionState &state) override; + void doResolve(ResolutionState &state) override; /** * Adds a FieldDescriptor and checks for name uniqueness. @@ -682,7 +682,7 @@ private: NodeVector typesystems; protected: - void continueResolve(ResolutionState &state) override; + void doResolve(ResolutionState &state) override; void addStructuredClass(Handle s); void addAnnotationClass(Handle a); diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index da83598..7565ba9 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -272,14 +272,14 @@ bool Node::resolve(ResolutionState &state) } } else { size_t resCount = state.resultCount(); - continueResolve(state); + doResolve(state); return state.resultCount() > resCount; } } return false; } -void Node::continueResolve(ResolutionState &state) +void Node::doResolve(ResolutionState &state) { // Do nothing in the default implementation } diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index 0523c69..f8893a7 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -207,7 +207,7 @@ protected: * * @param state is used internally to manage the resolution process. */ - virtual void continueResolve(ResolutionState &state); + virtual void doResolve(ResolutionState &state); /** * Tries to advance the resolution process with the compositum pointed at diff --git a/test/core/model/NodeTest.cpp b/test/core/model/NodeTest.cpp index 973ce22..8bbee05 100644 --- a/test/core/model/NodeTest.cpp +++ b/test/core/model/NodeTest.cpp @@ -26,7 +26,7 @@ namespace ousia { class TestNode : public Node { protected: - void continueResolve(ResolutionState &state) override + void doResolve(ResolutionState &state) override { continueResolveComposita(composita, composita.getIndex(), state); continueResolveReferences(references, state); -- cgit v1.2.3 From 5c832e5cc0d2ff948816bd4a492189435efa8578 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 18 Jan 2015 13:45:28 +0100 Subject: added test for VariantReader::parseGenericString --- test/core/common/VariantReaderTest.cpp | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/core') diff --git a/test/core/common/VariantReaderTest.cpp b/test/core/common/VariantReaderTest.cpp index 3ab38b9..9a9b694 100644 --- a/test/core/common/VariantReaderTest.cpp +++ b/test/core/common/VariantReaderTest.cpp @@ -762,6 +762,42 @@ TEST(VariantReader, parseGeneric) } } +TEST(VariantReader, parseGenericString) +{ + // Simple case, unescaped string + { + auto res = VariantReader::parseGenericString("foo", logger); + ASSERT_TRUE(res.first); + ASSERT_TRUE(res.second.isMagic()); + ASSERT_EQ("foo", res.second.asMagic()); + } + + // Simple case, unescaped string with space + { + auto res = VariantReader::parseGenericString("foo bar", logger); + ASSERT_TRUE(res.first); + ASSERT_FALSE(res.second.isMagic()); + ASSERT_TRUE(res.second.isString()); + ASSERT_EQ("foo bar", res.second.asString()); + } + + // Parse double + { + auto res = VariantReader::parseGenericString("12.3", logger); + ASSERT_TRUE(res.first); + ASSERT_TRUE(res.second.isDouble()); + ASSERT_EQ(12.3, res.second.asDouble()); + } + + // Parse string + { + auto res = VariantReader::parseGenericString("6 times 7 is 42", logger); + ASSERT_TRUE(res.first); + ASSERT_TRUE(res.second.isString()); + ASSERT_EQ("6 times 7 is 42", res.second.asString()); + } +} + TEST(VariantReader, parseGenericComplex) { CharReader reader("10 true [1, 2] [] [foo=bar,h]; []"); -- cgit v1.2.3