Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
placement-scope-test.cpp
Go to the documentation of this file.
1/*
2 PlacementScope(Test) - accessing and navigating placement scope
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"
25#include "lib/format-cout.hpp"
26#include "lib/util.hpp"
27
28
29namespace steam {
30namespace mobject {
31namespace session {
32namespace test {
33
34 namespace { // Helper to enumerate Contents
35 // of the test-dummy session
37
38 _Iter
40 {
41 return ScopeLocator::instance().query<MObject> (testSession->getRoot());
42 }
43
44 _Iter
46 {
47 Scope startScope(elm);
48 return ScopeLocator::instance().getRawPath (startScope);
49 }
50 }
51
52 using LERR_(NO_PARENT_SCOPE);
54
55
56
57
58 /***********************************************************************/
70 class PlacementScope_test : public Test
71 {
72
73 virtual void
74 run (Arg)
75 {
76 // Prepare an (test)Session
77 // with some dummy contents
78 PPIdx index = build_testScopes();
79
81 verifyLookup (index);
82 verifyNavigation (index);
83 }
84
85
86
87
91 void
93 {
94 for (_Iter ii = contents_of_testSession(sess); ii; ++ii)
95 {
96 PlacementMO& elm = *ii;
97 CHECK (elm.isValid());
98 Scope const& scope1 = Scope::containing(elm);
99 cout << "Scope: " << scope1 << endl;
100 cout << elm << endl;
101
102 RefPlacement ref (elm);
103 Scope const& scope2 = Scope::containing(ref);
104
105 // verify this with the scope registered within the index...
106 PlacementMO& scopeTop = sess->getScope(elm);
107 CHECK (scope1 == scopeTop);
108 CHECK (scope2 == scopeTop);
109 CHECK (scope1 == scope2);
110
111 CHECK (!isSameObject (scope1,scope2));
112 }
113 }
114
115
116
118 void
120 {
122 Scope scope1(aPlac);
123 Scope scope2(aPlac);
124 Scope nil;
125
126 CHECK (scope1 == scope2); CHECK (scope2 == scope1);
127 CHECK (scope1 != nil); CHECK (nil != scope1);
128 CHECK (scope2 != nil); CHECK (nil != scope2);
129
130 CHECK (aPlac == scope1); CHECK (scope1 == aPlac);
131 CHECK (aPlac == scope2); CHECK (scope2 == aPlac);
132 CHECK (aPlac != nil); CHECK (nil != aPlac);
133
134 Scope par (scope1.getParent());
135 CHECK (scope1 != par); CHECK (par != scope1);
136 CHECK (scope2 != par); CHECK (par != scope2);
137
138 PlacementMO& placm2 (scope2.getTop());
139 CHECK (aPlac.getID() == placm2.getID());
140
141 PlacementMO& parPlac (par.getTop());
142 CHECK (aPlac.getID() != parPlac.getID());
143 }
144
145
146
154 void
156 {
157 for (_Iter elm = contents_of_testSession(sess); elm; ++elm)
158 {
159 _Iter pathIter = pathToRoot(*elm);
160 Scope const& enclosing = Scope::containing(*elm);
161 CHECK (enclosing == Scope(*elm).getParent());
162 CHECK (*pathIter == Scope(*elm));
163
164 for ( ; pathIter; ++pathIter)
165 {
166 Scope sco(*pathIter);
167 if (sco.isRoot())
168 {
169 VERIFY_ERROR (NO_PARENT_SCOPE, sco.getParent() );
170 PlacementMO& top = sco.getTop();
171 PlacementMO& root = sess->getRoot();
172
173 CHECK (isSameObject (top,root));
174 }
175 else
176 {
177 Scope parent = sco.getParent();
178 PlacementMO& top = sco.getTop();
179 Scope parentsScope = Scope::containing(top);
180 PlacementMO& topsTop = sess->getScope(top);
181 CHECK (topsTop == parentsScope);
182 CHECK (isSameObject (topsTop, parentsScope.getTop()));
183 }}}
184 }
185
186 };
187
188
189
191 LAUNCHER (PlacementScope_test, "function session");
192
193
194}}}}// namespace steam::mobject::session::test
MObject is the interface class for all "Media Objects".
Definition mobject.hpp:72
static lib::Depend< ScopeLocator > instance
Storage holding the single ScopeLocator instance.
A Placement scope within the high-level-model.
Definition scope.hpp:70
static Scope containing(PlacementMO const &aPlacement)
discover the enclosing scope of a given Placement
Definition scope.cpp:184
PlacementMO & getTop() const
Definition scope.cpp:198
Scope getParent() const
retrieve the parent scope which encloses this scope.
Definition scope.cpp:209
#define LERR_(_NAME_)
Definition error.hpp:45
Automatically use custom string conversion in C++ stream output.
Core abstraction of the Session model: a media object.
PPIdx build_testScopes()
helper for tests: create a pseudo-session (actually just a PlacementIndex), which contains some neste...
std::shared_ptr< PlacementIndex > PPIdx
PlacementMO & retrieve_startElm()
complement to the helper: retrieve one of the dummy placements which is a Placement<> and way down in...
ScopeQuery< MObject >::iterator _ScopeIterMO
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
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Service to build the notion of a current location within the Sesison model.
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.
Unit test helper to generate a system of nested test scopes.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...