Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/util.hpp"
31 
32 #include "proc/assetmanager.hpp"
33 #include "proc/asset/media.hpp"
34 #include "proc/asset/proc.hpp"
35 
38 #include "lib/depend-inject.hpp"
39 
40 using util::isnil;
41 using std::string;
42 
43 
44 namespace proc {
45 namespace asset{
46 namespace test {
47 
49  ::Local<backend::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 
67  if (!isnil (arg))
69  TRACE (asset_mem, "leaving CreateAsset_test::run()");
70  }
71 
72 
74  typedef lib::P<Media> PM;
75 
82  void createMedia()
83  {
84  Category cat(VIDEO,"bin1");
85  Asset::Ident key("test-1", cat, "ichthyo", 5);
86  PM mm1 = asset::Media::create(key,"testfile.mov");
87  PM mm2 = asset::Media::create("test-1.mov", cat);
88  PM mm3 = asset::Media::create("test-2.mov", VIDEO);
89 
90  // Assets have been registered and can be retrieved by ID
92  PM registered;
93  registered = aMang.getAsset (mm1->getID());
94  CHECK (registered == mm1);
95  registered = aMang.getAsset (mm2->getID());
96  CHECK (registered == mm2);
97  registered = aMang.getAsset (mm3->getID());
98  CHECK (registered == mm3);
99 
100  registered = aMang.getAsset (mm1->getID());
101  CHECK (registered != mm2);
102 /*
103 * TODO: switch back to original version
104 * once the transition to P<XX> is done...
105 *
106  CHECK (aMang.getAsset (mm1->getID()) == mm1);
107  CHECK (aMang.getAsset (mm2->getID()) == mm2);
108  CHECK (aMang.getAsset (mm3->getID()) == mm3);
109 
110  CHECK (aMang.getAsset (mm1->getID()) != mm2);
111 */
112  PAsset aa1 = aMang.getAsset (ID<Asset>(mm1->getID())); // note we get an Asset ref
113  CHECK (aa1 == mm1);
114  PM mX1 = aMang.getAsset (mm1->getID()); // ..and now we get a Media ref
115  CHECK (mX1 == mm1);
116  CHECK (mX1 == aa1);
117 
118  CHECK (aMang.known (mm1->getID()));
119  CHECK (aMang.known (mm2->getID()));
120  CHECK (aMang.known (mm3->getID()));
121 
122  CHECK ( !aMang.known (mm3->getID(), Category(AUDIO))); // not found within AUDIO-Category
123  try
124  { // can't be found if specifying wrong Asset kind....
125  aMang.getAsset (ID<asset::Proc>(mm1->getID()));
126  NOTREACHED();
127  }
128  catch (lumiera::error::Invalid& xxx) {CHECK (xxx.getID()==LUMIERA_ERROR_WRONG_ASSET_KIND);}
129  try
130  { // try accessing nonexistent ID
131  aMang.getAsset (ID<Asset> (1234567890));
132  NOTREACHED();
133  }
134  catch (lumiera::error::Invalid& xxx) {CHECK (xxx.getID()==LUMIERA_ERROR_UNKNOWN_ASSET_ID);}
135  lumiera_error (); // reset errorflag
136 
137 
138  // checking the Ident-Fields
139  CHECK (mm1->ident.name == "test-1");
140  CHECK (mm2->ident.name == "test-1");
141  CHECK (mm3->ident.name == "test-2");
142 
143  CHECK (cat == Category (VIDEO,"bin1"));
144  CHECK (mm1->ident.category == Category (VIDEO,"bin1"));
145  CHECK (mm2->ident.category == Category (VIDEO,"bin1"));
146  CHECK (mm3->ident.category == Category (VIDEO ));
147 
148  CHECK (mm1->ident.org == "ichthyo");
149  CHECK (mm2->ident.org == "lumi");
150  CHECK (mm3->ident.org == "lumi");
151 
152  CHECK (mm1->ident.version == 5);
153  CHECK (mm2->ident.version == 1);
154  CHECK (mm3->ident.version == 1);
155 
156  CHECK (mm1->getFilename() == "testfile.mov");
157  CHECK (mm2->getFilename() == "test-1.mov");
158  CHECK (mm3->getFilename() == "test-2.mov");
159 
160 
161  TRACE (asset_mem, "leaving test method scope");
162  }
163 
164 
171  {
172  PM candi;
173 
174  Asset::Ident key1("test-1", Category(AUDIO), "ichthyo", 5);
175  candi = asset::Media::create(key1);
176  CHECK ( checkProperties (candi, key1, ""));
177 
178  candi = asset::Media::create(key1, string("test-1.wav"));
179  CHECK ( checkProperties (candi, key1, "test-1.wav"));
180 
181  Asset::Ident key2("", Category(AUDIO), "ichthyo", 5);
182  candi = asset::Media::create(key2, string("test-2.wav"));
183  CHECK ( checkProperties (candi, key2, "test-2.wav"));
184  CHECK (key2.name == "test-2"); // name filled in automatically
185 
186  candi = asset::Media::create(string("test-3.wav"), Category(AUDIO));
187  CHECK ( checkProperties (candi, Asset::Ident("test-3", Category(AUDIO), "lumi", 1)
188  , "test-3.wav"));
189 
190  candi = asset::Media::create("some/path/test-4.wav", Category(AUDIO));
191  CHECK ( checkProperties (candi, Asset::Ident("test-4", Category(AUDIO), "lumi", 1)
192  , "some/path/test-4.wav"));
193 
194  candi = asset::Media::create("", Category(AUDIO,"sub/bin"));
195  CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO,"sub/bin"), "lumi", 1)
196  , ""));
197 
198  candi = asset::Media::create("", AUDIO);
199  CHECK ( checkProperties (candi, Asset::Ident("nil", Category(AUDIO), "lumi", 1)
200  , ""));
201  }
202 
203  bool checkProperties (PM object, Asset::Ident identity, string filename)
204  {
205  return identity == object->ident
206  && filename == object->getFilename();
207  }
208  };
209 
210 
212  LAUNCHER (CreateAsset_test, "unit asset");
213 
214 
215 
216 }}} // namespace proc::asset::test
string name
element ID, comprehensible but sanitised.
Definition: asset.hpp:162
Proc-Layer Interface: Asset Lookup and Organisation.
Facade for the Asset subsystem.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:76
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
The asset subsystem of the Proc-Layer.
Definition: id-scheme.hpp:64
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
TRACE(test,"inserted %d", data)
a POD comprised of all the information sufficiently identifying any given Asset.
Definition: asset.hpp:156
Derived specific exceptions within Lumiera'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.
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
Tree like classification of Assets.
Definition: category.hpp:75
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
Small helper and diagnostic functions related to Asset and AssetManager.
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
bool checkProperties(PM object, Asset::Ident identity, string filename)
Configuration handle for temporarily shadowing a dependency by a test mock instance.
LAUNCHER(AssetCategory_test,"unit asset")
Register this test class...