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