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)
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/symbol.hpp"
27 #include "lib/util.hpp"
28 
29 #include <string>
30 
31 
32 
33 namespace steam {
34 namespace mobject {
35 namespace session {
36 namespace test {
37 
38  using util::contains;
39  using lib::Literal;
40  using std::string;
41 
42 
43  namespace { // helpers and shortcuts....
44 
47  bool
48  filter (Placement<DummyMO> const& candidate)
49  {
50  string desc = candidate->operator string();
51  return contains(desc, "MO2");
52  }
53 
54  template<class IT>
55  void
56  pullOut (IT const& iter)
57  {
58  for (IT elm(iter);
59  elm; ++elm)
60  cout << *elm << endl;
61  }
62 
63  void
64  announce (Literal description)
65  {
66  static uint nr(0);
67  cout << "--------------------------------Test-"<< ++nr << ": " << description << endl;
68  }
69 
70  }
71 
72 
73 
74  /******************************************************************************************/
87  class ScopeQuery_test : public Test
88  {
89  virtual void
90  run (Arg)
91  {
92  // Prepare an (test)Index (dummy "session")
93  PPIdx testSession (build_testScopes());
94 
96 
97  discover (ScopeQuery<MObject> (scope, CONTENTS) , "contents depth-first");
98  discover (ScopeQuery<Clip> (scope, CONTENTS) , "contents depth-first, filtered to Clip");
99  discover (ScopeQuery<DummyMO> (scope, CONTENTS) , "contents depth-first, filtered to DummyMO");
100  discover (ScopeQuery<TestSubMO1> (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO1");
101  discover (ScopeQuery<TestSubMO2> (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO2");
102 
103  discover (pickAllSuitable(scope, filter) , "contents depth-first, custom filtered DummyMO");
104  // note filter is typed to accept DummyMO
105  ScopeQuery<TestSubMO21> allM021(scope, CONTENTS);
106  ScopeQuery<TestSubMO21>::iterator specialEl (issue(allM021));
107  ++specialEl; // step in to second solution found...
108  CHECK (specialEl);
109 
110  discover (ScopeQuery<MObject> (*specialEl, PARENTS) , "parents of the second TestSubMO2 element found");
111  discover (ScopeQuery<MObject> (*specialEl, CHILDREN), "children of the this TestSubMO2 element");
112  discover (ScopeQuery<MObject> (*specialEl, PATH) , "path from there to root");
113  discover (ScopeQuery<TestSubMO2> (*specialEl, PATH) , "same path, but filtered to TestSubMO2");
114  announce ( "continue exploring partially used TestSubMO2 iterator");
115  pullOut (specialEl);
116  }
117 
118 
119 
120  template<class MO>
121  static void
122  discover (ScopeQuery<MO> const& query, Literal description)
123  {
124  announce (description);
125  pullOut (issue(query));
126  }
127 
128  template<class MO>
129  static typename ScopeQuery<MO>::iterator
130  issue (ScopeQuery<MO> const& query)
131  {
132  return query.resolveBy(SessionServiceExploreScope::getResolver());
133  }
134 
135  };
136 
137 
139  LAUNCHER (ScopeQuery_test, "unit session");
140 
141 
142 }}}} // 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:40
_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:76
PPIdx build_testScopes()
helper for tests: create a pseudo-session (actually just a PlacementIndex), which contains some neste...
Definition: test-scopes.cpp:38
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:65
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
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.
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