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)
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"
20 #include "lib/test/test-helper.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 
36 using std::string;
37 using lib::diff::MakeRec;
38 using lib::diff::Rec;
39 //using lib::idi::EntryID;
40 //using lib::diff::GenNode;
41 //using util::isSameObject;
42 //using util::isnil;
43 using util::contains;
44 
45 
46 namespace stage {
47 namespace 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 
61 namespace interact {
62 namespace test {
63 
64 // using lumiera::error::LUMIERA_ERROR_WRONG_TYPE;
65  using lib::test::showSizeof;
71 
72  using MockLoationSolver = lib::DependInject<UILocationSolver>::Local<>;
73  using MockElementAccess = lib::DependInject<ElementAccess>::Local<TestElementAccess>;
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();
95  verify_standardUsage();
96 // verify_alternatives();
97 
98  verify_genericInvocation();
99  }
100 
101 
102  void
103  verify_basicProperties()
104  {
105  UNIMPLEMENTED ("basic properties of the view spec DSL");
106  }
107 
108 
109  void
110  verify_standardUsage()
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
164  verify_alternatives()
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
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:129
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:40
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:546
Simplistic test class runner.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
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:141
static Builder currentWindow()
Builder: start definition of UI-Coordinates rooted in the currentWindow
Definition: ui-coord.hpp:669
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...