LocationSolver: draft the simple usage scenario (unit test) (#1127)
This commit is contained in:
parent
1238d416fc
commit
bf314482da
5 changed files with 75 additions and 18 deletions
|
|
@ -42,12 +42,12 @@
|
|||
#define GUI_INTERACT_UI_LOCATION_SOLVER_H
|
||||
|
||||
#include "lib/error.hpp"
|
||||
//#include "lib/symbol.hpp"
|
||||
#include "lib/symbol.hpp"
|
||||
//#include "lib/meta/function.hpp"
|
||||
//#include "lib/meta/tuple-helper.hpp"
|
||||
//#include "lib/meta/function-closure.hpp"
|
||||
#include "gui/interact/ui-coord.hpp"
|
||||
//#include "gui/interact/ui-coord-resolver.hpp"
|
||||
#include "gui/interact/ui-coord-resolver.hpp"
|
||||
|
||||
//#include <functional>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
|
@ -60,6 +60,16 @@ namespace interact {
|
|||
|
||||
// using std::forward;
|
||||
using std::move;
|
||||
using lib::Symbol;
|
||||
|
||||
|
||||
class LocationQuery;
|
||||
using LocationQueryAccess = std::function<LocationQuery&()>;
|
||||
|
||||
/** @internal access UI service to query and discover locations within UI topology */
|
||||
extern LocationQueryAccess loactionQuery;
|
||||
|
||||
|
||||
|
||||
class LocationClause
|
||||
: boost::noncopyable
|
||||
|
|
@ -141,14 +151,23 @@ namespace interact {
|
|||
// ctrl::GlobalCtx& globals_;
|
||||
|
||||
public:
|
||||
UILocationSolver()
|
||||
explicit
|
||||
UILocationSolver (LocationQueryAccess)
|
||||
{ }
|
||||
|
||||
explicit
|
||||
UILocationSolver (LocationQuery&)
|
||||
{ }
|
||||
|
||||
|
||||
/**
|
||||
* Access and possibly create _just some_ component view of the desired type
|
||||
*/
|
||||
UICoord solve();
|
||||
UICoord
|
||||
solve (LocationRule& rule, size_t depth, Symbol elementName)
|
||||
{
|
||||
UNIMPLEMENTED ("actually solve for a location according to the given rule");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ namespace interact {
|
|||
|
||||
ViewLocator::ViewLocator (ctrl::GlobalCtx& uiTopLevel, LocationQueryAccess getLocQuery)
|
||||
: globals_{uiTopLevel}
|
||||
, locResolver_{new UILocationSolver}
|
||||
, locResolver_{new UILocationSolver{getLocQuery}}
|
||||
{
|
||||
locationQuery = getLocQuery;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,6 @@ namespace interact {
|
|||
|
||||
using std::unique_ptr;
|
||||
// using std::string;
|
||||
class LocationQuery;
|
||||
using LocationQueryAccess = std::function<LocationQuery&()>;
|
||||
|
||||
class UILocationSolver;
|
||||
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@
|
|||
#include "lib/meta/function.hpp"
|
||||
#include "lib/meta/tuple-helper.hpp"
|
||||
#include "lib/meta/function-closure.hpp"
|
||||
#include "gui/interact/ui-location-solver.hpp"
|
||||
#include "gui/interact/ui-coord.hpp"
|
||||
|
||||
#include <functional>
|
||||
|
|
@ -113,12 +114,6 @@ namespace interact {
|
|||
|
||||
using std::forward;
|
||||
|
||||
class LocationQuery;
|
||||
|
||||
using LocationQueryAccess = std::function<LocationQuery&()>;
|
||||
|
||||
/** @internal access UI service to query and discover locations within UI topology */
|
||||
extern LocationQueryAccess loactionQuery;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@
|
|||
|
||||
#include "lib/test/run.hpp"
|
||||
#include "lib/test/test-helper.hpp"
|
||||
#include "gui/interact/view-spec-dsl.hpp"
|
||||
#include "gui/interact/ui-coord.hpp"
|
||||
#include "gui/interact/ui-location-solver.hpp"
|
||||
#include "gui/interact/gen-node-location-query.hpp"
|
||||
#include "lib/format-cout.hpp"
|
||||
//#include "lib/idi/entry-id.hpp"
|
||||
//#include "lib/diff/gen-node.hpp"
|
||||
|
|
@ -37,11 +38,15 @@
|
|||
//#include <string>
|
||||
|
||||
|
||||
//using std::string;
|
||||
using std::string;
|
||||
using lib::diff::MakeRec;
|
||||
using lib::diff::Rec;
|
||||
//using lib::Symbol;
|
||||
//using util::join;
|
||||
//using lib::idi::EntryID;
|
||||
//using lib::diff::GenNode;
|
||||
//using util::isSameObject;
|
||||
//using util::isnil;
|
||||
using util::isnil;
|
||||
|
||||
|
||||
namespace gui {
|
||||
|
|
@ -49,7 +54,7 @@ namespace interact {
|
|||
namespace test {
|
||||
|
||||
// using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
|
||||
using lib::test::showSizeof;
|
||||
// using lib::test::showSizeof;
|
||||
|
||||
namespace { //Test fixture...
|
||||
|
||||
|
|
@ -83,13 +88,53 @@ namespace test {
|
|||
}
|
||||
|
||||
|
||||
/** @test demonstrate the typical invocation and usage" */
|
||||
void
|
||||
simple_usage_example()
|
||||
{
|
||||
UNIMPLEMENTED ("demonstrate the typical invocation and usage");
|
||||
//-------------------------------------------------------------Test-Fixture
|
||||
// a Test dummy placeholder for the real UI structure
|
||||
Rec dummyUiStructure = MakeRec()
|
||||
.set("window-1"
|
||||
, MakeRec()
|
||||
.type("perspective-A")
|
||||
.set("exclusivePanel", MakeRec())
|
||||
);
|
||||
// helper to answer "location queries" backed by this structure
|
||||
GenNodeLocationQuery locationQuery{dummyUiStructure};
|
||||
//--------------------------------------------------------------(End)Test-Fixture
|
||||
|
||||
|
||||
// our test subject....
|
||||
UILocationSolver solver{locationQuery};
|
||||
|
||||
// a rule to probe (meaning: attach it at the "shoddy" panel)
|
||||
LocationRule rule{UICoord().panel("shoddy")};
|
||||
|
||||
// Now ask for a location to attach a view named "worldview" at the "shoddy" panel
|
||||
// No solution can be found, since there is no "shoddy" panel
|
||||
CHECK (isnil (solver.solve (rule, UIC_VIEW, "worldview")));
|
||||
|
||||
// add second location clause to the rule
|
||||
// (meaning: accept any suitable location within the first window)
|
||||
rule.append(UICoord::firstWindow());
|
||||
|
||||
// and now we get a solution, since the second rule can be wildcard-matched
|
||||
UICoord location = solver.solve (rule, UIC_VIEW, "worldview");
|
||||
CHECK (not isnil (location));
|
||||
|
||||
// the full solution filled in the missing parts and added the new view on top
|
||||
CHECK ("UI:window-1[perspective-A]-exclusivePanel.worldview" == string(location));
|
||||
|
||||
// NOTE: the new view does not (yet) exist, but the preceding part can be "covered"
|
||||
// To verify this, we attach a coordinate resolver (likewise backed by our dummy UI)
|
||||
UICoordResolver resolver{location, locationQuery};
|
||||
CHECK (resolver.isCoveredPartially());
|
||||
CHECK (UIC_PANEL == resolver.coverDepth());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
verify_cornerCases()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue