Lumiera  0.pre.03
»edit your freedom«
placement-ref-test.cpp
Go to the documentation of this file.
1 /*
2  PlacementRef(Test) - generic reference to a Placement within the Session
3 
4  Copyright (C)
5  2009, 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"
20 #include "lib/test/test-helper.hpp"
27 #include "lib/time/timevalue.hpp"
28 #include "lib/format-cout.hpp"
29 #include "lib/util.hpp"
30 
31 
32 namespace steam {
33 namespace mobject {
34 namespace session {
35 namespace test {
36 
37  using namespace mobject::test;
38 
39  using util::isSameObject;
40  using LERR_(NOT_IN_SESSION);
41  using LERR_(BOTTOM_PLACEMENTREF);
42 
43  using PSub = TestPlacement<TestSubMO21>;
44  using P_ID = PlacementMO::ID;
45 
46 
47 
48  /***********************************************************************/
60  class PlacementRef_test : public Test
61  {
62 
63  virtual void
64  run (Arg)
65  {
66  PSub testPlacement1(*new TestSubMO21);
67  PSub testPlacement2(*new TestSubMO21);
68 
69  lib::time::Time twoSec(0,2);
70  testPlacement2.chain (twoSec); // define start time of Placement-2 to be at t=2sec
71 
72  // Prepare an (test)Index backing the PlacementRefs
74  PMO& root = index->getRoot();
75 
76  P_ID id1 = index->insert (testPlacement1, root);
77  P_ID tmpID = index->insert (testPlacement2, root);
78  CHECK (2 == index->size());
79 
80  // References to the "live" placements within our test index
81  PMO& p1 = index->find(id1);
82  PMO& p2 = index->find(tmpID);
83 
84  PlacementMO::Id<TestSubMO21> id2 = p2.recastID<TestSubMO21>();
85  CHECK (id2);
86  CHECK (id2 != p1.getID());
87 
88  // create placement refs
89  PlacementRef<TestSubMO21> ref1 (p1);
90  PlacementRef<TestSubMO21> ref2 (id2);
91 
92  PlacementRef<MObject> refX (ref2);
93 
94  CHECK (ref1);
95  CHECK (ref2);
96  CHECK (refX);
97  CHECK (ref1 != ref2);
98  CHECK (ref2 == refX);
99 
100  // indeed a "reference": resolves to the same memory location
101  CHECK (isSameObject (p1, *ref1));
102  CHECK (isSameObject (p2, *ref2));
103  CHECK (isSameObject (p2, *refX));
104 
105  cout << *ref1 << endl;
106  cout << *ref2 << endl;
107  cout << *refX << endl;
108 
109  // PlacementRef mimics placement behaviour
110  ref1->specialAPI();
111  CHECK (2 == ref1.use_count());
112  CHECK (2 == ref2.use_count());
113  ExplicitPlacement exPla = refX.resolve();
114  CHECK (exPla.time == twoSec); // indeed get back the time we set on p2 above
115  CHECK (3 == ref2.use_count()); // exPla shares ownership with p2
116 
117  CHECK (index->contains(ref1)); // ref can stand-in for a placement-ID
118  CHECK (sizeof(id2) == sizeof(ref2)); // (and is actually implemented based on an ID)
119 
120  // assignment on placement refs
121  refX = ref1;
122  CHECK (ref1 != ref2);
123  CHECK (ref1 == refX);
124  CHECK (ref2 != refX);
125 
126  // re-assignment with a new placement
127  refX = p2;
128  CHECK (refX == ref2);
129  CHECK (isSameObject (*refX, p2));
130  refX = p1.getID();
131  CHECK (refX == ref1);
132  CHECK (refX != ref2);
133  CHECK (isSameObject (*refX, p1));
134 
135  LumieraUid luid2 (p2.getID().get());
136  refX = luid2; // assignment works even based on a plain LUID
137  ref2 = ref1;
138  ref1 = refX; // dynamic type check when downcasting
139  CHECK (isSameObject (p1, *ref2));
140  CHECK (isSameObject (p2, *ref1));
141  refX = ref2;
142  ref2 = ref1;
143  ref1 = refX;
144  CHECK (isSameObject (p1, *ref1));
145  CHECK (isSameObject (p1, *refX));
146  CHECK (isSameObject (p2, *ref2));
147  CHECK (ref1 != ref2);
148  CHECK (ref1 == refX);
149  CHECK (ref2 != refX);
150 
151  // resolution is indeed "live", we see changes to the referred placement
152  CHECK (refX.resolve().time == lib::time::Time::MIN);
153  p1.chain = p2.chain; // do a change on the placement within index....
154  CHECK (refX.resolve().time == twoSec); // now we get the time tie we originally set on p2
155 
156  CHECK (p1.getID() != p2.getID()); // but the instance identities are still unaltered
157  CHECK (2 == ref1.use_count());
158  CHECK (3 == ref2.use_count()); // one more because of shared ownership with exPla
159 
160 
161  // actively removing p2 invalidates the other refs to
162  index->remove (ref1);
163  CHECK (!ref1); // checks invalidity without throwing
164  CHECK (!refX);
165  VERIFY_ERROR(NOT_IN_SESSION, *ref1 );
166 
167  // deliberately create an invalid PlacementRef
169  CHECK (!bottom);
170  VERIFY_ERROR(BOTTOM_PLACEMENTREF, *bottom );
171  VERIFY_ERROR(BOTTOM_PLACEMENTREF, bottom->specialAPI() );
172  VERIFY_ERROR(BOTTOM_PLACEMENTREF, bottom.resolve() );
173 
174  //consistency check; then reset PlacementRef index to default
175  CHECK (1 == index->size());
176  CHECK (index->isValid());
177  index.reset();
178  }
179  };
180 
181 
183  LAUNCHER (PlacementRef_test, "unit session");
184 
185 
186 }}}} // namespace steam::mobject::session::test
Reference tag denoting a placement attached to the session.
Automatically use custom string conversion in C++ stream output.
Core abstraction: completely resolved placement of an MObject Within the session model, all media objects are attached with the help of mobject::Placement elements.
Definition: run.hpp:40
Core abstraction: placement of a media object into session context.
Special kind of Placement, where the location of the MObject has been nailed down to a fixed position...
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Core of the session implementation datastructure.
Simplistic 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.
A hierarchy of simple dummy-Media-Objects for easy unit testing.
Implementation level session API: PlacementIndex mock for tests.
A generic reference mechanism for Placements, as added to the current session.
static PPIdx install()
Re-define the implicit PlacementIndex temporarily, e.g.
a family of time value like entities and their relationships.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee&#39;s memory identities. ...
Definition: util.hpp:421