Lumiera  0.pre.03
»edityourfreedom«
basicpipetest.cpp
Go to the documentation of this file.
1 /*
2  BasicPipe(Test) - checking the basic properties of Pipe Assets
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 "include/logging.h"
29 #include "lib/test/run.hpp"
30 #include "lib/util.hpp"
31 
32 #include "proc/asset/category.hpp"
33 #include "proc/asset/pipe.hpp"
34 #include "proc/assetmanager.hpp"
35 #include "proc/mobject/session.hpp"
37 #include "lib/query-util.hpp"
38 #include "common/query.hpp"
39 
40 
41 using util::contains;
42 using util::isnil;
43 using std::string;
44 
45 
46 namespace proc {
47 namespace asset {
48 namespace test {
49 
50  using mobject::Session;
51  using lumiera::Query;
53 
54 
55 
56  /*******************************************************************/
65  class BasicPipe_test : public Test
66  {
67  virtual void
68  run (Arg arg)
69  {
70  string pipeID = isnil (arg)? "Black Hole" : arg[1];
71  string streamID = 2>arg.size()? "teststream" : arg[2] ;
72 
73  createExplicit (pipeID,streamID);
74  create_or_ref (pipeID);
76  dependProcPatt (pipeID);
77  }
78 
79 
80 
81 
82  void createExplicit (string pID, string sID)
83  {
84  string pID_sane{pID};
85  normaliseID (pID_sane);
86  CHECK (pID_sane != pID);
87 
88  PPipe thePipe = asset::Struct::retrieve.newPipe (pID,sID);
89 
90  CHECK (thePipe);
91  CHECK (thePipe->getProcPatt());
92  CHECK (thePipe->getPipeID() == pID_sane);
93  CHECK (thePipe->getStreamID() == StreamType::ID{sID});
94  CHECK (thePipe->shortDesc == pID_sane);
95 
96  Asset::Ident idi = thePipe->ident;
97  CHECK (idi.org == "lumi");
98  CHECK (contains (idi.name, thePipe->getPipeID()));
99  CHECK (contains (idi.name, thePipe->getStreamID()));
100 
101  Category cat{idi.category};
102  Category refcat{STRUCT,"pipes"};
103  CHECK ( cat.hasKind (STRUCT) );
104  CHECK ( cat.isWithin(refcat) );
105  }
106 
107 
108  void create_or_ref(string pID)
109  {
110  normaliseID (pID);
111 
112  PPipe pipe1 = Pipe::query ("pipe("+pID+")");
113  CHECK (pipe1);
114  CHECK (pipe1->getPipeID() == pID);
115 
116  string pID2 = "another-" + pID;
117  PPipe pipe2 = Pipe::query ("pipe("+pID2+")");
118  CHECK (pipe2);
119  CHECK (pipe2 != pipe1);
120  Category c1 = pipe1->ident.category;
121  Category c2 = pipe2->ident.category;
122  CHECK (c1 == c2);
123 
124  PPipe pipe3 = Pipe::query ("pipe("+pID2+")");
126  CHECK (pipe3 == pipe2);
127  }
128 
129 
131  {
132  PPipe pipe1 = Pipe::query (""); // "the default pipe"
133  PPipe pipe2;
134  CHECK (pipe1);
135  CHECK (pipe1 == Session::current->defaults (Query<Pipe>{}));
136  CHECK (pipe1->ident.category.hasKind(VIDEO));
137  CHECK (pipe1->getProcPatt());
138  PProcPatt propa = Session::current->defaults (Query<const ProcPatt>{"pipe(default)"});
139  CHECK (propa == pipe1->getProcPatt());
140 
141  // several variants to query for "the default pipe"
143  CHECK (pipe2 == pipe1);
145  CHECK (pipe2 == pipe1);
146  pipe2 = asset::Struct::retrieve (Query<Pipe>{"pipe(default)"});
147  CHECK (pipe2 == pipe1);
148 
149  string sID = pipe1->getStreamID(); // sort of a "default stream type"
150  PPipe pipe3 = Pipe::query ("stream("+sID+")");
151  CHECK (pipe3);
152  CHECK (pipe3->getStreamID() == StreamType::ID{sID});
153  CHECK (pipe3->getProcPatt() == Session::current->defaults (Query<const ProcPatt>{"stream("+sID+")"}));
154  }
155 
156 
157  void dependProcPatt(string pID)
158  {
159  typedef lib::P<Pipe> PPipe;
161 
162  PPipe thePipe = Pipe::query ("pipe("+pID+")");
163  CHECK (thePipe);
164  PProcPatt thePatt = thePipe->getProcPatt();
165  CHECK (thePatt);
166  CHECK (dependencyCheck (thePipe, thePatt));
167 
168  PProcPatt pattern2 = thePatt->newCopy("another");
169  CHECK (thePatt != pattern2);
170  CHECK (!dependencyCheck (thePipe, pattern2));
171  TODO ("add something to the new pattern, e.g. an effect");
172 
173  // now querying for a pipe using this pattern (created on-the-fly)
174  // note: because the pattern is new, this new pipe will be used as
175  // default pipe for this pattern automatically
176  PPipe pipe2x = Pipe::query ("pattern(another)");
177  CHECK (pattern2 == pipe2x->getProcPatt());
178  CHECK (pipe2x == Session::current->defaults (Query<Pipe>{"pattern(another)"}));
179 
180  thePipe->switchProcPatt(pattern2);
181  CHECK ( dependencyCheck (thePipe, pattern2));
182  CHECK (!dependencyCheck (thePipe, thePatt));
183 
185  CHECK ( aMang.known (thePipe->getID()));
186  CHECK ( aMang.known (thePatt->getID()));
187  CHECK ( aMang.known (pattern2->getID()));
188  aMang.remove (pattern2->getID());
189  CHECK ( aMang.known (thePatt->getID()));
190  CHECK (!aMang.known (pattern2->getID()));
191  CHECK (!aMang.known (thePipe->getID())); // has been unlinked too, because dependent on pattern2
192 
193  CHECK (thePipe);
194  PProcPatt pattern3 = thePipe->getProcPatt();
195  CHECK (thePipe->getProcPatt());
196  CHECK ( pattern3 == pattern2); // but is still valid, as long as the ref is alive....
197 
198  PPipe pipe3x = Pipe::query ("pattern(another)");
199  pattern3 = pipe3x->getProcPatt();
200  CHECK (pattern3 != pattern2); // because pattern2 is already unlinked...
201  CHECK (pipe3x == Session::current->defaults (Query<Pipe>{"pattern(another)"}));
202  CHECK (pipe3x != pipe2x); // ..we got a new default pipe for "pattern(another)" too!
203 
204 
205  TRACE (asset_mem, "leaving BasicPipe_test::dependProcPatt()");
206  // expect now pipe2x and pattern2 to be destroyed...
207  }
208  };
209 
210 
212  LAUNCHER (BasicPipe_test, "unit asset");
213 
214 
215 
216 }}} // namespace proc::asset::test
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:164
Utilities to support working with predicate queries.
Proc-Layer Interface: Asset Lookup and Organisation.
A "processing pipe" represented as Asset.
Facade for the Asset subsystem.
Basic and generic representation of an internal query.
lib::P< const asset::ProcPatt > PProcPatt
Definition: run.hpp:49
The asset subsystem of the Proc-Layer.
Definition: id-scheme.hpp:64
static session::SessManager & current
access point to the current Session
Definition: session.hpp:127
lib::P< Pipe > PPipe
Definition: pipe.hpp:51
This header is for including and configuring NoBug.
asset::Category category
primary tree like classification of the asset.
Definition: asset.hpp:169
virtual const ID< Struct > & getID() const
<
Definition: struct.hpp:119
lib::P< Pipe > newPipe(string pipeID, string streamID)
Factory method for creating Pipes explicitly.
Definition: struct.cpp:167
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:158
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.
static StructFactory retrieve
storage for the static StructFactory instance
Definition: struct.hpp:116
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition: util.hpp:205
std::vector< string > & Arg
Definition: run.hpp:54
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.
Tree like classification of Assets.
Definition: category.hpp:75
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
void createExplicit(string pID, string sID)
DefaultsAccess defaults
manages default configured objects
Definition: session.hpp:129
TRACE(test, "inserted %d", data)
static PPipe query(string const &properties)
convenience shortcut for retrieving default configured pipes
Definition: pipe.cpp:66
lib::P< ProcPatt > newCopy(string newID) const
create a new ProcPatt asset as a literal copy of this one.
Definition: procpatt.cpp:74
Small helper and diagnostic functions related to Asset and AssetManager.
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
LAUNCHER(AssetCategory_test, "unit asset")
Register this test class...
bool dependencyCheck(lib::P< CHI > child, lib::P< PAR > parent)
Definition of Asset categorisation.
const string org
origin or authorship id.
Definition: asset.hpp:176
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:279