4 #define BOOST_TEST_DYN_LINK
6 #define BOOST_TEST_MODULE RegisterCatalogue
7 #include <boost/test/unit_test.hpp>
8 using namespace boost::unit_test_framework;
18 myRegisterInfo(std::string path,
unsigned int nbOfElements,
unsigned int nbOfChannels,
unsigned int nbOfDimensions,
20 : _path(path), _nbOfElements(nbOfElements), _nbOfChannels(nbOfChannels), _nbOfDimensions(nbOfDimensions),
21 _dataDescriptor(dataDescriptor), _readable(readable), _writeable(writeable), _supportedFlags(supportedFlags) {}
39 [[nodiscard]] std::unique_ptr<BackendRegisterInfoBase>
clone()
const override {
41 return std::unique_ptr<BackendRegisterInfoBase>(info);
72 DataDescriptor dataDescriptor{DataDescriptor::FundamentalType::numeric,
false,
false, 8, 3, DataType::int32};
73 myRegisterInfo theInfo{
"/some/register/name", 42, 3, 2, dataDescriptor,
true,
false, {AccessMode::raw}};
75 DataDescriptor dataDescriptor2{DataDescriptor::FundamentalType::numeric,
true,
false, 12};
77 "/some/other/name", 1, 1, 0, dataDescriptor2,
true,
true, {AccessMode::raw, AccessMode::wait_for_new_data}};
80 myRegisterInfo theInfo3{
"/justAName", 1, 1, 0, dataDescriptor3,
false,
false, {}};
85 BOOST_AUTO_TEST_SUITE(RegisterCatalogueTestSuite)
93 BOOST_TEST(catalogue.getNumberOfRegisters() == 3);
95 auto info = catalogue.getRegister(
"/some/register/name");
97 BOOST_TEST(info.getRegisterName() ==
"/some/register/name");
98 BOOST_TEST(info.getNumberOfElements() == 42);
99 BOOST_TEST(info.getNumberOfChannels() == 3);
100 BOOST_TEST(info.getNumberOfDimensions() == 2);
101 BOOST_TEST(info.getDataDescriptor().fundamentalType() == DataDescriptor::FundamentalType::numeric);
102 BOOST_TEST(info.getDataDescriptor().isSigned() ==
false);
103 BOOST_TEST(info.getDataDescriptor().isIntegral() ==
false);
104 BOOST_TEST(info.getDataDescriptor().nDigits() == 8);
105 BOOST_TEST(info.getDataDescriptor().nFractionalDigits() == 3);
106 BOOST_TEST(info.getDataDescriptor().rawDataType() == DataType::int32);
107 BOOST_TEST(info.getDataDescriptor().rawDataType().isNumeric());
108 BOOST_TEST(info.getDataDescriptor().rawDataType().isIntegral());
109 BOOST_TEST(info.getDataDescriptor().rawDataType().isSigned());
110 BOOST_TEST(info.isReadable() ==
true);
111 BOOST_TEST(info.isWriteable() ==
false);
112 BOOST_TEST(info.getSupportedAccessModes().has(AccessMode::raw) ==
true);
113 BOOST_TEST(info.getSupportedAccessModes().has(AccessMode::wait_for_new_data) ==
false);
115 auto& theImpl = info.getImpl();
117 BOOST_TEST(theImpl_casted !=
nullptr);
118 BOOST_TEST(theImpl_casted != &generator.
theInfo);
120 info = catalogue.getRegister(
"/some/other/name");
121 BOOST_TEST(info.getRegisterName() ==
"/some/other/name");
122 BOOST_TEST(info.getNumberOfElements() == 1);
123 BOOST_TEST(info.getNumberOfChannels() == 1);
124 BOOST_TEST(info.getNumberOfDimensions() == 0);
125 BOOST_TEST(info.getDataDescriptor().fundamentalType() == DataDescriptor::FundamentalType::numeric);
126 BOOST_TEST(info.getDataDescriptor().isSigned() ==
false);
127 BOOST_TEST(info.getDataDescriptor().isIntegral() ==
true);
128 BOOST_TEST(info.getDataDescriptor().nDigits() == 12);
129 BOOST_TEST(info.getDataDescriptor().rawDataType() == DataType::none);
130 BOOST_TEST(info.getDataDescriptor().rawDataType().isNumeric() ==
false);
131 BOOST_TEST(info.getDataDescriptor().rawDataType().isIntegral() ==
false);
132 BOOST_TEST(info.getDataDescriptor().rawDataType().isSigned() ==
false);
133 BOOST_TEST(info.isReadable() ==
true);
134 BOOST_TEST(info.isWriteable() ==
true);
135 BOOST_TEST(info.getSupportedAccessModes().has(AccessMode::raw) ==
true);
136 BOOST_TEST(info.getSupportedAccessModes().has(AccessMode::wait_for_new_data) ==
true);
138 info = catalogue.getRegister(
"/justAName");
139 BOOST_TEST(info.getRegisterName() ==
"/justAName");
140 BOOST_TEST(info.getNumberOfElements() == 1);
141 BOOST_TEST(info.getNumberOfChannels() == 1);
142 BOOST_TEST(info.getNumberOfDimensions() == 0);
143 BOOST_TEST(info.getDataDescriptor().fundamentalType() == DataDescriptor::FundamentalType::string);
144 BOOST_TEST(info.getDataDescriptor().rawDataType() == DataType::none);
145 BOOST_TEST(info.getDataDescriptor().rawDataType().isNumeric() ==
false);
146 BOOST_TEST(info.getDataDescriptor().rawDataType().isIntegral() ==
false);
147 BOOST_TEST(info.getDataDescriptor().rawDataType().isSigned() ==
false);
148 BOOST_TEST(info.isReadable() ==
false);
149 BOOST_TEST(info.isWriteable() ==
false);
150 BOOST_TEST(info.getSupportedAccessModes().has(AccessMode::raw) ==
false);
151 BOOST_TEST(info.getSupportedAccessModes().has(AccessMode::wait_for_new_data) ==
false);
160 std::unique_ptr<BackendRegisterCatalogue<myRegisterInfo>> cat_copy(
162 BOOST_TEST(cat_copy->getNumberOfRegisters() == 3);
165 catalogue.getBackendRegister(
"/some/register/name") == cat_copy->getBackendRegister(
"/some/register/name"));
166 BOOST_CHECK(catalogue.getBackendRegister(
"/some/other/name") == cat_copy->getBackendRegister(
"/some/other/name"));
167 BOOST_CHECK(catalogue.getBackendRegister(
"/justAName") == cat_copy->getBackendRegister(
"/justAName"));
169 std::vector<myRegisterInfo> seenObjects;
170 for(
auto& i : *cat_copy) {
171 seenObjects.push_back(i);
174 BOOST_TEST(seenObjects.size() == 3);
175 BOOST_CHECK(seenObjects[0] == generator.
theInfo);
176 BOOST_CHECK(seenObjects[1] == generator.
theInfo2);
177 BOOST_CHECK(seenObjects[2] == generator.
theInfo3);
186 std::vector<myRegisterInfo> seenObjects;
187 for(
auto& elem : catalogue) {
188 seenObjects.push_back(elem);
191 BOOST_TEST(seenObjects.size() == 3);
192 BOOST_CHECK(seenObjects[0] == generator.
theInfo);
193 BOOST_CHECK(seenObjects[1] == generator.
theInfo2);
194 BOOST_CHECK(seenObjects[2] == generator.
theInfo3);
203 std::vector<myRegisterInfo> seenObjects;
204 for(
const auto& elem : catalogue) {
205 seenObjects.push_back(elem);
208 BOOST_TEST(seenObjects.size() == 3);
209 BOOST_CHECK(seenObjects[0] == generator.
theInfo);
210 BOOST_CHECK(seenObjects[1] == generator.
theInfo2);
211 BOOST_CHECK(seenObjects[2] == generator.
theInfo3);
221 std::vector<RegisterInfo> seenObjects;
222 for(
const auto& elem : catalogue) {
223 seenObjects.emplace_back(elem.clone());
226 BOOST_TEST(seenObjects.size() == 3);
234 BOOST_AUTO_TEST_SUITE_END()