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
This commit is contained in:
parent
dfefbea769
commit
ed2799b76f
7 changed files with 70 additions and 16 deletions
|
|
@ -51,4 +51,21 @@ namespace lumiera
|
|||
SingletonSub<ConfigRules> 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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -133,6 +133,17 @@ namespace lumiera
|
|||
return true;
|
||||
}
|
||||
|
||||
/** for entering "valid" solutions on-the-fly from tests */
|
||||
template<class TY>
|
||||
bool
|
||||
MockTable::set_new_mock_solution (Query<TY>& q, typename WrapReturn<TY>::Wrapper& obj)
|
||||
{
|
||||
answer_->insert (entry<TY> (q, obj));
|
||||
return true;
|
||||
}
|
||||
// generate the necessary specialisations-----------------------------
|
||||
template bool MockTable::set_new_mock_solution (Query<Pipe>&, PPipe&);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -109,9 +109,12 @@ namespace lumiera
|
|||
|
||||
// special cases....
|
||||
template<class TY>
|
||||
bool detect_case (Query<TY>& q);
|
||||
bool detect_case (typename WrapReturn<TY>::Wrapper&, Query<TY>& q);
|
||||
bool fabricate_matching_new_Pipe (Query<Pipe>& q, string const& pipeID, string const& streamID);
|
||||
bool fabricate_ProcPatt_on_demand (Query<const ProcPatt>& q, string const& streamID);
|
||||
|
||||
template<class TY>
|
||||
bool set_new_mock_solution (Query<TY>& q, typename WrapReturn<TY>::Wrapper& candidate);
|
||||
|
||||
|
||||
private:
|
||||
|
|
@ -150,11 +153,14 @@ namespace lumiera
|
|||
bool
|
||||
try_special_case (Ret& solution, const Query<TY>& q)
|
||||
{
|
||||
if (solution && isFakeBypass(q)) // backdoor for tests
|
||||
return solution;
|
||||
|
||||
Query<TY> 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<class TY>
|
||||
inline bool
|
||||
MockTable::detect_case (Query<TY>& q)
|
||||
MockTable::detect_case (typename WrapReturn<TY>::Wrapper&, Query<TY>& q)
|
||||
{
|
||||
q.clear(); // end recursion
|
||||
return false;
|
||||
}
|
||||
template<>
|
||||
inline bool
|
||||
MockTable::detect_case (Query<Pipe>& q)
|
||||
MockTable::detect_case (WrapReturn<Pipe>::Wrapper& candidate, Query<Pipe>& 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<const ProcPatt>& q)
|
||||
MockTable::detect_case (WrapReturn<const ProcPatt>::Wrapper& candidate, Query<const ProcPatt>& 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;
|
||||
|
|
|
|||
|
|
@ -58,9 +58,8 @@ namespace mobject
|
|||
shared_ptr<TAR> res;
|
||||
QueryHandler<TAR>& typeHandler = ConfigRules::instance();
|
||||
for (DefsRegistry::Iter<TAR> i = defsRegistry->candidates(capabilities);
|
||||
i.hasNext(); ++i )
|
||||
res = *i ; ++i )
|
||||
{
|
||||
shared_ptr<TAR> res (*i);
|
||||
typeHandler.resolve (res, capabilities);
|
||||
if (res)
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -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<Pipe> (""))); // unrestricted default
|
||||
|
||||
lumiera::query::setFakeBypass("stream("+sID+")"); ///////////////////////////////////TODO mock resolution
|
||||
ASSERT (Session::current->defaults.define (pipe2, Query<Pipe> ("stream("+sID+")")));
|
||||
|
||||
ASSERT ( find (pipe1->getPipeID()), "failure declaring object as default");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue