Lumiera  0.pre.03
»edit your freedom«
test-element-access.hpp
Go to the documentation of this file.
1 /*
2  TEST-ELEMENT-ACCESS.hpp - fake access directory to handle generic UI entities for test
3 
4  Copyright (C)
5  2018, 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 
14 
33 #ifndef STAGE_TEST_ELEMENT_ACCESS_H
34 #define STAGE_TEST_ELEMENT_ACCESS_H
35 
36 
37 #include "lib/error.hpp"
40 #include "test/mock-elm.hpp"
41 #include "lib/symbol.hpp"
42 //#include "lib/util.hpp"
43 
44 #include <string>
45 #include <memory>
46 
47 
48 
49 namespace stage {
50 namespace test {
51  namespace error = lumiera::error;
52 
53 // using util::isnil;
54  using std::string;
55  using lib::Literal;
56  using interact::UICoord;
57  using interact::UIC_VIEW;
58  using interact::UIC_TAB;
59 
60 
61 
62 
63  /* === Dummy Widgets for Unit testing === */
64 
66  : public MockElm
67  {
68  public:
69  virtual ~DummyWidget() { }
70 
71  DummyWidget(string name ="DummyWidget")
72  : MockElm{name}
73  { }
75  : DummyWidget{string (name)}
76  { }
77  };
78 
79  struct DummyTab
80  : DummyWidget
81  {
82  using DummyWidget::DummyWidget;
83  };
84 
85  struct DummyView
86  : DummyWidget
87  {
88  using DummyWidget::DummyWidget;
89  };
90 
91 
92 
98  : public model::ElementAccess
99  {
100 
101  public:
102  explicit
104  { }
105 
106 
107  /* == Test/Diagnostics interface == */
108 
111 
113  std::unique_ptr<model::Tangible> response;
114 
115 
116  /* == ElementAccess interface == */
117 
118  RawResult
119  performAccessTo (UICoord::Builder & target, size_t) override
120  {
121  UICoord const& location = target.uiCoord();
122 
123  CHECK (existingPath >= location);
124  if (existingPath > location and !response)
125  {
126  if (location.leafLevel() == UIC_VIEW)
127  response.reset(new DummyView(location[UIC_VIEW]));
128  else
129  if (location.leafLevel() == UIC_TAB)
130  response.reset(new DummyTab(location[UIC_TAB]));
131  else
132  throw error::Invalid("Mock ElementAccess supports only creation of VIEW and TAB. Requested Target was "+string(location));
133  }
134 
135  return response.get();
136  }
137 
138 
139  protected:
140  };
141 
142 
143 
144 
145 }} // namespace stage::test
146 #endif /*STAGE_TEST_ELEMENT_ACCESS_H*/
Describe a location within the UI through structural/topological coordinates.
Definition: ui-coord.hpp:129
Definition: run.hpp:40
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:76
RawResult performAccessTo(UICoord::Builder &target, size_t) override
Typesafe union record.
Definition: variant.hpp:215
Interface: access UI elements by navigating the UI topology.
Interface to discover and access raw UI elements in a cross cutting way.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
Marker types to indicate a literal string and a Symbol.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
A topological addressing scheme to designate structural locations within the UI.
Mock implementation of the model::ElementAccess interface for testing without actual UI...
std::unique_ptr< model::Tangible > response
...and if acceptable, we record the last answer here
Lumiera error handling (C++ interface).
virtual ~DummyWidget()
is an interface
Mock UI element or controller.
Definition: mock-elm.hpp:99
UICoord existingPath
the next query will fail unless it presents this Path
A generic interface element instrumented for unit testing.
ElementBoxWidget::Config::Qualifier name(string id)
define the name-ID displayed in the caption