Lumiera  0.pre.03
»edit your freedom«
create-asset-test.cpp
Go to the documentation of this file.
1 /*
2  CreateAsset(Test) - constructing and registering 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/test/test-helper.hpp"
22 
23 #include "steam/assetmanager.hpp"
24 #include "steam/asset/media.hpp"
25 #include "steam/asset/proc.hpp"
28 
31 #include "lib/time/timevalue.hpp"
32 #include "lib/depend-inject.hpp"
33 #include "lib/util.hpp"
34 
35 using util::isnil;
36 using std::string;
38 using lib::test::randStr;
39 
40 
41 namespace steam {
42 namespace asset{
43 namespace test {
44 
45  using LERR_(UNKNOWN_ASSET_ID);
46  using LERR_(WRONG_ASSET_KIND);
47 
48  using MediaAccessMock = lib::DependInject<vault::MediaAccessFacade>
49  ::Local<vault::test::MediaAccessMock>;
50 
51 
52 
53 
54  /*******************************************************************/
58  class CreateAsset_test : public Test
59  {
60  virtual void run(Arg arg)
61  {
62  MediaAccessMock useMockMedia;
63 
64  createMedia();
66  createMetaAssets();
67 
68  if (!isnil (arg))
69  dumpAssetManager();
70  TRACE (asset_mem, "leaving CreateAsset_test::run()");
71  }
72 
73 
75  using PM = lib::P<Media>;
76 
83  void
85  {
86  Category cat(VIDEO,"bin1");
87  Asset::Ident key("test-1", cat, "ichthyo", 5);
88  PM mm1 = asset::Media::create(key,"testfile.mov");
89  PM mm2 = asset::Media::create("test-1.mov", cat);
90  PM mm3 = asset::Media::create("test-2.mov", VIDEO);
91 
92  // Assets have been registered and can be retrieved by ID
94  PM registered;
95  registered = aMang.getAsset (mm1->getID());
96  CHECK (registered == mm1);
97  registered = aMang.getAsset (mm2->getID());
98  CHECK (registered == mm2);
99  registered = aMang.getAsset (mm3->getID());
100  CHECK (registered == mm3);
101 
102  registered = aMang.getAsset (mm1->getID());
103  CHECK (registered != mm2);
104 /*
105 * TODO: switch back to original version
106 * once the transition to P<XX> is done...
107 *
108  CHECK (aMang.getAsset (mm1->getID()) == mm1);
109  CHECK (aMang.getAsset (mm2->getID()) == mm2);
110  CHECK (aMang.getAsset (mm3->getID()) == mm3);
111 
112  CHECK (aMang.getAsset (mm1->getID()) != mm2);
113 */
114  PAsset aa1 = aMang.getAsset (ID<Asset>(mm1->getID())); // note we get an Asset ref
115  CHECK (aa1 == mm1);
116  PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref
117  CHECK (mX1 == mm1);
118  CHECK (mX1 == aa1);
119 
120  CHECK (aMang.known (mm1->getID()));
121  CHECK (aMang.known (mm2->getID()));
122  CHECK (aMang.known (mm3->getID()));
123 
124  CHECK ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category
125 
126  // can't be found if specifying wrong Asset kind....
127  VERIFY_ERROR (WRONG_ASSET_KIND, aMang.getAsset (ID<asset::Proc>(mm1->getID())) );
128 
129  // try accessing nonexistent ID
130  VERIFY_ERROR (UNKNOWN_ASSET_ID, aMang.getAsset (ID<Asset> (1234567890)) );
131 
132 
133  // checking the Ident-Fields
134  CHECK (mm1->ident.name == "test-1");
135  CHECK (mm2->ident.name == "test-1");
136  CHECK (mm3->ident.name == "test-2");
137 
138  CHECK (cat == Category (VIDEO,"bin1"));
139  CHECK (mm1->ident.category == Category (VIDEO,"bin1"));
140  CHECK (mm2->ident.category == Category (VIDEO,"bin1"));
141  CHECK (mm3->ident.category == Category (VIDEO ));
142 
143  CHECK (mm1->ident.org == "ichthyo");
144  CHECK (mm2->ident.org == "lumi");
145  CHECK (mm3->ident.org == "lumi");
146 
147  CHECK (mm1->ident.version == 5);
148  CHECK (mm2->ident.version == 1);
149  CHECK (mm3->ident.version == 1);
150 
151  CHECK (mm1->getFilename() == "testfile.mov");
152  CHECK (mm2->getFilename() == "test-1.mov");
153  CHECK (mm3->getFilename() == "test-2.mov");
154 
155 
156  TRACE (asset_mem, "leaving test method scope");
157  }
158 
159 
165  void
167  {
168  PM candi;
169 
170  Asset::Ident key1("test-1", Category(AUDIO), "ichthyo", 5);
171  candi = asset::Media::create(key1);
172  CHECK ( checkProperties (candi, key1, ""));
173 
174  candi = asset::Media::create(key1, string("test-1.wav"));
175  CHECK ( checkProperties (candi, key1, "test-1.wav"));
176 
177  Asset::Ident key2("", Category(AUDIO), "ichthyo", 5);
178  candi = asset::Media::create(key2, string("test-2.wav"));
179  CHECK ( checkProperties (candi, key2, "test-2.wav"));
180  CHECK (key2.name == "test-2"); // name filled in automatically
181 
182  candi = asset::Media::create(string("test-3.wav"), Category(AUDIO));
183  CHECK ( checkProperties (candi, Asset::Ident("test-3", Category(AUDIO), "lumi", 1)
184  , "test-3.wav"));
185 
186  candi = asset::Media::create("some/path/test-4.wav", Category(AUDIO));
187  CHECK ( checkProperties (candi, Asset::Ident("test-4", Category(AUDIO), "lumi", 1)
188  , "some/path/test-4.wav"));
189 
190  candi = asset::Media::create("", Category(AUDIO,"sub/bin"));
191  CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO,"sub/bin"), "lumi", 1)
192  , ""));
193 
194  candi = asset::Media::create("", AUDIO);
195  CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO), "lumi", 1)
196  , ""));
197  }
198 
199  bool checkProperties (PM object, Asset::Ident identity, string filename)
200  {
201  return identity == object->ident
202  && filename == object->getFilename();
203  }
204 
205 
206  void
207  createMetaAssets()
208  {
209  using asset::meta::GridID;
210  using asset::meta::PGrid;
211 
212  GridID myGrID (randStr(8));
213  auto gridSpec = asset::Meta::create (myGrID);
214  gridSpec.fps = FrameRate{23};
215  PGrid myGrid = gridSpec.commit();
216 
217  CHECK (myGrid);
218  CHECK (myGrid->ident.name == myGrID.getSym());
219 
220  CHECK (AssetManager::instance().known (myGrid->getID()));
221  CHECK (myGrid == AssetManager::instance().getAsset (myGrid->getID()));
222 
223  // for the ErrorLog assert, as of 8/2018 there is just one single global placeholder entity available
225 
226  CHECK (globalLog->ident.name == meta::theErrorLog_ID.getSym());
227  CHECK (AssetManager::instance().known (globalLog->getID()));
228  CHECK (2 == globalLog.use_count()); // AssetManager also holds a reference
229 
230  PAsset furtherRef = asset::meta::ErrorLog::global();
231  CHECK (3 == globalLog.use_count());
232  CHECK (furtherRef == globalLog);
233  }
234  };
235 
236 
238  LAUNCHER (CreateAsset_test, "unit asset");
239 
240 
241 
242 }}} // namespace steam::asset::test
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:155
Steam-Layer Interface: Asset Lookup and Organisation.
Media data represented a specific kind of Asset.
Tree like classification of Assets.
Definition: category.hpp:66
Definition: run.hpp:40
Framerate specified as frames per second.
Definition: timevalue.hpp:655
Per type specific configuration of instances created as service dependencies.
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:126
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Unit test helper to access an emulated media file.
Facade for the Asset subsystem.
This header is for including and configuring NoBug.
static MediaFactory create
storage for the static MediaFactory instance
Definition: media.hpp:75
Steam-Layer implementation namespace root.
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
string randStr(size_t len)
create garbage string of given length
Definition: test-helper.cpp:61
An entity to collect, possibly filter and persist incident records.
static MetaFactory create
storage for the static MetaFactory instance
Definition: asset/meta.hpp:114
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
Data processing Plugins and Codecs can be treated as a specific Kind of Asset.
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...
A collection of frequently used helper functions to support unit testing.
static PLog global()
retrieve (possibly create) the global singleton asset corresponding to "the" global error log...
Definition: error-log.cpp:58
lib::P< KIND > getAsset(const ID< KIND > &id)
find and return corresponding object
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:71
a family of time value like entities and their relationships.
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:35