summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-28 00:54:05 +0100
committerAndreas Stöckel <andreas@somweyr.de>2014-12-28 00:54:05 +0100
commit3f22fdbf6aa5d4543c122a91cf244046697a1ec9 (patch)
treea4ea51b9147d7773a5fa1d5fb1bbac3f644082ec /test
parent079b45a6745dc296a60622d5a4897ccdfcf1fa0f (diff)
Finished StructType implementation, started to write unit tests
Diffstat (limited to 'test')
-rw-r--r--test/core/common/VariantReaderTest.cpp4
-rw-r--r--test/core/model/DocumentTest.cpp6
-rw-r--r--test/core/model/DomainTest.cpp3
-rw-r--r--test/core/model/TestDomain.hpp10
-rw-r--r--test/core/model/TypesystemTest.cpp35
5 files changed, 43 insertions, 15 deletions
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> domain = constructBookDomain(mgr);
+ Rooted<Domain> domain = constructBookDomain(mgr, logger);
// Construct the document.
Rooted<Document> 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<Rooted<Managed>> &result, size_t idx,
TEST(Domain, testDomainResolving)
{
// Construct Manager
+ Logger logger;
Manager mgr{1};
// Get the domain.
- Rooted<Domain> domain = constructBookDomain(mgr);
+ Rooted<Domain> 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<Typesystem> constructTypeSystem(Manager &mgr)
+static Rooted<Typesystem> constructTypeSystem(Manager &mgr, Logger &logger)
{
Rooted<Typesystem> sys{new Typesystem(mgr, "std")};
Rooted<StringType> string{new StringType(mgr, sys)};
sys->addType(string);
- Rooted<StructType> string_struct{new StructType(
- mgr, "text", sys, {new Attribute(mgr, "content", string, "", false)})};
+ Rooted<StructType> 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<Typesystem> 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<Domain> constructBookDomain(Manager &mgr)
+static Rooted<Domain> constructBookDomain(Manager &mgr, Logger &logger)
{
// Start with the Domain itself.
Rooted<Domain> 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{EnumType::createValidated(
- mgr, "enum", nullptr, {}, logger)};
+ Rooted<EnumType> enumType{
+ EnumType::createValidated(mgr, "enum", nullptr, {}, logger)};
ASSERT_EQ(Severity::ERROR, logger.getMaxEncounteredSeverity());
}
{
Logger logger;
- Rooted<EnumType> enumType{EnumType::createValidated(
- mgr, "enum", nullptr, {"a a"}, logger)};
+ Rooted<EnumType> 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<StructType> createStructType(Manager &mgr, Logger &logger)
+{
+ Rooted<StringType> stringType{new StringType(mgr, nullptr)};
+ Rooted<IntType> intType{new IntType(mgr, nullptr)};
+ Rooted<StructType> structType{StructType::createValidated(
+ mgr, "struct", nullptr, nullptr,
+ NodeVector<Attribute>{
+ 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> structType = createStructType(mgr, logger);
+ ASSERT_TRUE(structType->isa(RttiTypes::StructType));
+ ASSERT_TRUE(structType->isa(typeOf<Type>()));
+ ASSERT_TRUE(structType->isa(typeOf<Node>()));
+}
+
/* Class ArrayType */
TEST(ArrayType, rtti)