From bf314482da4dac9ffbe0e435b2f9d2208baa73d4 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 8 Feb 2018 00:37:02 +0100 Subject: [PATCH] LocationSolver: draft the simple usage scenario (unit test) (#1127) --- src/gui/interact/ui-location-solver.hpp | 27 +++++++-- src/gui/interact/view-locator.cpp | 2 +- src/gui/interact/view-locator.hpp | 2 - src/gui/interact/view-spec-dsl.hpp | 7 +-- .../gui/interact/ui-location-solver-test.cpp | 55 +++++++++++++++++-- 5 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/gui/interact/ui-location-solver.hpp b/src/gui/interact/ui-location-solver.hpp index 4ab7366aa..1f1214365 100644 --- a/src/gui/interact/ui-location-solver.hpp +++ b/src/gui/interact/ui-location-solver.hpp @@ -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 #include @@ -60,6 +60,16 @@ namespace interact { // using std::forward; using std::move; + using lib::Symbol; + + + class LocationQuery; + using LocationQueryAccess = std::function; + + /** @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: diff --git a/src/gui/interact/view-locator.cpp b/src/gui/interact/view-locator.cpp index b783cabd3..64a980728 100644 --- a/src/gui/interact/view-locator.cpp +++ b/src/gui/interact/view-locator.cpp @@ -91,7 +91,7 @@ namespace interact { ViewLocator::ViewLocator (ctrl::GlobalCtx& uiTopLevel, LocationQueryAccess getLocQuery) : globals_{uiTopLevel} - , locResolver_{new UILocationSolver} + , locResolver_{new UILocationSolver{getLocQuery}} { locationQuery = getLocQuery; } diff --git a/src/gui/interact/view-locator.hpp b/src/gui/interact/view-locator.hpp index 6cd12ef49..4b9627f32 100644 --- a/src/gui/interact/view-locator.hpp +++ b/src/gui/interact/view-locator.hpp @@ -78,8 +78,6 @@ namespace interact { using std::unique_ptr; // using std::string; - class LocationQuery; - using LocationQueryAccess = std::function; class UILocationSolver; diff --git a/src/gui/interact/view-spec-dsl.hpp b/src/gui/interact/view-spec-dsl.hpp index 73ce3781a..ea8bf6e28 100644 --- a/src/gui/interact/view-spec-dsl.hpp +++ b/src/gui/interact/view-spec-dsl.hpp @@ -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 @@ -113,12 +114,6 @@ namespace interact { using std::forward; - class LocationQuery; - - using LocationQueryAccess = std::function; - - /** @internal access UI service to query and discover locations within UI topology */ - extern LocationQueryAccess loactionQuery; /** diff --git a/tests/gui/interact/ui-location-solver-test.cpp b/tests/gui/interact/ui-location-solver-test.cpp index 697adf055..dc9ba7d75 100644 --- a/tests/gui/interact/ui-location-solver-test.cpp +++ b/tests/gui/interact/ui-location-solver-test.cpp @@ -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 -//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() {