diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-22 02:47:36 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-22 02:47:36 +0100 |
commit | 4df98e9ae04dd077e47f0a5539aeb68b96c710c4 (patch) | |
tree | 918950c16bbb6f112309f7c3c8a1e6aca12d3650 /test | |
parent | f90a9bf51f300dd277071b1461d00411d7c21b89 (diff) | |
parent | 33008f1110523ae9c9b9e1d2ca24ed642637c40d (diff) |
Merge branch 'master' of somweyr.de:ousia
Diffstat (limited to 'test')
-rw-r--r-- | test/core/model/DocumentTest.cpp | 40 | ||||
-rw-r--r-- | test/core/model/DomainTest.cpp | 28 |
2 files changed, 60 insertions, 8 deletions
diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index 874fba7..a9c0dcc 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -128,10 +128,12 @@ TEST(Document, validate) // first an invalid one, which is empty. Rooted<Document> doc{new Document(mgr, "myDoc.oxd")}; doc->addDomain(domain); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_FALSE(doc->validate(logger)); // then add a root, which should make it valid. Rooted<StructuredEntity> root = buildRootStructuredEntity(doc, logger, {"root"}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_TRUE(doc->validate(logger)); } { @@ -140,6 +142,7 @@ TEST(Document, validate) doc->addDomain(domain); Rooted<StructuredEntity> root = buildRootStructuredEntity( doc, logger, {"root"}, {}, "my invalid root"); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_FALSE(doc->validate(logger)); } @@ -158,12 +161,15 @@ TEST(Document, validate) doc->addDomain(domain); Rooted<StructuredEntity> root = buildRootStructuredEntity(doc, logger, {"root"}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_FALSE(doc->validate(logger)); // but it should get valid if we add a proper child. buildStructuredEntity(doc, logger, root, {"child"}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_TRUE(doc->validate(logger)); // and it should get invalid again if we add one more child. buildStructuredEntity(doc, logger, root, {"child"}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_FALSE(doc->validate(logger)); } /* @@ -180,6 +186,7 @@ TEST(Document, validate) Rooted<StructuredEntity> root = buildRootStructuredEntity(doc, logger, {"root"}); buildStructuredEntity(doc, logger, root, {"childSub"}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_TRUE(doc->validate(logger)); } /* @@ -198,6 +205,7 @@ TEST(Document, validate) Rooted<StructuredEntity> root = buildRootStructuredEntity(doc, logger, {"root"}); buildStructuredEntity(doc, logger, root, {"childSub"}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_FALSE(doc->validate(logger)); } /* @@ -215,6 +223,7 @@ TEST(Document, validate) Rooted<StructuredEntity> root = buildRootStructuredEntity(doc, logger, {"root"}); buildStructuredEntity(doc, logger, root, {"childSub"}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_TRUE(doc->validate(logger)); } // add a primitive field to the subclass with integer content. @@ -231,14 +240,16 @@ TEST(Document, validate) buildRootStructuredEntity(doc, logger, {"root"}); Rooted<StructuredEntity> child = buildStructuredEntity(doc, logger, root, {"childSub"}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_FALSE(doc->validate(logger)); // if we add a DocumentPrimitive with the wrong content it should not // work either. Rooted<DocumentPrimitive> primitive{ new DocumentPrimitive(mgr, child, {"ololol"}, "int")}; - //TODO: ASSERT_FALSE(doc->validate(logger)); + ASSERT_FALSE(doc->validate(logger)); // but if we set the content right, it should work. primitive->setContent({2}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_TRUE(doc->validate(logger)); } @@ -258,14 +269,41 @@ TEST(Document, validate) Rooted<DocumentPrimitive> primitive{ new DocumentPrimitive(mgr, child, {2}, "int")}; Rooted<Anchor> end{new Anchor(mgr, "end", root)}; + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_TRUE(doc->validate(logger)); // then add an AnnotationEntity without Anchors. Rooted<AnnotationEntity> anno = buildAnnotationEntity(doc, logger, {"anno"}, nullptr, nullptr); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_FALSE(doc->validate(logger)); // but it should be valid again if we set the start end and Anchor. anno->setStart(start); anno->setEnd(end); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); + ASSERT_TRUE(doc->validate(logger)); + // add an attribute to the root, which should make it invalid. + root->setAttributes({2}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); + ASSERT_FALSE(doc->validate(logger)); + // if we reset it to null it should be valid again + root->setAttributes({}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); + ASSERT_TRUE(doc->validate(logger)); + // let's set an attribute descriptor. + Rooted<StructType> structType{StructType::createValidated( + mgr, "attributes", nullptr, nullptr, + NodeVector<Attribute>{ + new Attribute{mgr, "myAttr", sys->getStringType(), "default"}}, + logger)}; + childSubClass->setAttributesDescriptor(structType); + // the right map content should be valid now. + child->setAttributes( + std::map<std::string, Variant>{{"myAttr", "content"}}); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); + ASSERT_TRUE(doc->validate(logger)); + // but an empty map as well + child->setAttributes(std::map<std::string, Variant>()); + ASSERT_EQ(ValidationState::UNKNOWN, doc->getValidationState()); ASSERT_TRUE(doc->validate(logger)); } } diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index 8ece2c9..2b63aeb 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -293,77 +293,91 @@ TEST(Domain, validate) // start with an easy example: Our book domain should be valid. { Rooted<Domain> domain = constructBookDomain(mgr, sys, logger); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); } { // Even easier: An empty domain should be valid. Rooted<Domain> domain{new Domain(mgr, sys, "domain")}; + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); // if we add a StructureClass it should be valid still. Rooted<StructuredClass> base{ new StructuredClass(mgr, "myClass", domain)}; + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); - // if we tamper with the parent reference, however, it shouldn't be - // valid anymore. - base->setParent(nullptr); - ASSERT_FALSE(base->validate(logger)); - base->setParent(domain); - ASSERT_TRUE(domain->validate(logger)); - // the same goes for the name. + // if we tamper with the name, however, it shouldn't be valid anymore. base->setName(""); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_FALSE(domain->validate(logger)); base->setName("my class"); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_FALSE(domain->validate(logger)); base->setName("myClass"); + 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)}; // this should not be valid. + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_FALSE(domain->validate(logger)); // but it should be if we set the type. 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. + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); // and still if we add a superclass. sub->setSuperclass(base); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); // and still we we remove the subclass from the base class. base->removeSubclass(sub); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); ASSERT_EQ(nullptr, sub->getSuperclass()); // and still if we re-add it. base->addSubclass(sub); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); 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()); + 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. sub_field->addChild(base); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); // it should be invalid if we add it twice. sub_field->addChild(base); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_FALSE(domain->validate(logger)); // and valid again if we remove it once. sub_field->removeChild(base); + ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState()); ASSERT_TRUE(domain->validate(logger)); } } |