LUMIERA.clone/tests/gui/interact/ui-coord-resolver-test.cpp

215 lines
6.7 KiB
C++
Raw Normal View History

/*
UICoordResolver(Test) - resolve UI coordinates against actual topology
Copyright (C) Lumiera.org
2017, 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 ui-coord-resolver-test.cpp
** unit test \ref UICoordResolver_test
*/
#include "lib/test/run.hpp"
#include "lib/test/test-helper.hpp"
#include "gui/interact/ui-coord.hpp"
#include "gui/interact/ui-coord-resolver.hpp"
#include "gui/interact/gen-node-location-query.hpp"
#include "lib/diff/gen-node.hpp"
#include "lib/format-cout.hpp"/////////////////////////TODO RLY?
#include "lib/format-util.hpp"
//#include "lib/idi/entry-id.hpp"
//#include "lib/diff/gen-node.hpp"
#include "lib/util.hpp"
#include <string>
using std::string;
//using lib::idi::EntryID;
using lib::diff::MakeRec;
using lib::diff::Rec;
//using util::isSameObject;
using lib::Symbol;
using util::isnil;
using util::join;
namespace gui {
namespace interact {
namespace test {
// using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
using lumiera::error::LUMIERA_ERROR_INDEX_BOUNDS;
using lumiera::error::LUMIERA_ERROR_LOGIC;
namespace { //Test fixture...
}//(End)Test fixture
/******************************************************************************//**
* @test verify query and mutation of UICoord in relation to actual UI topology.
*
* @see UICoordResolver
* @see navigator.hpp
* @see ViewLocator
* @see UICoord_test
*/
class UICoordResolver_test : public Test
{
virtual void
run (Arg)
{
verify_simpleUsage();
verify_backingQuery();
verify_queryAnchor();
verify_queryCoverage();
verify_mutateAnchor();
verify_mutateCovered();
verify_mutateExtend();
}
/** @test introduction to UI coordinate resolution
* - use a backing "real" (dummy) data structure to resolve against
* - establish a suitable implementation of the LocationQuery interface
* - attach a resolver
* - have fun
*/
void
verify_simpleUsage()
{
// a Test dummy placeholder for the real UI structure
Rec dummyUiStructure = MakeRec().scope(
MakeRec().type("perspective-A")
.genNode("window-1"),
MakeRec().type("perspective-B")
.scope(
MakeRec().genNode("panelX")
).genNode("window-2")
);
// helper to answer "location queries" backed by this structure
GenNodeLocationQuery locationQuery{dummyUiStructure};
UICoord uic{"window-1","*","panelX","someView"};
UICoordResolver resolver{uic, locationQuery};
CHECK (not resolver.isCovered());
CHECK (not resolver.canCover());
UICoord uic2 = resolver.cover()
.extend("otherView");
CHECK ("UI:window-2[perspective-B]-panelX.otherView" == string(uic2));
}
void
verify_backingQuery()
{
UNIMPLEMENTED ("verify the command-and-query interface backing the resolver");
}
/** @test query anchorage of given UI coordinates.
* - an anchored UI coordinate spec explicitly rooted within a top level window.
*/
void
verify_queryAnchor()
{
GenNodeLocationQuery loQu{MakeRec().scope(
MakeRec().type("perspective-A")
.genNode("window-1"),
MakeRec().type("perspective-B")
.scope(
MakeRec()
.scope(
MakeRec()
.genNode("someView")
).genNode("panelX")
).genNode("window-2")
)};
UICoord uic1 = UICoord::window("window-1").persp("perspective-A");
UICoord uic2 = UICoord::window("windows");
UICoord uic3 = UICoord::firstWindow();
UICoord uic4 = UICoord::currentWindow().persp("perspective-B");
UICoord uic5 = UICoord::currentWindow().panel("panelY");
UICoord uic6 = UICoord().view("someView").path("α/β/γ");
UICoordResolver r1{uic1, loQu};
UICoordResolver r2{uic2, loQu};
UICoordResolver r3{uic3, loQu};
UICoordResolver r4{uic4, loQu};
UICoordResolver r5{uic5, loQu};
UICoordResolver r6{uic6, loQu};
CHECK ( r1.isAnchored());
CHECK (not r2.isAnchored());
CHECK ( r3.isAnchored());
CHECK ( r4.isAnchored());
CHECK (not r5.isAnchored());
CHECK (not r6.isAnchored());
CHECK ( r1.canAnchor());
CHECK (not r2.canAnchor());
CHECK ( r3.canAnchor());
CHECK ( r4.canAnchor());
CHECK (not r5.canAnchor());
CHECK ( r6.canAnchor());
}
void
verify_queryCoverage()
{
UNIMPLEMENTED ("query coverage of given UI coordinates with respect to actual UI");
}
void
verify_mutateAnchor()
{
UNIMPLEMENTED ("mutate given UI coordinates by anchoring them");
}
void
verify_mutateCovered()
{
UNIMPLEMENTED ("mutate given UI coordinates by reducing to covered part");
}
void
verify_mutateExtend()
{
UNIMPLEMENTED ("mutate given UI coordinates by uncovered extension");
}
};
/** Register this test class... */
LAUNCHER (UICoordResolver_test, "unit gui");
}}} // namespace gui::interact::test