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)
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 "include/logging.h"
20 #include "lib/test/run.hpp"
21 #include "lib/util.hpp"
22 
23 #include "steam/asset/category.hpp"
24 #include "steam/asset/pipe.hpp"
25 #include "steam/assetmanager.hpp"
28 #include "lib/query-util.hpp"
29 #include "common/query.hpp"
30 
31 
32 using util::contains;
33 using util::isnil;
34 using std::string;
35 
36 
37 namespace steam {
38 namespace asset {
39 namespace test {
40 
41  using mobject::Session;
42  using lumiera::Query;
44 
45 
46 
47  /*******************************************************************/
56  class BasicPipe_test : public Test
57  {
58  virtual void
59  run (Arg arg)
60  {
61  string pipeID = isnil (arg)? "Black Hole" : arg[1];
62  string streamID = 2>arg.size()? "teststream" : arg[2] ;
63 
64  createExplicit (pipeID,streamID);
65  create_or_ref (pipeID);
66  create_using_default ();
67  dependProcPatt (pipeID);
68  }
69 
70 
71 
72 
73  void createExplicit (string pID, string sID)
74  {
75  string pID_sane{pID};
76  normaliseID (pID_sane);
77  CHECK (pID_sane != pID);
78 
79  PPipe thePipe = asset::Struct::retrieve.newPipe (pID,sID);
80 
81  CHECK (thePipe);
82  CHECK (thePipe->getProcPatt());
83  CHECK (thePipe->getPipeID() == pID_sane);
84  CHECK (thePipe->getStreamID() == StreamType::ID{sID});
85  CHECK (thePipe->shortDesc == pID_sane);
86 
87  Asset::Ident idi = thePipe->ident;
88  CHECK (idi.org == "lumi");
89  CHECK (contains (idi.name, thePipe->getPipeID()));
90  CHECK (contains (idi.name, string{thePipe->getStreamID()}));
91 
92  Category cat{idi.category};
93  Category refcat{STRUCT,"pipes"};
94  CHECK ( cat.hasKind (STRUCT) );
95  CHECK ( cat.isWithin(refcat) );
96  }
97 
98 
99  void create_or_ref(string pID)
100  {
101  normaliseID (pID);
102 
103  PPipe pipe1 = Pipe::query ("pipe("+pID+")");
104  CHECK (pipe1);
105  CHECK (pipe1->getPipeID() == pID);
106 
107  string pID2 = "another-" + pID;
108  PPipe pipe2 = Pipe::query ("pipe("+pID2+")");
109  CHECK (pipe2);
110  CHECK (pipe2 != pipe1);
111  Category c1 = pipe1->ident.category;
112  Category c2 = pipe2->ident.category;
113  CHECK (c1 == c2);
114 
115  PPipe pipe3 = Pipe::query ("pipe("+pID2+")");
117  CHECK (pipe3 == pipe2);
118  }
119 
120 
121  void create_using_default()
122  {
123  PPipe pipe1 = Pipe::query (""); // "the default pipe"
124  PPipe pipe2;
125  CHECK (pipe1);
126  CHECK (pipe1 == Session::current->defaults (Query<Pipe>{}));
127  CHECK (pipe1->ident.category.hasKind(VIDEO));
128  CHECK (pipe1->getProcPatt());
129  PProcPatt propa = Session::current->defaults (Query<const ProcPatt>{"pipe(default)"});
130  CHECK (propa == pipe1->getProcPatt());
131 
132  // several variants to query for "the default pipe"
134  CHECK (pipe2 == pipe1);
136  CHECK (pipe2 == pipe1);
137  pipe2 = asset::Struct::retrieve (Query<Pipe>{"pipe(default)"});
138  CHECK (pipe2 == pipe1);
139 
140  auto sID = string{pipe1->getStreamID()}; // sort of a "default stream type"
141  PPipe pipe3 = Pipe::query ("stream("+sID+")");
142  CHECK (pipe3);
143  CHECK (pipe3->getStreamID() == StreamType::ID{sID});
144  CHECK (pipe3->getProcPatt() == Session::current->defaults (Query<const ProcPatt>{"stream("+sID+")"}));
145  }
146 
147 
148  void dependProcPatt(string pID)
149  {
150  typedef lib::P<Pipe> PPipe;
152 
153  PPipe thePipe = Pipe::query ("pipe("+pID+")");
154  CHECK (thePipe);
155  PProcPatt thePatt = thePipe->getProcPatt();
156  CHECK (thePatt);
157  CHECK (dependencyCheck (thePipe, thePatt));
158 
159  PProcPatt pattern2 = thePatt->newCopy("another");
160  CHECK (thePatt != pattern2);
161  CHECK (!dependencyCheck (thePipe, pattern2));
162  TODO ("add something to the new pattern, e.g. an effect");
163 
164  // now querying for a pipe using this pattern (created on-the-fly)
165  // note: because the pattern is new, this new pipe will be used as
166  // default pipe for this pattern automatically
167  PPipe pipe2x = Pipe::query ("pattern(another)");
168  CHECK (pattern2 == pipe2x->getProcPatt());
169  CHECK (pipe2x == Session::current->defaults (Query<Pipe>{"pattern(another)"}));
170 
171  thePipe->switchProcPatt(pattern2);
172  CHECK ( dependencyCheck (thePipe, pattern2));
173  CHECK (!dependencyCheck (thePipe, thePatt));
174 
176  CHECK ( aMang.known (thePipe->getID()));
177  CHECK ( aMang.known (thePatt->getID()));
178  CHECK ( aMang.known (pattern2->getID()));
179  aMang.remove (pattern2->getID());
180  CHECK ( aMang.known (thePatt->getID()));
181  CHECK (!aMang.known (pattern2->getID()));
182  CHECK (!aMang.known (thePipe->getID())); // has been unlinked too, because dependent on pattern2
183 
184  CHECK (thePipe);
185  PProcPatt pattern3 = thePipe->getProcPatt();
186  CHECK (thePipe->getProcPatt());
187  CHECK ( pattern3 == pattern2); // but is still valid, as long as the ref is alive....
188 
189  PPipe pipe3x = Pipe::query ("pattern(another)");
190  pattern3 = pipe3x->getProcPatt();
191  CHECK (pattern3 != pattern2); // because pattern2 is already unlinked...
192  CHECK (pipe3x == Session::current->defaults (Query<Pipe>{"pattern(another)"}));
193  CHECK (pipe3x != pipe2x); // ..we got a new default pipe for "pattern(another)" too!
194 
195 
196  TRACE (asset_mem, "leaving BasicPipe_test::dependProcPatt()");
197  // expect now pipe2x and pattern2 to be destroyed...
198  }
199  };
200 
201 
203  LAUNCHER (BasicPipe_test, "unit asset");
204 
205 
206 
207 }}} // namespace steam::asset::test
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:155
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:66
void normaliseID(string &id)
ensure standard format for a given id string.
Definition: query-util.cpp:52
Definition: run.hpp:40
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:120
Steam-Layer implementation namespace root.
DefaultsAccess defaults
manages default configured objects
Definition: session.hpp:122
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
virtual const ID< Struct > & getID() const
<
Definition: struct.hpp:110
static StructFactory retrieve
storage for the static StructFactory instance
Definition: struct.hpp:107
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:149
Simplistic 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:57
lib::P< Pipe > newPipe(string pipeID, string streamID)
Factory method for creating Pipes explicitly.
Definition: struct.cpp:158
const string org
origin or authorship id.
Definition: asset.hpp:167
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:71
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:65
asset::Category category
primary tree like classification of the asset.
Definition: asset.hpp:160
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:35
Definition of Asset categorisation.
Generic interface to express a query for specifically typed result elements exposing some capabilitie...
Definition: query.hpp:270
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
Definition: util.hpp:255