Lumiera  0.pre.03
»edit your freedom«
defs-manager-test.cpp
Go to the documentation of this file.
1 /*
2  DefsManager(Test) - checking basic behaviour 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/symbol.hpp"
30 #include "lib/util.hpp"
31 #include "lib/format-string.hpp"
32 #include "lib/query-util.hpp"
33 #include "common/query.hpp"
34 
35 #include "steam/asset.hpp"
36 #include "steam/asset/pipe.hpp"
37 #include "steam/asset/struct.hpp"
38 #include "steam/assetmanager.hpp"
40 #include "steam/streamtype.hpp"
41 
42 using util::_Fmt;
43 using util::isnil;
44 using std::string;
45 
46 
47 
48 namespace steam {
49 namespace mobject {
50 namespace session {
51 namespace test {
52 
53  using lib::Symbol;
54  using asset::ID;
55  using asset::Asset;
56  using asset::AssetManager;
57  using asset::Pipe;
58  using asset::PPipe;
59  using asset::Struct;
60  using lumiera::Query;
62 
63 
67  bool
68  find (Query<Pipe>& q)
69  {
70  return bool(Session::current->defaults.search (q));
71  }
72 
73 
74 
75 
76  /*******************************************************************/
86  class DefsManager_test : public Test
87  {
88  virtual void
89  run (Arg arg)
90  {
91  string pipeID = isnil(arg)? "Black Hole" : arg[1];
92  string streamID = 2>arg.size()? "teststream" : arg[2];
93 
94  normaliseID (pipeID);
95  normaliseID (streamID);
96 
97  retrieveSimpleDefault (pipeID);
98  retrieveConstrainedDefault (pipeID, streamID);
99  failureCreatesNewDefault();
100  verifyRemoval();
101  }
102 
103 
104 
105 
106  void
107  retrieveSimpleDefault (string)
108  {
109  PPipe pipe1 = Pipe::query (""); // "the default pipe"
110  PPipe pipe2;
111 
112  // several variants to query for "the default pipe"
113  pipe2 = Pipe::query ("");
114  CHECK (pipe2 == pipe1);
115  pipe2 = Pipe::query ("default(X)");
116  CHECK (pipe2 == pipe1);
117  pipe2 = Session::current->defaults(Query<Pipe> (""));
118  CHECK (pipe2 == pipe1);
119  pipe2 = asset::Struct::retrieve (Query<Pipe> (""));
120  CHECK (pipe2 == pipe1);
121  pipe2 = asset::Struct::retrieve (Query<Pipe> ("default(P)"));
122  CHECK (pipe2 == pipe1);
123  }
124 
125 
126  void
127  retrieveConstrainedDefault (string pID, string sID)
128  {
129  PPipe pipe1 = Pipe::query (""); // "the default pipe"
130  CHECK ( pipe1->getStreamID() != StreamType::ID{sID},
131  "stream-ID \"%s\" not suitable for test, because "
132  "the default-pipe \"%s\" happens to have the same "
133  "stream-ID. We need it to be different",
134  sID.c_str(), pID.c_str()
135  );
136 
137  string query_for_sID{"stream("+sID+")"};
138  PPipe pipe2 = Pipe::query (query_for_sID);
139  CHECK (pipe2->getStreamID() == StreamType::ID{sID});
140  CHECK (pipe2 != pipe1);
141  CHECK (pipe2 == Pipe::query (query_for_sID)); // reproducible
142  }
143 
144 
145  void
146  failureCreatesNewDefault()
147  {
148  PPipe pipe1 = Session::current->defaults(Query<Pipe>{""}); // "the default pipe"
149 
150  string new_pID = _Fmt{"dummy_%s_%i"}
151  % pipe1->getPipeID()
152  % std::rand()
153  ; // make random new pipeID
154  Query<Pipe> query_for_new{"pipe("+new_pID+")"};
155 
156  CHECK (!find (query_for_new)); // check it doesn't exist
157  PPipe pipe2 = Session::current->defaults (query_for_new); // triggers creation
158  CHECK ( find (query_for_new)); // check it exists now
159 
160  CHECK (pipe1 != pipe2);
161  CHECK (pipe2 == Session::current->defaults (query_for_new));
162  }
163 
164 
169  void
171  {
172  Symbol pID{"some_pipe"};
173  Query<Pipe> query_for_pID{"pipe("+pID+")"};
174  size_t hash;
175  {
176  // create new pipe and declare it to be a default
177  PPipe pipe1 = Struct::retrieve.newInstance<Pipe> (pID);
179 
180  CHECK (2 == pipe1.use_count()); // the pipe1 smart-ptr and the AssetManager
181  hash = pipe1->getID();
182  }
183  // pipe1 out of scope....
184  // AssetManager now should hold the only ref
185  ID<Asset> assetID (hash);
186 
188  CHECK ( aMang.known (assetID));
189  aMang.remove (assetID);
190  CHECK (!aMang.known (assetID));
191 
192 
193  CHECK (!find(query_for_pID)); // bare default-query should fail...
194  PPipe pipe2 = Session::current->defaults (query_for_pID); // triggers re-creation
195  CHECK ( find(query_for_pID)); // should succeed again
196  }
197  };
198 
199 
200 
202  LAUNCHER (DefsManager_test, "function session");
203 
204 
205 }}}} // 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.
Basic and generic representation of an internal query.
bool define(lib::P< TAR > const &, Query< TAR > const &=Query< TAR >())
register the given object as default, after ensuring it fulfils the query.
void normaliseID(string &id)
ensure standard format for a given id string.
Definition: query-util.cpp:61
Definition: run.hpp:49
void remove(IDA id)
remove the given asset from the internal DB.
Front-end for printf-style string template interpolation.
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
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 lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
void verifyRemoval()
verify the defaults manager holds only weak refs, so if an object goes out of scope, any defaults entries are purged silently
lib::P< STRU > newInstance(Symbol nameID="")
invoke the factory to create new Structural Asset.
Definition: struct.cpp:94
static StructFactory retrieve
storage for the static StructFactory instance
Definition: struct.hpp:116
Token or Atom with distinct identity.
Definition: symbol.hpp:126
Marker types to indicate a literal string and a Symbol.
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
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.
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
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition: asset.hpp:108