ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testHierarchyModifyingGroup.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#include "TestFacility.h"
4
5#include <chrono>
6#include <future>
7
8#define BOOST_TEST_MODULE testHierarchyModifyingGroup
9
10#include "Application.h"
11#include "ApplicationModule.h"
12#include "ModuleGroup.h"
13#include "ScalarAccessor.h"
14#include "VariableGroup.h"
15
16#include <boost/mpl/list.hpp>
17#include <boost/test/included/unit_test.hpp>
18#include <boost/thread.hpp>
19
21
22 using namespace boost::unit_test_framework;
23 namespace ctk = ChimeraTK;
24
25 /********************************************************************************************************************/
26 /********************************************************************************************************************/
27
37 /********************************************************************************************************************/
38 /********************************************************************************************************************/
39
40 struct TestGroup : public ctk::VariableGroup {
41 using ctk::VariableGroup::VariableGroup;
42 ctk::ScalarPushInput<int> myVar{this, "myVar", "MV/m", "Descrption"};
43 };
44
46 TestApplication() : Application("testSuite") {}
47 ~TestApplication() override { shutdown(); }
48
50 using ctk::ApplicationModule::ApplicationModule;
51
53
55 using ctk::VariableGroup::VariableGroup;
57 } extraHierarchy{this, "ExtraHierarchy", "Extra depth"};
58
59 void mainLoop() override {
60 if(getAccessorListRecursive().empty()) {
61 return;
62 }
63 assert(getAccessorListRecursive().size() == 1);
64 while(true) {
65 readAll();
66 }
67 }
68 } testModule{this, "mod", "The test module"};
69 };
70
71 /********************************************************************************************************************/
72
73 void check(TestApplication& app, TestGroup& group, const std::string& name) {
74 static int myCounter = 42;
75
77 auto acc = test.getScalar<int>(name + "/myVar");
78 test.runApplication();
79
80 acc = myCounter;
81 acc.write();
82
83 test.stepApplication();
84
85 BOOST_TEST(int(group.myVar) == myCounter);
86
87 ++myCounter;
88 }
89
90 /********************************************************************************************************************/
91 /********************************************************************************************************************/
92
93 BOOST_AUTO_TEST_CASE(VariableGroupLike) {
94 std::cout << "*** VariableGroupLike" << std::endl;
96 app.testModule.g = {&app.testModule, "VariableGroupLike", "Use like normal VariableGroup"};
97 check(app, app.testModule.g, "/mod/VariableGroupLike");
98 }
99
100 /********************************************************************************************************************/
101
103 std::cout << "*** MoveToRoot" << std::endl;
104 TestApplication app;
105 app.testModule.g = {&app.testModule, "/MoveToRoot", "Use like normal VariableGroup with MoveToRoot"};
106 check(app, app.testModule.g, "/MoveToRoot");
107 }
108
109 /********************************************************************************************************************/
110
112 std::cout << "*** ../oneUp" << std::endl;
113 TestApplication app;
114 app.testModule.g = {&app.testModule, "../oneUp", "Use like normal VariableGroup with oneUp"};
115 check(app, app.testModule.g, "/oneUp");
116 }
117
118 /********************************************************************************************************************/
119
121 std::cout << "*** .." << std::endl;
122 TestApplication app;
123 app.testModule.g = {&app.testModule, "..", "Use like normal VariableGroup with oneUpAndHide"};
124 check(app, app.testModule.g, "");
125 }
126
127 /********************************************************************************************************************/
128
129 BOOST_AUTO_TEST_CASE(local_hierarchy) {
130 std::cout << "*** local/hierarchy" << std::endl;
131 TestApplication app;
132 app.testModule.g = {&app.testModule, "local/hierarchy", "Create hierarchy locally"};
133 check(app, app.testModule.g, "/mod/local/hierarchy");
134 }
135
136 /********************************************************************************************************************/
137
138 BOOST_AUTO_TEST_CASE(AtRoot_hierarchy) {
139 std::cout << "*** /AtRoot/hierarchy" << std::endl;
140 TestApplication app;
141 app.testModule.g = {&app.testModule, "/AtRoot/hierarchy", "Create hierarchy at root"};
142 check(app, app.testModule.g, "/AtRoot/hierarchy");
143 }
144
145 /********************************************************************************************************************/
146
147 BOOST_AUTO_TEST_CASE(oneUp_hierarchy) {
148 std::cout << "*** ../oneUp/hierarchy" << std::endl;
149 TestApplication app;
150 app.testModule.g = {&app.testModule, "../oneUp/hierarchy", "Create hierarchy one level up"};
151 check(app, app.testModule.g, "/oneUp/hierarchy");
152 }
153
154 /********************************************************************************************************************/
155
156 BOOST_AUTO_TEST_CASE(local_very_deep_hierarchy) {
157 std::cout << "*** local/very/deep/hierarchy" << std::endl;
158 TestApplication app;
159 app.testModule.g = {&app.testModule, "local/very/deep/hierarchy", "Create deep hierarchy locally"};
160 check(app, app.testModule.g, "/mod/local/very/deep/hierarchy");
161 }
162
163 /********************************************************************************************************************/
164
165 BOOST_AUTO_TEST_CASE(root_very_deep_hierarchy) {
166 std::cout << "*** /root/very/deep/hierarchy" << std::endl;
167 TestApplication app;
168 app.testModule.g = {&app.testModule, "/root/very/deep/hierarchy", "Create deep hierarchy at root"};
169 check(app, app.testModule.g, "/root/very/deep/hierarchy");
170 }
171
172 /********************************************************************************************************************/
173
174 BOOST_AUTO_TEST_CASE(oneUp_very_deep_hierarchy) {
175 std::cout << "*** ../oneUp/very/deep/hierarchy" << std::endl;
176 TestApplication app;
177 app.testModule.g = {&app.testModule, "../oneUp/very/deep/hierarchy", "Create deep hierarchy one level up"};
178 check(app, app.testModule.g, "/oneUp/very/deep/hierarchy");
179 }
180
181 /********************************************************************************************************************/
182
183 BOOST_AUTO_TEST_CASE(extra_slashes_everywhere) {
184 std::cout << "*** //extra//slashes////everywhere///" << std::endl;
185 TestApplication app;
186 BOOST_CHECK_THROW((app.testModule.g = {&app.testModule, "//extra//slashes////everywhere///", "Extra slashes"}),
187 ChimeraTK::logic_error);
188 BOOST_CHECK_THROW((app.testModule.g = {&app.testModule, "/extra/slashes/everywhere/", "Extra slashs at the end"}),
189 ChimeraTK::logic_error);
190 BOOST_CHECK_THROW((app.testModule.g = {&app.testModule, "/extra/slashes//everywhere", "Extra slash in the middle"}),
191 ChimeraTK::logic_error);
192 BOOST_CHECK_THROW(
193 (app.testModule.g = {&app.testModule, "//extra/slashes/everywhere", "Extra slash in the beginning"}),
194 ChimeraTK::logic_error);
195 BOOST_CHECK_NO_THROW((app.testModule.g = {&app.testModule, "/extra/slashes/everywhere", "No extra slash"}));
196 }
197
198 /********************************************************************************************************************/
199
201 std::cout << "*** twoUp" << std::endl;
202 TestApplication app;
203 app.testModule.extraHierarchy.g = {&app.testModule.extraHierarchy, "../../twoUp", "Two levels up"};
204 check(app, app.testModule.extraHierarchy.g, "/twoUp");
205 }
206
207 /********************************************************************************************************************/
208
209 BOOST_AUTO_TEST_CASE(hierarchy_with_dots_anywhere_also_single_dots) {
210 std::cout << "*** hierarchy/with/../dots/../../anywhere/./also/./single/./dots/.." << std::endl;
211 TestApplication app;
212 app.testModule.g = {
213 &app.testModule, "hierarchy/with/../dots/../../anywhere/./also/./single/./dots/..", "Dots everywhere "};
214 app.getModel().writeGraphViz("vg_test.dot");
215 check(app, app.testModule.g, "/mod/anywhere/also/single");
216 }
217
218 /********************************************************************************************************************/
219
221 std::cout << "*** ." << std::endl;
222 TestApplication app;
223 app.testModule.g = {&app.testModule, ".", "This is like hideThis"};
224 check(app, app.testModule.g, "/mod");
225 }
226
227 /********************************************************************************************************************/
228
230 std::cout << "*** dot/at/end/." << std::endl;
231 TestApplication app;
232 app.testModule.g = {&app.testModule, "dot/at/end/.", "Gets effectively ignored..."};
233 check(app, app.testModule.g, "/mod/dot/at/end");
234 }
235
236 /********************************************************************************************************************/
237
238 BOOST_AUTO_TEST_CASE(MoveToRootFromHidden) {
239 std::cout << "*** MoveToRootFromHidden" << std::endl;
240 TestApplication app;
241 app.testModule = {&app, ".", "The test module is hidden now"};
242 app.testModule.g = {&app.testModule, "/MoveToRootFromHidden",
243 "Use like normal VariableGroup with MoveToRoot, and place inside a hidden to-level module"};
244 check(app, app.testModule.g, "/MoveToRootFromHidden");
245 }
246
247 /********************************************************************************************************************/
248
252
254 using ctk::ApplicationModule::ApplicationModule;
255 void mainLoop() override {}
256 } testModule{this, "TestModule", "The test module"};
257 };
258
259 /********************************************************************************************************************/
260
261 BOOST_AUTO_TEST_CASE(bad_path_exception) {
262 std::cout << "*** bad_path_exception" << std::endl;
264 BOOST_CHECK_THROW(TestGroup tg(&app.testModule, "/../cannot/work", "This is not allowed"), ctk::logic_error);
265 BOOST_CHECK_THROW(TestGroup tg(&app.testModule, "/..", "This is not allowed either"), ctk::logic_error);
266 BOOST_CHECK_THROW(
267 TestGroup tg(&app.testModule, "/somthing/less/../../../obvious", "This is also not allowed"), ctk::logic_error);
268 }
269
270 /********************************************************************************************************************/
271
272} // namespace Tests::testHierarchyModifyingGroup
Model::RootProxy getModel()
Return the root of the application model.
Definition Application.h:75
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
std::list< VariableNetworkNode > getAccessorListRecursive() const
Obtain the list of accessors/variables associated with this instance and any submodules.
void writeGraphViz(const std::string &filename, Args... args) const
Implementations of RootProxy.
Definition Model.h:1789
friend class Application
Definition ModuleGroup.h:47
void readAll(bool includeReturnChannels=false)
Read all readable variables in the group.
Definition Module.cc:72
Convenience class for input scalar accessors with UpdateMode::push.
Helper class to facilitate tests of applications based on ApplicationCore.
InvalidityTracer application module.
void check(TestApplication &app, TestGroup &group, const std::string &name)
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
This test checks use of relative paths in modules at the example of a VariableGroup.