From 73a1adcdf5099deb33170ca322b369f300d03581 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 11 Oct 2010 04:42:48 +0200 Subject: [PATCH] QueryFocus_test working now (still without diagnostic output) --- src/proc/mobject/session/query-focus.hpp | 13 +++-- src/proc/mobject/session/query-resolver.cpp | 2 +- tests/43session.tests | 3 +- .../proc/mobject/session/query-focus-test.cpp | 52 +++++++++---------- 4 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/proc/mobject/session/query-focus.hpp b/src/proc/mobject/session/query-focus.hpp index 466d5c2bc..20f8a67d4 100644 --- a/src/proc/mobject/session/query-focus.hpp +++ b/src/proc/mobject/session/query-focus.hpp @@ -89,8 +89,8 @@ namespace session { public: QueryFocus(); - ScopePath currentPath() const; - operator Scope() const; + ScopePath const& currentPath() const; + operator Scope() const; QueryFocus& attach (Scope const&); static QueryFocus push (Scope const&); @@ -130,8 +130,13 @@ namespace session { return focus_->getLeaf(); } - /**@note returning a copy */ - inline ScopePath + /** @return ref to internal datastructure + * @warning don't store it directly. Rather + * copy it or store a QueryFocus instance. + * @note use #attach if the intention is + * to \em manipulate the current + * focus location */ + inline ScopePath const& QueryFocus::currentPath() const { return *focus_; diff --git a/src/proc/mobject/session/query-resolver.cpp b/src/proc/mobject/session/query-resolver.cpp index 5b01ef3c5..1461cf7f5 100644 --- a/src/proc/mobject/session/query-resolver.cpp +++ b/src/proc/mobject/session/query-resolver.cpp @@ -101,7 +101,7 @@ namespace session { PReso QueryResolver::issue (Goal const& query) const { - TODO ("ensure proper initialisation"); + REQUIRE (!dispatcher_->empty(), "attempt to issue a query without having installed any resolver (yet)"); if (!canHandle (query)) throw lumiera::error::Invalid ("unable to resolve this kind of query"); ////TICKET #197 diff --git a/tests/43session.tests b/tests/43session.tests index 4bfab8f7f..7f0cb4233 100644 --- a/tests/43session.tests +++ b/tests/43session.tests @@ -195,7 +195,8 @@ out: ^Lumiera END -PLANNED "Query focus management" QueryFocus_test < #include @@ -46,37 +43,37 @@ namespace test { inline size_t refs (QueryFocus const& focus) { - return focus.currentPath().ref_count(); + return focus.currentPath().ref_count(); } } - //using util::isSameObject; - //using lumiera::Time; + using std::string; using std::cout; using std::endl; - /********************************************************************************** + /*********************************************************************************** * @test handling of current query focus when navigating a system of nested scopes. * Using a pseudo-session (actually just a PlacementIndex), this test * accesses some nested scopes and then checks moving the "current scope". * Moreover a (stack-like) sub-focus is created, temporarily moving aside - * the current focus and returning later on + * the current focus and returning later on. * * @see mobject::PlacementIndex * @see mobject::session::ScopePath * @see mobject::session::QueryFocus */ - class QueryFocus_test : public Test + class QueryFocus_test + : public Test { virtual void run (Arg) { - - // Prepare an (test)Index backing the PlacementRefs + // Prepare a (test)Session with + // some nested dummy placements PPIdx index = build_testScopes(); PMO& root = index->getRoot(); @@ -92,10 +89,13 @@ namespace test { QueryFocus currentFocus; ASSERT (scopePosition == Scope(currentFocus)); ASSERT (currentFocus == theFocus); + ASSERT (2 == refs(currentFocus)); + ASSERT (2 == refs(theFocus)); } - /** @test move the current focus to various locations + + /** @test move the current focus to different locations * and discover contents there. */ void checkNavigation (QueryFocus& focus) @@ -123,13 +123,12 @@ namespace test { // as the focus now has been moved up one level, // we'll re-discover the original starting point as immediate child CHECK (someObj == *focus.explore()); -#ifdef false ////////////////////////////////////////////////////////////////////////////////TICKET 384 -#endif } + /** @test side-effect free manipulation of a sub-focus, - * while the original focus is pushed on a stack */ + * while the original focus is pushed aside (stack) */ void manipulate_subFocus() { @@ -138,7 +137,7 @@ namespace test { ASSERT (num_refs > 1); // because the run() function also holds a ref QueryFocus subF = QueryFocus::push(); -// cout << string(subF) << endl; +// cout << string(subF) << endl; /////////////////////////////////////TICKET #679 display diagnostic output ASSERT (subF == original); ASSERT ( 1 == refs(subF) ); @@ -148,36 +147,35 @@ namespace test { QueryFocus subF2 = QueryFocus::push(Scope(subF).getParent()); ASSERT (subF2 != subF); ASSERT (subF == original); -// cout << string(subF2) << endl; +// cout << string(subF2) << endl; /////////////////////////////////////TICKET #679 display diagnostic output - ScopeQuery::iterator ii = subF2.query(); - while (ii) + ScopeQuery::iterator ii = subF2.explore(); + while (ii) // drill down depth first { subF2.attach(*ii); -// cout << string(subF2) << endl; - ii = subF2.query(); +// cout << string(subF2) << endl; /////////////////////////////////////TICKET #679 display diagnostic output + ii = subF2.explore(); } -// cout << string(subF2) << "<<<--discovery exhausted" << endl; +// cout << string(subF2) << "<<<--discovery exhausted" << endl; /////////////////////////////////////TICKET #679 display diagnostic output subF2.pop(); // releasing this focus and re-attaching to what's on stack top -// cout << string(subF2) << "<<<--after pop()" << endl; +// cout << string(subF2) << "<<<--after pop()" << endl; /////////////////////////////////////TICKET #679 display diagnostic output ASSERT (subF2 == subF); ASSERT (2 == refs(subF2)); // both are now attached to the same path ASSERT (2 == refs(subF)); } // subF2 went out of scope, but no auto-pop happens (because subF is still there) -// cout << string(subF) << endl; +// cout << string(subF) << endl; /////////////////////////////////////TICKET #679 display diagnostic output ASSERT ( 1 == refs(subF)); ASSERT (num_refs == refs(original)); // when subF goes out of scope now, auto-pop will happen... -#ifdef false ////////////////////////////////////////////////////////////////////////////////TICKET 384 -#endif } - + }; + /** Register this test class... */ LAUNCHER (QueryFocus_test, "unit session");