ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
testExceptionDummyDevice.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
4#define BOOST_TEST_DYN_LINK
5#define BOOST_TEST_MODULE testExceptionsDummy
6
7#include "BackendFactory.h"
8#include "Device.h"
10
11#include <boost/test/unit_test.hpp>
12
13using namespace boost::unit_test_framework;
14namespace ctk = ChimeraTK;
15
16auto exceptionDummy = boost::dynamic_pointer_cast<ctk::ExceptionDummy>(
17 ctk::BackendFactory::getInstance().createBackend("(ExceptionDummy:1?map=test3.map)"));
19
20BOOST_AUTO_TEST_CASE(testExceptionsDummyDevice) {
21 // test general function
22 BOOST_CHECK(!device.isFunctional());
23 device.open("(ExceptionDummy:1?map=test3.map)");
24 BOOST_CHECK(device.isFunctional());
25
26 // test DataValidity
27 auto devI1 = device.getScalarRegisterAccessor<int>("/dev/i1");
28 auto devI2 = device.getScalarRegisterAccessor<int>("/dev/i2");
29 exceptionDummy->setValidity("/dev/i1", ctk::DataValidity::faulty);
30 devI1.read();
31 devI2.read();
32 BOOST_CHECK(devI1.dataValidity() == ctk::DataValidity::faulty);
33 BOOST_CHECK(devI2.dataValidity() == ctk::DataValidity::ok);
34
35 // test throwExceptionRead
36 exceptionDummy->throwExceptionRead = true;
37 BOOST_CHECK(device.isFunctional());
38 BOOST_CHECK_THROW(
39 [[maybe_unused]] auto result = device.read<int32_t>("/Integers/signed32"), ChimeraTK::runtime_error);
40 BOOST_CHECK(!device.isFunctional());
41 BOOST_CHECK_NO_THROW(device.open("(ExceptionDummy:1?map=test3.map)"));
42 BOOST_CHECK(device.isFunctional());
43 exceptionDummy->throwExceptionRead = false;
44
45 // test throwExceptionWrite
46 exceptionDummy->throwExceptionWrite = true;
47 BOOST_CHECK(device.isFunctional());
48 BOOST_CHECK_THROW(device.write<int32_t>("/Integers/signed32", 0), ChimeraTK::runtime_error);
49 BOOST_CHECK(!device.isFunctional());
50 BOOST_CHECK_NO_THROW(device.open("(ExceptionDummy:1?map=test3.map)"));
51 BOOST_CHECK(device.isFunctional());
52
53 // test throwExceptionOpen
54 exceptionDummy->throwExceptionOpen = true;
55 BOOST_CHECK(device.isFunctional()); // has no effect yet, as no exception was thrown so far
56 BOOST_CHECK_THROW(device.open("(ExceptionDummy:1?map=test3.map)"), ChimeraTK::runtime_error);
57 BOOST_CHECK(!device.isFunctional());
58 exceptionDummy->throwExceptionOpen = false;
59 BOOST_CHECK(!device.isFunctional());
60 device.open("(ExceptionDummy:1?map=test3.map)");
61 BOOST_CHECK(device.isFunctional());
62}
Class allows to read/write registers from device.
Definition Device.h:39
ScalarRegisterAccessor< UserType > getScalarRegisterAccessor(const RegisterPath &registerPathName, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a ScalarRegisterObject object for the given register.
Definition Device.h:266
bool isFunctional() const
Return wether a device is working as intended, usually this means it is opened and does not have any ...
Definition Device.cc:82
UserType read(const RegisterPath &registerPathName, const AccessModeFlags &flags=AccessModeFlags({})) const
Inefficient convenience function to read a single-word register without obtaining an accessor.
Definition Device.h:296
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition Device.cc:58
void write(const RegisterPath &registerPathName, UserType value, const AccessModeFlags &flags=AccessModeFlags({}))
Inefficient convenience function to write a single-word register without obtaining an accessor.
Definition Device.h:317
Exception thrown when a runtime error has occured.
Definition Exception.h:18
auto exceptionDummy
ctk::Device device
BOOST_AUTO_TEST_CASE(testExceptionsDummyDevice)