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)
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 
29 
30 namespace steam {
31 namespace mobject {
32 namespace session {
33 namespace test {
34 
36  using session::PathQuery;
38  using util::isSameObject;
39 
40 
41  /************************************************************************/
51  class PlacementIndexQuery_test : public Test
52  {
53 
54  virtual void
55  run (Arg)
56  {
57  checkQueryResolver();
58  checkQueryOperations();
59  }
60 
61  void
62  checkQueryResolver()
63  {
64  PPIdx index = build_testScopes();
67 
68  CHECK (isSameObject (resolver1, resolver2));
69 
70  PlacementMO& root1 = index->getRoot();
72  CHECK (isSameObject (root1, root2));
73 
74  PlacementMO& elm1 = *ContentsQuery<TestSubMO2>(root1).resolveBy(resolver1);
75  PlacementMO& elm2 = *ContentsQuery<TestSubMO1>(root1).resolveBy(resolver1);
76  PlacementMO& elm3 = *(index->getReferrers(elm1));
77  CHECK (isSameObject (elm3, elm2));
78  // relying on the specific setup of the test index
79  // MO1 is the sole "referrer" of MO2 (the only content within MO2's scope)
80  // root \ TestSubMO2 \ TestSubMO1
81  }
82 
83  void
84  checkQueryOperations()
85  {
86  // Prepare an (test)Index (dummy "session")
87  PPIdx index = build_testScopes();
88  PlacementMO& root = index->getRoot();
89  PlacementIndexQueryResolver resolver(*index);
90 
91  cout << "explore contents depth-first..." << endl;
92  discover (ContentsQuery<MObject>(root).resolveBy(resolver));
93 
94  PlacementMO& elm = *ContentsQuery<TestSubMO1>(root).resolveBy(resolver);
95 
96  cout << "path to root starting at " << elm << endl;
97  discover (PathQuery<MObject> (elm).resolveBy(resolver));
98  }
99 
100 
101  template<class IT>
102  void
103  discover (IT result)
104  {
105  for ( ; result; ++result)
106  cout << *result << endl;
107  }
108 
109  };
110 
111 
113  LAUNCHER (PlacementIndexQuery_test, "unit session");
114 
115 
116 }}}} // 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:40
PPIdx build_testScopes()
helper for tests: create a pseudo-session (actually just a PlacementIndex), which contains some neste...
Definition: test-scopes.cpp:38
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:65
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...
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, based directly on the referee&#39;s memory identities. ...
Definition: util.hpp:421