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

            Line data    Source code
       1              : /**
       2              :  * @file ZmqPublisher_test.cxx ZmqPublisher 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 "ipm/Sender.hpp"
      10              : #include "ipm/ZmqContext.hpp"
      11              : 
      12              : #define BOOST_TEST_MODULE ZmqPublisher_test // NOLINT
      13              : 
      14              : #include "boost/test/unit_test.hpp"
      15              : #include "nlohmann/json.hpp"
      16              : 
      17              : #include <string>
      18              : #include <vector>
      19              : 
      20              : using namespace dunedaq::ipm;
      21              : 
      22              : BOOST_AUTO_TEST_SUITE(ZmqPublisher_test)
      23              : 
      24            2 : BOOST_AUTO_TEST_CASE(BasicTests)
      25              : {
      26            1 :   auto the_sender = make_ipm_sender("ZmqPublisher");
      27            1 :   BOOST_REQUIRE(the_sender != nullptr);
      28            1 :   BOOST_REQUIRE(!the_sender->can_send());
      29            1 : }
      30              : 
      31            2 : BOOST_AUTO_TEST_CASE(Errors)
      32              : {
      33            1 :   auto the_sender = make_ipm_sender("ZmqPublisher");
      34            1 :   BOOST_REQUIRE(the_sender != nullptr);
      35            1 :   BOOST_REQUIRE(!the_sender->can_send());
      36              : 
      37            1 :   nlohmann::json config_json;
      38              : 
      39            1 :   config_json["connection_string"] = "not a uri";
      40            3 :   BOOST_REQUIRE_EXCEPTION(the_sender->connect_for_sends(config_json), ZmqOperationError, [&](ZmqOperationError e) {
      41              :     return std::string(e.what()).find("invalid URI") != std::string::npos;
      42              :   });
      43            1 :   BOOST_REQUIRE(!the_sender->can_send());
      44              : 
      45            1 :   config_json["connection_string"] = "tcp://thishostddoesnotexist";
      46            3 :   BOOST_REQUIRE_EXCEPTION(the_sender->connect_for_sends(config_json), ZmqOperationError, [&](ZmqOperationError e) {
      47              :     return std::string(e.what()).find("Unable to resolve connection_string") != std::string::npos;
      48              :   });
      49            1 :   BOOST_REQUIRE(!the_sender->can_send());
      50              : 
      51            1 :   config_json["connection_string"] = "badproto://default";
      52            3 :   BOOST_REQUIRE_EXCEPTION(the_sender->connect_for_sends(config_json), ZmqOperationError, [&](ZmqOperationError e) {
      53              :     return std::string(e.what()).find("while calling bind on the ZMQ send socket") != std::string::npos;
      54              :   });
      55            1 :   BOOST_REQUIRE(!the_sender->can_send());
      56            1 : }
      57              : 
      58              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1