From 2765981db9801d40001467674c3ef1731ec2c6eb Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 8 Nov 2009 20:13:11 +0100 Subject: [PATCH] build a complete simplified mock Session/SessionManager --- src/proc/mobject/session.hpp | 15 +- src/proc/mobject/session/scope-query.hpp | 4 +- src/proc/mobject/session/session-impl.hpp | 2 + tests/43session.tests | 2 +- .../session/placement-index-query-test.cpp | 6 +- .../proc/mobject/session/scope-query-test.cpp | 10 +- .../session/session-service-access-test.cpp | 173 ++++++++++++++++-- 7 files changed, 182 insertions(+), 30 deletions(-) diff --git a/src/proc/mobject/session.hpp b/src/proc/mobject/session.hpp index 744113ccd..5e46e97a0 100644 --- a/src/proc/mobject/session.hpp +++ b/src/proc/mobject/session.hpp @@ -23,9 +23,22 @@ /** @file session.hpp ** Primary Interface to the current Session. + ** The session interface can be used to discover session's contents. + ** Mostly, these objects within the session are MObject subclasses, but they + ** are attached into the session by a Placement. Usually, you'd want to use + ** the discovered objects to invoke operations on them; in most cases, + ** invoking any mutating operation should be wrapped into a Command. + ** ** The Interface Session is abstract and only accessible via the ** static field Session::current, which actually refers to a SessManager - ** singleton instance. The latter acts as smart ptr-to-Impl. + ** singleton instance. The latter acts as smart ptr-to-Impl for accessing the + ** current session, but at the same time exposes a lifecycle/management API. + ** + ** @note if interested in the interplay of Session, SessManager and the + ** internal service APIs (SessionServices), you should have a look + ** at session-service-access-test.cpp, as this test creates a complete + ** but simplified mock setup of the session and session manager, without + ** any access and synchronisation and similar concerns, to read top down. ** */ diff --git a/src/proc/mobject/session/scope-query.hpp b/src/proc/mobject/session/scope-query.hpp index 5c9880f95..72e895851 100644 --- a/src/proc/mobject/session/scope-query.hpp +++ b/src/proc/mobject/session/scope-query.hpp @@ -21,8 +21,8 @@ */ -#ifndef MOBJECT_SESSION_CONTENTS_QUERY_H -#define MOBJECT_SESSION_CONTENTS_QUERY_H +#ifndef MOBJECT_SESSION_SCOPE_QUERY_H +#define MOBJECT_SESSION_SCOPE_QUERY_H #include "proc/mobject/placement.hpp" diff --git a/src/proc/mobject/session/session-impl.hpp b/src/proc/mobject/session/session-impl.hpp index ee0f70236..7b36f6887 100644 --- a/src/proc/mobject/session/session-impl.hpp +++ b/src/proc/mobject/session/session-impl.hpp @@ -29,6 +29,8 @@ ** ** This file contains the implementation classes, it should never ** be included by client code. + ** + ** @see session-service-access-test.cpp for a complete simplified mock session manager ** */ diff --git a/tests/43session.tests b/tests/43session.tests index a4a7fafe8..5c9b256b0 100644 --- a/tests/43session.tests +++ b/tests/43session.tests @@ -99,7 +99,7 @@ PLANNED "SessionManager_test" SessionManager_test <(resolver); discover (PathQuery(resolver,elm)); +#endif ////////////////////////////////////////////////////////////////////////////////////////TODO lots of things unimplemented.....!!!!! } diff --git a/tests/components/proc/mobject/session/scope-query-test.cpp b/tests/components/proc/mobject/session/scope-query-test.cpp index 8ec2c9d49..b360e6457 100644 --- a/tests/components/proc/mobject/session/scope-query-test.cpp +++ b/tests/components/proc/mobject/session/scope-query-test.cpp @@ -1,5 +1,5 @@ /* - ContentsQuery(Test) - running queries to discover container contents, filtering (sub)types + ScopeQuery(Test) - running queries to discover container contents, filtering (sub)types Copyright (C) Lumiera.org 2009, Hermann Vosseler @@ -36,7 +36,7 @@ namespace mobject { namespace session { namespace test { - using ContentsQuery; + using session::ContentsQuery; using std::string; using std::cout; using std::endl; @@ -73,10 +73,10 @@ namespace test { ScopeQuery specialEl(resolver,scope, "contents"); + discover (ScopeQuery (resolver,*specialEl, "parents")); + discover (ScopeQuery (resolver,*specialEl, "path")); + discover (ScopeQuery (resolver,*specialEl, "path")); discover (specialEl); - discover (ScopeQuery (resolver,specialEL, "parents")); - discover (ScopeQuery (resolver,specialEL, "path")); - discover (ScopeQuery (resolver,specialEL, "path")); } diff --git a/tests/components/proc/mobject/session/session-service-access-test.cpp b/tests/components/proc/mobject/session/session-service-access-test.cpp index 748cd795c..9214ea055 100644 --- a/tests/components/proc/mobject/session/session-service-access-test.cpp +++ b/tests/components/proc/mobject/session/session-service-access-test.cpp @@ -25,13 +25,20 @@ #include "proc/mobject/session.hpp" //#include "proc/mobject/session/testsession1.hpp" #include "proc/mobject/session/session-services.hpp" +#include "lib/singleton.hpp" //#include "lib/util.hpp" //#include -//#include +#include +#include +#include //using boost::format; -//using std::string; -//using std::cout; + using lib::Singleton; + using boost::lexical_cast; + using std::ostream; + using std::string; + using std::cout; + using std::endl; namespace mobject { @@ -39,36 +46,164 @@ namespace session { namespace test { + namespace { // what follows is a simulated (simplified) version + // of the complete Session + SessionManager setup..... + + + /* === Interface level === */ + + struct TSessManager; + typedef TSessManager& PSess; + + struct TSession + { + virtual ~TSession () { } + static TSessManager& current; + + virtual void externalOperation () =0; + }; + + struct TSessManager + { + /** access to the current session */ + virtual TSession* operator-> () =0; + + virtual void reset () =0; + virtual ~TSessManager() { }; + }; + + + /* === Implementation level === */ + + struct TSessionImpl : TSession + { + static uint magic_; + + /* ==== Session API ==== */ + void externalOperation() ; + + /* ==== Implementation level API ==== */ + void implementationService() ; + + /* ==== internals ==== */ + TSessionImpl() + { + ++magic_; + cout << "creating new Session " << magic_ << endl; + } + + operator string() const + { + return string("Session-Impl(") + + lexical_cast(magic_) + + ")"; + } + }; + + inline ostream& + operator<< (ostream& os, TSessionImpl const& simpl) + { + return os << string(simpl); + } + + void + TSessionImpl::externalOperation() + { + cout << *this << "::externalOperation()" << endl; + } + + /* ==== Implementation level API ==== */ + void + TSessionImpl::implementationService() + { + cout << *this << "::implementationService()" << endl; + } + + + + struct TSessManagerImpl : TSessManager + { + scoped_ptr pImpl_; + + TSessManagerImpl() + : pImpl_(0) + { } + + TSessionImpl* + operator-> () + { + if (!pImpl_) + this->reset(); + return pImpl_.get(); + } + + + /* ==== Manager API ==== */ + void + reset () + { + scoped_ptr tmpS (new TSessionImpl); + pImpl_.swap (tmpS); + } + }; + + + /* === storage and basic configuration === */ + + uint TSessionImpl::magic_; + + TSessManager& TSession::current = Singleton()(); + //note: comes up already during static initialisation + + + } // (END) simulated session management + + + + + /******************************************************************************* * Verify the access mechanism used by Proc-Layer internals for * accessing implementation level APIs of the session. * - * @todo WIP-WIP + * Actually, this test uses setup of the real session, + * complete with interfaces, implementation and a + * session manager frontend. + * + * @see session-impl.hpp the real thing + * @see SessionServices; */ class SessionServiceAccess_test : public Test { virtual void - run (Arg arg) + run (Arg) { -// getCurrentSession (); -// clearSession(); -// loadMockSession(); -// -// clearSession(); -// buildTestsession1(); -// string serialized; -// saveSession (serialized); -// loadSession (serialized); -// ASSERT (checkTestsession1()); + access_defaultSession(); + make_newSession(); + invoke_implService(); } - /** @test accessing the current (global) session */ void - getCurrentSession () + access_defaultSession () { -// PSess sess = Session::current; -// ASSERT (sess->isValid()); + cout << "Session not yet used...." << endl; + TSession::current->externalOperation(); + } + + + void + make_newSession () + { + TSession::current.reset(); + TSession::current->externalOperation(); + } + + + void + invoke_implService () + { + ///////////////////////////////TODO }