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 run(Arg arg)
68  {
69  string pipeID = isnil(arg)? "Black Hole" : arg[1];
70  string streamID = 2>arg.size()? "teststream" : arg[2] ;
71 
72  createExplicit (pipeID,streamID);
73  create_or_ref (pipeID);
75  dependProcPatt (pipeID);
76  }
77 
78 
79 
80 
81  void createExplicit (string pID, string sID)
82  {
83  string pID_sane (pID);
84  normaliseID (pID_sane);
85  CHECK (pID_sane != pID);
86 
87  PPipe thePipe = asset::Struct::retrieve.newPipe (pID,sID);
88 
89  CHECK (thePipe);
90  CHECK (thePipe->getProcPatt());
91  CHECK (thePipe->getPipeID() == pID_sane);
92  CHECK (thePipe->getStreamID() == StreamType::ID(sID));
93  CHECK (thePipe->shortDesc == pID_sane);
94 
95  Asset::Ident idi = thePipe->ident;
96  CHECK (idi.org == "lumi");
97  CHECK (contains (idi.name, thePipe->getPipeID()));
98  CHECK (contains (idi.name, thePipe->getStreamID()));
99 
100  Category cat (idi.category);
101  Category refcat (STRUCT,"pipes");
102  CHECK ( cat.hasKind(STRUCT) );
103  CHECK ( cat.isWithin(refcat) );
104  }
105 
106 
107  void create_or_ref(string pID)
108  {
109  normaliseID (pID);
110 
111  PPipe pipe1 = Pipe::query ("pipe("+pID+")");
112  CHECK (pipe1);
113  CHECK (pipe1->getPipeID() == pID);
114 
115  string pID2 = "another-" + pID;
116  PPipe pipe2 = Pipe::query ("pipe("+pID2+")");
117  CHECK (pipe2);
118  CHECK (pipe2 != pipe1);
119  Category c1 = pipe1->ident.category;
120  Category c2 = pipe2->ident.category;
121  CHECK (c1 == c2);
122 
123  PPipe pipe3 = Pipe::query ("pipe("+pID2+")");
125  CHECK (pipe3 == pipe2);
126  }
127 
128 
130  {
131  PPipe pipe1 = Pipe::query (""); // "the default pipe"
132  PPipe pipe2;
133  CHECK (pipe1);
134  CHECK (pipe1 == Session::current->defaults (Query<Pipe>()));
135  CHECK (pipe1->ident.category.hasKind(VIDEO));
136  CHECK (pipe1->getProcPatt());
137  PProcPatt propa = Session::current->defaults (Query<const ProcPatt>("pipe(default)"));
138  CHECK (propa == pipe1->getProcPatt());
139 
140  // several variants to query for "the default pipe"
142  CHECK (pipe2 == pipe1);
144  CHECK (pipe2 == pipe1);
145  pipe2 = asset::Struct::retrieve (Query<Pipe> ("pipe(default)"));
146  CHECK (pipe2 == pipe1);
147 
148  string sID = pipe1->getStreamID(); // sort of a "default stream type"
149  PPipe pipe3 = Pipe::query ("stream("+sID+")");
150  CHECK (pipe3);
151  CHECK (pipe3->getStreamID() == StreamType::ID(sID));
152  CHECK (pipe3->getProcPatt() == Session::current->defaults (Query<const ProcPatt>("stream("+sID+")")));
153  }
154 
155 
156  void dependProcPatt(string pID)
157  {
158  typedef lib::P<Pipe> PPipe;
160 
161  PPipe thePipe = Pipe::query ("pipe("+pID+")");
162  CHECK (thePipe);
163  PProcPatt thePatt = thePipe->getProcPatt();
164  CHECK (thePatt);
165  CHECK (dependencyCheck (thePipe, thePatt));
166 
167  PProcPatt pattern2 = thePatt->newCopy("another");
168  CHECK (thePatt != pattern2);
169  CHECK (!dependencyCheck (thePipe, pattern2));
170  TODO ("add something to the new pattern, e.g. an effect");
171 
172  // now querying for a pipe using this pattern (created on-the-fly)
173  // note: because the pattern is new, this new pipe will be used as
174  // default pipe for this pattern automatically
175  PPipe pipe2x = Pipe::query ("pattern(another)");
176  CHECK (pattern2 == pipe2x->getProcPatt());
177  CHECK (pipe2x == Session::current->defaults (Query<Pipe>("pattern(another)")));
178 
179  thePipe->switchProcPatt(pattern2);
180  CHECK ( dependencyCheck (thePipe, pattern2));
181  CHECK (!dependencyCheck (thePipe, thePatt));
182 
184  CHECK ( aMang.known (thePipe->getID()));
185  CHECK ( aMang.known (thePatt->getID()));
186  CHECK ( aMang.known (pattern2->getID()));
187  aMang.remove (pattern2->getID());
188  CHECK ( aMang.known (thePatt->getID()));
189  CHECK (!aMang.known (pattern2->getID()));
190  CHECK (!aMang.known (thePipe->getID())); // has been unlinked too, because dependent on pattern2
191 
192  CHECK (thePipe);
193  PProcPatt pattern3 = thePipe->getProcPatt();
194  CHECK (thePipe->getProcPatt());
195  CHECK ( pattern3 == pattern2); // but is still valid, as long as the ref is alive....
196 
197  PPipe pipe3x = Pipe::query ("pattern(another)");
198  pattern3 = pipe3x->getProcPatt();
199  CHECK (pattern3 != pattern2); // because pattern2 is already unlinked...
200  CHECK (pipe3x == Session::current->defaults (Query<Pipe>("pattern(another)")));
201  CHECK (pipe3x != pipe2x); // ..we got a new default pipe for "pattern(another)" too!
202 
203 
204  TRACE (asset_mem, "leaving BasicPipe_test::dependProcPatt()");
205  // expect now pipe2x and pattern2 to be destroyed...
206  }
207  };
208 
209 
211  LAUNCHER (BasicPipe_test, "unit asset");
212 
213 
214 
215 }}} // 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
bool hasKind(Kind refKind) const
Definition: category.hpp:88
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
bool isWithin(Category const &) const
hierarchical inclusion test.
Definition: category.cpp:69
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
lib::idi::EntryID< StreamType > ID
Definition: streamtype.hpp:76