Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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"
28#include "lib/format-cout.hpp"
29#include "lib/util.hpp"
30
31
32namespace steam {
33namespace mobject {
34namespace session {
35namespace test {
36
37 using namespace mobject::test;
38
40 using LERR_(NOT_IN_SESSION);
41 using LERR_(BOTTOM_PLACEMENTREF);
42
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
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
Lumiera's internal time value datatype.
static const Time MIN
Special kind of Placement, where the location of the MObject has been nailed down to a fixed position...
Reference tag denoting a placement attached to the session.
ExplicitPlacement resolve() const
static PPIdx install()
Re-define the implicit PlacementIndex temporarily, e.g.
#define LERR_(_NAME_)
Definition error.hpp:45
Core abstraction: completely resolved placement of an MObject Within the session model,...
Automatically use custom string conversion in C++ stream output.
lumiera_uid * LumieraUid
Definition hash-value.h:41
std::shared_ptr< PlacementIndex > PPIdx
TestPlacement< TestSubMO21 > PSub
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
Definition util.hpp:421
Core of the session implementation datastructure.
A generic reference mechanism for Placements, as added to the current session.
Core abstraction: placement of a media object into session context.
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Implementation level session API: PlacementIndex mock for tests.
A hierarchy of simple dummy-Media-Objects for easy unit testing.
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.
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...