From 68c66558cd7c8e64dd0d3b934ccb58603f8b9836 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Tue, 3 Mar 2015 19:07:48 +0100 Subject: prevented cycles in DocumentEntity::searchStartAnchor --- test/core/model/DocumentTest.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/core') diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index 9362af8..8ae9475 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -75,6 +75,41 @@ TEST(DocumentEntity, searchStartAnchor) ASSERT_EQ(b, root->searchStartAnchor(0, Alpha, "myAnno")); } + +TEST(DocumentEntity, searchStartAnchorCycles) +{ + // create a trivial ontology. + Logger logger; + Manager mgr{1}; + Rooted sys{new SystemTypesystem(mgr)}; + Rooted ontology{new Ontology(mgr, sys, "trivial")}; + // we only have one StructuredClass that may have itself as a child. + Rooted A = ontology->createStructuredClass( + "A", Cardinality::any(), nullptr, false, true); + Rooted A_field = A->createFieldDescriptor(logger).first; + A_field->addChild(A); + // create an AnnotationClass. + Rooted Alpha = ontology->createAnnotationClass("Alpha"); + // validate this ontology. + ASSERT_TRUE(ontology->validate(logger)); + + // create a trivial but cyclic document. + Rooted doc{new Document(mgr, "myDoc")}; + Rooted root = doc->createRootStructuredEntity(A); + // add an Anchor. + Rooted a = root->createChildAnchor(); + // create an AnnotationEntity with the Anchor as start. + doc->createChildAnnotation(Alpha, a, nullptr, Variant::mapType{}, "myAnno"); + // add the cyclic reference. + root->addStructureNode(root, 0); + // We should be able to find the Anchor now if we look for it. There should + // be no loops. + ASSERT_EQ(a, root->searchStartAnchor(0)); + ASSERT_EQ(a, root->searchStartAnchor(0, Alpha)); + ASSERT_EQ(a, root->searchStartAnchor(0, nullptr, "myAnno")); + ASSERT_EQ(a, root->searchStartAnchor(0, Alpha, "myAnno")); +} + TEST(DocumentEntity, searchStartAnchorUpwards) { // create a trivial ontology. -- cgit v1.2.3