From ed2799b76f80cf0323b945c3b50fff5ba40b9c23 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 7 Apr 2008 08:03:22 +0200 Subject: [PATCH] getting the first test of defsmanagerimpltest.cpp to run ..adding some backdoors and bashing at the mock implementation to fake the behaviour of a real resolution engine --- src/common/configrules.cpp | 17 +++++++++ src/common/configrules.hpp | 14 ++++++++ src/common/query/mockconfigrules.cpp | 11 ++++++ src/common/query/mockconfigrules.hpp | 36 ++++++++++++------- src/proc/mobject/session/defsmanager.cpp | 3 +- .../mobject/session/defsmanagerimpltest.cpp | 3 ++ .../mobject/session/defsregistryimpltest.cpp | 2 +- 7 files changed, 70 insertions(+), 16 deletions(-) diff --git a/src/common/configrules.cpp b/src/common/configrules.cpp index 504df330f..3a1ae1bdd 100644 --- a/src/common/configrules.cpp +++ b/src/common/configrules.cpp @@ -51,4 +51,21 @@ namespace lumiera SingletonSub ConfigRules::instance (typeinfo); + + + + namespace query + { + namespace // local definitions: implementing a backdoor for tests + { + string fakeBypass; + } + + void setFakeBypass(string const& q) { fakeBypass = q; } + bool isFakeBypass (string const& q) { return q == fakeBypass; } + + } // namespace query + + + } // namespace lumiera diff --git a/src/common/configrules.hpp b/src/common/configrules.hpp index 890a36a86..81da041ae 100644 --- a/src/common/configrules.hpp +++ b/src/common/configrules.hpp @@ -222,5 +222,19 @@ namespace lumiera }; + + + namespace query + { + + /** backdoor for tests: the next config query with this query string + * will magically suceed with every candidate object provided. This + * is currently necessary to get objects into the defaults manager, + * as the query system is not able to do real query resolution */ + void setFakeBypass(string const& q); + bool isFakeBypass (string const& q); + + } // namespace query + } // namespace lumiera #endif diff --git a/src/common/query/mockconfigrules.cpp b/src/common/query/mockconfigrules.cpp index 7589d84f7..f05f3c745 100644 --- a/src/common/query/mockconfigrules.cpp +++ b/src/common/query/mockconfigrules.cpp @@ -133,6 +133,17 @@ namespace lumiera return true; } + /** for entering "valid" solutions on-the-fly from tests */ + template + bool + MockTable::set_new_mock_solution (Query& q, typename WrapReturn::Wrapper& obj) + { + answer_->insert (entry (q, obj)); + return true; + } + // generate the necessary specialisations----------------------------- + template bool MockTable::set_new_mock_solution (Query&, PPipe&); + diff --git a/src/common/query/mockconfigrules.hpp b/src/common/query/mockconfigrules.hpp index c3f6684ca..c4f56aeef 100644 --- a/src/common/query/mockconfigrules.hpp +++ b/src/common/query/mockconfigrules.hpp @@ -109,9 +109,12 @@ namespace lumiera // special cases.... template - bool detect_case (Query& q); + bool detect_case (typename WrapReturn::Wrapper&, Query& q); bool fabricate_matching_new_Pipe (Query& q, string const& pipeID, string const& streamID); bool fabricate_ProcPatt_on_demand (Query& q, string const& streamID); + + template + bool set_new_mock_solution (Query& q, typename WrapReturn::Wrapper& candidate); private: @@ -150,11 +153,14 @@ namespace lumiera bool try_special_case (Ret& solution, const Query& q) { + if (solution && isFakeBypass(q)) // backdoor for tests + return solution; + Query newQuery = q; if (is_defaults_query (newQuery)) // modified query.. return solution = Session::current->defaults (newQuery); // may cause recursion - if (detect_case (newQuery)) + if (detect_case (solution, newQuery)) return resolve (solution, newQuery); return solution = Ret(); // fail: return default-constructed empty smart ptr @@ -165,35 +171,39 @@ namespace lumiera /** Hook for treating very special cases for individual types only */ template inline bool - MockTable::detect_case (Query& q) + MockTable::detect_case (typename WrapReturn::Wrapper&, Query& q) { q.clear(); // end recursion return false; } template<> inline bool - MockTable::detect_case (Query& q) + MockTable::detect_case (WrapReturn::Wrapper& candidate, Query& q) { const string pipeID = extractID("pipe", q); const string streamID = extractID("stream", q); + + if (candidate && pipeID == candidate->getPipeID()) + return set_new_mock_solution (q, candidate); // "learn" this solution to be "valid" + if (!isnil(pipeID) && !isnil(streamID)) - return fabricate_matching_new_Pipe (q, pipeID, streamID); + return fabricate_matching_new_Pipe (q, pipeID, streamID); q.clear(); return false; } template<> inline bool - MockTable::detect_case (Query& q) + MockTable::detect_case (WrapReturn::Wrapper& candidate, Query& q) { - const string streamID = extractID("stream", q); - if (!isnil(streamID)) - return fabricate_ProcPatt_on_demand (q, streamID); + if (!isnil (extractID("make", q))) + return false; // let the query fail here, + // so the invoking factory will go ahead + // and create a new object. - // note: we don't handle the case of "make(PP), capabilities....." specially - // because either someone puts a special object into the mock table, or the - // recursive query done by the StructFactory simply fails, resulting in - // the StructFactory issuing a ProcPatt ctor call. + const string streamID = extractID("stream", q); + if (!candidate && !isnil(streamID)) + return fabricate_ProcPatt_on_demand (q, streamID); q.clear(); return false; diff --git a/src/proc/mobject/session/defsmanager.cpp b/src/proc/mobject/session/defsmanager.cpp index 1d6f92e9a..c84e5116d 100644 --- a/src/proc/mobject/session/defsmanager.cpp +++ b/src/proc/mobject/session/defsmanager.cpp @@ -58,9 +58,8 @@ namespace mobject shared_ptr res; QueryHandler& typeHandler = ConfigRules::instance(); for (DefsRegistry::Iter i = defsRegistry->candidates(capabilities); - i.hasNext(); ++i ) + res = *i ; ++i ) { - shared_ptr res (*i); typeHandler.resolve (res, capabilities); if (res) return res; diff --git a/tests/components/proc/mobject/session/defsmanagerimpltest.cpp b/tests/components/proc/mobject/session/defsmanagerimpltest.cpp index ff94f8a85..8aa773d5f 100644 --- a/tests/components/proc/mobject/session/defsmanagerimpltest.cpp +++ b/tests/components/proc/mobject/session/defsmanagerimpltest.cpp @@ -105,7 +105,10 @@ namespace asset ASSERT (!find (pipe2->getPipeID()), "accidental clash of random test-IDs"); // now declare that these objects should be considered "default" +lumiera::query::setFakeBypass(""); /////////////////////////////////////////////////TODO mock resolution ASSERT (Session::current->defaults.define (pipe1, Query (""))); // unrestricted default + +lumiera::query::setFakeBypass("stream("+sID+")"); ///////////////////////////////////TODO mock resolution ASSERT (Session::current->defaults.define (pipe2, Query ("stream("+sID+")"))); ASSERT ( find (pipe1->getPipeID()), "failure declaring object as default"); diff --git a/tests/components/proc/mobject/session/defsregistryimpltest.cpp b/tests/components/proc/mobject/session/defsregistryimpltest.cpp index fa5d2c4c3..b67b6cbe2 100644 --- a/tests/components/proc/mobject/session/defsregistryimpltest.cpp +++ b/tests/components/proc/mobject/session/defsregistryimpltest.cpp @@ -201,7 +201,7 @@ namespace mobject uint d=0; uint d_prev=0; Iter23 j = reg_->candidates(Q23 ("some crap")); - for ( ; j.hasNext(); ++j ) + for ( ; *j ; ++j ) { ASSERT ( *j ); Q23 qx ((*j)->instanceID);