2018-02-01 23:08:43 +01:00
/*
UILocationSolver ( Test ) - verify mechanics of a DSL to configure view allocation
Copyright ( C ) Lumiera . org
2018 , 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 0213 9 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2018-04-04 03:29:26 +02:00
/** @file ui-location-solver-test.cpp
2018-02-01 23:08:43 +01:00
* * unit test \ ref UILocationSolver_test
*/
# include "lib/test/run.hpp"
# include "lib/test/test-helper.hpp"
# include "gui/interact/ui-coord.hpp"
2018-02-08 00:37:02 +01:00
# include "gui/interact/ui-location-solver.hpp"
2018-04-07 02:28:29 +02:00
# include "gen-node-location-query.hpp"
2018-02-16 07:34:48 +01:00
# include "lib/format-cout.hpp"
2018-02-01 23:08:43 +01:00
2018-02-16 07:34:48 +01:00
# include <string>
2018-02-01 23:08:43 +01:00
2018-02-08 00:37:02 +01:00
using std : : string ;
using lib : : diff : : MakeRec ;
using lib : : diff : : Rec ;
2018-02-16 07:34:48 +01:00
2018-02-08 00:37:02 +01:00
using util : : isnil ;
2018-02-01 23:08:43 +01:00
namespace gui {
namespace interact {
namespace test {
/******************************************************************************/ /**
2018-02-17 03:45:07 +01:00
* @ test verify a mechanism to resolve the desired location of an UI - element .
2018-02-01 23:08:43 +01:00
* The UILocationSolver is operated by the ViewLocator service , which itself
* is part of the InteractionDirector . In typical usage , the location rules
* are drawn from the [ ViewSpec - DSL ] ( \ ref view - spec - dsl . hpp ) , evaluated
* with the help of a [ Coordinate Resolver ] ( \ ref UICoordResolver ) , based on
* the real UI topology existing at that moment , accessible in abstracted
2018-02-07 03:11:12 +01:00
* form through the LocationQuery interface . This test setup here mimics that
2018-02-01 23:08:43 +01:00
* invocation scheme , but replaces the real UI by an abstract tree notation
* embedded directly into the individual test cases .
*
* @ see ui - location - solver . hpp
* @ see view - spec - dsl . hpp
* @ see UICoordResolver_test
*/
class UILocationSolver_test : public Test
{
virtual void
run ( Arg )
{
simple_usage_example ( ) ;
verify_cornerCases ( ) ;
verify_standardSituations ( ) ;
}
2018-04-04 03:29:26 +02:00
/** @test demonstrate the typical invocation and usage */
2018-02-01 23:08:43 +01:00
void
simple_usage_example ( )
{
2018-02-08 00:37:02 +01:00
//-------------------------------------------------------------Test-Fixture
// a Test dummy placeholder for the real UI structure
Rec dummyUiStructure = MakeRec ( )
. set ( " window-1 "
, MakeRec ( )
2018-02-17 03:45:07 +01:00
. type ( " perspective " )
2018-02-08 00:37:02 +01:00
. 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
2018-02-10 00:34:24 +01:00
// (meaning: accept any path leading down to an "exclusivePanel")
rule . append ( UICoord ( ) . panel ( " exclusivePanel " ) ) ;
2018-02-08 00:37:02 +01:00
// 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
2018-02-17 03:45:07 +01:00
CHECK ( " UI:window-1[perspective]-exclusivePanel.worldview " = = string ( location ) ) ;
2018-02-08 00:37:02 +01:00
// 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 ( ) ) ;
2018-02-10 00:34:24 +01:00
CHECK ( not resolver . isCoveredTotally ( ) ) ;
CHECK ( UIC_VIEW = = resolver . coverDepth ( ) ) ; // covered up to VIEW level
} // (the view itself is not covered)
2018-02-01 23:08:43 +01:00
2018-02-08 00:37:02 +01:00
2018-02-11 02:34:56 +01:00
/** @test cover theoretical corner cases regarding the process of location solving.
2018-02-16 07:34:48 +01:00
* Point in question are the requirements and limits when querying against one or several
2018-02-11 02:34:56 +01:00
* location specification clauses . The actual matching of a location pattern against a UI topology
* is beyond scope and covered [ elsewhere ] ( \ ref UICoordResolver_test : : verify_mutateCoverage )
* - empty clauses act as neutral element
* - prerequisites regarding the depth of a location clause relevant for solution
* - the impact of the query and especially its expected depth
* - completely explicit clauses vs clauses with wildcards
* - relevance of partial or total coverage for the solution
* - regular clauses vs . _create clauses_ ( which mandate creating parents as needed )
* - usage of the first applicable solution when several clauses are given
*/
2018-02-01 23:08:43 +01:00
void
verify_cornerCases ( )
{
2018-02-11 02:34:56 +01:00
//-------------------------------------------------------------Test-Fixture
GenNodeLocationQuery tree { MakeRec ( )
. set ( " win "
, MakeRec ( )
. type ( " A " )
. set ( " thePanel "
, MakeRec ( )
. set ( " theView "
, MakeRec ( )
. set ( " #5 "
, MakeRec ( )
2018-02-14 03:02:44 +01:00
. set ( " up " , MakeRec ( ) )
2018-02-11 02:34:56 +01:00
. set ( " down "
, MakeRec ( )
. set ( " the "
, MakeRec ( )
. set ( " kitchen "
, MakeRec ( )
. set ( " sink " , MakeRec ( ) )
)
)
)
)
)
)
) } ;
UILocationSolver solver { tree } ;
//--------------------------------------------------------------(End)Test-Fixture
2018-02-10 02:03:09 +01:00
/* === empty clause === */
2018-02-11 04:00:59 +01:00
LocationRule r1 { UICoord ( ) } ;
2018-02-11 02:34:56 +01:00
CHECK ( isnil ( solver . solve ( r1 , UIC_PATH , " to/salvation " ) ) ) ;
2018-02-11 04:36:11 +01:00
CHECK ( isnil ( solver . solve ( r1 , UIC_WINDOW , " redemption " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === empty clause is neutral === */
2018-02-11 04:00:59 +01:00
r1 . append ( UICoord ( ) . path ( " down/to " ) . create ( ) ) ;
auto s1 = solver . solve ( r1 , UIC_PATH + 2 , " hell " ) ;
2018-02-11 04:36:11 +01:00
CHECK ( " UI:win[A]-thePanel.theView.#5/down/to/hell " = = string { s1 } ) ;
2018-02-10 02:03:09 +01:00
/* === clause too short === */
2018-02-11 04:16:58 +01:00
LocationRule r2 { UICoord ( ) . path ( " down/the " ) } ;
CHECK ( isnil ( solver . solve ( r2 , UIC_PATH + 3 , " sink " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === clause too long === */
2018-02-11 04:16:58 +01:00
CHECK ( isnil ( solver . solve ( r2 , UIC_VIEW , " theView " ) ) ) ;
CHECK ( not isnil ( solver . solve ( r2 , UIC_PATH + 1 , " any " ) ) ) ;
CHECK ( not isnil ( solver . solve ( r2 , UIC_PATH + 2 , " kitchen " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === query on existing window === */
2018-02-11 04:36:11 +01:00
LocationRule r31 { UICoord : : window ( " win " ) } ;
CHECK ( " UI:win " = = string { solver . solve ( r31 , UIC_WINDOW , " wigwam " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on generic window spec === */
2018-02-11 04:36:11 +01:00
LocationRule r32 { UICoord : : currentWindow ( ) } ;
CHECK ( " UI:win " = = string { solver . solve ( r32 , UIC_WINDOW , " wigwam " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on non existing window === */
2018-02-11 04:36:11 +01:00
LocationRule r33 { UICoord : : window ( " lindows " ) } ;
CHECK ( isnil ( solver . solve ( r33 , UIC_WINDOW , " wigwam " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === query on existing window with create clause === */
2018-02-11 04:36:11 +01:00
LocationRule r34 { UICoord : : window ( " win " ) . create ( ) } ;
CHECK ( " UI:win " = = string { solver . solve ( r34 , UIC_WINDOW , " wigwam " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on non existing window with create clause === */
2018-02-11 04:36:11 +01:00
LocationRule r35 { UICoord : : window ( " windux " ) . create ( ) } ;
CHECK ( " UI:windux " = = string { solver . solve ( r35 , UIC_WINDOW , " wigwam " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on existing perspective === */
2018-02-13 01:51:51 +01:00
LocationRule r41 { UICoord ( ) . persp ( " A " ) } ;
CHECK ( " UI:win[A] " = = string { solver . solve ( r41 , UIC_PERSP , " x " ) } ) ;
CHECK ( " UI:win[A]-x " = = string { solver . solve ( r41 , UIC_PANEL , " x " ) } ) ;
2018-02-10 02:03:09 +01:00
2018-02-17 03:45:07 +01:00
/* === query on elided perspective ("just any existing") === */
2018-02-13 01:51:51 +01:00
LocationRule r42 { UICoord ( ) . persp ( UIC_ELIDED ) } ;
2018-02-16 07:34:48 +01:00
CHECK ( " UI:win[A] " = = string { solver . solve ( r42 , UIC_PERSP , " x " ) } ) ;
CHECK ( " UI:win[A]-x " = = string { solver . solve ( r42 , UIC_PANEL , " x " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on non existing perspective === */
2018-02-13 01:51:51 +01:00
LocationRule r43 { UICoord : : firstWindow ( ) . persp ( " Ω " ) } ;
CHECK ( isnil ( solver . solve ( r43 , UIC_PERSP , " x " ) ) ) ;
CHECK ( isnil ( solver . solve ( r43 , UIC_PANEL , " x " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === query on non existing perspective with create clause === */
2018-02-13 01:51:51 +01:00
LocationRule r44 { UICoord : : firstWindow ( ) . persp ( " Ω " ) . create ( ) } ;
CHECK ( " UI:win[Ω] " = = string { solver . solve ( r44 , UIC_PERSP , " x " ) } ) ;
CHECK ( " UI:win[Ω]-x " = = string { solver . solve ( r44 , UIC_PANEL , " x " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on deep path covered === */
2018-02-13 02:46:43 +01:00
LocationRule r51 { UICoord ( " firstWindow " , " A " , " thePanel " , " theView " , " #5 " , " down " , " the " , " kitchen " ) } ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/kitchen " = = string { solver . solve ( r51 , UIC_PATH + 2 , " drain " ) } ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/kitchen/drain " = = string { solver . solve ( r51 , UIC_PATH + 3 , " drain " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on deep path covered with create clause === */
2018-02-13 02:46:43 +01:00
LocationRule r52 { UICoord : : firstWindow ( ) . append ( " A/thePanel/theView/#5/down/the/kitchen " ) . create ( ) } ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/kitchen " = = string { solver . solve ( r52 , UIC_PATH + 2 , " drain " ) } ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/kitchen/drain " = = string { solver . solve ( r52 , UIC_PATH + 3 , " drain " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on deep path partially covered === */
2018-02-13 02:46:43 +01:00
LocationRule r53 { UICoord : : firstWindow ( ) . append ( " A/thePanel/theView/#5/down/the/drain " ) } ;
CHECK ( isnil ( solver . solve ( r53 , UIC_PATH + 2 , " drain " ) ) ) ;
CHECK ( isnil ( solver . solve ( r53 , UIC_PATH + 3 , " drain " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === query on deep path partially covered with create clause === */
2018-02-13 02:46:43 +01:00
LocationRule r54 { UICoord : : firstWindow ( ) . append ( " A/thePanel/theView/#5/down/the/drain " ) . create ( ) } ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/drain " = = string { solver . solve ( r54 , UIC_PATH + 2 , " drain " ) } ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/drain/drain " = = string { solver . solve ( r54 , UIC_PATH + 3 , " drain " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === query on deep path uncovered === */
2018-02-13 02:46:43 +01:00
LocationRule r55 { UICoord ( " rearWindow " , " A " , " thePanel " , " theView " , " #5 " , " down " , " the " , " kitchen " ) } ;
CHECK ( isnil ( solver . solve ( r55 , UIC_PATH + 2 , " floor " ) ) ) ;
CHECK ( isnil ( solver . solve ( r55 , UIC_PATH + 3 , " floor " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === query on deep path uncovered with create clause === */
2018-02-13 02:46:43 +01:00
LocationRule r56 { UICoord ( " rearWindow " , " A " , " thePanel " , " theView " , " #5 " , " down " , " the " , " kitchen " ) . rebuild ( ) . create ( ) } ;
CHECK ( " UI:rearWindow[A]-thePanel.theView.#5/down/the/kitchen " = = string { solver . solve ( r56 , UIC_PATH + 2 , " floor " ) } ) ;
CHECK ( " UI:rearWindow[A]-thePanel.theView.#5/down/the/kitchen/floor " = = string { solver . solve ( r56 , UIC_PATH + 3 , " floor " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === clause with wildcard covered === */
2018-02-13 03:13:53 +01:00
LocationRule r61 { UICoord ( ) . path ( " //kitchen " ) } ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/kitchen " = = string { solver . solve ( r61 , UIC_PATH + 2 , " drain " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === clause with wildcard covered without final element === */
2018-02-13 03:13:53 +01:00
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/kitchen/drain " = = string { solver . solve ( r61 , UIC_PATH + 3 , " drain " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === create clause with wildcard completely covered === */
2018-02-13 03:13:53 +01:00
LocationRule r62 { UICoord ( ) . path ( " //kitchen " ) . create ( ) } ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/kitchen " = = string { solver . solve ( r62 , UIC_PATH + 2 , " window " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === create clause with wildcard covered without final element === */
2018-02-13 03:13:53 +01:00
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/kitchen/window " = = string { solver . solve ( r62 , UIC_PATH + 3 , " window " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === clause with wildcard partially covered === */
2018-02-13 03:13:53 +01:00
LocationRule r63 { UICoord ( ) . path ( " /the/road " ) } ;
CHECK ( isnil ( solver . solve ( r63 , UIC_PATH + 2 , " kitchen " ) ) ) ; //NOTE: .../down/the/kitchen would match, but actually .../down/the/road is tested, which fails
2018-02-10 02:03:09 +01:00
/* === create clause with wildcard partially covered === */
2018-02-13 03:13:53 +01:00
LocationRule r64 { UICoord ( ) . path ( " /the/road " ) . create ( ) } ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/the/road " = = string { solver . solve ( r64 , UIC_PATH + 2 , " drain " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === clause with wildcard uncovered === */
2018-02-13 03:13:53 +01:00
LocationRule r65 { UICoord ( ) . path ( " //road " ) } ;
CHECK ( isnil ( solver . solve ( r65 , UIC_PATH + 2 , " kitchen " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === create clause with wildcard uncovered === */
2018-02-13 03:13:53 +01:00
LocationRule r66 { UICoord ( ) . path ( " //road " ) . create ( ) } ;
CHECK ( isnil ( solver . solve ( r66 , UIC_PATH + 2 , " kitchen " ) ) ) ;
2018-02-10 02:03:09 +01:00
/* === two clauses both satisfied === */
2018-02-14 03:02:44 +01:00
LocationRule r71 { UICoord ( ) . path ( " down " ) } ;
r71 . append ( UICoord ( ) . path ( " up " ) ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/time " = = string { solver . solve ( r71 , UIC_PATH + 1 , " time " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === two clauses first one unsatisfied === */
2018-02-14 03:02:44 +01:00
LocationRule r72 { UICoord ( ) . path ( " up/the " ) } ;
r72 . append ( UICoord ( ) . path ( " down/ " ) ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/time " = = string { solver . solve ( r72 , UIC_PATH + 1 , " time " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === create clause first and satisfied === */
2018-02-14 03:02:44 +01:00
LocationRule r73 { UICoord ( ) . path ( " up/link " ) . create ( ) } ;
r73 . append ( UICoord ( ) . path ( " down/ " ) ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/up/link " = = string { solver . solve ( r73 , UIC_PATH + 1 , " time " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === create clause first and unsatisfied === */
2018-02-14 03:02:44 +01:00
LocationRule r74 { UICoord ( ) . path ( " cross/link " ) . create ( ) } ;
r74 . append ( UICoord ( ) . path ( " down/ " ) ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/time " = = string { solver . solve ( r74 , UIC_PATH + 1 , " time " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === create clause second but first clause satisfied === */
2018-02-14 03:02:44 +01:00
LocationRule r75 { UICoord ( ) . path ( " up/ " ) } ;
r75 . append ( UICoord ( ) . path ( " down/link " ) . create ( ) ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/up/time " = = string { solver . solve ( r75 , UIC_PATH + 1 , " time " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === create clause second and satisfied === */
2018-02-14 03:02:44 +01:00
LocationRule r76 { UICoord ( ) . path ( " up/link " ) } ;
r76 . append ( UICoord ( ) . path ( " down/link " ) . create ( ) ) ;
CHECK ( " UI:win[A]-thePanel.theView.#5/down/link " = = string { solver . solve ( r76 , UIC_PATH + 1 , " time " ) } ) ;
2018-02-10 02:03:09 +01:00
/* === create clause second and both unsatisfied === */
2018-02-14 03:02:44 +01:00
LocationRule r77 { UICoord ( ) . path ( " up/link " ) } ;
r77 . append ( UICoord ( ) . path ( " town/link " ) . create ( ) ) ;
CHECK ( isnil ( solver . solve ( r77 , UIC_PATH + 1 , " time " ) ) ) ;
2018-02-10 02:03:09 +01:00
2018-02-14 03:02:44 +01:00
CHECK ( string { r77 } = = " =~ .. UI:?/up/link "
" \n OR UI:?/town/link create! " ) ;
2018-02-01 23:08:43 +01:00
}
2018-02-14 04:42:19 +01:00
/** @test emulate the relevant standard situations of view location resolution.
* The typical location specifications to be expected in practice can be subsumed
* under a small selection of standard situations ; this test demonstrates how these
* are triggered by specific tree configurations in a ( hopefully ) obvious way .
*
* For this purpose , we create a single set of location clauses here , but evaluate them
* each time against different ( simulated ) UI tree configurations to verify that the expected
* resulting location is actually derived in all those cases .
*/
2018-02-01 23:08:43 +01:00
void
verify_standardSituations ( )
{
2018-02-14 04:42:19 +01:00
// Test Fixture: a solver which always queries the current state of a (simulated) uiTree
Rec uiTree ;
std : : unique_ptr < GenNodeLocationQuery > query ;
UILocationSolver solver { [ & ] ( ) - > GenNodeLocationQuery &
{
query . reset ( new GenNodeLocationQuery ( uiTree ) ) ;
return * query ;
} } ;
// Test Fixture: common set of location clauses
LocationRule location { UICoord ( ) . persp ( " edit " ) . panel ( " viewer " ) } ;
location . append ( UICoord : : currentWindow ( ) . panel ( " viewer " ) ) ;
location . append ( UICoord ( ) . panel ( " viewer " ) ) ;
2018-02-16 03:24:37 +01:00
// location.append (UICoord().tab("assetType()")); //////////////////////TICKET #1130 : do we want to support match based on invocation context (here: the type of the asset to be displayed)
2018-02-14 04:42:19 +01:00
location . append ( UICoord ( ) . persp ( " asset " ) . view ( " asset " ) ) ;
2018-02-16 07:34:48 +01:00
location . append ( UICoord ( ) . panel ( " asset " ) . view ( " asset " ) . create ( ) ) ;
2018-02-17 05:11:34 +01:00
location . append ( UICoord : : currentWindow ( ) . panel ( " viewer " ) . create ( ) ) ; //Note: especially for this kind of rule, .persp(UIC_ELIDED) is injected automatically
2018-02-16 01:59:51 +01:00
location . append ( UICoord : : window ( " meta " ) . persp ( " config " ) . panel ( " infobox " ) . view ( " inspect " ) . create ( ) ) ;
2018-02-14 04:42:19 +01:00
cout < < location < < endl ;
2018-02-10 02:03:09 +01:00
/* === match by perspective + panel === */
2018-02-14 04:42:19 +01:00
uiTree = MakeRec ( )
. set ( " win "
, MakeRec ( )
. type ( " edit " )
. set ( " viewer " , MakeRec ( ) ) ) ;
2018-02-16 01:59:51 +01:00
CHECK ( " UI:win[edit]-viewer.video " = = string { solver . solve ( location , UIC_VIEW , " video " ) } ) ;
2018-02-10 02:03:09 +01:00
2018-02-14 04:42:19 +01:00
/* === match by generic window + panel === */
2018-02-16 01:59:51 +01:00
uiTree = MakeRec ( )
. set ( " win "
, MakeRec ( )
. type ( " murky " )
. set ( " viewer " , MakeRec ( ) ) )
. set ( " woe "
, MakeRec ( )
. type ( " gloomy " )
. set ( " viewer " , MakeRec ( ) ) ) ;
CHECK ( " UI:woe[gloomy]-viewer.video " = = string { solver . solve ( location , UIC_VIEW , " video " ) } ) ; //Note: first rule does not match due to perspective
2018-02-10 02:03:09 +01:00
/* === match by panel alone === */
2018-02-16 01:59:51 +01:00
uiTree = MakeRec ( )
. set ( " win "
, MakeRec ( )
. type ( " murky " )
. set ( " viewer " , MakeRec ( ) ) )
. set ( " woe "
, MakeRec ( )
. type ( " gloomy " )
. set ( " timeline " , MakeRec ( ) ) ) ;
CHECK ( " UI:win[murky]-viewer.video " = = string { solver . solve ( location , UIC_VIEW , " video " ) } ) ; //Note: current window (==last one) has no "viewer"-panel
2018-02-10 02:03:09 +01:00
2018-02-16 01:59:51 +01:00
/* === wildcard match on explicit existing view === */
uiTree = MakeRec ( )
. set ( " win "
, MakeRec ( )
. type ( " shady " )
. set ( " timeline " , MakeRec ( ) ) )
. set ( " woe "
, MakeRec ( )
. type ( " asset " )
. set ( " panel "
, MakeRec ( )
. set ( " asset " , MakeRec ( ) )
) ) ;
CHECK ( " UI:woe[asset]-panel.asset " = = string { solver . solve ( location , UIC_VIEW , " video " ) } ) ; //Note: the 4th Rule matches on existing view "asset",
// in spite of our query demanding a view "video"
2018-02-16 03:24:37 +01:00
/* === wildcard match based on the type of entity to be displaced === */
2018-04-05 19:43:10 +02:00
# if false ///////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1130 : not yet possible. Match based on placeholder substituted from context
2018-02-16 03:24:37 +01:00
// uiTree = MakeRec()
// .set("win"
// , MakeRec()
// .type("shady")
// .set ("special"
// , MakeRec()
// .set ("asset",
// MakeRec()
// .set ("specialAsset", MakeRec())
// )
// ))
// .set("woe"
// , MakeRec()
// .type("asset")
// .set ("panel"
// , MakeRec()
// .set ("asset", MakeRec())
// ));
// CHECK ("UI:win[shady]-special.asset.specialAsset" == string{solver.solve (location, UIC_TAB, "specialAsset")});
// //Note: the next rule would match on the general asset panel
// // but this special rule allows to re-use a tab dedicated to specialAsset
2018-04-05 19:43:10 +02:00
# endif ///////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1130 : not yet possible. Match based on placeholder substituted from context
2018-02-10 02:03:09 +01:00
2018-02-16 07:34:48 +01:00
/* === create clause to build on a specific anchor point === */
2018-02-16 01:59:51 +01:00
uiTree = MakeRec ( )
. set ( " win "
, MakeRec ( )
. type ( " shady " )
2018-02-16 07:34:48 +01:00
. set ( " asset " , MakeRec ( ) )
) ;
auto solution = solver . solve ( location , UIC_TAB , " video " ) ; //Note: here the first "create"-rule is triggered: UI:?-asset.asset
CHECK ( " UI:win[shady]-asset.asset.video " = = string { solution } ) ; // It requires a panel("asset") to exist, but creates the rest;
CHECK ( 3 = = UICoordResolver ( solution , * query ) // indeed only the part up to the panel is detected as covered.
2018-02-16 01:59:51 +01:00
. coverDepth ( ) ) ;
2018-02-16 07:34:48 +01:00
//Note: the following test cases can not trigger this rule, since it
/* === match on create clause with generic window spec and panel === */ // contains leading wildcards and thus requires panel("asset")
2018-02-16 01:59:51 +01:00
uiTree = MakeRec ( )
. set ( " win "
, MakeRec ( )
. type ( " shady " )
. set ( " timeline " , MakeRec ( ) ) )
. set ( " woe "
, MakeRec ( )
. type ( " shoddy " ) ) ;
2018-02-16 07:34:48 +01:00
solution = solver . solve ( location , UIC_VIEW , " video " ) ;
CHECK ( " UI:woe[shoddy]-viewer.video " = = string { solution } ) ;
CHECK ( 2 = = UICoordResolver ( solution , * query ) //Note: only window and perspective are covered, the rest is to be created
. coverDepth ( ) ) ;
/* === completely uncovered create-from-scratch === */
solution = solver . solve ( location , UIC_TAB , " engine " ) ; //Note: same UI-tree, but this time we ask for a tab, so the previous rule
CHECK ( " UI:meta[config]-infobox.inspect.engine " = = string { solution } ) ; // is too short and thus the last catch-all rule gets triggered;
CHECK ( 0 = = UICoordResolver ( solution , * query ) //Note: result is indeed entirely uncovered (-> create from scratch)
2018-02-16 01:59:51 +01:00
. coverDepth ( ) ) ;
2018-02-01 23:08:43 +01:00
}
} ;
/** Register this test class... */
LAUNCHER ( UILocationSolver_test , " unit gui " ) ;
} } } // namespace gui::interact::test