From 5e779c017020a8e0405ee8e43c6ea7d4a9a11ad2 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Mon, 19 Jan 2015 00:33:49 +0100 Subject: fixed some bugs in Document validation and added further tests. --- test/core/model/DocumentTest.cpp | 82 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index d8ccef1..fea5296 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -134,6 +134,14 @@ TEST(Document, validate) buildRootStructuredEntity(doc, logger, {"root"}); ASSERT_TRUE(doc->validate(logger)); } + { + // A root with an invalid name, however, should make it invalid + Rooted doc{new Document(mgr, "myDoc.oxd")}; + doc->addDomain(domain); + Rooted root = buildRootStructuredEntity( + doc, logger, {"root"}, {}, "my invalid root"); + ASSERT_FALSE(doc->validate(logger)); + } // now let's extend the rootClass with a default field. Rooted rootField{new FieldDescriptor(mgr, rootClass)}; @@ -192,8 +200,78 @@ TEST(Document, validate) buildStructuredEntity(doc, logger, root, {"childSub"}); ASSERT_FALSE(doc->validate(logger)); } - // TODO: Override child field in childSub such that an empty childSub is - // valid. + /* + * Override the default field in childSubClass. + */ + Rooted childSubField{ + new FieldDescriptor(mgr, childSubClass)}; + { + /* + * Now a document with one instance of the Child subclass should be + * valid, because of the override. + */ + Rooted doc{new Document(mgr, "myDoc.oxd")}; + doc->addDomain(domain); + Rooted root = + buildRootStructuredEntity(doc, logger, {"root"}); + buildStructuredEntity(doc, logger, root, {"childSub"}); + ASSERT_TRUE(doc->validate(logger)); + } + // add a primitive field to the subclass with integer content. + Rooted primitive_field{new FieldDescriptor( + mgr, childSubClass, sys->getIntType(), "int", false)}; + { + /* + * Now a document with one instance of the Child subclass should be + * invalid again, because we are missing the primitive content. + */ + Rooted doc{new Document(mgr, "myDoc.oxd")}; + doc->addDomain(domain); + Rooted root = + buildRootStructuredEntity(doc, logger, {"root"}); + buildStructuredEntity(doc, logger, root, {"childSub"}); + ASSERT_FALSE(doc->validate(logger)); + } + // TODO: Check wrongly typed primitive content. + + // Now add an Annotation class to the domain. + Rooted annoClass{new AnnotationClass(mgr, "anno", domain)}; + { + /* + * Create a valid document in itself. + */ + Rooted doc{new Document(mgr, "myDoc.oxd")}; + doc->addDomain(domain); + Rooted root = + buildRootStructuredEntity(doc, logger, {"root"}); + Rooted child = + buildStructuredEntity(doc, logger, root, {"childSub"}); + Rooted primitive{ + new DocumentPrimitive(mgr, child, {2}, "int")}; + ASSERT_TRUE(doc->validate(logger)); + // then add an AnnotationEntity without Anchors. + buildAnnotationEntity(doc, logger, {"anno"}, nullptr, nullptr); + ASSERT_FALSE(doc->validate(logger)); + } + { + /* + * Do the same again, but with a valid AnnotationEntity now. + */ + Rooted doc{new Document(mgr, "myDoc.oxd")}; + doc->addDomain(domain); + Rooted root = + buildRootStructuredEntity(doc, logger, {"root"}); + Rooted start{new Anchor(mgr, "start", root)}; + Rooted child = + buildStructuredEntity(doc, logger, root, {"childSub"}); + Rooted primitive{ + new DocumentPrimitive(mgr, child, {2}, "int")}; + Rooted end{new Anchor(mgr, "end", root)}; + ASSERT_TRUE(doc->validate(logger)); + // then add an AnnotationEntity without Anchors. + buildAnnotationEntity(doc, logger, {"anno"}, start, end); + ASSERT_TRUE(doc->validate(logger)); + } } } } -- cgit v1.2.3