LCOV - code coverage report
Current view: top level - artdaq-core-mu2e/test/Overlays - DTC_Event_t.cc (source / functions) Coverage Total Hit
Test: mu2edaq.info.cleaned Lines: 100.0 % 46 46
Test Date: 2026-07-30 01:56:44 Functions: 100.0 % 9 9

            Line data    Source code
       1              : #define BOOST_TEST_MODULE DTC_Event_t
       2              : #include <boost/test/unit_test.hpp>
       3              : 
       4              : #include "TRACE/tracemf.h"
       5              : #define TRACE_NAME "DTC_Event_t"
       6              : 
       7              : #include <fstream>
       8              : 
       9              : #include "artdaq-core-mu2e/Overlays/DTC_Packets/DTC_Event.h"
      10              : 
      11              : BOOST_AUTO_TEST_SUITE(DTC_Event_t)
      12              : 
      13            2 : BOOST_AUTO_TEST_CASE(Constructor)
      14              : {
      15            1 :         size_t size_bytes = sizeof(DTCLib::DTC_EventHeader);
      16              : 
      17            1 :         auto evt = std::make_unique<DTCLib::DTC_Event>(size_bytes);
      18              : 
      19            1 :         DTCLib::DTC_EventHeader evtHdr;
      20            1 :         evtHdr.inclusive_event_byte_count = size_bytes;
      21            1 :         evtHdr.num_dtcs = 0;
      22            1 :         evtHdr.event_tag_low = 1;
      23            1 :         evtHdr.event_tag_high = 0;
      24            1 :         memcpy(const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(evt->GetRawBufferPointer())), &evtHdr, sizeof(DTCLib::DTC_EventHeader));
      25              : 
      26            2 :         TLOG(TLVL_TRACE + 22) << "Calling SetupEvent";
      27            1 :         auto ok = evt->SetupEvent();
      28            1 :         BOOST_REQUIRE(ok);
      29              : 
      30            1 :         BOOST_REQUIRE_EQUAL(evt->GetSubEventCount(), 0);
      31            1 :         BOOST_REQUIRE_EQUAL(evt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      32            1 : }
      33              : 
      34            2 : BOOST_AUTO_TEST_CASE(GoodBinaryFile)
      35              : {
      36            1 :         std::ifstream input("event_test.bin", std::ios::binary);
      37            1 :         std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(input), {});
      38              : 
      39            1 :         auto evt = std::make_unique<DTCLib::DTC_Event>(buffer.data());
      40            1 :         auto ok = evt->SetupEvent();
      41            1 :         BOOST_REQUIRE(ok);
      42            1 :         BOOST_REQUIRE_EQUAL(evt->GetSubEventCount(), 3);
      43            1 :         BOOST_REQUIRE_EQUAL(evt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      44              : 
      45            1 :         auto subevt = evt->GetSubEvent(0);
      46            1 :         BOOST_REQUIRE_EQUAL(subevt->GetDataBlockCount(), 6);
      47            1 :         BOOST_REQUIRE_EQUAL(subevt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      48            1 :         BOOST_REQUIRE_EQUAL(subevt->GetDTCID(), 0);
      49            1 : }
      50              : 
      51            2 : BOOST_AUTO_TEST_CASE(BadBinaryFile_Short)
      52              : {
      53            1 :         std::ifstream input("event_test_short.bin", std::ios::binary);
      54            1 :         std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(input), {});
      55              : 
      56            1 :         auto evt = std::make_unique<DTCLib::DTC_Event>(buffer.data());
      57            1 :         auto ok = evt->SetupEvent();
      58            1 :         BOOST_REQUIRE(!ok);
      59            1 :         BOOST_REQUIRE_EQUAL(evt->GetSubEventCount(), 3);
      60            1 :         BOOST_REQUIRE_EQUAL(evt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      61            1 : }
      62              : 
      63            2 : BOOST_AUTO_TEST_CASE(BadBinaryFile_Long)
      64              : {
      65            1 :         std::ifstream input("event_test_long.bin", std::ios::binary);
      66            1 :         std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(input), {});
      67              : 
      68            1 :         auto evt = std::make_unique<DTCLib::DTC_Event>(buffer.data());
      69            1 :         auto ok = evt->SetupEvent();
      70            1 :         BOOST_REQUIRE(!ok);
      71            1 :         BOOST_REQUIRE_EQUAL(evt->GetSubEventCount(), 3);
      72            1 :         BOOST_REQUIRE_EQUAL(evt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      73            1 : }
      74              : 
      75              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1