Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
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
33namespace steam {
34namespace mobject {
35namespace session {
36namespace 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>
130 issue (ScopeQuery<MO> const& query)
131 {
133 }
134
135 };
136
137
139 LAUNCHER (ScopeQuery_test, "unit session");
140
141
142}}}} // namespace steam::mobject::session::test
Inline string literal.
Definition symbol.hpp:78
iterator resolveBy(QueryResolver const &resolver) const
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Query a scope to discover it's contents or location.
static void discover(ScopeQuery< MO > const &query, Literal description)
static ScopeQuery< MO >::iterator issue(ScopeQuery< MO > const &query)
Automatically use custom string conversion in C++ stream output.
unsigned int uint
Definition integral.hpp:29
MObject in the Session to represent a clip on the timeline.
bool filter(Placement< DummyMO > const &candidate)
a filter predicate to pick some objects from a resultset.
PPIdx build_testScopes()
helper for tests: create a pseudo-session (actually just a PlacementIndex), which contains some neste...
std::shared_ptr< PlacementIndex > PPIdx
Namespace of Session and user visible high-level objects.
Definition sequence.hpp:65
@ CONTENTS
discover any contained objects depth-first
@ PARENTS
discover the enclosing scopes
@ CHILDREN
discover the immediate children
@ PATH
discover the path to root
_PickResult< FUNC >::FilterQuery pickAllSuitable(PlacementMO const &scope, FUNC predicate)
convenience shortcut to issue a SpecificContentsQuery, figuring out the actual return/filter type aut...
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Specific queries to explore contents of a scope within the high-level model.
Implementation level session API: query a scope.
Implementation facility to query and retrieve session context with filtering conditions.
static lumiera::QueryResolver const & getResolver()
Marker types to indicate a literal string and a Symbol.
Unit test helper to generate a system of nested test scopes.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...