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

            Line data    Source code
       1              : /**
       2              :  * @file TimeSlice_test.cxx TimeSlice class Unit Tests
       3              :  *
       4              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "daqdataformats/TimeSlice.hpp"
      10              : 
      11              : /**
      12              :  * @brief Name of this test module
      13              :  */
      14              : #define BOOST_TEST_MODULE TimeSlice_test // NOLINT
      15              : 
      16              : #include "boost/test/unit_test.hpp"
      17              : 
      18              : #include <memory>
      19              : #include <string>
      20              : #include <utility>
      21              : #include <vector>
      22              : 
      23              : using namespace dunedaq::daqdataformats;
      24              : 
      25              : BOOST_AUTO_TEST_SUITE(TimeSlice_test)
      26              : 
      27              : /**
      28              :  * @brief Check that TimeSlices have appropriate Copy/Move semantics
      29              :  */
      30            2 : BOOST_AUTO_TEST_CASE(CopyAndMoveSemantics)
      31              : {
      32            1 :   BOOST_REQUIRE(!std::is_copy_constructible_v<TimeSlice>);
      33            1 :   BOOST_REQUIRE(!std::is_copy_assignable_v<TimeSlice>);
      34            1 :   BOOST_REQUIRE(std::is_move_constructible_v<TimeSlice>);
      35            1 :   BOOST_REQUIRE(std::is_move_assignable_v<TimeSlice>);
      36            1 : }
      37              : 
      38            2 : BOOST_AUTO_TEST_CASE(InitializerConstructor)
      39              : {
      40            1 :   auto record = std::make_unique<TimeSlice>(1, 2);
      41            1 :   BOOST_REQUIRE_EQUAL(record->get_header().timeslice_number, 1);
      42            1 :   BOOST_REQUIRE_EQUAL(record->get_header().run_number, 2);
      43            1 : }
      44              : 
      45              : /**
      46              :  * @brief Test constructor that uses and existing TimeSliceHeader
      47              :  */
      48            2 : BOOST_AUTO_TEST_CASE(HeaderConstructor)
      49              : {
      50              : 
      51            1 :   TimeSliceHeader header;
      52            1 :   header.timeslice_number = 1;
      53            1 :   header.run_number = 2;
      54            1 :   auto record = std::make_unique<TimeSlice>(header);
      55            1 :   BOOST_REQUIRE_EQUAL(record->get_header().timeslice_number, 1);
      56            1 :   BOOST_REQUIRE_EQUAL(record->get_header().run_number, 2);
      57            1 : }
      58              : 
      59              : /**
      60              :  *@brief Test TimeSliceHeader manipulation methods
      61              :  */
      62            2 : BOOST_AUTO_TEST_CASE(HeaderManipulation)
      63              : {
      64            1 :   TimeSlice record(1, 2);
      65            1 :   BOOST_REQUIRE_EQUAL(record.get_header().timeslice_number, 1);
      66            1 :   BOOST_REQUIRE_EQUAL(record.get_header().run_number, 2);
      67              : 
      68            1 :   TimeSliceHeader new_header;
      69            1 :   new_header.timeslice_number = 3;
      70            1 :   new_header.run_number = 4;
      71            1 :   record.set_header(new_header);
      72            1 :   BOOST_REQUIRE_EQUAL(record.get_header().timeslice_number, 3);
      73            1 :   BOOST_REQUIRE_EQUAL(record.get_header().run_number, 4);
      74            1 : }
      75              : 
      76              : /**
      77              :  * @brief Test Fragment vector manipulation methods
      78              :  */
      79            2 : BOOST_AUTO_TEST_CASE(FragmentManipulation)
      80              : {
      81            1 :   TimeSlice record(1, 2);
      82              : 
      83            1 :   BOOST_REQUIRE_EQUAL(record.get_fragments_ref().size(), 0);
      84              : 
      85            1 :   std::vector<uint8_t> buf1(10);
      86            1 :   auto frag = std::make_unique<Fragment>(buf1.data(), buf1.size());
      87            1 :   record.add_fragment(std::move(frag));
      88            1 :   BOOST_REQUIRE_EQUAL(record.get_fragments_ref().size(), 1);
      89            1 :   BOOST_REQUIRE_EQUAL(record.get_fragments_ref()[0]->get_size(), sizeof(FragmentHeader) + 10);
      90              : 
      91            1 :   BOOST_REQUIRE_EQUAL(record.get_total_size_bytes(), sizeof(TimeSliceHeader) +
      92              :                       sizeof(FragmentHeader) + 10);
      93            1 :   BOOST_REQUIRE_EQUAL(record.get_sum_of_fragment_payload_sizes(), 10);
      94              : 
      95            1 :   std::vector<std::unique_ptr<Fragment>> new_vector;
      96            1 :   record.set_fragments(std::move(new_vector));
      97            1 :   BOOST_REQUIRE_EQUAL(record.get_fragments_ref().size(), 0);
      98            1 : }
      99              : 
     100              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1