LUMIERA.clone/tests/core/steam/mobject/session/scope-query-test.cpp
Ichthyostega 806db414dd Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
 * there is no entity "Lumiera.org" which holds any copyrights
 * Lumiera source code is provided under the GPL Version 2+

== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''

The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!

The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00

142 lines
5 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
ScopeQuery(Test) - running queries to discover container contents, filtering (sub)types
Copyright (C)
2009, Hermann Vosseler <Ichthyostega@web.de>
  **Lumiera** is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the
  Free Software Foundation; either version 2 of the License, or (at your
  option) any later version. See the file COPYING for further details.
* *****************************************************************/
/** @file scope-query-test.cpp
** unit test \ref ScopeQuery_test
*/
#include "lib/test/run.hpp"
#include "steam/mobject/session/scope-query.hpp"
#include "steam/mobject/session/specific-contents-query.hpp"
#include "steam/mobject/session/session-service-explore-scope.hpp"
#include "steam/mobject/session/test-scopes.hpp"
#include "steam/mobject/session/clip.hpp"
#include "lib/format-cout.hpp"
#include "lib/symbol.hpp"
#include "lib/util.hpp"
#include <string>
namespace steam {
namespace mobject {
namespace session {
namespace test {
using util::contains;
using lib::Literal;
using std::string;
namespace { // helpers and shortcuts....
/** a filter predicate to pick some objects from a resultset.
* @note using the specific API of DummyMO, without cast! */
bool
filter (Placement<DummyMO> const& candidate)
{
string desc = candidate->operator string();
return contains(desc, "MO2");
}
template<class IT>
void
pullOut (IT const& iter)
{
for (IT elm(iter);
elm; ++elm)
cout << *elm << endl;
}
void
announce (Literal description)
{
static uint nr(0);
cout << "--------------------------------Test-"<< ++nr << ": " << description << endl;
}
}
/******************************************************************************************//**
* @test how to discover contents or location of a container-like part of the high-level model.
* As this container-like object is just a concept and actually implemented by the
* PlacementIndex, this means querying the index for elements registered with
* a given scope or finding the enclosing scopes. The discovered
* elements will be filtered by a runtime type check.
*
* @todo change that to use a more realistic test session, based on the actual model types //////////////// TICKET #532
*
* @see mobject::session::PlacementIndex
* @see mobject::session::QueryResolver
* @see mobject::session::ContentsQuery
*/
class ScopeQuery_test : public Test
{
virtual void
run (Arg)
{
// Prepare an (test)Index (dummy "session")
PPIdx testSession (build_testScopes());
PlacementMO const& scope = SessionServiceExploreScope::getScopeRoot();
discover (ScopeQuery<MObject> (scope, CONTENTS) , "contents depth-first");
discover (ScopeQuery<Clip> (scope, CONTENTS) , "contents depth-first, filtered to Clip");
discover (ScopeQuery<DummyMO> (scope, CONTENTS) , "contents depth-first, filtered to DummyMO"); ////////////////////// TICKET #532
discover (ScopeQuery<TestSubMO1> (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO1");
discover (ScopeQuery<TestSubMO2> (scope, CONTENTS) , "contents depth-first, filtered to TestSubMO2");
discover (pickAllSuitable(scope, filter) , "contents depth-first, custom filtered DummyMO");
// note filter is typed to accept DummyMO
ScopeQuery<TestSubMO21> allM021(scope, CONTENTS);
ScopeQuery<TestSubMO21>::iterator specialEl (issue(allM021));
++specialEl; // step in to second solution found...
CHECK (specialEl);
discover (ScopeQuery<MObject> (*specialEl, PARENTS) , "parents of the second TestSubMO2 element found");
discover (ScopeQuery<MObject> (*specialEl, CHILDREN), "children of the this TestSubMO2 element");
discover (ScopeQuery<MObject> (*specialEl, PATH) , "path from there to root");
discover (ScopeQuery<TestSubMO2> (*specialEl, PATH) , "same path, but filtered to TestSubMO2");
announce ( "continue exploring partially used TestSubMO2 iterator");
pullOut (specialEl);
}
template<class MO>
static void
discover (ScopeQuery<MO> const& query, Literal description)
{
announce (description);
pullOut (issue(query));
}
template<class MO>
static typename ScopeQuery<MO>::iterator
issue (ScopeQuery<MO> const& query)
{
return query.resolveBy(SessionServiceExploreScope::getResolver());
}
};
/** Register this test class... */
LAUNCHER (ScopeQuery_test, "unit session");
}}}} // namespace steam::mobject::session::test