Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
session-element-query-test.cpp
Go to the documentation of this file.
1/*
2 SessionElementQuery(Test) - querying and retrieving elements from the session
3
4 Copyright (C)
5 2010, 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/util.hpp"
26
27#include <functional>
28#include <string>
29
30
31
32namespace steam {
33namespace mobject {
34namespace session {
35namespace test {
36
37 using std::placeholders::_1;
38 using std::function;
39 using std::bind;
40 using std::string;
41
42 using util::contains;
43
44
45 namespace { // helpers and shortcuts....
46
47 typedef Placement<DummyMO> const& PDummy; // note const& required by ElementQuery filter definition
48
49
55 inline function<bool(PDummy)>
56 elementID_contains (string expectedText)
57 {
58 return [=] (PDummy candidate)
59 {
60 REQUIRE (candidate.isValid());
61 string desc(candidate->operator string());
62 return contains(desc, expectedText);
63 };
64 }
65
66 }
67
68
69
70 /******************************************************************************************/
85 class SessionElementQuery_test : public Test
86 {
87 virtual void
88 run (Arg)
89 {
90 // Prepare an (test)Index (dummy "session")
91 PPIdx testSession (build_testScopes());
92
93 ElementQuery queryAPI;
94
95 MORef<DummyMO> dummy1 = queryAPI.pick (elementID_contains("MO2"));
96 CHECK (dummy1);
97 CHECK (dummy1->isValid());
98 INFO (test, "Location in Tree: %s", cStr(ScopePath(dummy1.getPlacement())));
99
100 string elementID = dummy1->operator string();
101 CHECK (contains (elementID, "MO2"));
102
103 string specificID = elementID.substr(10); // should contain the random int-ID
104 MORef<DummyMO> dummy2;
105 CHECK (!dummy2);
106 dummy2 = queryAPI.pick (elementID_contains(specificID));
107 CHECK (dummy2); // found the same object again
108 CHECK (dummy2->isValid());
109 CHECK (dummy2 == dummy1);
110
111
112 // put aside a new handle holding onto the MObject
113 PDum newPlacement(dummy1.getPlacement());
114 CHECK (testSession->contains(dummy1));
115 CHECK (!testSession->contains(newPlacement));
116
117 // and now remove the placement and all contained elements
118 testSession->clear (dummy1);
119 CHECK (!testSession->contains(dummy1));
120
121 MORef<DummyMO> findAgain = queryAPI.pick (elementID_contains(specificID));
122 CHECK (!findAgain); // empty result because searched element was removed from session...
123
124 MORef<DummyMO> otherElm = queryAPI.pick (elementID_contains("MO21"));
125 CHECK (otherElm); // now pick just some other arbitrary element
126
127 testSession->insert(newPlacement, otherElm);
128 dummy2 = queryAPI.pick (elementID_contains(specificID));
129 CHECK (dummy2);
130 CHECK (dummy2 != dummy1);
131 CHECK (dummy2 != newPlacement);
132 CHECK (isSharedPointee(newPlacement, dummy2.getPlacement()));
133 CHECK (Scope::containing (dummy2.getRef()) == Scope (otherElm));
134 INFO (test, "New treelocation: %s", cStr(ScopePath(dummy2.getPlacement())));
135 }
136 };
137
138
139
141 LAUNCHER (SessionElementQuery_test, "function session");
142
143
144}}}} // namespace steam::mobject::session::test
An active (smart-ptr like) external reference to a specifically placed MObject "instance" within the ...
PlacementRef< MO > const & getRef() const
allow to use a MObjectRef like a (bare) PlacementRef
Placement< MO > & getPlacement() const
A refcounting Handle to an MObject of type MO, used to constrain or explicitly specify the location w...
Access point to session global search and query functions.
_PickRes< PRED >::Result pick(PRED const &searchPredicate)
pick the first element from session satisfying a predicate.
Sequence of nested scopes within the high-level model.
A Placement scope within the high-level-model.
Definition scope.hpp:70
static Scope containing(PlacementMO const &aPlacement)
discover the enclosing scope of a given Placement
Definition scope.cpp:184
Search and query services to discover contents of the session.
External MObject/Placement reference.
function< bool(PDummy)> elementID_contains(string expectedText)
a filter predicate to pick some objects from a resultset, based on string match with the element's se...
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
TestPlacement< DummyMO > PDummy
bool isSharedPointee(MORef< MOX > const &ref1, MORef< MOY > const &ref2)
check if the two references actually share ownership on the same underlying MObject (as opposed to re...
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
An Object representing a sequence of nested scopes within the Session.
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition symbol.hpp:60
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...