Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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"
31#include "steam/streamtype.hpp"
32
33using util::_Fmt;
34using util::isnil;
35using std::string;
36
37
38
39namespace steam {
40namespace mobject {
41namespace session {
42namespace test {
43
44 using lib::Symbol;
45 using asset::ID;
46 using asset::Asset;
48 using asset::Pipe;
49 using asset::PPipe;
50 using asset::Struct;
51 using lumiera::Query;
53
54
58 bool
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);
93 }
94
95
96
97
98 void
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);
110 CHECK (pipe2 == pipe1);
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
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
Steam-Layer Interface: Assets.
Steam-Layer Interface: Asset Lookup and Organisation.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
Token or Atom with distinct identity.
Definition symbol.hpp:120
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition query.hpp:254
bool define(lib::P< TAR > const &, Query< TAR > const &=Query< TAR >())
register the given object as default, after ensuring it fulfils the query.
Facade for the Asset subsystem.
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
void remove(IDA id)
remove the given asset from the internal DB.
Superinterface describing especially bookkeeping properties.
Definition asset.hpp:139
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition asset.hpp:98
structural asset corresponding to the part of the model forming a processing pipe for generating medi...
Definition pipe.hpp:72
static PPipe query(string const &properties)
convenience shortcut for retrieving default configured pipes
Definition pipe.cpp:57
lib::P< STRU > newInstance(Symbol nameID="")
invoke the factory to create new Structural Asset.
Definition struct.cpp:85
key abstraction: structural asset Created automatically as a sideeffect of building the structure of ...
Definition struct.hpp:105
static StructFactory retrieve
storage for the static StructFactory instance
Definition struct.hpp:107
DefaultsAccess defaults
manages default configured objects
Definition session.hpp:122
static session::SessManager & current
access point to the current Session
Definition session.hpp:120
void verifyRemoval()
verify the defaults manager holds only weak refs, so if an object goes out of scope,...
A front-end for using printf-style formatting.
Front-end for printf-style string template interpolation.
#define hash
void normaliseID(string &id)
ensure standard format for a given id string.
bool find(Query< Pipe > &q)
shortcut: run just a query without creating new instances
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool isnil(lib::time::Duration const &dur)
A "processing pipe" represented as Asset.
Utilities to support working with predicate queries.
Basic and generic representation of an internal query.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Primary Interface to the current Session.
Framework for classification of media streams.
Asset representation of structural elements within the model.
Marker types to indicate a literal string and a Symbol.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...