ChimeraTK-DeviceAccess  03.18.00
testLMapForceReadOnlyPlugin.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 LMapForceReadOnlyPluginTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
8 
9 #include "BackendFactory.h"
10 #include "Device.h"
11 #include "DeviceAccessVersion.h"
12 #include "DummyBackend.h"
13 
14 using namespace ChimeraTK;
15 
16 /**********************************************************************************************************************/
17 
20  device.open("(logicalNameMap?map=forceReadOnlyPlugin.xlmap)");
21 
22  auto cat = device.getRegisterCatalogue();
23  auto info = cat.getRegister("test");
24  BOOST_CHECK(!info.isWriteable());
25  BOOST_CHECK(info.isReadable());
26 
27  auto acc = device.getScalarRegisterAccessor<double>("test");
28  BOOST_CHECK(!acc.isWriteable());
29  BOOST_CHECK(acc.isReadable());
30 
31  BOOST_CHECK_THROW(acc.write(), ChimeraTK::logic_error);
32  BOOST_CHECK_NO_THROW(acc.read());
33 }
34 
35 /**********************************************************************************************************************/
36 
37 BOOST_AUTO_TEST_CASE(testWithMathPlugin) {
38  // this xlmap was causing a logic_error although it should not.
39  // See ticket https://redmine.msktools.desy.de/issues/9551
40 
42  device.open("(logicalNameMap?map=forceReadOnlyPlugin2.xlmap)");
43 
44  auto cat = device.getRegisterCatalogue();
45  auto infoA = cat.getRegister("Test/A");
46  BOOST_CHECK(!infoA.isWriteable());
47  BOOST_CHECK(infoA.isReadable());
48 
49  auto accA = device.getScalarRegisterAccessor<double>("Test/A");
50  BOOST_CHECK(!accA.isWriteable());
51  BOOST_CHECK(accA.isReadable());
52 
53  auto infoB = cat.getRegister("Test/B");
54  BOOST_CHECK(!infoB.isWriteable());
55  BOOST_CHECK(infoB.isReadable());
56 
57  auto accB = device.getScalarRegisterAccessor<double>("Test/B");
58  BOOST_CHECK(!accB.isWriteable());
59  BOOST_CHECK(accB.isReadable());
60  BOOST_CHECK_NO_THROW(accB.read());
61 }
62 
63 /**********************************************************************************************************************/
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test)
Definition: testLMapForceReadOnlyPlugin.cc:18
device
ctk::Device device
Definition: testExceptionDummyDevice.cc:18
DummyBackend.h
ChimeraTK::RegisterCatalogue::getRegister
RegisterInfo getRegister(const RegisterPath &registerPathName) const
Get register information for a given full path name.
Definition: RegisterCatalogue.cc:43
Device.h
ChimeraTK::Device::getRegisterCatalogue
RegisterCatalogue getRegisterCatalogue() const
Return the register catalogue with detailed information on all registers.
Definition: Device.cc:22
ChimeraTK::Device
Class allows to read/write registers from device.
Definition: Device.h:39
ChimeraTK::Device::open
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition: Device.cc:58
ChimeraTK::Device::getScalarRegisterAccessor
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:263
BackendFactory.h
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51