LCOV - code coverage report
Current view: top level - fddetdataformats/unittest - WIBFrame_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 383 383
Test Date: 2025-12-21 13:07:08 Functions: 100.0 % 33 33

            Line data    Source code
       1              : 
       2              : /**
       3              :  * @file WIBFrame_test.cxx WIBFrame class Unit Tests
       4              :  *
       5              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       6              :  * Licensing/copyright details are in the COPYING file that you should have
       7              :  * received with this code.
       8              :  */
       9              : 
      10              : #include "fddetdataformats/WIBFrame.hpp"
      11              : 
      12              : /**
      13              :  * @brief Name of this test module
      14              :  */
      15              : #define BOOST_TEST_MODULE WIBFrame_test // NOLINT
      16              : 
      17              : #include "boost/test/unit_test.hpp"
      18              : 
      19              : #include <string>
      20              : #include <vector>
      21              : 
      22              : using namespace dunedaq::fddetdataformats;
      23              : 
      24              : BOOST_AUTO_TEST_SUITE(WIBFrame_test)
      25              : 
      26            2 : BOOST_AUTO_TEST_CASE(WIBHeader_TimestampMethods)
      27              : {
      28            1 :   WIBHeader header;
      29            1 :   header.z = 0;
      30            1 :   header.wib_counter_1 = 0x7FFF;
      31            1 :   header.timestamp_1 = 0x11111111;
      32            1 :   header.timestamp_2 = 0x2222;
      33              : 
      34            1 :   BOOST_REQUIRE_EQUAL(header.get_timestamp(), 0x7FFF222211111111);
      35            1 :   BOOST_REQUIRE_EQUAL(header.get_wib_counter(), 0);
      36              : 
      37            1 :   header.set_wib_counter(0x3333);
      38            1 :   BOOST_REQUIRE_EQUAL(header.get_timestamp(), 0x7FFF222211111111);
      39            1 :   BOOST_REQUIRE_EQUAL(header.get_wib_counter(), 0);
      40              : 
      41            1 :   header.set_timestamp(0xF333444455555555); // Try to toggle z bit
      42            1 :   BOOST_REQUIRE_EQUAL(header.get_timestamp(), 0x7333444455555555);
      43            1 :   BOOST_REQUIRE_EQUAL(header.wib_counter_1, 0x7333);
      44            1 :   BOOST_REQUIRE_EQUAL(header.timestamp_1, 0x55555555);
      45            1 :   BOOST_REQUIRE_EQUAL(header.timestamp_2, 0x4444);
      46            1 :   BOOST_REQUIRE_EQUAL(header.z, 0);
      47              : 
      48            1 :   header.z = 1;
      49            1 :   header.wib_counter_1 = 0x7FFF;
      50            1 :   header.timestamp_1 = 0x11111111;
      51            1 :   header.timestamp_2 = 0x2222;
      52              : 
      53            1 :   BOOST_REQUIRE_EQUAL(header.get_timestamp(), 0x222211111111);
      54            1 :   BOOST_REQUIRE_EQUAL(header.get_wib_counter(), 0x7FFF);
      55              : 
      56            1 :   header.set_wib_counter(0x7333); // Try to toggle z bit
      57            1 :   BOOST_REQUIRE_EQUAL(header.get_timestamp(), 0x222211111111);
      58            1 :   BOOST_REQUIRE_EQUAL(header.get_wib_counter(), 0x7333);
      59            1 :   BOOST_REQUIRE_EQUAL(header.z, 1);
      60              : 
      61            1 :   header.set_timestamp(0xFFFF444455555555); // Try to change wib_counter_1
      62            1 :   BOOST_REQUIRE_EQUAL(header.get_timestamp(), 0x444455555555);
      63            1 :   BOOST_REQUIRE_EQUAL(header.wib_counter_1, 0x7333);
      64            1 :   BOOST_REQUIRE_EQUAL(header.timestamp_1, 0x55555555);
      65            1 :   BOOST_REQUIRE_EQUAL(header.timestamp_2, 0x4444);
      66            1 : }
      67            2 : BOOST_AUTO_TEST_CASE(WIBHeader_StreamMethods)
      68              : {
      69            1 :   WIBHeader header {};
      70              : 
      71            1 :   std::ostringstream ostr;
      72            1 :   header.print_hex(ostr);
      73            1 :   std::string output = ostr.str();
      74            1 :   BOOST_TEST_MESSAGE("Print hex: " << output);
      75            1 :   BOOST_REQUIRE(!output.empty());
      76              : 
      77            1 :   ostr.str("");
      78            1 :   ostr.clear();
      79              : 
      80            1 :   header.print_bits(ostr);
      81            1 :   output = ostr.str();
      82            1 :   BOOST_TEST_MESSAGE("Print bits: " << output);
      83            1 :   BOOST_REQUIRE(!output.empty());
      84              : 
      85            1 :   ostr.str("");
      86            1 :   ostr.clear();
      87              : 
      88            1 :   ostr << header;
      89            1 :   output = ostr.str();
      90            1 :   BOOST_TEST_MESSAGE("Stream operator: " << output);
      91            1 :   BOOST_REQUIRE(!output.empty());
      92            1 : }
      93              : 
      94            2 : BOOST_AUTO_TEST_CASE(ColdataHeader_ChecksumMethods)
      95              : {
      96            1 :   ColdataHeader header;
      97            1 :   header.checksum_a_1 = 0x11;
      98            1 :   header.checksum_a_2 = 0x22;
      99            1 :   header.checksum_b_1 = 0x33;
     100            1 :   header.checksum_b_2 = 0x44;
     101              : 
     102            1 :   BOOST_REQUIRE_EQUAL(header.get_checksum_a(), 0x2211);
     103            1 :   BOOST_REQUIRE_EQUAL(header.get_checksum_b(), 0x4433);
     104              : 
     105            1 :   header.set_checksum_a(0x5566);
     106            1 :   header.set_checksum_b(0x7788);
     107            1 :   BOOST_REQUIRE_EQUAL(header.get_checksum_a(), 0x5566);
     108            1 :   BOOST_REQUIRE_EQUAL(header.get_checksum_b(), 0x7788);
     109            1 :   BOOST_REQUIRE_EQUAL(header.checksum_a_1, 0x66);
     110            1 :   BOOST_REQUIRE_EQUAL(header.checksum_a_2, 0x55);
     111            1 :   BOOST_REQUIRE_EQUAL(header.checksum_b_1, 0x88);
     112            1 :   BOOST_REQUIRE_EQUAL(header.checksum_b_2, 0x77);
     113            1 : }
     114            2 : BOOST_AUTO_TEST_CASE(ColdataHeader_HdrMethods)
     115              : {
     116            1 :   ColdataHeader header;
     117            1 :   header.hdr_1 = 0x1;
     118            1 :   header.hdr_2 = 0x2;
     119            1 :   header.hdr_3 = 0x3;
     120            1 :   header.hdr_4 = 0x4;
     121            1 :   header.hdr_5 = 0x5;
     122            1 :   header.hdr_6 = 0x6;
     123            1 :   header.hdr_7 = 0x7;
     124            1 :   header.hdr_8 = 0x8;
     125              : 
     126            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(1), 0x1);
     127            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(2), 0x2);
     128            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(3), 0x3);
     129            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(4), 0x4);
     130            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(5), 0x5);
     131            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(6), 0x6);
     132            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(7), 0x7);
     133            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(8), 0x8);
     134            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(9), 0x0);
     135            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(0), 0x0);
     136              : 
     137            1 :   header.set_hdr(1, 0x9);
     138            1 :   BOOST_REQUIRE_EQUAL(header.hdr_1, 0x9);
     139            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(1), 0x9);
     140            1 :   header.set_hdr(2, 0xA);
     141            1 :   BOOST_REQUIRE_EQUAL(header.hdr_2, 0xA);
     142            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(2), 0xA);
     143            1 :   header.set_hdr(3, 0xB);
     144            1 :   BOOST_REQUIRE_EQUAL(header.hdr_3, 0xB);
     145            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(3), 0xB);
     146              : 
     147            1 :   header.set_hdr(4, 0xFF);
     148            1 :   BOOST_REQUIRE_EQUAL(header.hdr_4, 0xF);
     149            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(4), 0xF);
     150            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(3), 0xB);
     151            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(5), 0x5);
     152              : 
     153            1 :   header.set_hdr(5, 0xC);
     154            1 :   BOOST_REQUIRE_EQUAL(header.hdr_5, 0xC);
     155            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(5), 0xC);
     156            1 :   header.set_hdr(6, 0xD);
     157            1 :   BOOST_REQUIRE_EQUAL(header.hdr_6, 0xD);
     158            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(6), 0xD);
     159            1 :   header.set_hdr(7, 0xE);
     160            1 :   BOOST_REQUIRE_EQUAL(header.hdr_7, 0xE);
     161            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(7), 0xE);
     162            1 :   header.set_hdr(8, 0xF);
     163            1 :   BOOST_REQUIRE_EQUAL(header.hdr_8, 0xF);
     164            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(8), 0xF);
     165              : 
     166            1 :   header.set_hdr(0, 0xB);
     167            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(1), 0x9);
     168            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(2), 0xA);
     169            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(3), 0xB);
     170            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(4), 0xF);
     171            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(5), 0xC);
     172            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(6), 0xD);
     173            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(7), 0xE);
     174            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(8), 0xF);
     175            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(9), 0x0);
     176            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(0), 0x0);
     177              : 
     178            1 :   header.set_hdr(9, 0xC);
     179            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(1), 0x9);
     180            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(2), 0xA);
     181            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(3), 0xB);
     182            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(4), 0xF);
     183            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(5), 0xC);
     184            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(6), 0xD);
     185            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(7), 0xE);
     186            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(8), 0xF);
     187            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(9), 0x0);
     188            1 :   BOOST_REQUIRE_EQUAL(header.get_hdr(0), 0x0);
     189            1 : }
     190            2 : BOOST_AUTO_TEST_CASE(ColdataHeader_StreamMethods)
     191              : {
     192            1 :   ColdataHeader header {};
     193              : 
     194            1 :   std::ostringstream ostr;
     195            1 :   header.print_hex(ostr);
     196            1 :   std::string output = ostr.str();
     197            1 :   BOOST_TEST_MESSAGE("Print hex: " << output);
     198            1 :   BOOST_REQUIRE(!output.empty());
     199              : 
     200            1 :   ostr.str("");
     201            1 :   ostr.clear();
     202              : 
     203            1 :   header.print_bits(ostr);
     204            1 :   output = ostr.str();
     205            1 :   BOOST_TEST_MESSAGE("Print bits: " << output);
     206            1 :   BOOST_REQUIRE(!output.empty());
     207              : 
     208            1 :   ostr.str("");
     209            1 :   ostr.clear();
     210              : 
     211            1 :   ostr << header;
     212            1 :   output = ostr.str();
     213            1 :   BOOST_TEST_MESSAGE("Stream operator: " << output);
     214            1 :   BOOST_REQUIRE(!output.empty());
     215            1 : }
     216              : 
     217            2 : BOOST_AUTO_TEST_CASE(ColdataSegment_ChannelMethods)
     218              : {
     219            1 :   ColdataSegment segment {};
     220            1 :   segment.adc0ch0_1 = 0x11;
     221            1 :   segment.adc1ch0_1 = 0x22;
     222            1 :   segment.adc0ch0_2 = 0x3;
     223            1 :   segment.adc0ch1_1 = 0x4;
     224            1 :   segment.adc1ch0_2 = 0x5;
     225            1 :   segment.adc1ch1_1 = 0x6;
     226            1 :   segment.adc0ch1_2 = 0x77;
     227            1 :   segment.adc1ch1_2 = 0x88;
     228            1 :   segment.adc0ch2_1 = 0x99;
     229            1 :   segment.adc1ch2_1 = 0xAA;
     230            1 :   segment.adc0ch2_2 = 0xB;
     231            1 :   segment.adc0ch3_1 = 0xC;
     232            1 :   segment.adc1ch2_2 = 0xD;
     233            1 :   segment.adc1ch3_1 = 0xE;
     234            1 :   segment.adc0ch3_2 = 0xFF;
     235            1 :   segment.adc1ch3_2 = 0x10;
     236              : 
     237            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 0), 0x311);
     238            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 1), 0x774);
     239            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 2), 0xB99);
     240            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 3), 0xFFC);
     241              : 
     242            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 0), 0x522);
     243            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 1), 0x886);
     244            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 2), 0xDAA);
     245            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 3), 0x10E);
     246              : 
     247            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(2, 0), 0x311);
     248            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(2, 1), 0x774);
     249            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(2, 2), 0xB99);
     250            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(2, 3), 0xFFC);
     251              : 
     252            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 4), 0x311);
     253            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 5), 0x774);
     254            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 6), 0xB99);
     255            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 7), 0xFFC);
     256              : 
     257            1 :   segment.set_channel(0, 0, 0x1133);
     258            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 0), 0x133);
     259            1 :   BOOST_REQUIRE_EQUAL(segment.adc0ch0_1, 0x33);
     260            1 :   BOOST_REQUIRE_EQUAL(segment.adc0ch0_2, 0x1);
     261            1 :   segment.set_channel(0, 1, 0x447);
     262            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 1), 0x447);
     263            1 :   BOOST_REQUIRE_EQUAL(segment.adc0ch1_1, 0x7);
     264            1 :   BOOST_REQUIRE_EQUAL(segment.adc0ch1_2, 0x44);
     265            1 :   segment.set_channel(0, 2, 0x9BB);
     266            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 2), 0x9BB);
     267            1 :   BOOST_REQUIRE_EQUAL(segment.adc0ch2_1, 0xBB);
     268            1 :   BOOST_REQUIRE_EQUAL(segment.adc0ch2_2, 0x9);
     269            1 :   segment.set_channel(0, 3, 0xCCF);
     270            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(0, 3), 0xCCF);
     271            1 :   BOOST_REQUIRE_EQUAL(segment.adc0ch3_1, 0xF);
     272            1 :   BOOST_REQUIRE_EQUAL(segment.adc0ch3_2, 0xCC);
     273              : 
     274            1 :   segment.set_channel(1, 0, 0x255);
     275            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 0), 0x255);
     276            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch0_1, 0x55);
     277            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch0_2, 0x2);
     278            1 :   segment.set_channel(1, 1, 0x668);
     279            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 1), 0x668);
     280            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch1_1, 0x8);
     281            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch1_2, 0x66);
     282            1 :   segment.set_channel(1, 2, 0xADD);
     283            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 2), 0xADD);
     284            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch2_1, 0xDD);
     285            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch2_2, 0xA);
     286            1 :   segment.set_channel(1, 3, 0xEE1);
     287            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 3), 0xEE1);
     288            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch3_1, 0x1);
     289            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch3_2, 0xEE);
     290              : 
     291            1 :   segment.set_channel(3, 5, 0x6688);
     292            1 :   BOOST_REQUIRE_EQUAL(segment.get_channel(1, 1), 0x688);
     293            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch1_1, 0x8);
     294            1 :   BOOST_REQUIRE_EQUAL(segment.adc1ch1_2, 0x68);
     295            1 : }
     296              : 
     297            2 : BOOST_AUTO_TEST_CASE(ColdataBlock_ChannelMethods)
     298              : {
     299            1 :   ColdataBlock block;
     300            1 :   ColdataSegment segment;
     301            1 :   segment.adc0ch0_1 = 0x11;
     302            1 :   segment.adc1ch0_1 = 0x22;
     303            1 :   segment.adc0ch0_2 = 0x3;
     304            1 :   segment.adc0ch1_1 = 0x4;
     305            1 :   segment.adc1ch0_2 = 0x5;
     306            1 :   segment.adc1ch1_1 = 0x6;
     307            1 :   segment.adc0ch1_2 = 0x77;
     308            1 :   segment.adc1ch1_2 = 0x88;
     309            1 :   segment.adc0ch2_1 = 0x99;
     310            1 :   segment.adc1ch2_1 = 0xAA;
     311            1 :   segment.adc0ch2_2 = 0xB;
     312            1 :   segment.adc0ch3_1 = 0xC;
     313            1 :   segment.adc1ch2_2 = 0xD;
     314            1 :   segment.adc1ch3_1 = 0xE;
     315            1 :   segment.adc0ch3_2 = 0xFF;
     316            1 :   segment.adc1ch3_2 = 0x10;
     317              : 
     318            1 :   ColdataSegment rev_seg;
     319            1 :   rev_seg.adc0ch0_1 = 0xAA;
     320            1 :   rev_seg.adc1ch0_1 = 0x99;
     321            1 :   rev_seg.adc0ch0_2 = 0xD;
     322            1 :   rev_seg.adc1ch2_1 = 0x11;
     323            1 :   rev_seg.adc1ch2_2 = 0x3;
     324            1 :   rev_seg.adc1ch3_1 = 0x4;
     325            1 :   rev_seg.adc1ch3_2 = 0x77;
     326            1 :   rev_seg.adc1ch0_2 = 0xB;
     327            1 :   rev_seg.adc1ch1_1 = 0xC;
     328            1 :   rev_seg.adc1ch1_2 = 0xFF;
     329            1 :   rev_seg.adc0ch2_1 = 0x22;
     330            1 :   rev_seg.adc0ch2_2 = 0x5;
     331            1 :   rev_seg.adc0ch3_1 = 0x6;
     332            1 :   rev_seg.adc0ch3_2 = 0x88;
     333            1 :   rev_seg.adc0ch1_1 = 0xE;
     334            1 :   rev_seg.adc0ch1_2 = 0x10;
     335              : 
     336            1 :   block.segments[0] = segment;
     337            1 :   block.segments[1] = rev_seg;
     338              : 
     339            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(0, 0), segment.get_channel(0, 0));
     340            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(0, 1), segment.get_channel(0, 1));
     341            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(0, 2), segment.get_channel(0, 2));
     342            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(0, 3), segment.get_channel(0, 3));
     343            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(0, 4), rev_seg.get_channel(0, 0));
     344            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(0, 5), rev_seg.get_channel(0, 1));
     345            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(0, 6), rev_seg.get_channel(0, 2));
     346            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(0, 7), rev_seg.get_channel(0, 3));
     347            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(1, 0), segment.get_channel(1, 0));
     348            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(1, 1), segment.get_channel(1, 1));
     349            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(1, 2), segment.get_channel(1, 2));
     350            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(1, 3), segment.get_channel(1, 3));
     351            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(1, 4), rev_seg.get_channel(1, 0));
     352            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(1, 5), rev_seg.get_channel(1, 1));
     353            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(1, 6), rev_seg.get_channel(1, 2));
     354            1 :   BOOST_REQUIRE_EQUAL(block.get_channel(1, 7), rev_seg.get_channel(1, 3));
     355              : 
     356            1 :   block.set_channel(0, 0, 0xFFFF);
     357            1 :   BOOST_REQUIRE_EQUAL(block.segments[0].adc0ch0_1, 0xFF);
     358            1 :   BOOST_REQUIRE_EQUAL(block.segments[0].adc0ch0_2, 0xF);
     359            1 :   BOOST_REQUIRE_EQUAL(block.segments[0].adc1ch0_1, 0x22);
     360            1 :   BOOST_REQUIRE_EQUAL(block.segments[0].adc0ch1_1, 0x4);
     361              : 
     362              :   uint8_t invalid_adc = ColdataBlock::s_num_adc_per_block; // NOLINT(build/unsigned)
     363            3 :   BOOST_REQUIRE_EXCEPTION(block.get_channel(invalid_adc, 0),
     364              :                           std::out_of_range,
     365              :                           [&](std::out_of_range) { return true; });
     366            3 :   BOOST_REQUIRE_EXCEPTION(block.set_channel(invalid_adc, 0, 0x123),
     367              :                           std::out_of_range,
     368              :                           [&](std::out_of_range) { return true; });
     369            1 : }
     370            2 : BOOST_AUTO_TEST_CASE(ColdataBlock_StreamOperator)
     371              : {
     372            1 :   ColdataBlock block {};
     373              : 
     374            1 :   std::ostringstream ostr;
     375            1 :   ostr << block;
     376            1 :   auto output = ostr.str();
     377            1 :   BOOST_TEST_MESSAGE("Stream operator: " << output);
     378            1 :   BOOST_REQUIRE(!output.empty());
     379            1 : }
     380              : 
     381            2 : BOOST_AUTO_TEST_CASE(WIBFrame_StructMethods)
     382              : {
     383            1 :   WIBFrame frame {};
     384              : 
     385            1 :   BOOST_REQUIRE(frame.get_wib_header() != nullptr);
     386            1 :   BOOST_REQUIRE(frame.get_coldata_header(0) != nullptr);
     387            3 :   BOOST_REQUIRE_EXCEPTION(frame.get_coldata_header(WIBFrame::s_num_block_per_frame),
     388              :                           std::out_of_range,
     389              :                           [&](std::out_of_range) { return true; });
     390              : 
     391            1 :   BOOST_REQUIRE_NO_THROW(frame.get_block(0));
     392            1 :   ;
     393            1 : }
     394            2 : BOOST_AUTO_TEST_CASE(WIBFrame_HeaderMutators)
     395              : {
     396              : 
     397            1 :   {
     398            1 :     WIBFrame frame;
     399            1 :     frame.set_wib_errors(0xFC5F);
     400            1 :     BOOST_REQUIRE_EQUAL(frame.get_wib_header()->wib_errors, 0xFC5F);
     401              :   }
     402              : 
     403            1 :   {
     404            1 :     WIBFrame frame;
     405            1 :     frame.get_wib_header()->z = 1;
     406            1 :     frame.set_timestamp(0x7333444455555555);
     407            1 :     BOOST_REQUIRE_EQUAL(frame.get_wib_header()->get_timestamp(), 0x444455555555);
     408              :   }
     409              : 
     410            1 :   {
     411            1 :     WIBFrame frame;
     412            1 :     frame.get_wib_header()->z = 0;
     413            1 :     frame.set_timestamp(0xF333444455555555);
     414            1 :     BOOST_REQUIRE_EQUAL(frame.get_wib_header()->get_timestamp(), 0x7333444455555555);
     415              :   }
     416            1 : }
     417            2 : BOOST_AUTO_TEST_CASE(WIBFrame_BlockChannelMethods)
     418              : {
     419            1 :   WIBFrame frame;
     420            1 :   frame.set_channel(0, 0x111);
     421            1 :   frame.set_channel(1, 0x222);
     422            1 :   frame.set_channel(64, 0x333);
     423            1 :   frame.set_channel(65, 0x444);
     424            1 :   frame.set_channel(2, 0, 0x555);
     425            1 :   frame.set_channel(2, 63, 0x666);
     426            1 :   frame.set_channel(3, 0, 0, 0x777);
     427            1 :   frame.set_channel(3, 1, 3, 0x888);
     428              : 
     429            3 :   BOOST_REQUIRE_EXCEPTION(frame.set_channel(WIBFrame::s_num_block_per_frame, 0, 0x123),
     430              :                           std::out_of_range,
     431              :                           [&](std::out_of_range) { return true; });
     432            3 :   BOOST_REQUIRE_EXCEPTION(frame.set_channel(WIBFrame::s_num_block_per_frame, 0, 0, 0x123),
     433              :                           std::out_of_range,
     434              :                           [&](std::out_of_range) { return true; });
     435              : 
     436            1 :   BOOST_REQUIRE_EQUAL(frame.get_channel(0), 0x111);
     437            1 :   BOOST_REQUIRE_EQUAL(frame.get_channel(1, 0), 0x333);
     438            1 :   BOOST_REQUIRE_EQUAL(frame.get_channel(3, 0, 0), 0x777);
     439            3 :   BOOST_REQUIRE_EXCEPTION(frame.get_channel(WIBFrame::s_num_block_per_frame, 0),
     440              :                           std::out_of_range,
     441              :                           [&](std::out_of_range) { return true; });
     442            3 :   BOOST_REQUIRE_EXCEPTION(frame.get_channel(WIBFrame::s_num_block_per_frame, 0, 0),
     443              :                           std::out_of_range,
     444              :                           [&](std::out_of_range) { return true; });
     445              : 
     446            1 :   auto block_0 = frame.get_block(0);
     447            1 :   BOOST_REQUIRE_EQUAL(block_0.get_channel(0, 0), 0x111);
     448            1 :   BOOST_REQUIRE_EQUAL(block_0.get_channel(0, 1), 0x222);
     449              : 
     450            1 :   auto block_1 = frame.get_block(1);
     451            1 :   BOOST_REQUIRE_EQUAL(block_1.get_channel(0, 0), 0x333);
     452            1 :   BOOST_REQUIRE_EQUAL(block_1.get_channel(0, 1), 0x444);
     453              : 
     454            1 :   auto block_2 = frame.get_block(2);
     455            1 :   BOOST_REQUIRE_EQUAL(block_2.get_channel(0, 0), 0x555);
     456            1 :   BOOST_REQUIRE_EQUAL(block_2.get_channel(7, 7), 0x666);
     457              : 
     458            1 :   auto block_3 = frame.get_block(3);
     459            1 :   BOOST_REQUIRE_EQUAL(block_3.get_channel(0, 0), 0x777);
     460            1 :   BOOST_REQUIRE_EQUAL(block_3.get_channel(1, 3), 0x888);
     461            1 : }
     462            2 : BOOST_AUTO_TEST_CASE(WIBFrame_StreamOperator)
     463              : {
     464            1 :   WIBFrame frame {};
     465              : 
     466            1 :   std::ostringstream ostr;
     467            1 :   ostr << frame;
     468            1 :   auto output = ostr.str();
     469            1 :   BOOST_TEST_MESSAGE("Stream operator: " << output);
     470            1 :   BOOST_REQUIRE(!output.empty());
     471            1 : }
     472              : 
     473            2 : BOOST_AUTO_TEST_CASE(WIBFrame_FromRawData)
     474              : {
     475            1 :   WIBHeader header;
     476            1 :   header.timestamp_1 = 0x12345678;
     477            1 :   header.timestamp_2 = 0x9ABC;
     478            1 :   header.wib_counter_1 = 0xDEF;
     479            1 :   header.z = 1;
     480            1 :   ColdataBlock blocks[WIBFrame::s_num_block_per_frame];
     481            1 :   blocks[0].head.checksum_a_1 = 0x11;
     482            1 :   blocks[0].head.checksum_b_1 = 0x22;
     483            1 :   blocks[0].head.checksum_a_2 = 0x33;
     484            1 :   blocks[0].head.checksum_b_2 = 0x44;
     485              : 
     486            1 :   uint8_t* buff = static_cast<uint8_t*>(malloc(sizeof(header) + sizeof(blocks))); // NOLINT(build/unsigned)
     487            1 :   memcpy(buff, &header, sizeof(header));
     488            1 :   memcpy(buff + sizeof(header), blocks, sizeof(ColdataBlock) * WIBFrame::s_num_block_per_frame);
     489              : 
     490            1 :   WIBFrame* from_raw_data = reinterpret_cast<WIBFrame*>(buff); // NOLINT
     491              : 
     492            1 :   BOOST_REQUIRE_EQUAL(from_raw_data->get_wib_header()->get_timestamp(), 0x9ABC12345678);
     493            1 :   BOOST_REQUIRE_EQUAL(from_raw_data->get_coldata_header(0)->get_checksum_a(), 0x3311);
     494            1 :   BOOST_REQUIRE_EQUAL(from_raw_data->get_coldata_header(0)->get_checksum_b(), 0x4422);
     495              : 
     496            1 :   from_raw_data = nullptr;
     497            1 :   free(buff);
     498            1 : }
     499              : 
     500              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1