Lumiera  0.pre.03
»edityourfreedom«
create-asset-test.cpp
Go to the documentation of this file.
1 /*
2  CreateAsset(Test) - constructing and registering 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/test/test-helper.hpp"
31 
32 #include "proc/assetmanager.hpp"
33 #include "proc/asset/media.hpp"
34 #include "proc/asset/proc.hpp"
37 
40 #include "lib/time/timevalue.hpp"
41 #include "lib/depend-inject.hpp"
42 #include "lib/util.hpp"
43 
44 using util::isnil;
45 using std::string;
47 using lib::test::randStr;
48 
49 
50 namespace proc {
51 namespace asset{
52 namespace test {
53 
55  ::Local<backend::test::MediaAccessMock>;
56 
57 
58 
59 
60  /*******************************************************************/
64  class CreateAsset_test : public Test
65  {
66  virtual void run(Arg arg)
67  {
68  MediaAccessMock useMockMedia;
69 
70  createMedia();
73 
74  if (!isnil (arg))
76  TRACE (asset_mem, "leaving CreateAsset_test::run()");
77  }
78 
79 
81  using PM = lib::P<Media>;
82 
89  void
91  {
92  Category cat(VIDEO,"bin1");
93  Asset::Ident key("test-1", cat, "ichthyo", 5);
94  PM mm1 = asset::Media::create(key,"testfile.mov");
95  PM mm2 = asset::Media::create("test-1.mov", cat);
96  PM mm3 = asset::Media::create("test-2.mov", VIDEO);
97 
98  // Assets have been registered and can be retrieved by ID
100  PM registered;
101  registered = aMang.getAsset (mm1->getID());
102  CHECK (registered == mm1);
103  registered = aMang.getAsset (mm2->getID());
104  CHECK (registered == mm2);
105  registered = aMang.getAsset (mm3->getID());
106  CHECK (registered == mm3);
107 
108  registered = aMang.getAsset (mm1->getID());
109  CHECK (registered != mm2);
110 /*
111 * TODO: switch back to original version
112 * once the transition to P<XX> is done...
113 *
114  CHECK (aMang.getAsset (mm1->getID()) == mm1);
115  CHECK (aMang.getAsset (mm2->getID()) == mm2);
116  CHECK (aMang.getAsset (mm3->getID()) == mm3);
117 
118  CHECK (aMang.getAsset (mm1->getID()) != mm2);
119 */
120  PAsset aa1 = aMang.getAsset (ID<Asset>(mm1->getID())); // note we get an Asset ref
121  CHECK (aa1 == mm1);
122  PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref
123  CHECK (mX1 == mm1);
124  CHECK (mX1 == aa1);
125 
126  CHECK (aMang.known (mm1->getID()));
127  CHECK (aMang.known (mm2->getID()));
128  CHECK (aMang.known (mm3->getID()));
129 
130  CHECK ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category
131  try
132  { // can't be found if specifying wrong Asset kind....
133  aMang.getAsset (ID<asset::Proc>(mm1->getID()));
134  NOTREACHED();
135  }
136  catch (lumiera::error::Invalid& xxx) {CHECK (xxx.getID()==LUMIERA_ERROR_WRONG_ASSET_KIND);}
137  try
138  { // try accessing nonexistent ID
139  aMang.getAsset (ID<Asset> (1234567890));
140  NOTREACHED();
141  }
142  catch (lumiera::error::Invalid& xxx) {CHECK (xxx.getID()==LUMIERA_ERROR_UNKNOWN_ASSET_ID);}
143  lumiera_error (); // reset errorflag
144 
145 
146  // checking the Ident-Fields
147  CHECK (mm1->ident.name == "test-1");
148  CHECK (mm2->ident.name == "test-1");
149  CHECK (mm3->ident.name == "test-2");
150 
151  CHECK (cat == Category (VIDEO,"bin1"));
152  CHECK (mm1->ident.category == Category (VIDEO,"bin1"));
153  CHECK (mm2->ident.category == Category (VIDEO,"bin1"));
154  CHECK (mm3->ident.category == Category (VIDEO ));
155 
156  CHECK (mm1->ident.org == "ichthyo");
157  CHECK (mm2->ident.org == "lumi");
158  CHECK (mm3->ident.org == "lumi");
159 
160  CHECK (mm1->ident.version == 5);
161  CHECK (mm2->ident.version == 1);
162  CHECK (mm3->ident.version == 1);
163 
164  CHECK (mm1->getFilename() == "testfile.mov");
165  CHECK (mm2->getFilename() == "test-1.mov");
166  CHECK (mm3->getFilename() == "test-2.mov");
167 
168 
169  TRACE (asset_mem, "leaving test method scope");
170  }
171 
172 
178  void
180  {
181  PM candi;
182 
183  Asset::Ident key1("test-1", Category(AUDIO), "ichthyo", 5);
184  candi = asset::Media::create(key1);
185  CHECK ( checkProperties (candi, key1, ""));
186 
187  candi = asset::Media::create(key1, string("test-1.wav"));
188  CHECK ( checkProperties (candi, key1, "test-1.wav"));
189 
190  Asset::Ident key2("", Category(AUDIO), "ichthyo", 5);
191  candi = asset::Media::create(key2, string("test-2.wav"));
192  CHECK ( checkProperties (candi, key2, "test-2.wav"));
193  CHECK (key2.name == "test-2"); // name filled in automatically
194 
195  candi = asset::Media::create(string("test-3.wav"), Category(AUDIO));
196  CHECK ( checkProperties (candi, Asset::Ident("test-3", Category(AUDIO), "lumi", 1)
197  , "test-3.wav"));
198 
199  candi = asset::Media::create("some/path/test-4.wav", Category(AUDIO));
200  CHECK ( checkProperties (candi, Asset::Ident("test-4", Category(AUDIO), "lumi", 1)
201  , "some/path/test-4.wav"));
202 
203  candi = asset::Media::create("", Category(AUDIO,"sub/bin"));
204  CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO,"sub/bin"), "lumi", 1)
205  , ""));
206 
207  candi = asset::Media::create("", AUDIO);
208  CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO), "lumi", 1)
209  , ""));
210  }
211 
212  bool checkProperties (PM object, Asset::Ident identity, string filename)
213  {
214  return identity == object->ident
215  && filename == object->getFilename();
216  }
217 
218 
219  void
221  {
222  using asset::meta::GridID;
223  using asset::meta::PGrid;
224 
225  GridID myGrID (randStr(8));
226  auto gridSpec = asset::Meta::create (myGrID);
227  gridSpec.fps = FrameRate{23};
228  PGrid myGrid = gridSpec.commit();
229 
230  CHECK (myGrid);
231  CHECK (myGrid->ident.name == myGrID.getSym());
232 
233  CHECK (AssetManager::instance().known (myGrid->getID()));
234  CHECK (myGrid == AssetManager::instance().getAsset (myGrid->getID()));
235 
236  // for the ErrorLog assert, as of 8/2018 there is just one single global placeholder entity available
238 
239  CHECK (globalLog->ident.name == meta::theErrorLog_ID.getSym());
240  CHECK (AssetManager::instance().known (globalLog->getID()));
241  CHECK (2 == globalLog.use_count()); // AssetManager also holds a reference
242 
243  PAsset furtherRef = asset::meta::ErrorLog::global();
244  CHECK (3 == globalLog.use_count());
245  CHECK (furtherRef == globalLog);
246  }
247  };
248 
249 
251  LAUNCHER (CreateAsset_test, "unit asset");
252 
253 
254 
255 }}} // namespace proc::asset::test
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:164
Proc-Layer Interface: Asset Lookup and Organisation.
Facade for the Asset subsystem.
string randStr(size_t len)
create garbage string of given length
Definition: test-helper.cpp:61
lib::P< KIND > getAsset(const ID< KIND > &id)
find and return corresponding object
Media data represented a specific kind of Asset.
Definition: run.hpp:49
Framerate specified as frames per second.
Definition: timevalue.hpp:547
The asset subsystem of the Proc-Layer.
Definition: id-scheme.hpp:64
std::shared_ptr< const Grid > PGrid
Definition: grid.hpp:78
Per type specific configuration of instances created as service dependencies.
Unit test helper to access an emulated media file.
static MediaFactory create
storage for the static MediaFactory instance
Definition: media.hpp:84
This header is for including and configuring NoBug.
lib::DependInject< backend::MediaAccessFacade > ::Local< backend::test::MediaAccessMock > MediaAccessMock
lib::P< TimeGrid > PGrid
Definition: time-grid.hpp:72
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:158
An entity to collect, possibly filter and persist incident records.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:196
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
std::vector< string > & Arg
Definition: run.hpp:54
Data processing Plugins and Codecs can be treated as a specific Kind of Asset.
static PLog global()
retrieve (possibly create) the global singleton asset corresponding to "the" global error log...
Definition: error-log.cpp:67
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
lumiera_err lumiera_error(void)
Get and clear current error state.
Definition: error-state.c:124
static MetaFactory create
storage for the static MetaFactory instance
Definition: asset/meta.hpp:123
Tree like classification of Assets.
Definition: category.hpp:75
A collection of frequently used helper functions to support unit testing.
lib::idi::EntryID< ErrorLog > theErrorLog_ID
storage for an unique, globally known ID.
Definition: error-log.cpp:57
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
TRACE(test, "inserted %d", data)
lib::idi::EntryID< TimeGrid > GridID
Definition: time-grid.hpp:73
Small helper and diagnostic functions related to Asset and AssetManager.
To establish a reference scale for quantised time values.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:76
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
LAUNCHER(AssetCategory_test, "unit asset")
Register this test class...
a family of time value like entities and their relationships.
bool checkProperties(PM object, Asset::Ident identity, string filename)