Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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"
22
24#include "steam/asset/media.hpp"
25#include "steam/asset/proc.hpp"
28
32#include "lib/depend-inject.hpp"
33#include "lib/util.hpp"
34
35using util::isnil;
36using std::string;
39
40
41namespace steam {
42namespace asset{
43namespace test {
44
45 using LERR_(UNKNOWN_ASSET_ID);
46 using LERR_(WRONG_ASSET_KIND);
47
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
67
68 if (!isnil (arg))
70 TRACE (asset_mem, "leaving CreateAsset_test::run()");
71 }
72
73
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 and filename == object->getFilename();
203 }
204
205
206 void
208 {
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
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
Small helper and diagnostic functions related to Asset and AssetManager.
Steam-Layer Interface: Asset Lookup and Organisation.
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition p.hpp:77
Framerate specified as frames per second.
Facade for the Asset subsystem.
lib::P< KIND > getAsset(const ID< KIND > &id)
find and return corresponding object
static lib::Depend< AssetManager > instance
get at the system-wide asset manager instance.
Tree like classification of Assets.
Definition category.hpp:68
thin wrapper around a size_t hash ID used as primary key for all Asset objects.
Definition asset.hpp:98
static MediaFactory create
storage for the static MediaFactory instance
Definition media.hpp:75
static MetaFactory create
storage for the static MetaFactory instance
static PLog global()
retrieve (possibly create) the global singleton asset corresponding to "the" global error log,...
Definition error-log.cpp:58
bool checkProperties(PM object, Asset::Ident identity, string filename)
Per type specific configuration of instances created as service dependencies.
An entity to collect, possibly filter and persist incident records.
#define LERR_(_NAME_)
Definition error.hpp:45
This header is for including and configuring NoBug.
Unit test helper to access an emulated media file.
Media data represented a specific kind of Asset.
string randStr(size_t len)
create garbage string of given length
lib::idi::EntryID< ErrorLog > theErrorLog_ID
storage for an unique, globally known ID.
Definition error-log.cpp:48
lib::DependInject< vault::MediaAccessFacade > ::Local< vault::test::MediaAccessMock > MediaAccessMock
The asset subsystem of the Steam-Layer.
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool isnil(lib::time::Duration const &dur)
Data processing Plugins and Codecs can be treated as a specific Kind of Asset.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
typed symbolic and hash ID for asset-like position accounting.
Definition entry-id.hpp:219
a POD comprised of all the information sufficiently identifying any given Asset.
Definition asset.hpp:147
string name
element ID, comprehensible but sanitised.
Definition asset.hpp:151
A collection of frequently used helper functions to support unit testing.
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
To establish a reference scale for quantised time values.
a family of time value like entities and their relationships.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...