ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testTestFacility2.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#define BOOST_TEST_MODULE testTestFaciliy2
4#include <boost/test/included/unit_test.hpp>
5using namespace boost::unit_test_framework;
6
7#include "Application.h"
8#include "ApplicationModule.h"
9#include "ScalarAccessor.h"
10#include "TestFacility.h"
11
13
14 namespace ctk = ChimeraTK;
15
17 using ctk::ApplicationModule::ApplicationModule;
18
19 ctk::ScalarPushInput<double> input{this, "/input", "", ""};
20 ctk::ScalarOutput<double> output{this, "/output", "", ""};
21
22 void mainLoop() override {
23 std::cout << "starting main loop" << std::endl;
24 output = 2 * double(input);
25 output.write();
26
27 while(true) {
28 input.read();
29 output = 3 * double(input);
30 output.write();
31 }
32 }
33 };
34
35 /********************************************************************************************************************/
36
37 struct TestApp : public ctk::Application {
38 TestApp() : Application("TestApp") {}
39 ~TestApp() override { shutdown(); }
40
41 MyModule myModule{this, "MyModule", ""};
42 };
43
44 /********************************************************************************************************************/
45
46 BOOST_AUTO_TEST_CASE(testSumLimiter) {
47 TestApp theTestApp;
48 ChimeraTK::TestFacility testFacility(theTestApp);
49 testFacility.setScalarDefault<double>("/input", 25.);
50
51 testFacility.runApplication();
52
53 // at this point all main loops should have started, default values are processed and inputs waiting in read()
54
55 BOOST_CHECK_CLOSE(testFacility.readScalar<double>("/output"), 50., 0.001);
56
57 testFacility.writeScalar<double>("/input", 30.);
58 std::cout << "about to step" << std::endl;
59 // however, the main loop only starts in the first step.
60 testFacility.stepApplication();
61 std::cout << "step finished" << std::endl;
62
63 BOOST_CHECK_CLOSE(testFacility.readScalar<double>("/output"), 90., 0.001);
64 }
65
66 /********************************************************************************************************************/
67
68} // namespace Tests::testTestFaciliy2
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
friend class Application
Definition ModuleGroup.h:47
bool write(ChimeraTK::VersionNumber versionNumber)=delete
Convenience class for input scalar accessors with UpdateMode::push.
Helper class to facilitate tests of applications based on ApplicationCore.
TYPE readScalar(const std::string &name)
Convenience function to read the latest value of a scalar process variable in a single call.
void writeScalar(const std::string &name, TYPE value)
Convenience function to write a scalar process variable in a single call.
void stepApplication(bool waitForDeviceInitialisation=true) const
Perform a "step" of the application.
void runApplication() const
Start the application in testable mode.
void setScalarDefault(const ChimeraTK::RegisterPath &name, const T &value)
Set default value for scalar process variable.
InvalidityTracer application module.
BOOST_AUTO_TEST_CASE(testSumLimiter)
Convenience class for output scalar accessors (always UpdateMode::push)
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ctk::ScalarPushInput< double > input
ctk::ScalarOutput< double > output