Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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"
28#include "steam/streamtype.hpp"
29#include "lib/format-string.hpp"
30#include "lib/query-util.hpp"
32
33using util::_Fmt;
34using util::isnil;
35using std::string;
36
37
38namespace steam {
39namespace mobject {
40namespace session {
41namespace test {
42
43 using lib::Symbol;
44 using asset::Asset;
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 /********************************************************************/
85 class DefsManagerImpl_test : public Test
86 {
87 virtual void
88 run(Arg)
89 {
90 seedRand();
91
93 string pipeID = create();
94 forget(pipeID);
95 }
96
97
98
99
100 void
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 ("");
120 CHECK (Session::current->defaults.define (pipe1, justAnyPipe)); // unrestricted default
121
122 Query<Pipe> pipeWithSpecificStream("stream("+sID+")");
123lumiera::query::setFakeBypass(pipeWithSpecificStream);
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&
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
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
lib::P< TAR > create(Query< TAR > const &)
retrieve an object fulfilling the query and register it as default.
the "front side" interface: the Steam-Layer code can use this QueryHandler to retrieve instances of t...
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.
user-visible Interface to the ConfigRules subsystem.
static lib::Depend< ConfigResolver > instance
Singleton factory instance, configured with the actual implementation type.
Facade for the Asset subsystem.
Superinterface describing especially bookkeeping properties.
Definition asset.hpp:139
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< Pipe > newPipe(string pipeID, string streamID)
Factory method for creating Pipes explicitly.
Definition struct.cpp:158
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
A front-end for using printf-style formatting.
Definition of the concrete frontend for rule based configuration within the session.
Implementation of the core defaults-management operations.
Front-end for printf-style string template interpolation.
void normaliseID(string &id)
ensure standard format for a given id string.
void setFakeBypass(lumiera::QueryKey const &q)
backdoor for tests: the next config query with this query string will magically succeed with every ca...
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.
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.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...