From 0cef067c11fbfd885573c8ab22baa58afa6f3285 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 28 Oct 2009 04:45:17 +0100 Subject: [PATCH] WIP adapt unit test and the argument-accepting MultiFact specialisation --- src/lib/multifact-arg.hpp | 4 ++- src/lib/multifact.hpp | 36 ++++++++++++++++++------ tests/42query.tests | 8 ++++++ tests/43session.tests | 4 --- tests/lib/multifact-argument-test.cpp | 40 +++++++++++++++------------ 5 files changed, 62 insertions(+), 30 deletions(-) diff --git a/src/lib/multifact-arg.hpp b/src/lib/multifact-arg.hpp index fda2d087a..d47ddd6c4 100644 --- a/src/lib/multifact-arg.hpp +++ b/src/lib/multifact-arg.hpp @@ -41,6 +41,8 @@ #include "lib/multifact.hpp" +#include + namespace lib { @@ -54,7 +56,7 @@ namespace lib { struct FabTraits { typedef TY RawProduct; - typedef RawProduct FacSig(ARG); + typedef RawProduct FabSig(ARG); typedef ARG Argument; }; diff --git a/src/lib/multifact.hpp b/src/lib/multifact.hpp index 37ff84d4f..fee171b96 100644 --- a/src/lib/multifact.hpp +++ b/src/lib/multifact.hpp @@ -40,6 +40,7 @@ #include "util.hpp" #include +#include #include @@ -55,17 +56,33 @@ namespace lib { template struct PassReference { + typedef TAR& RType; typedef TAR& PType; - PType wrap (TAR& object) { return object; } + PType wrap (RType object) { return object; } }; + /** + * Wrapper taking ownership, + * by wrapping into smart-ptr + */ + template + struct BuildRefcountPtr + { + typedef TAR* RType; + typedef std::tr1::shared_ptr PType; + + PType wrap (RType ptr) { return PType (ptr); } + }; + + + template struct FabTraits { typedef TY RawProduct; - typedef RawProduct FacSig(void); + typedef RawProduct FabSig(void); }; @@ -78,7 +95,7 @@ namespace lib { template struct Fab { - typedef typename FabTraits::FacSig Signature; + typedef typename FabTraits::FabSig Signature; typedef std::tr1::function FactoryFunc; @@ -126,15 +143,18 @@ namespace lib { class MultiFact : Wrapper::RawProduct> { - typedef Fab _Fab; + typedef Wrapper::RawProduct> _Wrap; + typedef typename FabTraits::RawProduct RawType; + typedef typename _Wrap::PType WrappedProduct; + typedef typename _Wrap::RType FabProduct; + typedef Fab _Fab; _Fab funcTable_; - protected: - typedef typename FabTraits::RawProduct RawType; - typedef typename Wrapper::PType Product; - typedef typename _Fab::FactoryFunc Creator; + protected: + typedef typename _Fab::FactoryFunc Creator; + typedef WrappedProduct Product; Creator& selectProducer (ID const& id) diff --git a/tests/42query.tests b/tests/42query.tests index d05c27fcc..5d437cc41 100644 --- a/tests/42query.tests +++ b/tests/42query.tests @@ -2,6 +2,14 @@ TESTING "Proc Layer config rules Test Suite" ./test-lib --group=query +PLANNED "issuing typed queries" QueryResolver_test < @@ -45,27 +45,27 @@ namespace test{ using std::cout; using std::endl; using std::tr1::bind; + using std::tr1::function; + using std::tr1::placeholders::_1; // using lumiera::error::LUMIERA_ERROR_INVALID; - namespace { // a test-dummy ID type, used to encapsulate additional arguments + namespace { // dummy fabrication function, creating wrapped numbers, controlled by an additional argument - enum baseType + enum prodID { ONE = 1 , TWO }; - struct DummyID - { - baseType bas; - int additionalInfo; - }; - - struct Num { int n_; }; - /** dummy "factory" function to be invoked */ + /** dummy "factory" function to be invoked + * @return pointer to heap allocated product object + * @note this function needs to deliver the product in a form + * which can be accepted by the concrete wrapper, which + * is going to be configured into the factory. + */ Num* fabricateNumberz (int base, int offset) { @@ -76,7 +76,11 @@ namespace test{ } - typedef factory::MultiFact TestFactory; + /** the factory instantiation used for this test */ + typedef factory::MultiFact< function // nominal signature of fabrication + , prodID // select factory function by prodID + , factory::BuildRefcountPtr // wrapper: manage product by smart-ptr + > TestFactory; } @@ -88,6 +92,11 @@ namespace test{ * @test define a MultiFact (factory with dynamic registration), * which accepts additional arguments and passes them * through to the registered factory function(s). + * @note we set up fabrication functions by binding such as to match + * the function signature declared in the factory; thereby one + * argument remains unclosed, which is the argument to be + * supplied on each factory invocation by the client code. + * * @see lib::MultiFact * @see query-resolver.cpp */ @@ -104,11 +113,8 @@ namespace test{ typedef TestFactory::Product PP; - DummyID id1 = {ONE, 2}; - DummyID id1 = {TWO, 3}; - - PP p1 = theFact(id1); - PP p2 = theFact(id2); + PP p1 = theFact(ONE, 2); + PP p2 = theFact(TWO, 3); ASSERT (1*2 == p1->n_); ASSERT (2*3 == p2->n_); }