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)
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"
25 #include "lib/format-cout.hpp"
26 #include "lib/util.hpp"
27 
28 
29 namespace steam {
30 namespace mobject {
31 namespace session {
32 namespace test {
33 
34  namespace { // Helper to enumerate Contents
35  // of the test-dummy session
36  typedef _ScopeIterMO _Iter;
37 
38  _Iter
39  contents_of_testSession (PPIdx testSession)
40  {
41  return ScopeLocator::instance().query<MObject> (testSession->getRoot());
42  }
43 
44  _Iter
45  pathToRoot (PlacementMO& elm)
46  {
47  Scope startScope(elm);
48  return ScopeLocator::instance().getRawPath (startScope);
49  }
50  }
51 
52  using LERR_(NO_PARENT_SCOPE);
53  using util::isSameObject;
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  {
121  PlacementMO& aPlac = retrieve_startElm();
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
Automatically use custom string conversion in C++ stream output.
Scope getParent() const
retrieve the parent scope which encloses this scope.
Definition: scope.cpp:209
Definition: run.hpp:40
PPIdx build_testScopes()
helper for tests: create a pseudo-session (actually just a PlacementIndex), which contains some neste...
Definition: test-scopes.cpp:38
#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:184
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
A Placement scope within the high-level-model.
Definition: scope.hpp:69
MObject is the interface class for all "Media Objects".
Definition: mobject.hpp:70
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:87
Unit test helper to generate a system of nested test scopes.
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.
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. ...