Lumiera  0.pre.03
»edit your freedom«
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) Lumiera.org
5  2017, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/test/test-helper.hpp"
35 #include "lib/depend-inject.hpp"
36 #include "lib/format-cout.hpp"
37 //#include "lib/idi/entry-id.hpp"
38 //#include "lib/diff/gen-node.hpp"
39 #include "lib/util.hpp"
40 
41 //#include <string>
42 //#include <vector>
43 
44 
45 using std::string;
46 using lib::diff::MakeRec;
47 using lib::diff::Rec;
48 //using lib::idi::EntryID;
49 //using lib::diff::GenNode;
50 //using util::isSameObject;
51 //using util::isnil;
52 using util::contains;
53 
54 
55 namespace stage {
56 namespace idi { //------Mock ViewSpec definitions for component test
57 
58 
59  /* ==== Dummy ViewSpec rules for those two mock view types (--> see id-scheme.hpp) ==== */
60 
61  template<>
62  struct Descriptor<test::DummyView>
63  {
64  ViewSpec locate = UICoord::currentWindow().panel("parentLocation");
65  Allocator alloc = limitAllocation(2);
66  };
67 
68 }//----------------(End)Mock ViewSpec definitions
69 
70 namespace interact {
71 namespace test {
72 
73 // using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
74  using lib::test::showSizeof;
80 
81  using MockLoationSolver = lib::DependInject<UILocationSolver>::Local<>;
82  using MockElementAccess = lib::DependInject<ElementAccess>::Local<TestElementAccess>;
83 
84  namespace { //Test fixture...
85 
86  }//(End)Test fixture
87 
88 
89  /******************************************************************************/
97  class ViewSpecDSL_test : public Test
98  {
99 
100  virtual void
101  run (Arg)
102  {
103 // verify_basicProperties();
104  verify_standardUsage();
105 // verify_alternatives();
106 
107  verify_genericInvocation();
108  }
109 
110 
111  void
112  verify_basicProperties()
113  {
114  UNIMPLEMENTED ("basic properties of the view spec DSL");
115  }
116 
117 
118  void
119  verify_standardUsage()
120  {
121  //-------------------------------------------------------------Test-Fixture
122  // a Test dummy placeholder for the real UI structure
123  Rec dummyUiStructure = MakeRec()
124  .set("win-1"
125  , MakeRec()
126  .type("perspective")
127  .set("parentLocation", MakeRec())
128  );
129  // answer "location queries" backed by this structure
130  GenNodeLocationQuery locationQuery{dummyUiStructure};
131  MockLoationSolver mock ([&]{ return new UILocationSolver{locationQuery}; });
132  //--------------------------------------------------------------(End)Test-Fixture
133 
134 
135 
136  uint allocCounter = 0;
137 
138  // Simulation/Example for an allocator-builder
139  AllocSpec<uint> limitAllocation =[&](UICoord target, uint limit)
140  {
141  if (allocCounter < limit)
142  return target.tab(++allocCounter);
143  else
144  return target.tab(limit);
145  };
146 
147  // the actual View Specification would then be written as...
148  ViewSpec locate = UICoord::currentWindow().panel("parentLocation");
149  Allocator alloc = limitAllocation(3);
150 
151  // ...and it would be evaluated as follows
152  UICoord targetLocation = locate("viewID");
153  UICoord realView1 = alloc(targetLocation);
154  CHECK (1 == allocCounter);
155  CHECK (string{realView1} == "UI:win-1[perspective]-parentLocation.viewID.#1");
156 
157  UICoord realView2 = alloc(targetLocation);
158  CHECK (2 == allocCounter);
159  CHECK (string{realView2} == "UI:win-1[perspective]-parentLocation.viewID.#2");
160  CHECK (realView2 != realView1);
161 
162  UICoord realView3 = alloc(targetLocation);
163  CHECK (3 == allocCounter);
164  CHECK (string{realView3} == "UI:win-1[perspective]-parentLocation.viewID.#3");
165 
166  UICoord realView3b = alloc(targetLocation);
167  CHECK (3 == allocCounter);
168  CHECK (realView3b == realView3);
169  }
170 
171 
172  void
173  verify_alternatives()
174  {
175  UNIMPLEMENTED ("querying and selection of location alternatives");
176  }
177 
178 
192  void
194  {
195  ViewLocator viewLocator;
196 
197  //-------------------------------------------------------------Test-Fixture
198  // a Test dummy placeholder for the real UI structure
199  Rec dummyUiStructure = MakeRec()
200  .set("win-1"
201  , MakeRec()
202  .type("perspective")
203  .set("parentLocation", MakeRec())
204  );
205  // answer "location queries" backed by this structure
206  GenNodeLocationQuery locationQuery{dummyUiStructure};
207  MockLoationSolver mock ([&]{ return new UILocationSolver{locationQuery}; });
208 
209  MockElementAccess fakeAccessor;
210  fakeAccessor.triggerCreate();
211  //--------------------------------------------------------------(End)Test-Fixture
212 
213 
214  //--------------------------------------------------------------Staging: Testcase-1
215  fakeAccessor->existingPath = UICoord{"win-1","perspective","parentLocation"};
216  CHECK (not fakeAccessor->response); // not yet created
217  //--------------------------------------------------------------Staging: Testcase-1
218 
219  DummyView& view1 = viewLocator.get<DummyView>();
220  cout << "created view:" << view1.getID() << endl;
221  CHECK (fakeAccessor->response); // a new "widget" was created
222  CHECK (contains (view1.getID(), "DummyView")); // using the type name as ID prefix
224 
226  }
227  };
228 
229 
231  LAUNCHER (ViewSpecDSL_test, "unit stage");
232 
233 
234 }}} // namespace stage::interact::test
std::function< UICoord(UICoord)> Allocator
Allocator is a functor to resolve a given, desired location of a view within the UI, resulting in creation or allocation of the view – which happens as side-effect. The result of this invocation are the UI coordinates of an existing or newly created view.
Test/Diagnostics: implementation of the LocationQuery-API based on a abstract topological structure g...
Access or allocate a UI component view.
Describe a location within the UI through structural/topological coordinates.
Definition: ui-coord.hpp:138
Service to determine the location of an UI component view.
Automatically use custom string conversion in C++ stream output.
Implementation of the stage::interact::LocationQuery interface to work on a GenNode tree...
Access and allocation of UI component views.
A framework for configuration of view access and allocation patterns.
Definition: run.hpp:49
Generic Component View descriptors.
Per type specific configuration of instances created as service dependencies.
A specification to describe the desired location of a component view within the Lumiera UI...
Interface: access UI elements by navigating the UI topology.
V & get()
Access and possibly create just some component view of the desired type.
Builder && panel(Literal panelID)
augment UI coordinates to indicate a specific view to be used
Definition: ui-coord.hpp:555
Simple test class runner.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A topological addressing scheme to designate structural locations within the UI.
Mock implementation of the model::ElementAccess interface for testing without actual UI...
A collection of frequently used helper functions to support unit testing.
MOC & triggerCreate()
trigger lazy service object instantiation
Unit test helper for access to UI elements without actually running an UI.
object-like record of data.
Definition: record.hpp:150
static Builder currentWindow()
Builder: start definition of UI-Coordinates rooted in the currentWindow
Definition: ui-coord.hpp:678
Configuration handle for temporarily shadowing a dependency by a test mock instance.
LocatorSpec< UIC_VIEW > ViewSpec
A specification to describe the desired location of a component view within the Lumiera UI...
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
Definition: util.hpp:255
A specification to describe the strategy for allocating (placing, retrieving) a component view...