Lumiera  0.pre.03
»edit your freedom«
placement-scope-test.cpp
Go to the documentation of this file.
1 /*
2  PlacementScope(Test) - accessing and navigating placement scope
3 
4  Copyright (C) Lumiera.org
5  2009, 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 "lib/test/test-helper.hpp"
34 #include "lib/format-cout.hpp"
35 #include "lib/util.hpp"
36 
37 
38 namespace steam {
39 namespace mobject {
40 namespace session {
41 namespace test {
42 
43  namespace { // Helper to enumerate Contents
44  // of the test-dummy session
45  typedef _ScopeIterMO _Iter;
46 
47  _Iter
48  contents_of_testSession (PPIdx testSession)
49  {
50  return ScopeLocator::instance().query<MObject> (testSession->getRoot());
51  }
52 
53  _Iter
54  pathToRoot (PlacementMO& elm)
55  {
56  Scope startScope(elm);
57  return ScopeLocator::instance().getRawPath (startScope);
58  }
59  }
60 
61  using LERR_(NO_PARENT_SCOPE);
62  using util::isSameObject;
63 
64 
65 
66 
67  /***********************************************************************/
79  class PlacementScope_test : public Test
80  {
81 
82  virtual void
83  run (Arg)
84  {
85  // Prepare an (test)Session
86  // with some dummy contents
87  PPIdx index = build_testScopes();
88 
90  verifyLookup (index);
91  verifyNavigation (index);
92  }
93 
94 
95 
96 
100  void
102  {
103  for (_Iter ii = contents_of_testSession(sess); ii; ++ii)
104  {
105  PlacementMO& elm = *ii;
106  CHECK (elm.isValid());
107  Scope const& scope1 = Scope::containing(elm);
108  cout << "Scope: " << scope1 << endl;
109  cout << elm << endl;
110 
111  RefPlacement ref (elm);
112  Scope const& scope2 = Scope::containing(ref);
113 
114  // verify this with the scope registered within the index...
115  PlacementMO& scopeTop = sess->getScope(elm);
116  CHECK (scope1 == scopeTop);
117  CHECK (scope2 == scopeTop);
118  CHECK (scope1 == scope2);
119 
120  CHECK (!isSameObject (scope1,scope2));
121  }
122  }
123 
124 
125 
127  void
129  {
130  PlacementMO& aPlac = retrieve_startElm();
131  Scope scope1(aPlac);
132  Scope scope2(aPlac);
133  Scope nil;
134 
135  CHECK (scope1 == scope2); CHECK (scope2 == scope1);
136  CHECK (scope1 != nil); CHECK (nil != scope1);
137  CHECK (scope2 != nil); CHECK (nil != scope2);
138 
139  CHECK (aPlac == scope1); CHECK (scope1 == aPlac);
140  CHECK (aPlac == scope2); CHECK (scope2 == aPlac);
141  CHECK (aPlac != nil); CHECK (nil != aPlac);
142 
143  Scope par (scope1.getParent());
144  CHECK (scope1 != par); CHECK (par != scope1);
145  CHECK (scope2 != par); CHECK (par != scope2);
146 
147  PlacementMO& placm2 (scope2.getTop());
148  CHECK (aPlac.getID() == placm2.getID());
149 
150  PlacementMO& parPlac (par.getTop());
151  CHECK (aPlac.getID() != parPlac.getID());
152  }
153 
154 
155 
163  void
165  {
166  for (_Iter elm = contents_of_testSession(sess); elm; ++elm)
167  {
168  _Iter pathIter = pathToRoot(*elm);
169  Scope const& enclosing = Scope::containing(*elm);
170  CHECK (enclosing == Scope(*elm).getParent());
171  CHECK (*pathIter == Scope(*elm));
172 
173  for ( ; pathIter; ++pathIter)
174  {
175  Scope sco(*pathIter);
176  if (sco.isRoot())
177  {
178  VERIFY_ERROR (NO_PARENT_SCOPE, sco.getParent() );
179  PlacementMO& top = sco.getTop();
180  PlacementMO& root = sess->getRoot();
181 
182  CHECK (isSameObject (top,root));
183  }
184  else
185  {
186  Scope parent = sco.getParent();
187  PlacementMO& top = sco.getTop();
188  Scope parentsScope = Scope::containing(top);
189  PlacementMO& topsTop = sess->getScope(top);
190  CHECK (topsTop == parentsScope);
191  CHECK (isSameObject (topsTop, parentsScope.getTop()));
192  }}}
193  }
194 
195  };
196 
197 
198 
200  LAUNCHER (PlacementScope_test, "function session");
201 
202 
203 }}}}// namespace steam::mobject::session::test
Automatically use custom string conversion in C++ stream output.
Scope getParent() const
retrieve the parent scope which encloses this scope.
Definition: scope.cpp:218
Definition: run.hpp:49
PPIdx build_testScopes()
helper for tests: create a pseudo-session (actually just a PlacementIndex), which contains some neste...
Definition: test-scopes.cpp:47
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
Core abstraction of the Session model: a media object.
static Scope containing(PlacementMO const &aPlacement)
discover the enclosing scope of a given Placement
Definition: scope.cpp:193
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
A Placement scope within the high-level-model.
Definition: scope.hpp:78
MObject is the interface class for all "Media Objects".
Definition: mobject.hpp:79
PlacementMO & retrieve_startElm()
complement to the helper: retrieve one of the dummy placements which is a Placement<> and way down in...
Definition: test-scopes.cpp:96
Unit test helper to generate a system of nested test scopes.
Simple 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.
Service to build the notion of a current location within the Sesison model.
static lib::Depend< ScopeLocator > instance
Storage holding the single ScopeLocator instance.
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...