WIP: test-driven brainstorming: how to build the query dispatcher table?
This commit is contained in:
parent
5968d35cdf
commit
ec4b2eef00
4 changed files with 224 additions and 8 deletions
|
|
@ -41,10 +41,14 @@ namespace session {
|
|||
QueryResolver::Resolution::~Resolution() { }
|
||||
|
||||
|
||||
struct QueryDispatcher
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** TODO??? */
|
||||
QueryResolver::Resolution
|
||||
PReso
|
||||
QueryResolver::issue (Goal& query)
|
||||
{
|
||||
if (!canHandleQuery (query.getQID()))
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include "lib/iter-adapter.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <tr1/memory>
|
||||
//#include <vector>
|
||||
//#include <string>
|
||||
|
|
@ -46,6 +47,7 @@ namespace session {
|
|||
|
||||
class Goal;
|
||||
class QueryResolver;
|
||||
class QueryDispatcher;
|
||||
class QueryResolver::Resolution;
|
||||
|
||||
/** Allow for taking ownership of a result set */
|
||||
|
|
@ -82,7 +84,7 @@ namespace session {
|
|||
void *cur_;
|
||||
|
||||
protected:
|
||||
void pointAt(void* p) { cur_ = p; }
|
||||
void point_at(void* p) { cur_ = p; }
|
||||
|
||||
template<typename RES>
|
||||
RES&
|
||||
|
|
@ -141,10 +143,10 @@ namespace session {
|
|||
: public Goal::Result
|
||||
{
|
||||
public:
|
||||
RES& operator* () { return access<RES>(); }
|
||||
RES* operator->() { return & access<RES>(); }
|
||||
RES& operator* () { return access<RES>(); }
|
||||
RES* operator->() { return & access<RES>(); }
|
||||
|
||||
void pointAt(RES* r){ Goal::Result::pointAt(r);}
|
||||
void point_at(RES* r){ Goal::Result::pointAt(r);}
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -161,6 +163,7 @@ namespace session {
|
|||
*/
|
||||
class QueryResolver
|
||||
{
|
||||
boost::scoped_ptr<QueryDispatcher> dispatcher_;
|
||||
|
||||
public:
|
||||
|
||||
|
|
@ -189,11 +192,11 @@ namespace session {
|
|||
resultSet->nextResult(pos);
|
||||
}
|
||||
|
||||
virtual Result prepareResolution() =0;
|
||||
virtual Result prepareResolution() =0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual Result const& nextResult(Result& pos) =0;
|
||||
virtual void nextResult(Result& pos) =0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
//#include "proc/mobject/session/test-scopes.hpp"
|
||||
//#include "proc/mobject/placement-index.hpp"
|
||||
#include "proc/mobject/session/query-resolver.hpp"
|
||||
//#include "lib/symbol.hpp"
|
||||
//#include "lib/access-casted.hpp"
|
||||
//#include "lib/variant.hpp"
|
||||
//#include "lib/meta/typelist.hpp"
|
||||
|
|
@ -51,10 +52,81 @@ namespace test {
|
|||
|
||||
namespace { // a test query resolving facility
|
||||
|
||||
|
||||
|
||||
template<typename TY>
|
||||
class DummySolution;
|
||||
|
||||
class DummySolution<int>
|
||||
{
|
||||
int resNr_;
|
||||
|
||||
public:
|
||||
DummySolution() : resNr_(7) {}
|
||||
|
||||
int* next () { --resNr_; return &resNr_; }
|
||||
bool exhausted() { return bool(resNr_); }
|
||||
};
|
||||
|
||||
class DummySolution<string>
|
||||
: DummySolution<int>
|
||||
{
|
||||
string currentText_;
|
||||
|
||||
public:
|
||||
string*
|
||||
next ()
|
||||
{
|
||||
static char* lumi ="Lumiera";
|
||||
currentText_ = string (lumi[*DummySolution<int>::next()]);
|
||||
return ¤tText_;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename TY>
|
||||
struct DummyResultSet
|
||||
: QueryResolver::Resolution
|
||||
{
|
||||
DummySolution<TY> solution_;
|
||||
|
||||
typedef typename Query<TY>::Cursor Cursor;
|
||||
|
||||
Result
|
||||
prepareResolution()
|
||||
{
|
||||
Cursor cursor;
|
||||
cursor.pointAt (solution_.next());
|
||||
return cursor;
|
||||
}
|
||||
|
||||
void
|
||||
nextResult(Result& pos)
|
||||
{
|
||||
Cursor& cursor = static_cast<Cursor&> (pos);
|
||||
|
||||
if (solution_.exhausted())
|
||||
cursor.point_at (0);
|
||||
else
|
||||
cursor.point_at (solution_.next());
|
||||
}
|
||||
};
|
||||
|
||||
class TypeMatchFilter
|
||||
: public QueryResolver
|
||||
{
|
||||
bool
|
||||
canHandleQuery (Goal::QueryID qID) const
|
||||
{
|
||||
return Goal::GENERIC == qID.kind
|
||||
&& (wantResultType<int> (qID)
|
||||
||wantResultType<string>(qID));
|
||||
}
|
||||
|
||||
template<typename TY>
|
||||
bool
|
||||
wantResultType (Goal::QueryID qID)
|
||||
{
|
||||
return qID.type == ResultType::ID<TY>::get();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
137
tests/lib/multifact-argument-test.cpp
Normal file
137
tests/lib/multifact-argument-test.cpp
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
MultiFact(Test) - unittest for the configurable object-family creating factory
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2009, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
* *****************************************************/
|
||||
|
||||
|
||||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
#include "lib/multifact.hpp"
|
||||
#include "lib/util.hpp"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
|
||||
namespace lib {
|
||||
namespace test{
|
||||
|
||||
using boost::lexical_cast;
|
||||
using lib::test::showSizeof;
|
||||
using util::isSameObject;
|
||||
using util::isnil;
|
||||
using std::ostream;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
using lumiera::error::LUMIERA_ERROR_INVALID;
|
||||
|
||||
|
||||
namespace { // hierarchy of test dummy objects
|
||||
|
||||
struct Interface
|
||||
{
|
||||
virtual ~Interface() {};
|
||||
virtual operator string () =0;
|
||||
};
|
||||
|
||||
inline ostream& operator<< (ostream& os, Interface& ifa) { return os << string(ifa); }
|
||||
|
||||
|
||||
enum theID
|
||||
{ ONE = 1
|
||||
, TWO
|
||||
, THR
|
||||
, FOU
|
||||
};
|
||||
|
||||
typedef factory::MultiFact<Interface, theID, factory::PassReference> TestFactory;
|
||||
|
||||
|
||||
template<theID ii>
|
||||
class Implementation
|
||||
: public Interface
|
||||
{
|
||||
operator string()
|
||||
{
|
||||
return "Impl-"+lexical_cast<string> (ii);
|
||||
}
|
||||
|
||||
public:
|
||||
static theID getTypeID() { return ii; }
|
||||
};
|
||||
|
||||
/** Factory instance for the tests... */
|
||||
TestFactory theFact;
|
||||
|
||||
// Configure the products to be fabricated....
|
||||
TestFactory::Singleton<Implementation<ONE> > holder1 (theFact,ONE);
|
||||
TestFactory::Singleton<Implementation<TWO> > holder2 (theFact,TWO);
|
||||
TestFactory::Singleton<Implementation<THR> > holder3 (theFact,THR);
|
||||
TestFactory::Singleton<Implementation<FOU> > holder4 (theFact,FOU);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
* @test verify simple setup of the MultiFact template.
|
||||
* Define a hierarchy of test dummy objects, such as to
|
||||
* register them automatically for creation through a suitable
|
||||
* instantiation of MultiFact. Verify we get the correct product
|
||||
* when invoking this MultiFac flavour.
|
||||
* @see lib::MultiFact
|
||||
*/
|
||||
class MultiFact_test : public Test
|
||||
{
|
||||
void
|
||||
run (Arg)
|
||||
{
|
||||
cout << theFact(ONE) << endl;
|
||||
cout << theFact(TWO) << endl;
|
||||
cout << theFact(THR) << endl;
|
||||
cout << theFact(FOU) << endl;
|
||||
cout << showSizeof (theFact) << endl;
|
||||
|
||||
Interface & o1 = theFact(ONE);
|
||||
Interface & o2 = theFact(ONE);
|
||||
ASSERT (isSameObject(o1,o2));
|
||||
|
||||
TestFactory anotherFact;
|
||||
ASSERT (isnil (anotherFact));
|
||||
VERIFY_ERROR (INVALID, anotherFact(ONE) );
|
||||
|
||||
TestFactory::Singleton<Implementation<ONE> > anotherSingletonHolder (anotherFact,ONE);
|
||||
Interface & o3 = anotherFact(ONE);
|
||||
ASSERT (isSameObject(o2,o3));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** Register this test class... */
|
||||
LAUNCHER (MultiFact_test, "unit common");
|
||||
|
||||
|
||||
|
||||
}} // namespace lib::test
|
||||
Loading…
Reference in a new issue