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

            Line data    Source code
       1              : /**
       2              :  * @file SourceID_test.cxx SourceID struct 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/SourceID.hpp"
      10              : 
      11              : /**
      12              :  * @brief Name of this test module
      13              :  */
      14              : #define BOOST_TEST_MODULE SourceID_test // NOLINT
      15              : 
      16              : #include "boost/test/unit_test.hpp"
      17              : 
      18              : #include <functional>
      19              : #include <limits>
      20              : #include <sstream>
      21              : #include <string>
      22              : #include <vector>
      23              : 
      24              : using namespace dunedaq::daqdataformats;
      25              : 
      26              : BOOST_AUTO_TEST_SUITE(SourceID_test)
      27              : 
      28            2 : BOOST_AUTO_TEST_CASE(SubsystemConversion)
      29              : {
      30            1 :   BOOST_REQUIRE_EQUAL(SourceID::subsystem_to_string(SourceID::Subsystem::kUnknown), "Unknown");
      31            1 :   BOOST_REQUIRE_EQUAL(SourceID::string_to_subsystem("Unknown"), SourceID::Subsystem::kUnknown);
      32              : 
      33            1 :   BOOST_REQUIRE_EQUAL(SourceID::subsystem_to_string(SourceID::Subsystem::kDetectorReadout), "Detector_Readout");
      34            1 :   BOOST_REQUIRE_EQUAL(SourceID::string_to_subsystem("Detector_Readout"), SourceID::Subsystem::kDetectorReadout);
      35              : 
      36            1 :   BOOST_REQUIRE_EQUAL(SourceID::subsystem_to_string(SourceID::Subsystem::kHwSignalsInterface), "HW_Signals_Interface");
      37            1 :   BOOST_REQUIRE_EQUAL(SourceID::string_to_subsystem("HW_Signals_Interface"), SourceID::Subsystem::kHwSignalsInterface);
      38              : 
      39            1 :   BOOST_REQUIRE_EQUAL(SourceID::subsystem_to_string(SourceID::Subsystem::kTrigger), "Trigger");
      40            1 :   BOOST_REQUIRE_EQUAL(SourceID::string_to_subsystem("Trigger"), SourceID::Subsystem::kTrigger);
      41              : 
      42            1 :   BOOST_REQUIRE_EQUAL(SourceID::subsystem_to_string(SourceID::Subsystem::kTRBuilder), "TR_Builder");
      43            1 :   BOOST_REQUIRE_EQUAL(SourceID::string_to_subsystem("TR_Builder"), SourceID::Subsystem::kTRBuilder);
      44            1 : }
      45              : 
      46              : /**
      47              :  * @brief Test that SourceID::operator<< functions as expected
      48              :  */
      49            2 : BOOST_AUTO_TEST_CASE(StreamOperator)
      50              : {
      51            1 :   SourceID test = { SourceID::Subsystem::kDetectorReadout, 314159 };
      52              : 
      53            1 :   std::ostringstream ostr;
      54            1 :   ostr << test;
      55              : 
      56            1 :   std::string output = ostr.str();
      57            1 :   BOOST_TEST_MESSAGE("Stream operator: " << output);
      58              : 
      59            1 :   BOOST_REQUIRE(!output.empty());
      60              : 
      61            1 :   auto pos = output.find(std::to_string(test.id));
      62            1 :   BOOST_REQUIRE(pos != std::string::npos);
      63              : 
      64            1 :   BOOST_TEST_MESSAGE("About to try to input from \"" << output << "\"");
      65            1 :   std::istringstream istr(output);
      66            1 :   SourceID test2;
      67            1 :   istr >> test2;
      68            1 :   BOOST_TEST_MESSAGE("Looks like the output-from-the-input is \"" << test2) << "\"";
      69            1 :   BOOST_REQUIRE_EQUAL(test.subsystem, test2.subsystem); // Recall that output was generated from streaming out a SourceID instance
      70              : 
      71            1 :   SourceID::Subsystem cat{ SourceID::Subsystem::kTrigger };
      72            1 :   std::ostringstream cat_ostr;
      73            1 :   cat_ostr << cat;
      74            1 :   std::istringstream cat_istr(cat_ostr.str());
      75            1 :   SourceID::Subsystem cat2{ SourceID::Subsystem::kUnknown };
      76            1 :   cat_istr >> cat2;
      77              : 
      78            1 :   BOOST_REQUIRE_EQUAL(cat, cat2);
      79            1 : }
      80              : 
      81              : /**
      82              :  * @brief Test that SourceID::operator< functions as expected
      83              :  */
      84            2 : BOOST_AUTO_TEST_CASE(ComparisonOperator)
      85              : {
      86            1 :   SourceID lesser{ SourceID::Subsystem::kDetectorReadout, 1 };
      87            1 :   SourceID greater{ SourceID::Subsystem::kDetectorReadout, 2 };
      88              : 
      89            1 :   BOOST_REQUIRE(lesser != greater);
      90            1 :   BOOST_REQUIRE(lesser == lesser);
      91            1 :   BOOST_REQUIRE(greater == greater);
      92            1 :   BOOST_REQUIRE(lesser < greater);
      93            1 :   BOOST_REQUIRE(!(greater < lesser));
      94            1 : }
      95              : 
      96            2 : BOOST_AUTO_TEST_CASE(Validity)
      97              : {
      98            1 :   SourceID test;
      99            1 :   BOOST_REQUIRE(!test.is_in_valid_state());
     100              : 
     101            1 :   test = { SourceID::Subsystem::kHwSignalsInterface, 3141592 };
     102            1 :   BOOST_REQUIRE(test.is_in_valid_state());
     103              : 
     104            1 :   test.id = SourceID::s_invalid_id;
     105            1 :   BOOST_REQUIRE(!test.is_in_valid_state());
     106            1 : }
     107              : 
     108              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1