From c2ea15695ebac5c92bcfa1990119c8926e0b1c59 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 11 May 2014 02:08:53 +0200 Subject: [PATCH] amend harmless PlacementIndex test failures. Test Suite PASS c++11 uses another hashtable implementation. This uncovered some poorly written tests, which relied on objects being returned in a specific order. As far as poissible, we're using generic query functions now to get our test objects. But these tests still rely on a specifically crafted test index content, which as such is acceptable IMHO. The only remaining problem is that we check the order of generated output in some tests, and this order is still implementation dependent. --- src/proc/mobject/session/placement-index.cpp | 2 +- .../session/specific-contents-query.hpp | 5 ++-- tests/43session.tests | 30 +++++++++---------- .../session/placement-index-query-test.cpp | 10 +++++-- .../proc/mobject/session/scope-path-test.cpp | 3 +- .../session/session-element-query-test.cpp | 20 ++++++------- .../core/proc/mobject/session/test-scopes.cpp | 19 ++++++++++-- .../core/proc/mobject/session/test-scopes.hpp | 2 ++ 8 files changed, 55 insertions(+), 36 deletions(-) diff --git a/src/proc/mobject/session/placement-index.cpp b/src/proc/mobject/session/placement-index.cpp index 003408b19..1a100c9aa 100644 --- a/src/proc/mobject/session/placement-index.cpp +++ b/src/proc/mobject/session/placement-index.cpp @@ -486,7 +486,7 @@ namespace session { /** Retrieve all the elements attached to the given entry (scope) * Each element (Placement) can act as a scope, containing other Placements, * which will be discovered by this query one level deep (not recursive). - * @return an Lumiera Forward Iterator, yielding the children, + * @return a Lumiera Forward Iterator, yielding the children, * possibly empty if the denoted element is a leaf. * @note results are returned in arbitrary order (hashtable) */ diff --git a/src/proc/mobject/session/specific-contents-query.hpp b/src/proc/mobject/session/specific-contents-query.hpp index 20654b22b..531f8d067 100644 --- a/src/proc/mobject/session/specific-contents-query.hpp +++ b/src/proc/mobject/session/specific-contents-query.hpp @@ -42,7 +42,6 @@ namespace session { /** - * Specialised version of the ContentsQuery to pick some objects * from the session, based on a filter predicate. As the parent type, * ContentsQuery, the resolution of this query requires to explore the * given scope depth first; but in addition to filter based on type, @@ -145,7 +144,7 @@ namespace session { - /** convenience shortcut to issue a SpecialContentsQuery, + /** convenience shortcut to issue a SpecificContentsQuery, * figuring out the actual return/filter type automatically, * based on the predicate given as parameter */ @@ -159,7 +158,7 @@ namespace session { } /** convenience shortcut (variant), automatically to build - * and execute a suitable SpecialContentsQuery + * and execute a suitable SpecificContentsQuery * @return iterator yielding placements of the type as * defined through the parameter of the predicate */ diff --git a/tests/43session.tests b/tests/43session.tests index d25fdab99..f06033092 100644 --- a/tests/43session.tests +++ b/tests/43session.tests @@ -127,10 +127,10 @@ END TEST "Querying the index" PlacementIndexQuery_test < ..... use-cnt=1 out: Placement<.+TestSubMO2.> ...... use-cnt=1 out: Placement<.+TestSubMO1.> ...... use-cnt=1 out: Placement<.+DummyMO.> .......... use-cnt=1 +out: Placement<.+TestSubMO21.> ..... use-cnt=1 out: path to root starting at Placement<.+TestSubMO1 out: Placement<.+TestSubMO2.> ...... use-cnt=1 out: Placement<.+session.Label.> ......... use-cnt=1 @@ -139,24 +139,24 @@ END TEST "discovering scopes" ScopeQuery_test < out: Placement<.+TestSubMO2.> out: Placement<.+TestSubMO1.> out: Placement<.+DummyMO.> +out: Placement<.+TestSubMO21.> out: --------------------------------Test-2: contents depth-first, filtered to Clip out: --------------------------------Test-3: contents depth-first, filtered to DummyMO -out: Placement<.+TestSubMO21.> out: Placement<.+TestSubMO2.> out: Placement<.+TestSubMO1.> out: Placement<.+DummyMO.> +out: Placement<.+TestSubMO21.> out: --------------------------------Test-4: contents depth-first, filtered to TestSubMO1 out: Placement<.+TestSubMO1.> out: --------------------------------Test-5: contents depth-first, filtered to TestSubMO2 -out: Placement<.+TestSubMO21.> out: Placement<.+TestSubMO2.> +out: Placement<.+TestSubMO21.> out: --------------------------------Test-6: contents depth-first, custom filtered DummyMO -out: Placement<.+TestSubMO21.> out: Placement<.+TestSubMO2.> +out: Placement<.+TestSubMO21.> out: --------------------------------Test-7: parents of the second TestSubMO2 element found out: Placement<.+TestSubMO21.> out: Placement<.+mobject.session.Label.> @@ -175,21 +175,21 @@ END TEST "Placement search scope" PlacementScope_test < -out: Scope: \[DummyMO\.[0-9]{3}\] -out: Placement<.+TestSubMO21.> -out: Scope: \[DummyMO\.[0-9]{3}\] -out: Placement<.+TestSubMO21.> -out: Scope: \[DummyMO\.[0-9]{3}\] -out: Placement<.+TestSubMO21.> -out: Scope: \[DummyMO\.[0-9]{3}\] -out: Placement<.+TestSubMO21.> -out: Scope: \[Label\.[0-9]{3}\] out: Placement<.+TestSubMO2.> out: Scope: \[DummyMO\.[0-9]{3}\] out: Placement<.+TestSubMO1.> out: Scope: \[Label\.[0-9]{3}\] out: Placement<.+DummyMO.> +out: Scope: \[Label\.[0-9]{3}\] +out: Placement<.+TestSubMO21.> +out: Scope: \[DummyMO\.[0-9]{3}\] +out: Placement<.+TestSubMO21.> +out: Scope: \[DummyMO\.[0-9]{3}\] +out: Placement<.+TestSubMO21.> +out: Scope: \[DummyMO\.[0-9]{3}\] +out: Placement<.+TestSubMO21.> +out: Scope: \[DummyMO\.[0-9]{3}\] +out: Placement<.+TestSubMO21.> return: 0 END diff --git a/tests/core/proc/mobject/session/placement-index-query-test.cpp b/tests/core/proc/mobject/session/placement-index-query-test.cpp index 64c1f3cfa..dfb8d44bd 100644 --- a/tests/core/proc/mobject/session/placement-index-query-test.cpp +++ b/tests/core/proc/mobject/session/placement-index-query-test.cpp @@ -81,9 +81,13 @@ namespace test { PlacementMO& root2 = SessionServiceExploreScope::getScopeRoot(); CHECK (isSameObject (root1, root2)); - PlacementMO& elm1 = *ContentsQuery(root1).resolveBy(resolver1); - PlacementMO& elm2 = *(index->getReferrers(root1)); - CHECK (isSameObject (elm1, elm2)); + PlacementMO& elm1 = *ContentsQuery(root1).resolveBy(resolver1); + PlacementMO& elm2 = *ContentsQuery(root1).resolveBy(resolver1); + PlacementMO& elm3 = *(index->getReferrers(elm1)); + CHECK (isSameObject (elm3, elm2)); + // relying on the specific setup of the test index + // MO1 is the sole "referrer" of MO2 (the only content within MO2's scope) + // root \ TestSubMO2 \ TestSubMO1 } void diff --git a/tests/core/proc/mobject/session/scope-path-test.cpp b/tests/core/proc/mobject/session/scope-path-test.cpp index fc28c689f..b3684a2ba 100644 --- a/tests/core/proc/mobject/session/scope-path-test.cpp +++ b/tests/core/proc/mobject/session/scope-path-test.cpp @@ -370,8 +370,7 @@ namespace test { // now explore a completely separate branch.... PMO& separatePlacement = *explore_testScope ( *explore_testScope ( - *explore_testScope ( - root.getTop()))); + retrieve_firstTestSubMO21())); path.navigate (separatePlacement); CHECK (path); CHECK (disjoint (path,refPath)); diff --git a/tests/core/proc/mobject/session/session-element-query-test.cpp b/tests/core/proc/mobject/session/session-element-query-test.cpp index 2cda7d0ea..df647c77d 100644 --- a/tests/core/proc/mobject/session/session-element-query-test.cpp +++ b/tests/core/proc/mobject/session/session-element-query-test.cpp @@ -55,18 +55,18 @@ namespace test { /** a filter predicate to pick some objects from a resultset, * based on string match with the element's self-display string. - * @note using the specific API of DummyMO, without cast! */ - bool - filter_typeID (PDummy candidate, string expectedText) - { - string desc = candidate->operator string(); - return contains(desc, expectedText); - } - + * @note the query system allows us to use the specific API of DummyMO, + * without the need for any cast. It is sufficient to declare + * a suitable signature on the query predicate! */ inline function elementID_contains (string expectedText) { - return bind (filter_typeID, _1, expectedText); + return [=] (PDummy candidate) + { + REQUIRE (candidate.isValid()); + string desc(candidate->operator string()); + return contains(desc, expectedText); + }; } } @@ -127,7 +127,7 @@ namespace test { MORef findAgain = queryAPI.pick (elementID_contains(specificID)); CHECK (!findAgain); // empty result because searched element was removed from session... - MORef otherElm = queryAPI.pick (elementID_contains("MO1")); + MORef otherElm = queryAPI.pick (elementID_contains("MO21")); CHECK (otherElm); // now pick just some other arbitrary element testSession->insert(newPlacement, otherElm); diff --git a/tests/core/proc/mobject/session/test-scopes.cpp b/tests/core/proc/mobject/session/test-scopes.cpp index 9ec6d4576..4145f3762 100644 --- a/tests/core/proc/mobject/session/test-scopes.cpp +++ b/tests/core/proc/mobject/session/test-scopes.cpp @@ -69,6 +69,16 @@ namespace test { return index; } + namespace { + template + PlacementMO& + retrieve_firstElmOfType() + { + return *ContentsQuery(SessionServiceExploreScope::getScopeRoot()) + .resolveBy(SessionServiceExploreScope::getResolver()); + } + } + /** @note this test helper only works if build_testScopes is invoked * beforehand, and the returned smart-ptr to the created test/dummy index @@ -79,8 +89,13 @@ namespace test { PlacementMO& retrieve_startElm() { - return *ContentsQuery(SessionServiceExploreScope::getScopeRoot()) - .resolveBy(SessionServiceExploreScope::getResolver()); + return retrieve_firstElmOfType(); + } + + PlacementMO& + retrieve_firstTestSubMO21() + { + return retrieve_firstElmOfType(); } diff --git a/tests/core/proc/mobject/session/test-scopes.hpp b/tests/core/proc/mobject/session/test-scopes.hpp index c7d73906c..f1e1a60fc 100644 --- a/tests/core/proc/mobject/session/test-scopes.hpp +++ b/tests/core/proc/mobject/session/test-scopes.hpp @@ -63,6 +63,8 @@ namespace test { * which is a Placement<> and way down into the hierarchy */ PlacementMO& retrieve_startElm(); + + PlacementMO& retrieve_firstTestSubMO21(); /** shortcut to explore the contents of a scope within the current index.