From 3f22fdbf6aa5d4543c122a91cf244046697a1ec9 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 28 Dec 2014 00:54:05 +0100 Subject: Finished StructType implementation, started to write unit tests --- test/core/common/VariantReaderTest.cpp | 4 ++-- test/core/model/DocumentTest.cpp | 6 +++--- test/core/model/DomainTest.cpp | 3 ++- test/core/model/TestDomain.hpp | 10 +++++----- test/core/model/TypesystemTest.cpp | 35 ++++++++++++++++++++++++++++++---- 5 files changed, 43 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/core/common/VariantReaderTest.cpp b/test/core/common/VariantReaderTest.cpp index 9f21c19..3ab38b9 100644 --- a/test/core/common/VariantReaderTest.cpp +++ b/test/core/common/VariantReaderTest.cpp @@ -23,8 +23,8 @@ namespace ousia { -// static TerminalLogger logger{std::cerr, true}; -static Logger logger; +static TerminalLogger logger{std::cerr, true}; +//static Logger logger; TEST(VariantReader, readString) { diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index 26553dd..9e3229c 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -27,16 +27,16 @@ namespace ousia { namespace model { - TEST(Document, testDocumentConstruction) { // Construct Manager + Logger logger; Manager mgr{1}; // Get the domain. - Rooted domain = constructBookDomain(mgr); + Rooted domain = constructBookDomain(mgr, logger); // Construct the document. Rooted doc = constructBookDocument(mgr, domain); - + // If that works we are happy already. ASSERT_FALSE(doc.isNull()); } diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index e16da96..a69d805 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -46,9 +46,10 @@ void assert_path(std::vector> &result, size_t idx, TEST(Domain, testDomainResolving) { // Construct Manager + Logger logger; Manager mgr{1}; // Get the domain. - Rooted domain = constructBookDomain(mgr); + Rooted domain = constructBookDomain(mgr, logger); /* * Start with the "book" search keyword. This should resolve to the domain diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp index 55a5d9b..d55bff7 100644 --- a/test/core/model/TestDomain.hpp +++ b/test/core/model/TestDomain.hpp @@ -30,13 +30,13 @@ namespace model { * * Currently contained: string, text (struct wrapper for string) */ -static Rooted constructTypeSystem(Manager &mgr) +static Rooted constructTypeSystem(Manager &mgr, Logger &logger) { Rooted sys{new Typesystem(mgr, "std")}; Rooted string{new StringType(mgr, sys)}; sys->addType(string); - Rooted string_struct{new StructType( - mgr, "text", sys, {new Attribute(mgr, "content", string, "", false)})}; + Rooted string_struct{StructType::createValidated( + mgr, "text", sys, nullptr, {new Attribute(mgr, "content", string, "", false)}, logger)}; sys->addType(string_struct); return sys; @@ -46,12 +46,12 @@ static Rooted constructTypeSystem(Manager &mgr) * This constructs the "book" domain for test purposes. The structure of the * domain is fairly simple and can be seen from the construction itself. */ -static Rooted constructBookDomain(Manager &mgr) +static Rooted constructBookDomain(Manager &mgr, Logger &logger) { // Start with the Domain itself. Rooted domain{new Domain(mgr, "book")}; // The standard type system. - domain->getTypesystems().push_back(constructTypeSystem(mgr)); + domain->getTypesystems().push_back(constructTypeSystem(mgr, logger)); // Set up the cardinalities we'll need. Cardinality single; single.merge({1}); diff --git a/test/core/model/TypesystemTest.cpp b/test/core/model/TypesystemTest.cpp index f94e91b..5757213 100644 --- a/test/core/model/TypesystemTest.cpp +++ b/test/core/model/TypesystemTest.cpp @@ -337,15 +337,15 @@ TEST(EnumType, createValidated) { Logger logger; - Rooted enumType{EnumType::createValidated( - mgr, "enum", nullptr, {}, logger)}; + Rooted enumType{ + EnumType::createValidated(mgr, "enum", nullptr, {}, logger)}; ASSERT_EQ(Severity::ERROR, logger.getMaxEncounteredSeverity()); } { Logger logger; - Rooted enumType{EnumType::createValidated( - mgr, "enum", nullptr, {"a a"}, logger)}; + Rooted enumType{ + EnumType::createValidated(mgr, "enum", nullptr, {"a a"}, logger)}; ASSERT_EQ(Severity::ERROR, logger.getMaxEncounteredSeverity()); } } @@ -380,6 +380,33 @@ TEST(EnumType, valueOf) ASSERT_THROW(enumType->valueOf("e"), LoggableException); } +/* Class StructType */ + +static Rooted createStructType(Manager &mgr, Logger &logger) +{ + Rooted stringType{new StringType(mgr, nullptr)}; + Rooted intType{new IntType(mgr, nullptr)}; + Rooted structType{StructType::createValidated( + mgr, "struct", nullptr, nullptr, + NodeVector{ + new Attribute{mgr, "attr1", stringType, "attr1default"}, + new Attribute{mgr, "attr2", stringType}, + new Attribute{mgr, "attr3", intType, 3}, + new Attribute{mgr, "attr4", intType}}, + logger)}; + return structType; +} + +TEST(StructType, rtti) +{ + Logger logger; + Manager mgr; + Rooted structType = createStructType(mgr, logger); + ASSERT_TRUE(structType->isa(RttiTypes::StructType)); + ASSERT_TRUE(structType->isa(typeOf())); + ASSERT_TRUE(structType->isa(typeOf())); +} + /* Class ArrayType */ TEST(ArrayType, rtti) -- cgit v1.2.3