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)
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/symbol.hpp"
21 #include "lib/util.hpp"
22 #include "lib/format-string.hpp"
23 #include "lib/query-util.hpp"
24 #include "common/query.hpp"
25 
26 #include "steam/asset.hpp"
27 #include "steam/asset/pipe.hpp"
28 #include "steam/asset/struct.hpp"
29 #include "steam/assetmanager.hpp"
31 #include "steam/streamtype.hpp"
32 
33 using util::_Fmt;
34 using util::isnil;
35 using std::string;
36 
37 
38 
39 namespace steam {
40 namespace mobject {
41 namespace session {
42 namespace test {
43 
44  using lib::Symbol;
45  using asset::ID;
46  using asset::Asset;
47  using asset::AssetManager;
48  using asset::Pipe;
49  using asset::PPipe;
50  using asset::Struct;
51  using lumiera::Query;
53 
54 
58  bool
59  find (Query<Pipe>& q)
60  {
61  return bool(Session::current->defaults.search (q));
62  }
63 
64 
65 
66 
67  /*******************************************************************/
77  class DefsManager_test : public Test
78  {
79  virtual void
80  run (Arg arg)
81  {
82  seedRand();
83  string pipeID = isnil(arg)? "Black Hole" : arg[1];
84  string streamID = 2>arg.size()? "teststream" : arg[2];
85 
86  normaliseID (pipeID);
87  normaliseID (streamID);
88 
89  retrieveSimpleDefault (pipeID);
90  retrieveConstrainedDefault (pipeID, streamID);
91  failureCreatesNewDefault();
92  verifyRemoval();
93  }
94 
95 
96 
97 
98  void
99  retrieveSimpleDefault (string)
100  {
101  PPipe pipe1 = Pipe::query (""); // "the default pipe"
102  PPipe pipe2;
103 
104  // several variants to query for "the default pipe"
105  pipe2 = Pipe::query ("");
106  CHECK (pipe2 == pipe1);
107  pipe2 = Pipe::query ("default(X)");
108  CHECK (pipe2 == pipe1);
109  pipe2 = Session::current->defaults(Query<Pipe> (""));
110  CHECK (pipe2 == pipe1);
111  pipe2 = asset::Struct::retrieve (Query<Pipe> (""));
112  CHECK (pipe2 == pipe1);
113  pipe2 = asset::Struct::retrieve (Query<Pipe> ("default(P)"));
114  CHECK (pipe2 == pipe1);
115  }
116 
117 
118  void
119  retrieveConstrainedDefault (string pID, string sID)
120  {
121  PPipe pipe1 = Pipe::query (""); // "the default pipe"
122  CHECK ( pipe1->getStreamID() != StreamType::ID{sID},
123  "stream-ID \"%s\" not suitable for test, because "
124  "the default-pipe \"%s\" happens to have the same "
125  "stream-ID. We need it to be different",
126  sID.c_str(), pID.c_str()
127  );
128 
129  string query_for_sID{"stream("+sID+")"};
130  PPipe pipe2 = Pipe::query (query_for_sID);
131  CHECK (pipe2->getStreamID() == StreamType::ID{sID});
132  CHECK (pipe2 != pipe1);
133  CHECK (pipe2 == Pipe::query (query_for_sID)); // reproducible
134  }
135 
136 
137  void
138  failureCreatesNewDefault()
139  {
140  PPipe pipe1 = Session::current->defaults(Query<Pipe>{""}); // "the default pipe"
141 
142  string new_pID = _Fmt{"dummy_%s_%i"}
143  % pipe1->getPipeID()
144  % rani(10'000)
145  ; // make random new pipeID
146  Query<Pipe> query_for_new{"pipe("+new_pID+")"};
147 
148  CHECK (!find (query_for_new)); // check it doesn't exist
149  PPipe pipe2 = Session::current->defaults (query_for_new); // triggers creation
150  CHECK ( find (query_for_new)); // check it exists now
151 
152  CHECK (pipe1 != pipe2);
153  CHECK (pipe2 == Session::current->defaults (query_for_new));
154  }
155 
156 
161  void
163  {
164  Symbol pID{"some_pipe"};
165  Query<Pipe> query_for_pID{"pipe("+pID+")"};
166  size_t hash;
167  {
168  // create new pipe and declare it to be a default
169  PPipe pipe1 = Struct::retrieve.newInstance<Pipe> (pID);
171 
172  CHECK (2 == pipe1.use_count()); // the pipe1 smart-ptr and the AssetManager
173  hash = pipe1->getID();
174  }
175  // pipe1 out of scope....
176  // AssetManager now should hold the only ref
177  ID<Asset> assetID (hash);
178 
180  CHECK ( aMang.known (assetID));
181  aMang.remove (assetID);
182  CHECK (!aMang.known (assetID));
183 
184 
185  CHECK (!find(query_for_pID)); // bare default-query should fail...
186  PPipe pipe2 = Session::current->defaults (query_for_pID); // triggers re-creation
187  CHECK ( find(query_for_pID)); // should succeed again
188  }
189  };
190 
191 
192 
194  LAUNCHER (DefsManager_test, "function session");
195 
196 
197 }}}} // 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:52
Definition: run.hpp:40
void remove(IDA id)
remove the given asset from the internal DB.
Front-end for printf-style string template interpolation.
int rani(uint bound=_iBOUND())
Definition: random.hpp:135
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
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
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:85
static StructFactory retrieve
storage for the static StructFactory instance
Definition: struct.hpp:107
Token or Atom with distinct identity.
Definition: symbol.hpp:117
Marker types to indicate a literal string and a Symbol.
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.
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