Lumiera  0.pre.03
»edit your freedom«
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 "steam/asset.hpp"
32 #include "steam/asset/pipe.hpp"
33 #include "steam/asset/struct.hpp"
35 #include "steam/assetmanager.hpp"
37 #include "steam/streamtype.hpp"
38 #include "lib/format-string.hpp"
39 #include "lib/query-util.hpp"
41 
42 using util::_Fmt;
43 using util::isnil;
44 using std::string;
45 
46 
47 namespace steam {
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
97  run(Arg)
98  {
99  define_and_search();
100  string pipeID = create();
101  forget(pipeID);
102  }
103 
104 
105 
106 
107  void
108  define_and_search ()
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&
143  create()
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 steam::mobject::session::test
Utilities to support working with predicate queries.
Steam-Layer Interface: Asset Lookup and Organisation.
A "processing pipe" represented as Asset.
Framework for classification of media streams.
the "front side" interface: the Steam-Layer code can use this QueryHandler to retrieve instances of t...
void normaliseID(string &id)
ensure standard format for a given id string.
Definition: query-util.cpp:61
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.
lib::P< TAR > create(Query< TAR > const &)
retrieve an object fulfilling the query and register it as default.
Facade for the Asset subsystem.
static session::SessManager & current
access point to the current Session
Definition: session.hpp:129
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
DefaultsAccess defaults
manages default configured objects
Definition: session.hpp:131
Definition of the concrete frontend for rule based configuration within the session.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition: pipe.hpp:79
static StructFactory retrieve
storage for the static StructFactory instance
Definition: struct.hpp:116
Token or Atom with distinct identity.
Definition: symbol.hpp:126
static lib::Depend< ConfigResolver > instance
Singleton factory instance, configured with the actual implementation type.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Superinterface describing especially bookkeeping properties.
Definition: asset.hpp:148
Steam-Layer Interface: Assets.
static PPipe query(string const &properties)
convenience shortcut for retrieving default configured pipes
Definition: pipe.cpp:66
lib::P< Pipe > newPipe(string pipeID, string streamID)
Factory method for creating Pipes explicitly.
Definition: struct.cpp:167
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:80
key abstraction: structural asset Created automatically as a sideeffect of building the structure of ...
Definition: struct.hpp:113
Primary Interface to the current Session.
user-visible Interface to the ConfigRules subsystem.
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
Implementation of the core defaults-management operations.