LUMIERA.clone/tests/core/proc/mobject/session/placement-index-query-test.cpp
Ichthyostega 24b3bec4be Doxygen: prepare all unit tests for inclusion in the documentation
Doxygen will only process files with a @file documentation comment.
Up to now, none of our test code has such a comment, preventing the
cross-links to unit tests from working.

This is unfortunate, since unit tests, and even the code comments there,
can be considered as the most useful form of technical documentation.
Thus I'll start an initiative to fill in those missing comments automatically
2017-02-22 01:54:20 +01:00

125 lines
4.2 KiB
C++

/*
PlacementIndexQuery(Test) - querying the placement index through the generic query interface
Copyright (C) Lumiera.org
2009, Hermann Vosseler <Ichthyostega@web.de>
This program 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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* *****************************************************/
/** @file placement-index-query-test.cpp
** unit test §§TODO§§
*/
#include "lib/test/run.hpp"
#include "proc/mobject/session/scope-query.hpp"
#include "proc/mobject/session/session-service-explore-scope.hpp"
#include "proc/mobject/session/placement-index-query-resolver.hpp"
#include "proc/mobject/session/test-scopes.hpp"
#include "common/query/query-resolver.hpp"
#include "lib/format-cout.hpp"
#include "lib/util.hpp"
namespace proc {
namespace mobject {
namespace session {
namespace test {
using lumiera::QueryResolver;
using session::PathQuery;
using session::ContentsQuery;
using util::isSameObject;
/************************************************************************//**
* @test accessing the PlacementIndex through the generic query interface,
* for discovering scope contents and containing scope.
*
* @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 PlacementIndexQuery_test : public Test
{
virtual void
run (Arg)
{
checkQueryResolver();
checkQueryOperations();
}
void
checkQueryResolver()
{
PPIdx index = build_testScopes();
QueryResolver const& resolver1 (SessionServiceExploreScope::getResolver());
QueryResolver const& resolver2 (SessionServiceExploreScope::getResolver());
CHECK (isSameObject (resolver1, resolver2));
PlacementMO& root1 = index->getRoot();
PlacementMO& root2 = SessionServiceExploreScope::getScopeRoot();
CHECK (isSameObject (root1, root2));
PlacementMO& elm1 = *ContentsQuery<TestSubMO2>(root1).resolveBy(resolver1);
PlacementMO& elm2 = *ContentsQuery<TestSubMO1>(root1).resolveBy(resolver1);
PlacementMO& elm3 = *(index->getReferrers(elm1));
CHECK (isSameObject (elm3, elm2));
// relying on the specific setup of the test index
// MO1 is the sole "referrer" of MO2 (the only content within MO2's scope)
// root \ TestSubMO2 \ TestSubMO1
}
void
checkQueryOperations()
{
// Prepare an (test)Index (dummy "session")
PPIdx index = build_testScopes();
PlacementMO& root = index->getRoot();
PlacementIndexQueryResolver resolver(*index);
cout << "explore contents depth-first..." << endl;
discover (ContentsQuery<MObject>(root).resolveBy(resolver));
PlacementMO& elm = *ContentsQuery<TestSubMO1>(root).resolveBy(resolver); ////////////////////// TICKET #532
cout << "path to root starting at " << elm << endl;
discover (PathQuery<MObject> (elm).resolveBy(resolver));
}
template<class IT>
void
discover (IT result)
{
for ( ; result; ++result)
cout << *result << endl;
}
};
/** Register this test class... */
LAUNCHER (PlacementIndexQuery_test, "unit session");
}}}} // namespace proc::mobject::session::test