2017-09-09 23:30:44 +02:00
/*
ViewSpecDSL ( Test ) - verify mechanics of a DSL to configure view allocation
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 0213 9 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** @file view-spec-dsl-test.cpp
* * unit test \ ref ViewSpecDSL_test
*/
# include "lib/test/run.hpp"
2017-09-23 01:21:06 +02:00
# include "lib/test/test-helper.hpp"
2017-09-14 22:24:54 +02:00
# include "gui/interact/ui-coord.hpp"
2018-04-15 01:39:46 +02:00
# include "gui/interact/view-locator.hpp"
# include "gui/interact/view-spec-dsl.hpp"
2018-04-07 02:28:29 +02:00
# include "gen-node-location-query.hpp"
2018-04-15 01:39:46 +02:00
# include "test/test-element-access.hpp"
2018-04-05 01:09:13 +02:00
# include "lib/depend-inject.hpp"
2018-04-15 03:07:54 +02:00
# include "lib/format-cout.hpp" ////////////////TODO only while this test is under development
2017-09-09 23:30:44 +02:00
//#include "lib/idi/entry-id.hpp"
//#include "lib/diff/gen-node.hpp"
2018-06-15 18:02:08 +02:00
# include "lib/util.hpp"
2017-09-09 23:30:44 +02:00
//#include <string>
2018-04-05 01:09:13 +02:00
//#include <vector>
2017-09-09 23:30:44 +02:00
2018-04-05 01:09:13 +02:00
using std : : string ;
using lib : : diff : : MakeRec ;
using lib : : diff : : Rec ;
2017-09-09 23:30:44 +02:00
//using lib::idi::EntryID;
//using lib::diff::GenNode;
//using util::isSameObject;
//using util::isnil;
2018-06-15 18:02:08 +02:00
using util : : contains ;
2017-09-09 23:30:44 +02:00
2018-06-15 16:42:51 +02:00
namespace gui {
2018-04-15 01:39:46 +02:00
namespace idi { //------Mock ViewSpec definitions for component test
/* ==== Dummy ViewSpec rules for those two mock view types (--> see id-scheme.hpp) ==== */
template < >
2018-06-15 16:42:51 +02:00
struct Descriptor < test : : DummyView >
2018-04-15 01:39:46 +02:00
{
ViewSpec locate = UICoord : : currentWindow ( ) . panel ( " parentLocation " ) ;
Allocator alloc = limitAllocation ( 2 ) ;
} ;
} //----------------(End)Mock ViewSpec definitions
2017-09-09 23:30:44 +02:00
namespace interact {
namespace test {
// using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
2017-09-23 01:21:06 +02:00
using lib : : test : : showSizeof ;
2018-04-15 01:39:46 +02:00
using gui : : model : : ElementAccess ;
using gui : : test : : TestElementAccess ;
using gui : : test : : DummyWidget ;
using gui : : test : : DummyView ;
using gui : : test : : DummyTab ;
2017-09-09 23:30:44 +02:00
2018-04-05 01:09:13 +02:00
using MockLoationSolver = lib : : DependInject < UILocationSolver > : : Local < > ;
2018-04-15 01:39:46 +02:00
using MockElementAccess = lib : : DependInject < ElementAccess > : : Local < TestElementAccess > ;
2018-04-05 01:09:13 +02:00
2017-09-10 00:32:31 +02:00
namespace { //Test fixture...
} //(End)Test fixture
2017-09-09 23:30:44 +02:00
/******************************************************************************/ /**
* @ test verify the mechanics of a functor based internal DSL
* to configure access and allocation patters for component views .
*
* @ see id - scheme . hpp
* @ see ViewLocator
* @ see UICoord_test
*/
class ViewSpecDSL_test : public Test
{
virtual void
run ( Arg )
{
2018-01-13 01:38:43 +01:00
// verify_basicProperties();
2017-09-10 00:32:31 +02:00
verify_standardUsage ( ) ;
2018-04-15 01:39:46 +02:00
// verify_alternatives();
2018-04-05 19:43:10 +02:00
verify_genericInvocation ( ) ;
2017-09-10 00:32:31 +02:00
}
void
verify_basicProperties ( )
{
UNIMPLEMENTED ( " basic properties of the view spec DSL " ) ;
}
void
verify_standardUsage ( )
{
2018-04-05 01:09:13 +02:00
//-------------------------------------------------------------Test-Fixture
// a Test dummy placeholder for the real UI structure
Rec dummyUiStructure = MakeRec ( )
. set ( " win-1 "
, MakeRec ( )
. type ( " perspective " )
. set ( " parentLocation " , MakeRec ( ) )
) ;
// answer "location queries" backed by this structure
GenNodeLocationQuery locationQuery { dummyUiStructure } ;
MockLoationSolver mock ( [ & ] { return new UILocationSolver { locationQuery } ; } ) ;
//--------------------------------------------------------------(End)Test-Fixture
2017-09-14 22:24:54 +02:00
uint allocCounter = 0 ;
2017-09-23 01:21:06 +02:00
// Simulation/Example for an allocator-builder
AllocSpec < uint > limitAllocation = [ & ] ( UICoord target , uint limit )
{
if ( allocCounter < limit )
return target . tab ( + + allocCounter ) ;
else
return target . tab ( limit ) ;
} ;
// the actual View Specification would then be written as...
2018-02-23 05:07:39 +01:00
ViewSpec locate = UICoord : : currentWindow ( ) . panel ( " parentLocation " ) ;
2017-09-23 01:21:06 +02:00
Allocator alloc = limitAllocation ( 3 ) ;
// ...and it would be evaluated as follows
2018-02-23 05:07:39 +01:00
UICoord targetLocation = locate ( " viewID " ) ;
2017-09-23 01:21:06 +02:00
UICoord realView1 = alloc ( targetLocation ) ;
CHECK ( 1 = = allocCounter ) ;
2018-02-23 05:07:39 +01:00
CHECK ( string { realView1 } = = " UI:win-1[perspective]-parentLocation.viewID.#1 " ) ;
2017-09-23 01:21:06 +02:00
UICoord realView2 = alloc ( targetLocation ) ;
CHECK ( 2 = = allocCounter ) ;
2018-02-23 05:07:39 +01:00
CHECK ( string { realView2 } = = " UI:win-1[perspective]-parentLocation.viewID.#2 " ) ;
2017-09-23 02:25:52 +02:00
CHECK ( realView2 ! = realView1 ) ;
2017-09-23 01:21:06 +02:00
UICoord realView3 = alloc ( targetLocation ) ;
CHECK ( 3 = = allocCounter ) ;
2018-02-23 05:07:39 +01:00
CHECK ( string { realView3 } = = " UI:win-1[perspective]-parentLocation.viewID.#3 " ) ;
2017-09-14 22:24:54 +02:00
2017-09-23 01:21:06 +02:00
UICoord realView3b = alloc ( targetLocation ) ;
CHECK ( 3 = = allocCounter ) ;
CHECK ( realView3b = = realView3 ) ;
2017-09-10 00:32:31 +02:00
}
void
verify_alternatives ( )
{
UNIMPLEMENTED ( " querying and selection of location alternatives " ) ;
2017-09-09 23:30:44 +02:00
}
2018-04-05 19:43:10 +02:00
2018-04-15 03:07:54 +02:00
/** @test generic integrated access through ViewLocator
* This test demonstrates and verifies the way ViewLocator combines type based
* selection of the applicable DSL clauses , the invocation of those DSL definitions ,
* the allocation of a suitable element and finally specifically typed access to this
* located or allocated element .
* @ remarks due to limitations of our unit test setup ( GTK is prohibited ) , this component
* integration test can not be performed against the actual DSL definitions of the
* real UI , even while it uses the actual code from ViewLocator . Simply because we
2018-06-14 17:02:34 +02:00
* can not instantiate UI widgets in a unit test . We have to resort to mock UI
2018-04-15 03:07:54 +02:00
* elements and thus use a dummy " view type " together with faked DSL definitions
* for this dummy . These definitions are given in the test fixture above , right
* within this translation unit . ( see ` namespace idi ` and the class ` MockView1 ` ) .
*/
2018-04-05 19:43:10 +02:00
void
verify_genericInvocation ( )
{
2018-04-15 01:39:46 +02:00
ViewLocator viewLocator ;
2018-04-05 19:43:10 +02:00
//-------------------------------------------------------------Test-Fixture
// a Test dummy placeholder for the real UI structure
Rec dummyUiStructure = MakeRec ( )
. set ( " win-1 "
, MakeRec ( )
. type ( " perspective " )
. set ( " parentLocation " , MakeRec ( ) )
) ;
// answer "location queries" backed by this structure
GenNodeLocationQuery locationQuery { dummyUiStructure } ;
MockLoationSolver mock ( [ & ] { return new UILocationSolver { locationQuery } ; } ) ;
2018-04-15 01:39:46 +02:00
MockElementAccess fakeAccessor ;
2018-04-15 03:07:54 +02:00
fakeAccessor . triggerCreate ( ) ;
2018-04-05 19:43:10 +02:00
//--------------------------------------------------------------(End)Test-Fixture
2018-04-15 03:07:54 +02:00
//--------------------------------------------------------------Staging: Testcase-1
fakeAccessor - > existingPath = UICoord { " win-1 " , " perspective " , " parentLocation " } ;
CHECK ( not fakeAccessor - > response ) ; // not yet created
//--------------------------------------------------------------Staging: Testcase-1
2018-04-15 01:39:46 +02:00
2018-06-15 16:42:51 +02:00
DummyView & view1 = viewLocator . get < DummyView > ( ) ;
2018-04-15 03:07:54 +02:00
cout < < " created view: " < < view1 . getID ( ) < < endl ;
2018-06-15 18:02:08 +02:00
CHECK ( fakeAccessor - > response ) ; // a new "widget" was created
CHECK ( contains ( view1 . getID ( ) , " DummyView " ) ) ; // using the type name as ID prefix
2018-04-15 03:07:54 +02:00
/////////////////////////////////////////////TICKET 1129 : some way to verify the last allocated path. Should be a child of "parentLocation"
2018-04-05 19:43:10 +02:00
/////////////////////////////////////////////////////////////////////////////////////////TICKET 1129 : use an EventLog to verify the forwarded invocations??
}
2017-09-09 23:30:44 +02:00
} ;
/** Register this test class... */
LAUNCHER ( ViewSpecDSL_test , " unit gui " ) ;
} } } // namespace gui::interact::test