Lumiera  0.pre.03
»edit your freedom«
dependent-assets-test.cpp
Go to the documentation of this file.
1 /*
2  DependentAssets(Test) - check the asset dependency handling
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 "lib/test/run.hpp"
23 #include "lib/depend-inject.hpp"
24 #include "steam/asset/media.hpp"
25 #include "steam/asset/clip.hpp"
26 #include "lib/util.hpp"
27 
28 using util::contains;
29 using util::isnil;
30 
31 
32 namespace steam {
33 namespace asset{
34 namespace test {
35 
36  using MediaAccessMock = lib::DependInject<vault::MediaAccessFacade>
37  ::Local<vault::test::MediaAccessMock>;
38 
39 
40 
41 
42  /***************************************************************/
48  class DependentAssets_test : public Test
49  {
50  virtual void run (Arg)
51  {
53  checkUnlinking ();
56  }
57 
58  typedef TestAsset<Asset> TA;
59  typedef TA::PA PTestA;
60 
61 
65  {
66  PAsset a1 = TA::create();
67  CHECK (isnil (a1->getParents()));
68  CHECK (isnil (a1->getDependant()));
69 
70  PTestA a2 = TA::create(a1);
71  CHECK (a1 == a2->getParents()[0]); // TestAsset registered a1 as parent
72  CHECK (a2 == a1->getDependant()[0]);
73 
74  PAsset a3 = TA::create();
75  a2->set_depend(a3);
76  CHECK (a3 == a2->getParents()[1]);
77  CHECK (a2 == a3->getDependant()[0]);
78  CHECK (!contains (a1->getDependant(), a3));
79  }
80 
81 
85  {
86  PTestA a1_ = TA::create();
87  PAsset a1 (a1_);
88  PTestA a2_ = TA::create(a1);
89  PAsset a2 (a2_);
90  PAsset a3 = TA::create(a2);
91  CHECK (a1 == a2->getParents()[0]);
92  CHECK (a2 == a1->getDependant()[0]);
93  CHECK (a2 == a3->getParents()[0]);
94  CHECK (a3 == a2->getDependant()[0]);
95 
96  a2_->call_unlink();
97  CHECK (isnil (a2->getDependant()));
98  CHECK (!contains (a1->getDependant(), a2)); // has been propagated up
99  CHECK (!isnil (a2->getParents()));
100  CHECK (contains (a3->getParents(), a2)); // but up-links remain intact
101 
102  a2_->call_unlink(a1->getID());
103  a2_->set_depend(a1);
104  PAsset a4 = TA::create(a1);
105  CHECK (a1 == a2->getParents()[0]);
106  CHECK (a1 == a4->getParents()[0]);
107  CHECK (a2 == a1->getDependant()[0]);
108  CHECK (a4 == a1->getDependant()[1]);
109 
110  a1_->call_unlink(a4->getID());
111  CHECK (!contains (a1->getDependant(), a4)); // selectively removed
112  CHECK ( contains (a1->getDependant(), a2));
113  CHECK (a1 == a4->getParents()[0]); // no propagation
114  }
115 
116 
121  {
122  PAsset a1 = TA::create();
123  PTestA a2_= TA::create(a1);
124  PAsset a2 (a2_);
125  PAsset a3 = TA::create(); // not dependant
126 
127  CHECK (a1->isActive());
128  CHECK (a2->isActive());
129  CHECK (a3->isActive());
130 
131  a1->enable(false);
132  CHECK (!a1->isActive());
133  CHECK (!a2->isActive());
134  CHECK (a3->isActive());
135 
136  a2->enable(true);
137  CHECK (!a1->isActive());
138  CHECK (!a2->isActive()); // ignored because parent is disabled
139 
140  a1->enable(true);
141  CHECK (a1->isActive());
142  CHECK (a2->isActive());
143 
144  a2->enable(false);
145  CHECK (a1->isActive());
146  CHECK (!a2->isActive()); // disabling not propagated to parent
147  a2->enable(true);
148  CHECK (a1->isActive());
149  CHECK (a2->isActive());
150 
151  a3->enable(false);
152  CHECK (a1->isActive());
153  CHECK (a2->isActive());
154  CHECK (!a3->isActive()); // no dependency...
155 
156  a1->enable(false);
157  a3->enable();
158  CHECK (!a1->isActive());
159  CHECK (!a2->isActive());
160  CHECK (a3->isActive());
161 
162  a1->enable();
163  a2_->set_depend(a3); // now add a new parent dependency
164  a3->enable(false);
165  CHECK (a1->isActive());
166  CHECK (!a2->isActive()); // has been propagated via the new dependency
167  CHECK (!a3->isActive());
168 
169  a2->enable(true);
170  CHECK (a1->isActive()); // no change because one of the parents is disbled
171  CHECK (!a2->isActive());
172  CHECK (!a3->isActive());
173  a1->enable(false);
174  CHECK (!a1->isActive());
175  a3->enable(true);
176  CHECK (!a1->isActive()); // no propagation because the disabled other parent (a1)
177  CHECK (!a2->isActive());
178  CHECK (a3->isActive());
179  a1->enable(true);
180  CHECK (a1->isActive()); // but now propagation is possible
181  CHECK (a2->isActive());
182  CHECK (a3->isActive());
183  }
184 
185 
193  {
194  MediaAccessMock useMockMedia;
195 
196  // -----Media and Clip--------------------------------
197  typedef lib::P<Media> PM;
198  typedef lib::P<Clip> PC;
199  PM mm = asset::Media::create("test-1", VIDEO);
200  PC cc = mm->createClip()->findClipAsset();
201  CHECK (dependencyCheck (cc,mm));
202  }
203 
204  };
205 
206 
208  LAUNCHER (DependentAssets_test, "unit function asset");
209 
210 
211 
212 }}} // namespace steam::asset::test
Media data represented a specific kind of Asset.
Definition: run.hpp:40
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:75
Steam-Layer implementation namespace root.
This framework allows to (re)configure the lib::Depend front-end for dependency-injection.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A mock asset to support unit testing.
Definition of Asset representation for a media clip.
Test(mock) asset subclass usable for hijacking a given asset class (template parameter) and subsequen...
Definition: testasset.hpp:43
Small helper and diagnostic functions related to Asset and AssetManager.
Customised refcounting smart pointer template, built upon std::shared_ptr, but forwarding type relati...
Definition: trait.hpp:71
The asset subsystem of the Steam-Layer.
Definition: wrapperptr.hpp:35
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
Definition: util.hpp:255