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)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/util.hpp"
21 
22 #include "steam/asset.hpp"
23 #include "steam/asset/pipe.hpp"
24 #include "steam/asset/struct.hpp"
26 #include "steam/assetmanager.hpp"
28 #include "steam/streamtype.hpp"
29 #include "lib/format-string.hpp"
30 #include "lib/query-util.hpp"
32 
33 using util::_Fmt;
34 using util::isnil;
35 using std::string;
36 
37 
38 namespace steam {
39 namespace mobject {
40 namespace session {
41 namespace test {
42 
43  using lib::Symbol;
44  using asset::Asset;
45  using asset::AssetManager;
46  using asset::Pipe;
47  using asset::PPipe;
48  using asset::Struct;
49 
50  using lumiera::Query;
53 
55 
56 
57  namespace { // test fixture...
58 
60  bool
61  find (const string& pID)
62  {
63  return bool(Session::current->defaults.search (Query<Pipe> ("pipe("+pID+")")));
64  }
65 
66 
67  _Fmt pattern ("dummy_%s_%i");
68 
70  string
71  newID (Symbol prefix)
72  {
73  return pattern % prefix % rani(10'000);
74  }
75  }//(end)test fixture
76 
77 
78 
79 
80  /********************************************************************//**
81  * @test verify some general assumptions regarding implementation details
82  * of the the defaults manager.
83  * @see DefsManager_test for the "big picture"
84  */
85  class DefsManagerImpl_test : public Test
86  {
87  virtual void
88  run(Arg)
89  {
90  seedRand();
91 
92  define_and_search();
93  string pipeID = create();
94  forget(pipeID);
95  }
96 
97 
98 
99 
100  void
101  define_and_search ()
102  {
103  string sID = newID ("stream");
104  StreamType::ID stID (sID);
105 
106  // create Pipes explicitly
107  // (without utilising default queries)
108  PPipe pipe1 = Struct::retrieve.newPipe (newID("pipe"), newID("stream"));
109  PPipe pipe2 = Struct::retrieve.newPipe (newID("pipe"), sID );
110 
111  CHECK (pipe1 != pipe2);
112  CHECK (stID == pipe2->getStreamID());
113 
114  CHECK (!find (pipe1->getPipeID()), "accidental clash of random test-IDs");
115  CHECK (!find (pipe2->getPipeID()), "accidental clash of random test-IDs");
116 
117  // now declare that these objects should be considered "default"
118  Query<Pipe> justAnyPipe ("");
119 lumiera::query::setFakeBypass(justAnyPipe); /////////////////////////////////////////////////TODO mock resolution
120  CHECK (Session::current->defaults.define (pipe1, justAnyPipe)); // unrestricted default
121 
122  Query<Pipe> pipeWithSpecificStream("stream("+sID+")");
123 lumiera::query::setFakeBypass(pipeWithSpecificStream); ///////////////////////////////////TODO mock resolution
124  CHECK (Session::current->defaults.define (pipe2, pipeWithSpecificStream));
125 
126  CHECK ( find (pipe1->getPipeID()), "failure declaring object as default");
127  CHECK ( find (pipe2->getPipeID()), "failure declaring object as default");
128 
129  CHECK (stID != pipe1->getStreamID(), "accidental clash");
130  CHECK (!Session::current->defaults.define (pipe1, Query<Pipe> ("stream("+sID+")")));
131  // can't be registered with this query, due to failure caused by wrong stream-ID
132  }
133 
134 
135  const string&
136  create()
137  {
138  string sID = newID ("stream");
139  Query<Pipe> query_for_streamID ("stream("+sID+")");
140 
141  // issue a ConfigQuery directly, without involving the DefaultsManager
143  PPipe pipe1;
144  typeHandler.resolve (pipe1, query_for_streamID);
145  CHECK (pipe1);
146 
147  CHECK (!find (pipe1->getPipeID()));
148  PPipe pipe2 = Session::current->defaults.create (query_for_streamID);
149  CHECK (pipe2);
150  CHECK (pipe2 == pipe1);
151  CHECK ( find (pipe1->getPipeID())); // now declared as "default Pipe" for this stream-ID
152 
153  return pipe1->getPipeID();
154  }
155 
156 
157  void
158  forget (string pID)
159  {
160  PPipe pipe = Pipe::query ("pipe("+pID+")");
161  REQUIRE (find (pipe->getPipeID()), "test assumes pre-registered default pipe");
162  long cnt = pipe.use_count();
163 
164  // now de-register the pipe as "default Pipe"
165  CHECK (Session::current->defaults.forget (pipe));
166  CHECK (!find (pipe->getPipeID()));
167  CHECK (cnt == pipe.use_count()); // indicates DefaultsManager holding only a weak ref.
168  }
169  };
170 
171 
173  LAUNCHER (DefsManagerImpl_test, "function session");
174 
175 
176 
177 }}}} // 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:52
Definition: run.hpp:40
Front-end for printf-style string template interpolation.
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
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:120
Steam-Layer implementation namespace root.
A front-end for using printf-style formatting.
DefaultsAccess defaults
manages default configured objects
Definition: session.hpp:122
Definition of the concrete frontend for rule based configuration within the session.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition: pipe.hpp:70
Token or Atom with distinct identity.
Definition: symbol.hpp:117
static lib::Depend< ConfigResolver > instance
Singleton factory instance, configured with the actual implementation type.
Simplistic 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:139
Steam-Layer Interface: Assets.
static PPipe query(string const &properties)
convenience shortcut for retrieving default configured pipes
Definition: pipe.cpp:57
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
key abstraction: structural asset Created automatically as a sideeffect of building the structure of ...
Definition: struct.hpp:104
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:270
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition: asset.hpp:99
Implementation of the core defaults-management operations.