Lumiera  0.pre.03
»edityourfreedom«
defs-manager-impl-test.cpp
Go to the documentation of this file.
1 /*
2  DefsManagerImpl(Test) - checking implementation details of the defaults manager
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/util.hpp"
30 
31 #include "proc/asset.hpp"
32 #include "proc/asset/pipe.hpp"
33 #include "proc/asset/struct.hpp"
34 #include "proc/config-resolver.hpp"
35 #include "proc/assetmanager.hpp"
36 #include "proc/mobject/session.hpp"
37 #include "proc/streamtype.hpp"
38 #include "lib/format-string.hpp"
39 #include "lib/query-util.hpp"
40 #include "common/query.hpp"
41 
42 using util::_Fmt;
43 using util::isnil;
44 using std::string;
45 
46 
47 namespace proc {
48 namespace mobject {
49 namespace session {
50 namespace test {
51 
52  using lib::Symbol;
53  using asset::Asset;
54  using asset::AssetManager;
55  using asset::Pipe;
56  using asset::PPipe;
57  using asset::Struct;
58 
59  using lumiera::Query;
62 
64 
65 
66  namespace { // test fixture...
67 
69  bool
70  find (const string& pID)
71  {
72  return bool(Session::current->defaults.search (Query<Pipe> ("pipe("+pID+")")));
73  }
74 
75 
76  _Fmt pattern ("dummy_%s_%i");
77 
79  string
80  newID (Symbol prefix)
81  {
82  return pattern % prefix % std::rand();
83  }
84  }//(end)test fixture
85 
86 
87 
88 
89  /********************************************************************/
94  class DefsManagerImpl_test : public Test
95  {
96  virtual void
98  {
100  string pipeID = create();
101  forget(pipeID);
102  }
103 
104 
105 
106 
107  void
109  {
110  string sID = newID ("stream");
111  StreamType::ID stID (sID);
112 
113  // create Pipes explicitly
114  // (without utilising default queries)
115  PPipe pipe1 = Struct::retrieve.newPipe (newID("pipe"), newID("stream"));
116  PPipe pipe2 = Struct::retrieve.newPipe (newID("pipe"), sID );
117 
118  CHECK (pipe1 != pipe2);
119  CHECK (stID == pipe2->getStreamID());
120 
121  CHECK (!find (pipe1->getPipeID()), "accidental clash of random test-IDs");
122  CHECK (!find (pipe2->getPipeID()), "accidental clash of random test-IDs");
123 
124  // now declare that these objects should be considered "default"
125  Query<Pipe> justAnyPipe ("");
126 lumiera::query::setFakeBypass(justAnyPipe);
127  CHECK (Session::current->defaults.define (pipe1, justAnyPipe)); // unrestricted default
128 
129  Query<Pipe> pipeWithSpecificStream("stream("+sID+")");
130 lumiera::query::setFakeBypass(pipeWithSpecificStream);
131  CHECK (Session::current->defaults.define (pipe2, pipeWithSpecificStream));
132 
133  CHECK ( find (pipe1->getPipeID()), "failure declaring object as default");
134  CHECK ( find (pipe2->getPipeID()), "failure declaring object as default");
135 
136  CHECK (stID != pipe1->getStreamID(), "accidental clash");
137  CHECK (!Session::current->defaults.define (pipe1, Query<Pipe> ("stream("+sID+")")));
138  // can't be registered with this query, due to failure caused by wrong stream-ID
139  }
140 
141 
142  const string&
144  {
145  string sID = newID ("stream");
146  Query<Pipe> query_for_streamID ("stream("+sID+")");
147 
148  // issue a ConfigQuery directly, without involving the DefaultsManager
150  PPipe pipe1;
151  typeHandler.resolve (pipe1, query_for_streamID);
152  CHECK (pipe1);
153 
154  CHECK (!find (pipe1->getPipeID()));
155  PPipe pipe2 = Session::current->defaults.create (query_for_streamID);
156  CHECK (pipe2);
157  CHECK (pipe2 == pipe1);
158  CHECK ( find (pipe1->getPipeID())); // now declared as "default Pipe" for this stream-ID
159 
160  return pipe1->getPipeID();
161  }
162 
163 
164  void
165  forget (string pID)
166  {
167  PPipe pipe = Pipe::query ("pipe("+pID+")");
168  REQUIRE (find (pipe->getPipeID()), "test assumes pre-registered default pipe");
169  long cnt = pipe.use_count();
170 
171  // now de-register the pipe as "default Pipe"
172  CHECK (Session::current->defaults.forget (pipe));
173  CHECK (!find (pipe->getPipeID()));
174  CHECK (cnt == pipe.use_count()); // indicates DefaultsManager holding only a weak ref.
175  }
176  };
177 
178 
180  LAUNCHER (DefsManagerImpl_test, "function session");
181 
182 
183 
184 }}}} // namespace proc::mobject::session::test
Utilities to support working with predicate queries.
Proc-Layer Interface: Asset Lookup and Organisation.
A "processing pipe" represented as Asset.
Framework for classification of media streams.
Facade for the Asset subsystem.
Basic and generic representation of an internal query.
the "front side" interface: the Proc-Layer code can use this QueryHandler to retrieve instances of th...
Definition: run.hpp:49
Front-end for printf-style string template interpolation.
virtual bool resolve(P< TY > &solution, Query< TY > const &q)=0
try to find or create an object of type TY fulfilling the given query.
static session::SessManager & current
access point to the current Session
Definition: session.hpp:127
lib::P< TAR > create(Query< TAR > const &)
retrieve an object fulfilling the query and register it as default.
void setFakeBypass(lumiera::QueryKey const &q)
backdoor for tests: the next config query with this query string will magically succeed with every ca...
lib::P< Pipe > PPipe
Definition: pipe.hpp:51
LAUNCHER(PlacementBasic_test, "unit session")
Register this test class...
A front-end for using printf-style formatting.
Definition of the concrete frontend for rule based configuration within the session.
key abstraction: structural asset Created automatically as a sideeffect of building the structure of ...
Definition: struct.hpp:113
Superinterface describing especially bookkeeping properties.
Definition: asset.hpp:148
lib::P< Pipe > newPipe(string pipeID, string streamID)
Factory method for creating Pipes explicitly.
Definition: struct.cpp:167
bool find(Query< Pipe > &q)
shortcut: run just a query without creating new instances
void normaliseID(string &id)
ensure standard format for a given id string.
Definition: query-util.cpp:60
Token or Atom with distinct identity.
Definition: symbol.hpp:116
static StructFactory retrieve
storage for the static StructFactory instance
Definition: struct.hpp:116
std::vector< string > & Arg
Definition: run.hpp:54
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Proc-Layer Interface: Assets.
static lib::Depend< ConfigResolver > instance
Singleton factory instance, configured with the actual implementation type.
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
DefaultsAccess defaults
manages default configured objects
Definition: session.hpp:129
user-visible Interface to the ConfigRules subsystem.
static PPipe query(string const &properties)
convenience shortcut for retrieving default configured pipes
Definition: pipe.cpp:66
Namespace of Session and user visible high-level objects.
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition: pipe.hpp:79
const_SList pattern
Definition: slist.h:605
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:76
Primary Interface to the current Session.
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
Asset representation of structural elements within the model.
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:279