Lumiera 0.pre.04~rc.1
»edit your freedom«
Loading...
Searching...
No Matches
view-spec-dsl-test.cpp
Go to the documentation of this file.
1/*
2 ViewSpecDSL(Test) - verify mechanics of a DSL to configure view allocation
3
4 Copyright (C)
5 2017, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
19#include "lib/test/run.hpp"
26#include "lib/depend-inject.hpp"
27#include "lib/format-cout.hpp"
28//#include "lib/idi/entry-id.hpp"
29//#include "lib/diff/gen-node.hpp"
30#include "lib/util.hpp"
31
32//#include <string>
33//#include <vector>
34
35
36using std::string;
38using lib::diff::Rec;
39//using lib::idi::EntryID;
40//using lib::diff::GenNode;
41//using util::isSameObject;
42//using util::isnil;
43using util::contains;
44
45
46namespace stage {
47namespace idi { //------Mock ViewSpec definitions for component test
48
49
50 /* ==== Dummy ViewSpec rules for those two mock view types (--> see id-scheme.hpp) ==== */
51
52 template<>
53 struct Descriptor<test::DummyView>
54 {
55 ViewSpec locate = UICoord::currentWindow().panel("parentLocation");
56 Allocator alloc = limitAllocation(2);
57 };
58
59}//----------------(End)Mock ViewSpec definitions
60
61namespace interact {
62namespace test {
63
64// using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
65 using lib::test::showSizeof;
71
74
75 namespace { //Test fixture...
76
77 }//(End)Test fixture
78
79
80 /******************************************************************************/
88 class ViewSpecDSL_test : public Test
89 {
90
91 virtual void
92 run (Arg)
93 {
94// verify_basicProperties();
96// verify_alternatives();
97
99 }
100
101
102 void
104 {
105 UNIMPLEMENTED ("basic properties of the view spec DSL");
106 }
107
108
109 void
111 {
112 //-------------------------------------------------------------Test-Fixture
113 // a Test dummy placeholder for the real UI structure
114 Rec dummyUiStructure = MakeRec()
115 .set("win-1"
116 , MakeRec()
117 .type("perspective")
118 .set("parentLocation", MakeRec())
119 );
120 // answer "location queries" backed by this structure
121 GenNodeLocationQuery locationQuery{dummyUiStructure};
122 MockLoationSolver mock ([&]{ return new UILocationSolver{locationQuery}; });
123 //--------------------------------------------------------------(End)Test-Fixture
124
125
126
127 uint allocCounter = 0;
128
129 // Simulation/Example for an allocator-builder
130 AllocSpec<uint> limitAllocation =[&](UICoord target, uint limit)
131 {
132 if (allocCounter < limit)
133 return target.tab(++allocCounter);
134 else
135 return target.tab(limit);
136 };
137
138 // the actual View Specification would then be written as...
139 ViewSpec locate = UICoord::currentWindow().panel("parentLocation");
140 Allocator alloc = limitAllocation(3);
141
142 // ...and it would be evaluated as follows
143 UICoord targetLocation = locate("viewID");
144 UICoord realView1 = alloc(targetLocation);
145 CHECK (1 == allocCounter);
146 CHECK (string{realView1} == "UI:win-1[perspective]-parentLocation.viewID.#1");
147
148 UICoord realView2 = alloc(targetLocation);
149 CHECK (2 == allocCounter);
150 CHECK (string{realView2} == "UI:win-1[perspective]-parentLocation.viewID.#2");
151 CHECK (realView2 != realView1);
152
153 UICoord realView3 = alloc(targetLocation);
154 CHECK (3 == allocCounter);
155 CHECK (string{realView3} == "UI:win-1[perspective]-parentLocation.viewID.#3");
156
157 UICoord realView3b = alloc(targetLocation);
158 CHECK (3 == allocCounter);
159 CHECK (realView3b == realView3);
160 }
161
162
163 void
165 {
166 UNIMPLEMENTED ("querying and selection of location alternatives");
167 }
168
169
183 void
185 {
186 ViewLocator viewLocator;
187
188 //-------------------------------------------------------------Test-Fixture
189 // a Test dummy placeholder for the real UI structure
190 Rec dummyUiStructure = MakeRec()
191 .set("win-1"
192 , MakeRec()
193 .type("perspective")
194 .set("parentLocation", MakeRec())
195 );
196 // answer "location queries" backed by this structure
197 GenNodeLocationQuery locationQuery{dummyUiStructure};
198 MockLoationSolver mock ([&]{ return new UILocationSolver{locationQuery}; });
199
200 MockElementAccess fakeAccessor;
201 fakeAccessor.triggerCreate();
202 //--------------------------------------------------------------(End)Test-Fixture
203
204
205 //--------------------------------------------------------------Staging: Testcase-1
206 fakeAccessor->existingPath = UICoord{"win-1","perspective","parentLocation"};
207 CHECK (not fakeAccessor->response); // not yet created
208 //--------------------------------------------------------------Staging: Testcase-1
209
210 DummyView& view1 = viewLocator.get<DummyView>();
211 cout << "created view:" << view1.getID() << endl;
212 CHECK (fakeAccessor->response); // a new "widget" was created
213 CHECK (contains (view1.getID(), "DummyView")); // using the type name as ID prefix
215
217 }
218 };
219
220
222 LAUNCHER (ViewSpecDSL_test, "unit stage");
223
224
225}}} // namespace stage::interact::test
Configuration handle for temporarily shadowing a dependency by a test mock instance.
MOC & triggerCreate()
trigger lazy service object instantiation
Mutator && set(string const &key, X &&content)
Definition record.hpp:462
object-like record of data.
Definition record.hpp:142
A specification to describe the strategy for allocating (placing, retrieving) a component view.
Test/Diagnostics: implementation of the LocationQuery-API based on a abstract topological structure g...
Builder && panel(Literal panelID)
augment UI coordinates to indicate a specific view to be used
Definition ui-coord.hpp:547
Describe a location within the UI through structural/topological coordinates.
Definition ui-coord.hpp:131
Builder tab(Literal tabID) const
Definition ui-coord.hpp:714
static Builder currentWindow()
Builder: start definition of UI-Coordinates rooted in the currentWindow
Definition ui-coord.hpp:670
Service to determine the location of an UI component view.
Access or allocate a UI component view.
V & get()
Access and possibly create just some component view of the desired type.
Interface: access UI elements by navigating the UI topology.
Mock implementation of the model::ElementAccess interface for testing without actual UI.
Per type specific configuration of instances created as service dependencies.
Automatically use custom string conversion in C++ stream output.
Implementation of the stage::interact::LocationQuery interface to work on a GenNode tree.
unsigned int uint
Definition integral.hpp:29
AllocSpec< uint > limitAllocation
Generic Component View descriptors.
LocatorSpec< UIC_VIEW > ViewSpec
A specification to describe the desired location of a component view within the Lumiera UI.
std::function< UICoord(UICoord)> Allocator
Allocator is a functor to resolve a given, desired location of a view within the UI.
Lumiera GTK UI implementation root.
Definition guifacade.cpp:37
Test runner and basic definitions for tests.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Unit test helper for access to UI elements without actually running an UI.
A collection of frequently used helper functions to support unit testing.
A topological addressing scheme to designate structural locations within the UI.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Access and allocation of UI component views.
A framework for configuration of view access and allocation patterns.