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) Lumiera.org
5  2018, 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 
23 
42 #ifndef STAGE_TEST_ELEMENT_ACCESS_H
43 #define STAGE_TEST_ELEMENT_ACCESS_H
44 
45 
46 #include "lib/error.hpp"
49 #include "test/mock-elm.hpp"
50 #include "lib/symbol.hpp"
51 //#include "lib/util.hpp"
52 
53 #include <string>
54 #include <memory>
55 
56 
57 
58 namespace stage {
59 namespace test {
60  namespace error = lumiera::error;
61 
62 // using util::isnil;
63  using std::string;
64  using lib::Literal;
65  using interact::UICoord;
66  using interact::UIC_VIEW;
67  using interact::UIC_TAB;
68 
69 
70 
71 
72  /* === Dummy Widgets for Unit testing === */
73 
75  : public MockElm
76  {
77  public:
78  virtual ~DummyWidget() { }
79 
80  DummyWidget(string name ="DummyWidget")
81  : MockElm{name}
82  { }
84  : DummyWidget{string (name)}
85  { }
86  };
87 
88  struct DummyTab
89  : DummyWidget
90  {
91  using DummyWidget::DummyWidget;
92  };
93 
94  struct DummyView
95  : DummyWidget
96  {
97  using DummyWidget::DummyWidget;
98  };
99 
100 
101 
107  : public model::ElementAccess
108  {
109 
110  public:
111  explicit
113  { }
114 
115 
116  /* == Test/Diagnostics interface == */
117 
120 
122  std::unique_ptr<model::Tangible> response;
123 
124 
125  /* == ElementAccess interface == */
126 
127  RawResult
128  performAccessTo (UICoord::Builder & target, size_t) override
129  {
130  UICoord const& location = target.uiCoord();
131 
132  CHECK (existingPath >= location);
133  if (existingPath > location and !response)
134  {
135  if (location.leafLevel() == UIC_VIEW)
136  response.reset(new DummyView(location[UIC_VIEW]));
137  else
138  if (location.leafLevel() == UIC_TAB)
139  response.reset(new DummyTab(location[UIC_TAB]));
140  else
141  throw error::Invalid("Mock ElementAccess supports only creation of VIEW and TAB. Requested Target was "+string(location));
142  }
143 
144  return response.get();
145  }
146 
147 
148  protected:
149  };
150 
151 
152 
153 
154 }} // namespace stage::test
155 #endif /*STAGE_TEST_ELEMENT_ACCESS_H*/
Describe a location within the UI through structural/topological coordinates.
Definition: ui-coord.hpp:138
Definition: run.hpp:49
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
RawResult performAccessTo(UICoord::Builder &target, size_t) override
Typesafe union record.
Definition: variant.hpp:224
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:199
Marker types to indicate a literal string and a Symbol.
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
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:108
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