Lumiera  0.pre.03
»edityourfreedom«
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 "proc/asset.hpp"
36 #include "proc/asset/pipe.hpp"
37 #include "proc/asset/struct.hpp"
38 #include "proc/assetmanager.hpp"
39 #include "proc/mobject/session.hpp"
40 #include "proc/streamtype.hpp"
41 
42 using util::_Fmt;
43 using util::isnil;
44 using std::string;
45 
46 
47 
48 namespace proc {
49 namespace mobject {
50 namespace session {
51 namespace test {
52 
53  using util::cStr;
54  using lib::Symbol;
55  using asset::ID;
56  using asset::Asset;
57  using asset::AssetManager;
58  using asset::Pipe;
59  using asset::PPipe;
60  using asset::Struct;
61  using lumiera::Query;
63 
64 
68  bool
70  {
71  return bool(Session::current->defaults.search (q));
72  }
73 
74 
75 
76 
77  /*******************************************************************/
87  class DefsManager_test : public Test
88  {
89  virtual void
90  run (Arg arg)
91  {
92  string pipeID = isnil(arg)? "Black Hole" : arg[1];
93  string streamID = 2>arg.size()? "teststream" : arg[2];
94 
95  normaliseID (pipeID);
96  normaliseID (streamID);
97 
98  retrieveSimpleDefault (pipeID);
99  retrieveConstrainedDefault (pipeID, streamID);
101  verifyRemoval();
102  }
103 
104 
105 
106 
107  void
109  {
110  PPipe pipe1 = Pipe::query (""); // "the default pipe"
111  PPipe pipe2;
112 
113  // several variants to query for "the default pipe"
114  pipe2 = Pipe::query ("");
115  CHECK (pipe2 == pipe1);
116  pipe2 = Pipe::query ("default(X)");
117  CHECK (pipe2 == pipe1);
118  pipe2 = Session::current->defaults(Query<Pipe> (""));
119  CHECK (pipe2 == pipe1);
120  pipe2 = asset::Struct::retrieve (Query<Pipe> (""));
121  CHECK (pipe2 == pipe1);
122  pipe2 = asset::Struct::retrieve (Query<Pipe> ("default(P)"));
123  CHECK (pipe2 == pipe1);
124  }
125 
126 
127  void
128  retrieveConstrainedDefault (string pID, string sID)
129  {
130  PPipe pipe1 = Pipe::query (""); // "the default pipe"
131  CHECK ( pipe1->getStreamID() != StreamType::ID{sID},
132  "stream-ID \"%s\" not suitable for test, because "
133  "the default-pipe \"%s\" happens to have the same "
134  "stream-ID. We need it to be different",
135  sID.c_str(), pID.c_str()
136  );
137 
138  string query_for_sID{"stream("+sID+")"};
139  PPipe pipe2 = Pipe::query (query_for_sID);
140  CHECK (pipe2->getStreamID() == StreamType::ID{sID});
141  CHECK (pipe2 != pipe1);
142  CHECK (pipe2 == Pipe::query (query_for_sID)); // reproducible
143  }
144 
145 
146  void
148  {
149  PPipe pipe1 = Session::current->defaults(Query<Pipe>{""}); // "the default pipe"
150 
151  string new_pID = _Fmt{"dummy_%s_%i"}
152  % pipe1->getPipeID()
153  % std::rand()
154  ; // make random new pipeID
155  Query<Pipe> query_for_new{"pipe("+new_pID+")"};
156 
157  CHECK (!find (query_for_new)); // check it doesn't exist
158  PPipe pipe2 = Session::current->defaults (query_for_new); // triggers creation
159  CHECK ( find (query_for_new)); // check it exists now
160 
161  CHECK (pipe1 != pipe2);
162  CHECK (pipe2 == Session::current->defaults (query_for_new));
163  }
164 
165 
170  void
172  {
173  Symbol pID{"some_pipe"};
174  Query<Pipe> query_for_pID{"pipe("+pID+")"};
175  size_t hash;
176  {
177  // create new pipe and declare it to be a default
178  PPipe pipe1 = Struct::retrieve.newInstance<Pipe> (pID);
180 
181  CHECK (2 == pipe1.use_count()); // the pipe1 smart-ptr and the AssetManager
182  hash = pipe1->getID();
183  }
184  // pipe1 out of scope....
185  // AssetManager now should hold the only ref
186  ID<Asset> assetID (hash);
187 
189  CHECK ( aMang.known (assetID));
190  aMang.remove (assetID);
191  CHECK (!aMang.known (assetID));
192 
193 
194  CHECK (!find(query_for_pID)); // bare default-query should fail...
195  PPipe pipe2 = Session::current->defaults (query_for_pID); // triggers re-creation
196  CHECK ( find(query_for_pID)); // should succeed again
197  }
198  };
199 
200 
201 
203  LAUNCHER (DefsManager_test, "function session");
204 
205 
206 }}}} // namespace proc::mobject::session::test
#define hash
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.
bool define(lib::P< TAR > const &, Query< TAR > const &=Query< TAR >())
register the given object as default, after ensuring it fulfils the query.
Definition: run.hpp:49
Front-end for printf-style string template interpolation.
static session::SessManager & current
access point to the current Session
Definition: session.hpp:127
lib::P< STRU > newInstance(Symbol nameID="")
invoke the factory to create new Structural Asset.
Definition: struct.cpp:94
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.
const char * cStr(string const &org)
convenience shortcut: conversion to c-String via string.
Definition: util.hpp:397
void verifyRemoval()
verify the defaults manager holds only weak refs, so if an object goes out of scope, any defaults entries are purged silently
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
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
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
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
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...
void remove(IDA id)
remove the given asset from the internal DB.
Proc-Layer Interface: Assets.
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
DefaultsAccess defaults
manages default configured objects
Definition: session.hpp:129
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.
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition: asset.hpp:108
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition: pipe.hpp:79
void retrieveConstrainedDefault(string pID, string sID)
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
lib::idi::BareEntryID const & ID
Definition: id-scheme.hpp:87