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) 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 "steam/assetmanager.hpp"
33 #include "steam/asset/media.hpp"
34 #include "steam/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 steam {
51 namespace asset{
52 namespace test {
53 
54  using LERR_(UNKNOWN_ASSET_ID);
55  using LERR_(WRONG_ASSET_KIND);
56 
57  using MediaAccessMock = lib::DependInject<vault::MediaAccessFacade>
58  ::Local<vault::test::MediaAccessMock>;
59 
60 
61 
62 
63  /*******************************************************************/
67  class CreateAsset_test : public Test
68  {
69  virtual void run(Arg arg)
70  {
71  MediaAccessMock useMockMedia;
72 
73  createMedia();
75  createMetaAssets();
76 
77  if (!isnil (arg))
78  dumpAssetManager();
79  TRACE (asset_mem, "leaving CreateAsset_test::run()");
80  }
81 
82 
84  using PM = lib::P<Media>;
85 
92  void
94  {
95  Category cat(VIDEO,"bin1");
96  Asset::Ident key("test-1", cat, "ichthyo", 5);
97  PM mm1 = asset::Media::create(key,"testfile.mov");
98  PM mm2 = asset::Media::create("test-1.mov", cat);
99  PM mm3 = asset::Media::create("test-2.mov", VIDEO);
100 
101  // Assets have been registered and can be retrieved by ID
103  PM registered;
104  registered = aMang.getAsset (mm1->getID());
105  CHECK (registered == mm1);
106  registered = aMang.getAsset (mm2->getID());
107  CHECK (registered == mm2);
108  registered = aMang.getAsset (mm3->getID());
109  CHECK (registered == mm3);
110 
111  registered = aMang.getAsset (mm1->getID());
112  CHECK (registered != mm2);
113 /*
114 * TODO: switch back to original version
115 * once the transition to P<XX> is done...
116 *
117  CHECK (aMang.getAsset (mm1->getID()) == mm1);
118  CHECK (aMang.getAsset (mm2->getID()) == mm2);
119  CHECK (aMang.getAsset (mm3->getID()) == mm3);
120 
121  CHECK (aMang.getAsset (mm1->getID()) != mm2);
122 */
123  PAsset aa1 = aMang.getAsset (ID<Asset>(mm1->getID())); // note we get an Asset ref
124  CHECK (aa1 == mm1);
125  PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref
126  CHECK (mX1 == mm1);
127  CHECK (mX1 == aa1);
128 
129  CHECK (aMang.known (mm1->getID()));
130  CHECK (aMang.known (mm2->getID()));
131  CHECK (aMang.known (mm3->getID()));
132 
133  CHECK ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category
134 
135  // can't be found if specifying wrong Asset kind....
136  VERIFY_ERROR (WRONG_ASSET_KIND, aMang.getAsset (ID<asset::Proc>(mm1->getID())) );
137 
138  // try accessing nonexistent ID
139  VERIFY_ERROR (UNKNOWN_ASSET_ID, aMang.getAsset (ID<Asset> (1234567890)) );
140 
141 
142  // checking the Ident-Fields
143  CHECK (mm1->ident.name == "test-1");
144  CHECK (mm2->ident.name == "test-1");
145  CHECK (mm3->ident.name == "test-2");
146 
147  CHECK (cat == Category (VIDEO,"bin1"));
148  CHECK (mm1->ident.category == Category (VIDEO,"bin1"));
149  CHECK (mm2->ident.category == Category (VIDEO,"bin1"));
150  CHECK (mm3->ident.category == Category (VIDEO ));
151 
152  CHECK (mm1->ident.org == "ichthyo");
153  CHECK (mm2->ident.org == "lumi");
154  CHECK (mm3->ident.org == "lumi");
155 
156  CHECK (mm1->ident.version == 5);
157  CHECK (mm2->ident.version == 1);
158  CHECK (mm3->ident.version == 1);
159 
160  CHECK (mm1->getFilename() == "testfile.mov");
161  CHECK (mm2->getFilename() == "test-1.mov");
162  CHECK (mm3->getFilename() == "test-2.mov");
163 
164 
165  TRACE (asset_mem, "leaving test method scope");
166  }
167 
168 
174  void
176  {
177  PM candi;
178 
179  Asset::Ident key1("test-1", Category(AUDIO), "ichthyo", 5);
180  candi = asset::Media::create(key1);
181  CHECK ( checkProperties (candi, key1, ""));
182 
183  candi = asset::Media::create(key1, string("test-1.wav"));
184  CHECK ( checkProperties (candi, key1, "test-1.wav"));
185 
186  Asset::Ident key2("", Category(AUDIO), "ichthyo", 5);
187  candi = asset::Media::create(key2, string("test-2.wav"));
188  CHECK ( checkProperties (candi, key2, "test-2.wav"));
189  CHECK (key2.name == "test-2"); // name filled in automatically
190 
191  candi = asset::Media::create(string("test-3.wav"), Category(AUDIO));
192  CHECK ( checkProperties (candi, Asset::Ident("test-3", Category(AUDIO), "lumi", 1)
193  , "test-3.wav"));
194 
195  candi = asset::Media::create("some/path/test-4.wav", Category(AUDIO));
196  CHECK ( checkProperties (candi, Asset::Ident("test-4", Category(AUDIO), "lumi", 1)
197  , "some/path/test-4.wav"));
198 
199  candi = asset::Media::create("", Category(AUDIO,"sub/bin"));
200  CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO,"sub/bin"), "lumi", 1)
201  , ""));
202 
203  candi = asset::Media::create("", AUDIO);
204  CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO), "lumi", 1)
205  , ""));
206  }
207 
208  bool checkProperties (PM object, Asset::Ident identity, string filename)
209  {
210  return identity == object->ident
211  && filename == object->getFilename();
212  }
213 
214 
215  void
216  createMetaAssets()
217  {
218  using asset::meta::GridID;
219  using asset::meta::PGrid;
220 
221  GridID myGrID (randStr(8));
222  auto gridSpec = asset::Meta::create (myGrID);
223  gridSpec.fps = FrameRate{23};
224  PGrid myGrid = gridSpec.commit();
225 
226  CHECK (myGrid);
227  CHECK (myGrid->ident.name == myGrID.getSym());
228 
229  CHECK (AssetManager::instance().known (myGrid->getID()));
230  CHECK (myGrid == AssetManager::instance().getAsset (myGrid->getID()));
231 
232  // for the ErrorLog assert, as of 8/2018 there is just one single global placeholder entity available
234 
235  CHECK (globalLog->ident.name == meta::theErrorLog_ID.getSym());
236  CHECK (AssetManager::instance().known (globalLog->getID()));
237  CHECK (2 == globalLog.use_count()); // AssetManager also holds a reference
238 
239  PAsset furtherRef = asset::meta::ErrorLog::global();
240  CHECK (3 == globalLog.use_count());
241  CHECK (furtherRef == globalLog);
242  }
243  };
244 
245 
247  LAUNCHER (CreateAsset_test, "unit asset");
248 
249 
250 
251 }}} // namespace steam::asset::test
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:164
Steam-Layer Interface: Asset Lookup and Organisation.
Media data represented a specific kind of Asset.
Tree like classification of Assets.
Definition: category.hpp:75
Definition: run.hpp:49
Framerate specified as frames per second.
Definition: timevalue.hpp:664
Per type specific configuration of instances created as service dependencies.
typed symbolic and hash ID for asset-like position accounting.
Definition: entry-id.hpp:135
#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:84
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:69
An entity to collect, possibly filter and persist incident records.
static MetaFactory create
storage for the static MetaFactory instance
Definition: asset/meta.hpp:123
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:158
Simple 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:67
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:80
a family of time value like entities and their relationships.
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:44