LCOV - code coverage report
Current view: top level - daqdataformats/unittest - SourceID_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 39 39
Test Date: 2026-05-24 15:29:04 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              :   // BOOST_TEST_MESSAGE("About to try to input from \"" << output << "\"");
      65              :   // std::istringstream istr(output);
      66              :   // SourceID test2;
      67              :   // istr >> test2;
      68              :   // BOOST_TEST_MESSAGE("Looks like the output-from-the-input is \"" << test2) << "\"";
      69              :   // BOOST_REQUIRE_EQUAL(test.subsystem, test2.subsystem); // Recall that output was generated from streaming out a
      70              :   // SourceID instance
      71              : 
      72              :   // SourceID::Subsystem cat{ SourceID::Subsystem::kTrigger };
      73              :   // std::ostringstream cat_ostr;
      74              :   // cat_ostr << cat;
      75              :   // std::istringstream cat_istr(cat_ostr.str());
      76              :   // SourceID::Subsystem cat2{ SourceID::Subsystem::kUnknown };
      77              :   // cat_istr >> cat2;
      78              : 
      79              :   // BOOST_REQUIRE_EQUAL(cat, cat2);
      80            1 : }
      81              : 
      82              : /**
      83              :  * @brief Test that SourceID::operator< functions as expected
      84              :  */
      85            2 : BOOST_AUTO_TEST_CASE(ComparisonOperator)
      86              : {
      87            1 :   SourceID lesser{ SourceID::Subsystem::kDetectorReadout, 1 };
      88            1 :   SourceID greater{ SourceID::Subsystem::kDetectorReadout, 2 };
      89              : 
      90            1 :   BOOST_REQUIRE(lesser != greater);
      91            1 :   BOOST_REQUIRE(lesser == lesser);
      92            1 :   BOOST_REQUIRE(greater == greater);
      93            1 :   BOOST_REQUIRE(lesser < greater);
      94            1 :   BOOST_REQUIRE(!(greater < lesser));
      95            1 : }
      96              : 
      97            2 : BOOST_AUTO_TEST_CASE(Validity)
      98              : {
      99            1 :   SourceID test;
     100            1 :   BOOST_REQUIRE(!test.is_in_valid_state());
     101              : 
     102            1 :   test = { SourceID::Subsystem::kHwSignalsInterface, 3141592 };
     103            1 :   BOOST_REQUIRE(test.is_in_valid_state());
     104              : 
     105            1 :   test.id = SourceID::s_invalid_id;
     106            1 :   BOOST_REQUIRE(!test.is_in_valid_state());
     107            1 : }
     108              : 
     109              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1