summaryrefslogtreecommitdiff
path: root/test/core/model
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-11 17:51:50 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2015-02-11 17:51:50 +0100
commitf812e01570aedd5033245a76846b5afc0063bc17 (patch)
tree012cbf8bc2dc482be094d789dd433ec4523c120b /test/core/model
parent5659292bf1a317235a51a946df640376f325b124 (diff)
made isSubtree (fieldType) and primitivity orthogonal concepts: PRIMITIVE is no FieldType anymore.
Diffstat (limited to 'test/core/model')
-rw-r--r--test/core/model/DocumentTest.cpp38
-rw-r--r--test/core/model/DomainTest.cpp66
-rw-r--r--test/core/model/TestAdvanced.hpp4
-rw-r--r--test/core/model/TestDomain.hpp18
4 files changed, 67 insertions, 59 deletions
diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp
index 3164b7e..5acf13f 100644
--- a/test/core/model/DocumentTest.cpp
+++ b/test/core/model/DocumentTest.cpp
@@ -67,11 +67,9 @@ TEST(Document, construct)
ASSERT_EQ("text", text->getDescriptor()->getName());
ASSERT_TRUE(text->getDescriptor()->hasField());
ASSERT_EQ(1U, text->getField().size());
- ASSERT_TRUE(
- text->getField()[0]->isa(typeOf<DocumentPrimitive>()));
- Variant content = text->getField()[0]
- .cast<DocumentPrimitive>()
- ->getContent();
+ ASSERT_TRUE(text->getField()[0]->isa(typeOf<DocumentPrimitive>()));
+ Variant content =
+ text->getField()[0].cast<DocumentPrimitive>()->getContent();
ASSERT_EQ("Some introductory text", content.asString());
}
}
@@ -101,11 +99,10 @@ TEST(Document, construct)
ASSERT_EQ("text", text->getDescriptor()->getName());
ASSERT_TRUE(text->getDescriptor()->hasField());
ASSERT_EQ(1U, text->getField().size());
- ASSERT_TRUE(text->getField()[0]->isa(
- typeOf<DocumentPrimitive>()));
- Variant content = text->getField()[0]
- .cast<DocumentPrimitive>()
- ->getContent();
+ ASSERT_TRUE(
+ text->getField()[0]->isa(typeOf<DocumentPrimitive>()));
+ Variant content =
+ text->getField()[0].cast<DocumentPrimitive>()->getContent();
ASSERT_EQ("Some actual text", content.asString());
}
}
@@ -149,7 +146,8 @@ TEST(Document, validate)
}
// now let's extend the rootClass with a default field.
- Rooted<FieldDescriptor> rootField{new FieldDescriptor(mgr, rootClass)};
+ Rooted<FieldDescriptor> rootField =
+ rootClass->createFieldDescriptor(logger);
// and add a child class for it.
Rooted<StructuredClass> childClass{
new StructuredClass(mgr, "child", domain, single)};
@@ -195,7 +193,8 @@ TEST(Document, validate)
* Make it even more complicated: child gets a field for further child
* instances now.
*/
- Rooted<FieldDescriptor> childField{new FieldDescriptor(mgr, childClass)};
+ Rooted<FieldDescriptor> childField =
+ childClass->createFieldDescriptor(logger);
childField->addChild(childClass);
{
/*
@@ -211,10 +210,13 @@ TEST(Document, validate)
ASSERT_FALSE(doc->validate(logger));
}
/*
- * Override the default field in childSubClass.
+ * Override the default field in childSubClass with an optional field.
*/
- Rooted<FieldDescriptor> childSubField{
- new FieldDescriptor(mgr, childSubClass)};
+ Rooted<FieldDescriptor> childSubField =
+ childSubClass->createFieldDescriptor(
+ logger, FieldDescriptor::FieldType::TREE, "dummy", true);
+ // add a child pro forma to make it valid.
+ childSubField->addChild(childSubClass);
{
/*
* Now a document with one instance of the Child subclass should be
@@ -229,8 +231,10 @@ TEST(Document, validate)
ASSERT_TRUE(doc->validate(logger));
}
// add a primitive field to the subclass with integer content.
- Rooted<FieldDescriptor> primitive_field{new FieldDescriptor(
- mgr, childSubClass, sys->getIntType(), "int", false)};
+ Rooted<FieldDescriptor> primitive_field =
+ childSubClass->createPrimitiveFieldDescriptor(
+ sys->getIntType(), logger, FieldDescriptor::FieldType::SUBTREE,
+ "int", false);
{
/*
* Now a document with one instance of the Child subclass should be
diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp
index 32ef7f0..59062f0 100644
--- a/test/core/model/DomainTest.cpp
+++ b/test/core/model/DomainTest.cpp
@@ -145,9 +145,10 @@ TEST(Descriptor, pathToAdvanced)
* 8.) E is transparent and has target as child in the default field
* (longer path)
*
- * So the path start_field , E , E_field should be returned.
+ * So the path A_second_field, C, C_field should be returned.
*/
Manager mgr{1};
+ Logger logger;
Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)};
// Construct the domain
Rooted<Domain> domain{new Domain(mgr, sys, "nasty")};
@@ -162,8 +163,8 @@ TEST(Descriptor, pathToAdvanced)
Rooted<StructuredClass> B{new StructuredClass(
mgr, "B", domain, Cardinality::any(), {nullptr}, true, false)};
- Rooted<StructuredClass> C{
- new StructuredClass(mgr, "C", domain, Cardinality::any(), B, true, false)};
+ Rooted<StructuredClass> C{new StructuredClass(
+ mgr, "C", domain, Cardinality::any(), B, true, false)};
Rooted<StructuredClass> D{new StructuredClass(
mgr, "D", domain, Cardinality::any(), {nullptr}, true, false)};
@@ -175,31 +176,32 @@ TEST(Descriptor, pathToAdvanced)
new StructuredClass(mgr, "target", domain, Cardinality::any())};
// We create two fields for A
- Rooted<FieldDescriptor> A_field{new FieldDescriptor(mgr, A)};
+ Rooted<FieldDescriptor> A_field = A->createFieldDescriptor(logger);
A_field->addChild(target);
- Rooted<FieldDescriptor> A_field2{new FieldDescriptor(
- mgr, A, FieldDescriptor::FieldType::SUBTREE, "second")};
+ Rooted<FieldDescriptor> A_field2 = A->createFieldDescriptor(
+ logger, FieldDescriptor::FieldType::SUBTREE, "second", false);
A_field2->addChild(B);
// We create no field for B
// One for C
- Rooted<FieldDescriptor> C_field{new FieldDescriptor(mgr, C)};
+ Rooted<FieldDescriptor> C_field = C->createFieldDescriptor(logger);
C_field->addChild(target);
// one for start
- Rooted<FieldDescriptor> start_field{new FieldDescriptor(mgr, start)};
+ Rooted<FieldDescriptor> start_field = start->createFieldDescriptor(logger);
start_field->addChild(D);
// One for D
- Rooted<FieldDescriptor> D_field{new FieldDescriptor(mgr, D)};
+ Rooted<FieldDescriptor> D_field = D->createFieldDescriptor(logger);
D_field->addChild(E);
// One for E
- Rooted<FieldDescriptor> E_field{new FieldDescriptor(mgr, E)};
+ Rooted<FieldDescriptor> E_field = E->createFieldDescriptor(logger);
E_field->addChild(target);
+ ASSERT_TRUE(domain->validate(logger));
#ifdef MANAGER_GRAPHVIZ_EXPORT
// dump the manager state
mgr.exportGraphviz("nastyDomain.dot");
@@ -313,8 +315,8 @@ TEST(Domain, validate)
ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
ASSERT_TRUE(domain->validate(logger));
// Let's add a primitive field (without a primitive type at first)
- Rooted<FieldDescriptor> base_field{
- new FieldDescriptor(mgr, base, nullptr)};
+ Rooted<FieldDescriptor> base_field =
+ base->createPrimitiveFieldDescriptor(nullptr, logger);
// this should not be valid.
ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
ASSERT_FALSE(domain->validate(logger));
@@ -322,13 +324,6 @@ TEST(Domain, validate)
base_field->setPrimitiveType(sys->getStringType());
ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
ASSERT_TRUE(domain->validate(logger));
- // not anymore, however, if we tamper with the FieldType.
- base_field->setFieldType(FieldDescriptor::FieldType::TREE);
- ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
- ASSERT_FALSE(domain->validate(logger));
- base_field->setFieldType(FieldDescriptor::FieldType::PRIMITIVE);
- ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
- ASSERT_TRUE(domain->validate(logger));
// add a subclass for our base class.
Rooted<StructuredClass> sub{new StructuredClass(mgr, "sub", domain)};
// this should be valid in itself.
@@ -338,7 +333,7 @@ TEST(Domain, validate)
sub->setSuperclass(base, logger);
ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
ASSERT_TRUE(domain->validate(logger));
- // and still we we remove the subclass from the base class.
+ // and still if we remove the subclass from the base class.
base->removeSubclass(sub, logger);
ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
ASSERT_TRUE(domain->validate(logger));
@@ -349,19 +344,11 @@ TEST(Domain, validate)
ASSERT_TRUE(domain->validate(logger));
ASSERT_EQ(base, sub->getSuperclass());
// add a non-primitive field to the child class.
- Rooted<FieldDescriptor> sub_field{new FieldDescriptor(mgr, sub)};
- // this should be valid
- ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
- ASSERT_TRUE(domain->validate(logger));
- // .. until we set a primitive type.
- sub_field->setPrimitiveType(sys->getStringType());
+ Rooted<FieldDescriptor> sub_field = sub->createFieldDescriptor(logger);
+ // this should not be valid because we allow no children.
ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
ASSERT_FALSE(domain->validate(logger));
- // and valid again if we unset it.
- sub_field->setPrimitiveType(nullptr);
- ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
- ASSERT_TRUE(domain->validate(logger));
- // we should also be able to add a child and have it still be valid.
+ // we should also be able to add a child and make it valid.
sub_field->addChild(base);
ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
ASSERT_TRUE(domain->validate(logger));
@@ -373,6 +360,23 @@ TEST(Domain, validate)
sub_field->removeChild(base);
ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
ASSERT_TRUE(domain->validate(logger));
+ // if we set a primitive type it should be invalid
+ sub_field->setPrimitiveType(sys->getStringType());
+ ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
+ ASSERT_FALSE(domain->validate(logger));
+ // and valid again if we unset it.
+ sub_field->setPrimitiveType(nullptr);
+ ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
+ ASSERT_TRUE(domain->validate(logger));
+ // It should be invalid if we set another TREE field.
+ Rooted<FieldDescriptor> sub_field2 = sub->createFieldDescriptor(
+ logger, FieldDescriptor::FieldType::TREE, "test", false);
+ ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
+ ASSERT_FALSE(domain->validate(logger));
+ // but valid again if we remove it
+ sub->removeFieldDescriptor(sub_field2);
+ ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());
+ ASSERT_TRUE(domain->validate(logger));
}
}
}
diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp
index 915d973..9c95400 100644
--- a/test/core/model/TestAdvanced.hpp
+++ b/test/core/model/TestAdvanced.hpp
@@ -65,8 +65,8 @@ static Rooted<Domain> constructHeadingDomain(Manager &mgr,
"paragraph"};
for (auto &s : secclasses) {
Rooted<StructuredClass> desc = resolveDescriptor(bookDomain, s);
- Rooted<FieldDescriptor> heading_field{new FieldDescriptor(
- mgr, desc, FieldDescriptor::FieldType::SUBTREE, "heading")};
+ Rooted<FieldDescriptor> heading_field = desc->createFieldDescriptor(
+ logger, FieldDescriptor::FieldType::SUBTREE, "heading", true);
heading_field->addChild(heading);
}
return domain;
diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp
index 5ac510c..c107a0d 100644
--- a/test/core/model/TestDomain.hpp
+++ b/test/core/model/TestDomain.hpp
@@ -42,7 +42,7 @@ static Rooted<Domain> constructBookDomain(Manager &mgr,
mgr, "book", domain, single, {nullptr}, false, true)};
// The structure field of it.
- Rooted<FieldDescriptor> book_field{new FieldDescriptor(mgr, book)};
+ Rooted<FieldDescriptor> book_field = book->createFieldDescriptor(logger);
// From there on the "section".
Rooted<StructuredClass> section{
@@ -50,7 +50,8 @@ static Rooted<Domain> constructBookDomain(Manager &mgr,
book_field->addChild(section);
// And the field of it.
- Rooted<FieldDescriptor> section_field{new FieldDescriptor(mgr, section)};
+ Rooted<FieldDescriptor> section_field =
+ section->createFieldDescriptor(logger);
// We also add the "paragraph", which is transparent.
Rooted<StructuredClass> paragraph{new StructuredClass(
@@ -59,8 +60,8 @@ static Rooted<Domain> constructBookDomain(Manager &mgr,
book_field->addChild(paragraph);
// And the field of it.
- Rooted<FieldDescriptor> paragraph_field{
- new FieldDescriptor(mgr, paragraph)};
+ Rooted<FieldDescriptor> paragraph_field =
+ paragraph->createFieldDescriptor(logger);
// We append "subsection" to section.
Rooted<StructuredClass> subsection{
@@ -68,8 +69,8 @@ static Rooted<Domain> constructBookDomain(Manager &mgr,
section_field->addChild(subsection);
// And the field of it.
- Rooted<FieldDescriptor> subsection_field{
- new FieldDescriptor(mgr, subsection)};
+ Rooted<FieldDescriptor> subsection_field =
+ subsection->createFieldDescriptor(logger);
// and we add the paragraph to subsections fields
subsection_field->addChild(paragraph);
@@ -80,9 +81,8 @@ static Rooted<Domain> constructBookDomain(Manager &mgr,
paragraph_field->addChild(text);
// ... and has a primitive field.
- Rooted<FieldDescriptor> text_field{new FieldDescriptor(
- mgr, text, domain->getTypesystems()[0]->getTypes()[0],
- DEFAULT_FIELD_NAME, false)};
+ Rooted<FieldDescriptor> text_field =
+ text->createPrimitiveFieldDescriptor(sys->getStringType(), logger);
return domain;
}