Lumiera  0.pre.03
»edit your freedom«
placement-index-query-test.cpp
Go to the documentation of this file.
1 /*
2  PlacementIndexQuery(Test) - querying the placement index through the generic query interface
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"
34 #include "lib/format-cout.hpp"
35 #include "lib/util.hpp"
36 
37 
38 
39 namespace steam {
40 namespace mobject {
41 namespace session {
42 namespace test {
43 
45  using session::PathQuery;
47  using util::isSameObject;
48 
49 
50  /************************************************************************/
60  class PlacementIndexQuery_test : public Test
61  {
62 
63  virtual void
64  run (Arg)
65  {
66  checkQueryResolver();
67  checkQueryOperations();
68  }
69 
70  void
71  checkQueryResolver()
72  {
73  PPIdx index = build_testScopes();
76 
77  CHECK (isSameObject (resolver1, resolver2));
78 
79  PlacementMO& root1 = index->getRoot();
81  CHECK (isSameObject (root1, root2));
82 
83  PlacementMO& elm1 = *ContentsQuery<TestSubMO2>(root1).resolveBy(resolver1);
84  PlacementMO& elm2 = *ContentsQuery<TestSubMO1>(root1).resolveBy(resolver1);
85  PlacementMO& elm3 = *(index->getReferrers(elm1));
86  CHECK (isSameObject (elm3, elm2));
87  // relying on the specific setup of the test index
88  // MO1 is the sole "referrer" of MO2 (the only content within MO2's scope)
89  // root \ TestSubMO2 \ TestSubMO1
90  }
91 
92  void
93  checkQueryOperations()
94  {
95  // Prepare an (test)Index (dummy "session")
96  PPIdx index = build_testScopes();
97  PlacementMO& root = index->getRoot();
98  PlacementIndexQueryResolver resolver(*index);
99 
100  cout << "explore contents depth-first..." << endl;
101  discover (ContentsQuery<MObject>(root).resolveBy(resolver));
102 
103  PlacementMO& elm = *ContentsQuery<TestSubMO1>(root).resolveBy(resolver);
104 
105  cout << "path to root starting at " << elm << endl;
106  discover (PathQuery<MObject> (elm).resolveBy(resolver));
107  }
108 
109 
110  template<class IT>
111  void
112  discover (IT result)
113  {
114  for ( ; result; ++result)
115  cout << *result << endl;
116  }
117 
118  };
119 
120 
122  LAUNCHER (PlacementIndexQuery_test, "unit session");
123 
124 
125 }}}} // namespace steam::mobject::session::test
Implementation level session API: query a scope.
Automatically use custom string conversion in C++ stream output.
Wrapper for the PlacementIndex, allowing to resolve scope contents discovery.
static lumiera::QueryResolver const & getResolver()
Interface: a facility for resolving (some kind of) queries A concrete subclass has the ability to cre...
framework and to resolve logical queries.
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
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
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...
Specific queries to explore contents of a scope within the high-level model.
Implementing resolution of "discover contents"-queries based on PlacementIndex.
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.
Definition: util.hpp:347