Lumiera  0.pre.03
»edit your freedom«
scope-query-test.cpp
Go to the documentation of this file.
1 /*
2  ScopeQuery(Test) - running queries to discover container contents, filtering (sub)types
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/symbol.hpp"
36 #include "lib/util.hpp"
37 
38 #include <string>
39 
40 
41 
42 namespace steam {
43 namespace mobject {
44 namespace session {
45 namespace test {
46 
47  using util::contains;
48  using lib::Literal;
49  using std::string;
50 
51 
52  namespace { // helpers and shortcuts....
53 
56  bool
57  filter (Placement<DummyMO> const& candidate)
58  {
59  string desc = candidate->operator string();
60  return contains(desc, "MO2");
61  }
62 
63  template<class IT>
64  void
65  pullOut (IT const& iter)
66  {
67  for (IT elm(iter);
68  elm; ++elm)
69  cout << *elm << endl;
70  }
71 
72  void
73  announce (Literal description)
74  {
75  static uint nr(0);
76  cout << "--------------------------------Test-"<< ++nr << ": " << description << endl;
77  }
78 
79  }
80 
81 
82 
83  /******************************************************************************************/
96  class ScopeQuery_test : public Test
97  {
98  virtual void
99  run (Arg)
100  {
101  // Prepare an (test)Index (dummy "session")
102  PPIdx testSession (build_testScopes());
103 
105 
106  discover (ScopeQuery<MObject> (scope, CONTENTS) , "contents depth-first");
107  discover (ScopeQuery<Clip> (scope, CONTENTS) , "contents depth-first, filtered to Clip");
108  discover (ScopeQuery<DummyMO> (scope, CONTENTS) , "contents depth-first, filtered to DummyMO");
109  discover (ScopeQuery<TestSubMO1> (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO1");
110  discover (ScopeQuery<TestSubMO2> (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO2");
111 
112  discover (pickAllSuitable(scope, filter) , "contents depth-first, custom filtered DummyMO");
113  // note filter is typed to accept DummyMO
114  ScopeQuery<TestSubMO21> allM021(scope, CONTENTS);
115  ScopeQuery<TestSubMO21>::iterator specialEl (issue(allM021));
116  ++specialEl; // step in to second solution found...
117  CHECK (specialEl);
118 
119  discover (ScopeQuery<MObject> (*specialEl, PARENTS) , "parents of the second TestSubMO2 element found");
120  discover (ScopeQuery<MObject> (*specialEl, CHILDREN), "children of the this TestSubMO2 element");
121  discover (ScopeQuery<MObject> (*specialEl, PATH) , "path from there to root");
122  discover (ScopeQuery<TestSubMO2> (*specialEl, PATH) , "same path, but filtered to TestSubMO2");
123  announce ( "continue exploring partially used TestSubMO2 iterator");
124  pullOut (specialEl);
125  }
126 
127 
128 
129  template<class MO>
130  static void
131  discover (ScopeQuery<MO> const& query, Literal description)
132  {
133  announce (description);
134  pullOut (issue(query));
135  }
136 
137  template<class MO>
138  static typename ScopeQuery<MO>::iterator
139  issue (ScopeQuery<MO> const& query)
140  {
141  return query.resolveBy(SessionServiceExploreScope::getResolver());
142  }
143 
144  };
145 
146 
148  LAUNCHER (ScopeQuery_test, "unit session");
149 
150 
151 }}}} // namespace steam::mobject::session::test
Implementation level session API: query a scope.
Query a scope to discover it&#39;s contents or location.
Automatically use custom string conversion in C++ stream output.
static lumiera::QueryResolver const & getResolver()
bool filter(Placement< DummyMO > const &candidate)
a filter predicate to pick some objects from a resultset.
Definition: run.hpp:49
_PickResult< FUNC >::FilterQuery pickAllSuitable(PlacementMO const &scope, FUNC predicate)
convenience shortcut to issue a SpecificContentsQuery, figuring out the actual return/filter type aut...
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
PPIdx build_testScopes()
helper for tests: create a pseudo-session (actually just a PlacementIndex), which contains some neste...
Definition: test-scopes.cpp:47
MObject in the Session to represent a clip on the timeline.
discover any contained objects depth-first
Steam-Layer implementation namespace root.
Namespace of Session and user visible high-level objects.
Definition: sequence.hpp:74
Implementation facility to query and retrieve session context with filtering conditions.
discover the path to root
Unit test helper to generate a system of nested test scopes.
Marker types to indicate a literal string and a Symbol.
discover the enclosing 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.
discover the immediate children
Adapter for building an implementation of the »Lumiera Forward Iterator« concept. ...
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
Definition: util.hpp:255