Lumiera  0.pre.03
»edityourfreedom«
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dependent-assets-test.cpp
Go to the documentation of this file.
1 /*
2  DependentAssets(Test) - check the asset dependency handling
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 "lib/test/run.hpp"
29 #include "proc/asset/testasset.hpp"
32 #include "lib/depend-inject.hpp"
33 #include "proc/asset/media.hpp"
34 #include "proc/asset/clip.hpp"
35 #include "lib/util.hpp"
36 
37 using util::contains;
38 using util::isnil;
39 
40 
41 namespace proc {
42 namespace asset{
43 namespace test {
44 
46  ::Local<backend::test::MediaAccessMock>;
47 
48 
49 
50 
51  /***************************************************************/
57  class DependentAssets_test : public Test
58  {
59  virtual void run (Arg)
60  {
62  checkUnlinking ();
65  }
66 
68  typedef TA::PA PTestA;
69 
70 
74  {
75  PAsset a1 = TA::create();
76  CHECK (isnil (a1->getParents()));
77  CHECK (isnil (a1->getDependant()));
78 
79  PTestA a2 = TA::create(a1);
80  CHECK (a1 == a2->getParents()[0]); // TestAsset registered a1 as parent
81  CHECK (a2 == a1->getDependant()[0]);
82 
83  PAsset a3 = TA::create();
84  a2->set_depend(a3);
85  CHECK (a3 == a2->getParents()[1]);
86  CHECK (a2 == a3->getDependant()[0]);
87  CHECK (!contains (a1->getDependant(), a3));
88  }
89 
90 
94  {
95  PTestA a1_ = TA::create();
96  PAsset a1 (a1_);
97  PTestA a2_ = TA::create(a1);
98  PAsset a2 (a2_);
99  PAsset a3 = TA::create(a2);
100  CHECK (a1 == a2->getParents()[0]);
101  CHECK (a2 == a1->getDependant()[0]);
102  CHECK (a2 == a3->getParents()[0]);
103  CHECK (a3 == a2->getDependant()[0]);
104 
105  a2_->call_unlink();
106  CHECK (isnil (a2->getDependant()));
107  CHECK (!contains (a1->getDependant(), a2)); // has been propagated up
108  CHECK (!isnil (a2->getParents()));
109  CHECK (contains (a3->getParents(), a2)); // but up-links remain intact
110 
111  a2_->call_unlink(a1->getID());
112  a2_->set_depend(a1);
113  PAsset a4 = TA::create(a1);
114  CHECK (a1 == a2->getParents()[0]);
115  CHECK (a1 == a4->getParents()[0]);
116  CHECK (a2 == a1->getDependant()[0]);
117  CHECK (a4 == a1->getDependant()[1]);
118 
119  a1_->call_unlink(a4->getID());
120  CHECK (!contains (a1->getDependant(), a4)); // selectively removed
121  CHECK ( contains (a1->getDependant(), a2));
122  CHECK (a1 == a4->getParents()[0]); // no propagation
123  }
124 
125 
130  {
131  PAsset a1 = TA::create();
132  PTestA a2_= TA::create(a1);
133  PAsset a2 (a2_);
134  PAsset a3 = TA::create(); // not dependant
135 
136  CHECK (a1->isActive());
137  CHECK (a2->isActive());
138  CHECK (a3->isActive());
139 
140  a1->enable(false);
141  CHECK (!a1->isActive());
142  CHECK (!a2->isActive());
143  CHECK (a3->isActive());
144 
145  a2->enable(true);
146  CHECK (!a1->isActive());
147  CHECK (!a2->isActive()); // ignored because parent is disabled
148 
149  a1->enable(true);
150  CHECK (a1->isActive());
151  CHECK (a2->isActive());
152 
153  a2->enable(false);
154  CHECK (a1->isActive());
155  CHECK (!a2->isActive()); // disabling not propagated to parent
156  a2->enable(true);
157  CHECK (a1->isActive());
158  CHECK (a2->isActive());
159 
160  a3->enable(false);
161  CHECK (a1->isActive());
162  CHECK (a2->isActive());
163  CHECK (!a3->isActive()); // no dependency...
164 
165  a1->enable(false);
166  a3->enable();
167  CHECK (!a1->isActive());
168  CHECK (!a2->isActive());
169  CHECK (a3->isActive());
170 
171  a1->enable();
172  a2_->set_depend(a3); // now add a new parent dependency
173  a3->enable(false);
174  CHECK (a1->isActive());
175  CHECK (!a2->isActive()); // has been propagated via the new dependency
176  CHECK (!a3->isActive());
177 
178  a2->enable(true);
179  CHECK (a1->isActive()); // no change because one of the parents is disbled
180  CHECK (!a2->isActive());
181  CHECK (!a3->isActive());
182  a1->enable(false);
183  CHECK (!a1->isActive());
184  a3->enable(true);
185  CHECK (!a1->isActive()); // no propagation because the disabled other parent (a1)
186  CHECK (!a2->isActive());
187  CHECK (a3->isActive());
188  a1->enable(true);
189  CHECK (a1->isActive()); // but now propagation is possible
190  CHECK (a2->isActive());
191  CHECK (a3->isActive());
192  }
193 
194 
202  {
203  MediaAccessMock useMockMedia;
204 
205  // -----Media and Clip--------------------------------
206  typedef lib::P<Media> PM;
207  typedef lib::P<Clip> PC;
208  PM mm = asset::Media::create("test-1", VIDEO);
209  PC cc = mm->createClip()->findClipAsset();
210  CHECK (dependencyCheck (cc,mm));
211  }
212 
213  };
214 
215 
217  LAUNCHER (DependentAssets_test, "unit function asset");
218 
219 
220 
221 }}} // namespace proc::asset::test
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:76
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
lib::DependInject< backend::MediaAccessFacade >::Local< backend::test::MediaAccessMock > MediaAccessMock
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition: util.hpp:205
std::vector< string > & Arg
Definition: run.hpp:54
Definition of Asset representation for a media clip.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
A mock asset to support unit testing.
shared_ptr< asset::Media > PM
Definition: testclip.cpp:46
Test(mock) asset subclass usable for hijacking a given asset class (template parameter) and subsequen...
Definition: testasset.hpp:52
Small helper and diagnostic functions related to Asset and AssetManager.
Proc-Layer implementation namespace root.
Definition: id-scheme.hpp:63
bool dependencyCheck(lib::P< CHI > child, lib::P< PAR > parent)
Configuration handle for temporarily shadowing a dependency by a test mock instance.
LAUNCHER(AssetCategory_test,"unit asset")
Register this test class...