ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testOptimiseUnmappedVariables.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 <chrono>
4#include <future>
5
6#define BOOST_TEST_MODULE testOptimiseUnmappedVariables
7
8#include "Application.h"
9#include "Multiplier.h"
10#include "Pipe.h"
11#include "TestFacility.h"
12
13#include <libxml++/libxml++.h>
14
15#include <boost/filesystem.hpp>
16#include <boost/mpl/list.hpp>
17#include <boost/thread.hpp>
18
19#define BOOST_NO_EXCEPTIONS
20#include <boost/test/included/unit_test.hpp>
21#undef BOOST_NO_EXCEPTIONS
22
24
25 using namespace boost::unit_test_framework;
26 namespace ctk = ChimeraTK;
27
28 /********************************************************************************************************************/
29 /* Application without name */
30
31 struct TestApp : public ctk::Application {
32 explicit TestApp(const std::string& name) : ctk::Application(name) {}
33 ~TestApp() override { shutdown(); }
34
35 ctk::ConstMultiplier<double> multiplierD{this, "Multiplier", "Some module", 42};
36 ctk::ScalarPipe<double> pipe{this, "/Multiplier/output", "/mySubModule/output", "unit", "Some pipe module"};
37 };
38
39 /********************************************************************************************************************/
40
41 BOOST_AUTO_TEST_CASE(testOptimiseUnmappedVariables) {
42 std::cout << "***************************************************************" << std::endl;
43 std::cout << "==> testOptimiseUnmappedVariables" << std::endl;
44
45 // test without even calling the function
46 {
47 TestApp app("testApp");
48 app.getModel().writeGraphViz("testOptimiseUnmappedVariables.dot");
49 ctk::TestFacility test{app};
50 auto input = test.getScalar<double>("/Multiplier/input");
51 auto tap = test.getScalar<double>("/Multiplier/output");
52 auto output = test.getScalar<double>("/mySubModule/output");
53 test.runApplication();
54 input = 10;
55 input.write();
56 test.stepApplication();
57 BOOST_CHECK(tap.readNonBlocking());
58 BOOST_CHECK_CLOSE(double(tap), 420., 0.001);
59 BOOST_CHECK(!tap.readNonBlocking());
60 BOOST_CHECK(output.readNonBlocking());
61 BOOST_CHECK_CLOSE(double(output), 420., 0.001);
62 BOOST_CHECK(!output.readNonBlocking());
63 }
64
65 // test passing empty set
66 {
67 TestApp app("testApp");
68 ctk::TestFacility test{app};
69 auto input = test.getScalar<double>("/Multiplier/input");
70 auto tap = test.getScalar<double>("/Multiplier/output");
71 auto output = test.getScalar<double>("/mySubModule/output");
73 test.runApplication();
74 input = 10;
75 input.write();
76 test.stepApplication();
77 BOOST_CHECK(tap.readNonBlocking());
78 BOOST_CHECK_CLOSE(double(tap), 420., 0.001);
79 BOOST_CHECK(!tap.readNonBlocking());
80 BOOST_CHECK(output.readNonBlocking());
81 BOOST_CHECK_CLOSE(double(output), 420., 0.001);
82 BOOST_CHECK(!output.readNonBlocking());
83 }
84
85 // test passing single variable
86 {
87 TestApp app("testApp");
88 ctk::TestFacility test{app};
89 auto input = test.getScalar<double>("/Multiplier/input");
90 auto tap = test.getScalar<double>("/Multiplier/output");
91 auto output = test.getScalar<double>("/mySubModule/output");
92 app.optimiseUnmappedVariables({"/Multiplier/output"});
93 test.runApplication();
94 input = 10;
95 input.write();
96 test.stepApplication();
97 BOOST_CHECK(!tap.readNonBlocking());
98 BOOST_CHECK(output.readNonBlocking());
99 BOOST_CHECK_CLOSE(double(output), 420., 0.001);
100 BOOST_CHECK(!output.readNonBlocking());
101 }
102
103 // test passing two variables
104 {
105 TestApp app("testApp");
106 ctk::TestFacility test{app};
107 auto input = test.getScalar<double>("/Multiplier/input");
108 auto tap = test.getScalar<double>("/Multiplier/output");
109 auto output = test.getScalar<double>("/mySubModule/output");
110 app.optimiseUnmappedVariables({"/Multiplier/output", "/mySubModule/output"});
111 test.runApplication();
112 input = 10;
113 input.write();
114 test.stepApplication();
115 BOOST_CHECK(!tap.readNonBlocking());
116 BOOST_CHECK(!output.readNonBlocking());
117 }
118
119 // test passing unknown variables
120 {
121 TestApp app("testApp");
122 ctk::TestFacility test{app};
123 auto input = test.getScalar<double>("/Multiplier/input");
124 auto tap = test.getScalar<double>("/Multiplier/output");
125 auto output = test.getScalar<double>("/mySubModule/output");
126 BOOST_CHECK_THROW(app.optimiseUnmappedVariables({"/Multiplier/output", "/this/is/not/known"}), std::out_of_range);
127 }
128 }
129
130} // namespace Tests::testOptimiseUnmappedVariables
Model::RootProxy getModel()
Return the root of the application model.
Definition Application.h:75
void optimiseUnmappedVariables(const std::set< std::string > &names) override
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
void writeGraphViz(const std::string &filename, Args... args) const
Implementations of RootProxy.
Definition Model.h:1789
friend class Application
Definition ModuleGroup.h:47
Helper class to facilitate tests of applications based on ApplicationCore.
InvalidityTracer application module.
BOOST_AUTO_TEST_CASE(testOptimiseUnmappedVariables)
Generic module to pipe through a scalar value without altering it.
Definition Pipe.h:17