4 #define BOOST_TEST_DYN_LINK
6 #define BOOST_TEST_MODULE NumericAddressedBackendRegisterAccessorTest
8 #include <boost/test/unit_test.hpp>
9 using namespace boost::unit_test_framework;
38 BOOST_AUTO_TEST_SUITE(NumericAddressedBackendRegisterAccessorTestSuite)
56 BOOST_CHECK(accessor1.getNElements() == 10);
59 BOOST_CHECK(accessor2.getNElements() == 5);
62 BOOST_CHECK(accessor3.getNElements() == 3);
81 BOOST_CHECK(accessor5.getNElements() == 10);
107 BOOST_CHECK(accToReadOnly.isReadOnly());
108 BOOST_CHECK(!accToReadOnly.isWriteable());
120 for(
auto& value : accessor1) {
128 for(
auto& value : accessor2) {
129 BOOST_CHECK(value == 0xFF);
132 for(
auto& value : accessor1) {
136 for(
auto& value : accessor1) {
137 BOOST_CHECK(value == 0x77);
141 for(
auto& value : accessor2) {
142 BOOST_CHECK(value == 0x77);
148 for(
auto& value : accessor2) {
149 BOOST_CHECK(value == 0x77);
171 for(
auto& value : a1) {
177 BOOST_CHECK(standalone[0] == 0x77);
178 BOOST_CHECK(standalone[1] == 0x77);
181 for(
auto& value : a1) {
188 for(
int i = 0; i < 2; ++i) {
191 for(
auto& value : a1) {
192 BOOST_CHECK(value == 0xFF);
195 BOOST_CHECK(standalone[0] == 0xFF);
196 BOOST_CHECK(standalone[1] == 0xFF);
200 standalone[0] = 0xAA;
201 standalone[1] = 0xAA;
204 for(
int i = 0; i < 2; ++i) {
206 for(
auto& value : a1) {
207 BOOST_CHECK(value == 0xAA);
211 standalone[0] = 0xAB;
212 standalone[1] = 0xAB;
217 for(
auto& value : a1) {
218 BOOST_CHECK(value == 0xAB);
222 BOOST_CHECK(standalone[0] == 0xAB);
223 BOOST_CHECK(standalone[1] == 0xAB);
226 for(
auto& value : a2) {
233 group.addAccessor(a2);
234 for(
auto& value : a1) {
237 for(
auto& value : a2) {
241 for(
int i = 0; i < 2; ++i) {
243 for(
auto& value : a1) {
244 BOOST_CHECK(value == 0xFD);
246 for(
auto& value : a2) {
247 BOOST_CHECK(value == 0xFE);
250 BOOST_CHECK(standalone[0] == 0xFD);
251 BOOST_CHECK(standalone[1] == 0xFD);
252 BOOST_CHECK(standalone[2] == 0xFE);
253 BOOST_CHECK(standalone[3] == 0xFE);
256 standalone[0] = 0xA1;
257 standalone[1] = 0xA2;
258 standalone[2] = 0xA3;
259 standalone[3] = 0xA4;
264 BOOST_CHECK(a1[0] == 0xA1);
265 BOOST_CHECK(a1[1] == 0xA2);
266 BOOST_CHECK(a2[0] == 0xA3);
267 BOOST_CHECK(a2[1] == 0xA4);
270 BOOST_CHECK(standalone[0] == 0xA1);
271 BOOST_CHECK(standalone[1] == 0xA2);
272 BOOST_CHECK(standalone[2] == 0xA3);
273 BOOST_CHECK(standalone[3] == 0xA4);
286 auto deviceDescriptor =
"(dummy?map=goodMapFile.map)";
289 boost::dynamic_pointer_cast<DummyBackend>(BackendFactory::getInstance().createBackend(deviceDescriptor));
296 auto user1Dummy = dummyBackend->getRawAccessor(
"MODULE0",
"WORD_USER1");
300 auto bufferLock = user1Dummy.getBufferLock();
307 BOOST_CHECK_CLOSE(
float(user1Coocked), 2148.125, 0.0001);
310 user1Coocked.write();
313 auto bufferLock = user1Dummy.getBufferLock();
314 BOOST_CHECK_EQUAL(int32_t(user1Dummy), 0xfff8);
320 BOOST_CHECK_EQUAL(int32_t(user1Raw), 0xfff8);
321 BOOST_CHECK_CLOSE(user1Raw.getAsCooked<
float>(), -1, 0.0001);
323 user1Raw.setAsCooked(-2.5);
328 auto bufferLock = user1Dummy.getBufferLock();
329 BOOST_CHECK_EQUAL(int32_t(user1Dummy), 0xffec);
334 user1CoockedInt.read();
336 BOOST_CHECK_EQUAL(
int(user1CoockedInt), -3);
338 user1CoockedInt = 16;
339 user1CoockedInt.write();
342 auto bufferLock = user1Dummy.getBufferLock();
343 BOOST_CHECK_EQUAL(int32_t(user1Dummy), 0x80);
349 auto floatTestDummy = dummyBackend->getRawAccessor(
"FLOAT_TEST",
"ARRAY");
351 float testValue = 1.1;
352 void* warningAvoider = &testValue;
354 auto bufferLock = floatTestDummy.getBufferLock();
355 floatTestDummy[0] = *(
reinterpret_cast<int32_t*
>(warningAvoider));
357 floatTestDummy[1] = *(
reinterpret_cast<int32_t*
>(warningAvoider));
359 floatTestDummy[2] = *(
reinterpret_cast<int32_t*
>(warningAvoider));
361 floatTestDummy[3] = *(
reinterpret_cast<int32_t*
>(warningAvoider));
365 floatTestCoocked.read();
367 BOOST_CHECK_CLOSE(floatTestCoocked[0], 1.1, 0.0001);
368 BOOST_CHECK_CLOSE(floatTestCoocked[1], 2.2, 0.0001);
369 BOOST_CHECK_CLOSE(floatTestCoocked[2], 3.3, 0.0001);
370 BOOST_CHECK_CLOSE(floatTestCoocked[3], 4.4, 0.0001);
372 floatTestCoocked[3] = 44.4;
373 floatTestCoocked.write();
376 auto bufferLock = floatTestDummy.getBufferLock();
377 *(
reinterpret_cast<int32_t*
>(warningAvoider)) = floatTestDummy[3];
379 BOOST_CHECK_CLOSE(testValue, 44.4, 0.0001);
384 *(
reinterpret_cast<int32_t*
>(warningAvoider)) = floatTestRaw[2];
386 BOOST_CHECK_CLOSE(testValue, 3.3, 0.0001);
387 BOOST_CHECK_CLOSE(floatTestRaw.getAsCooked<
float>(0), 1.1, 0.0001);
389 floatTestRaw.setAsCooked(0, -2.5);
391 floatTestRaw.write();
394 auto bufferLock = floatTestDummy.getBufferLock();
395 *(
reinterpret_cast<int32_t*
>(warningAvoider)) = floatTestDummy[0];
397 BOOST_CHECK_CLOSE(testValue, -2.5, 0.0001);
401 floatTestCoockedInt.read();
403 BOOST_CHECK_EQUAL(floatTestCoockedInt[0], -3);
404 BOOST_CHECK_EQUAL(floatTestCoockedInt[1], 2);
405 BOOST_CHECK_EQUAL(floatTestCoockedInt[2], 3);
406 BOOST_CHECK_EQUAL(floatTestCoockedInt[3], 44);
408 floatTestCoockedInt[1] = 16;
409 floatTestCoockedInt.write();
412 auto bufferLock = floatTestDummy.getBufferLock();
413 *(
reinterpret_cast<int32_t*
>(warningAvoider)) = floatTestDummy[1];
415 BOOST_CHECK_CLOSE(testValue, 16.0, 0.001);
421 Device d(
"(dummy?map=goodMapFile.map)");
423 BOOST_CHECK_NO_THROW((
void)catalogue.getRegister(
"MODULE0/WORD_USER1"));
426 BOOST_CHECK_NO_THROW(d.
open());
433 BackendFactory::getInstance().setDMapFilePath(
"dummies.dmap");
452 auto mux0i = boost::dynamic_pointer_cast<NDRegisterAccessor<int>>(mux0.getHighLevelImplElement());
453 auto mux1i = boost::dynamic_pointer_cast<NDRegisterAccessor<int>>(mux1.getHighLevelImplElement());
454 auto mux2i = boost::dynamic_pointer_cast<NDRegisterAccessor<int>>(mux2.getHighLevelImplElement());
455 auto mux3i = boost::dynamic_pointer_cast<NDRegisterAccessor<int>>(mux3.getHighLevelImplElement());
458 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] != mux1i->getHardwareAccessingElements()[0]);
459 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] != mux2i->getHardwareAccessingElements()[0]);
460 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] != mux3i->getHardwareAccessingElements()[0]);
461 BOOST_CHECK(mux1i->getHardwareAccessingElements()[0] != mux2i->getHardwareAccessingElements()[0]);
462 BOOST_CHECK(mux1i->getHardwareAccessingElements()[0] != mux3i->getHardwareAccessingElements()[0]);
463 BOOST_CHECK(mux2i->getHardwareAccessingElements()[0] != mux3i->getHardwareAccessingElements()[0]);
467 llelem = boost::static_pointer_cast<NumericAddressedLowLevelTransferElement>(mux0i->getHardwareAccessingElements()[0])
471 llelem = boost::static_pointer_cast<NumericAddressedLowLevelTransferElement>(mux1i->getHardwareAccessingElements()[0])
475 llelem = boost::static_pointer_cast<NumericAddressedLowLevelTransferElement>(mux2i->getHardwareAccessingElements()[0])
479 llelem = boost::static_pointer_cast<NumericAddressedLowLevelTransferElement>(mux3i->getHardwareAccessingElements()[0])
493 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] == mux1i->getHardwareAccessingElements()[0]);
494 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] == mux2i->getHardwareAccessingElements()[0]);
495 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] == mux3i->getHardwareAccessingElements()[0]);
498 llelem = boost::static_pointer_cast<NumericAddressedLowLevelTransferElement>(mux0i->getHardwareAccessingElements()[0])
511 BOOST_CHECK(mux0b == 42);
513 BOOST_CHECK(mux1b == 120);
515 BOOST_CHECK(mux2b == 84);
517 BOOST_CHECK(mux3b == 240);
522 BOOST_CHECK(mux0 == 123);
523 BOOST_CHECK(mux1 == 120);
524 BOOST_CHECK(mux2 == 84);
525 BOOST_CHECK(mux3 == 240);
530 BOOST_CHECK(mux0 == 123);
531 BOOST_CHECK(mux1 == 234);
532 BOOST_CHECK(mux2 == 84);
533 BOOST_CHECK(mux3 == 240);
538 BOOST_CHECK(mux0 == 123);
539 BOOST_CHECK(mux1 == 234);
540 BOOST_CHECK(mux2 == 345);
541 BOOST_CHECK(mux3 == 240);
546 BOOST_CHECK(mux0 == 123);
547 BOOST_CHECK(mux1 == 234);
548 BOOST_CHECK(mux2 == 345);
549 BOOST_CHECK(mux3 == 456);
555 BackendFactory::getInstance().setDMapFilePath(
"dummies.dmap");
574 auto mux0i = boost::dynamic_pointer_cast<NDRegisterAccessor<uint16_t>>(mux0.getHighLevelImplElement());
575 auto mux1i = boost::dynamic_pointer_cast<NDRegisterAccessor<uint16_t>>(mux1.getHighLevelImplElement());
576 auto mux2i = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(mux2.getHighLevelImplElement());
577 auto mux3i = boost::dynamic_pointer_cast<NDRegisterAccessor<int64_t>>(mux3.getHighLevelImplElement());
580 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] != mux1i->getHardwareAccessingElements()[0]);
581 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] != mux2i->getHardwareAccessingElements()[0]);
582 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] != mux3i->getHardwareAccessingElements()[0]);
583 BOOST_CHECK(mux1i->getHardwareAccessingElements()[0] != mux2i->getHardwareAccessingElements()[0]);
584 BOOST_CHECK(mux1i->getHardwareAccessingElements()[0] != mux3i->getHardwareAccessingElements()[0]);
585 BOOST_CHECK(mux2i->getHardwareAccessingElements()[0] != mux3i->getHardwareAccessingElements()[0]);
596 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] == mux1i->getHardwareAccessingElements()[0]);
597 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] == mux2i->getHardwareAccessingElements()[0]);
598 BOOST_CHECK(mux0i->getHardwareAccessingElements()[0] == mux3i->getHardwareAccessingElements()[0]);
615 BOOST_CHECK(mux0b == 42);
617 BOOST_CHECK(mux1b == 120);
619 BOOST_CHECK(mux2b == 84);
621 BOOST_CHECK(mux3b == 240);
626 BOOST_CHECK(mux0 == 123);
627 BOOST_CHECK(mux1 == 120);
628 BOOST_CHECK(mux2 == 84);
629 BOOST_CHECK(mux3 == 240);
634 BOOST_CHECK(mux0 == 123);
635 BOOST_CHECK(mux1 == 234);
636 BOOST_CHECK(mux2 == 84);
637 BOOST_CHECK(mux3 == 240);
642 BOOST_CHECK(mux0 == 123);
643 BOOST_CHECK(mux1 == 234);
644 BOOST_CHECK(mux2 == 345);
645 BOOST_CHECK(mux3 == 240);
650 BOOST_CHECK(mux0 == 123);
651 BOOST_CHECK(mux1 == 234);
652 BOOST_CHECK(mux2 == 345);
653 BOOST_CHECK(mux3 == 456);
658 BOOST_AUTO_TEST_SUITE_END()