Lumiera  0.pre.03
»edit your freedom«
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 "steam/asset/category.hpp"
33 #include "steam/asset/pipe.hpp"
34 #include "steam/assetmanager.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 steam {
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);
75  create_using_default ();
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, string{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 
130  void create_using_default()
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  auto sID = string{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 steam::asset::test
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:164
Utilities to support working with predicate queries.
Steam-Layer Interface: Asset Lookup and Organisation.
A "processing pipe" represented as Asset.
Basic and generic representation of an internal query.
Tree like classification of Assets.
Definition: category.hpp:75
void normaliseID(string &id)
ensure standard format for a given id string.
Definition: query-util.cpp:61
Definition: run.hpp:49
void remove(IDA id)
remove the given asset from the internal DB.
Facade for the Asset subsystem.
This header is for including and configuring NoBug.
static session::SessManager & current
access point to the current Session
Definition: session.hpp:129
Steam-Layer implementation namespace root.
DefaultsAccess defaults
manages default configured objects
Definition: session.hpp:131
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
virtual const ID< Struct > & getID() const
<
Definition: struct.hpp:119
static StructFactory retrieve
storage for the static StructFactory instance
Definition: struct.hpp:116
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:158
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
static PPipe query(string const &properties)
convenience shortcut for retrieving default configured pipes
Definition: pipe.cpp:66
lib::P< Pipe > newPipe(string pipeID, string streamID)
Factory method for creating Pipes explicitly.
Definition: struct.cpp:167
const string org
origin or authorship id.
Definition: asset.hpp:176
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:80
Primary Interface to the current Session.
lib::P< ProcPatt > newCopy(string newID) const
create a new ProcPatt asset as a literal copy of this one.
Definition: procpatt.cpp:74
asset::Category category
primary tree like classification of the asset.
Definition: asset.hpp:169
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:44
Definition of Asset categorisation.
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:279
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
Definition: util.hpp:255