Line data Source code
1 : /**
2 : * @file TriggerRecordHeaderData_test.cxx TriggerRecordHeaderData 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 "daqdataformats/TriggerRecordHeaderData.hpp"
10 :
11 : /**
12 : * @brief Name of this test module
13 : */
14 : #define BOOST_TEST_MODULE TriggerRecordHeaderData_test // NOLINT
15 :
16 : #include "boost/test/unit_test.hpp"
17 :
18 : #include <string>
19 : #include <vector>
20 :
21 : using namespace dunedaq::daqdataformats;
22 :
23 : BOOST_AUTO_TEST_SUITE(TriggerRecordHeaderData_test)
24 :
25 : /**
26 : * @brief Test that TriggerRecordHeaderData::operator<< functions as expected
27 : */
28 2 : BOOST_AUTO_TEST_CASE(StreamOperator)
29 : {
30 1 : TriggerRecordHeaderData header;
31 1 : header.num_requested_components = 0;
32 1 : header.trigger_number = 1;
33 1 : header.trigger_timestamp = 2;
34 1 : header.run_number = 3;
35 1 : header.error_bits = 0xa5;
36 1 : header.trigger_type = 4;
37 1 : header.sequence_number = 5;
38 1 : header.max_sequence_number = 6;
39 1 : SourceID sid(SourceID::Subsystem::kTRBuilder, 99);
40 1 : header.element_id = sid;
41 :
42 1 : std::ostringstream ostr;
43 1 : ostr << header;
44 1 : std::string output = ostr.str();
45 1 : BOOST_TEST_MESSAGE("Stream operator: " << output);
46 :
47 1 : BOOST_REQUIRE(!output.empty());
48 1 : auto pos = output.find("trigger_number: 1,");
49 1 : BOOST_REQUIRE(pos != std::string::npos);
50 1 : pos = output.find("trigger_timestamp: 2,");
51 1 : BOOST_REQUIRE(pos != std::string::npos);
52 1 : pos = output.find("run_number: 3,");
53 1 : BOOST_REQUIRE(pos != std::string::npos);
54 :
55 1 : std::istringstream istr(output);
56 1 : TriggerRecordHeaderData reconstituted_header;
57 1 : istr >> reconstituted_header;
58 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.num_requested_components, 0);
59 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.trigger_number, 1);
60 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.trigger_timestamp, 2);
61 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.run_number, 3);
62 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.error_bits, 0xa5);
63 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.trigger_type, 4);
64 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.sequence_number, 5);
65 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.max_sequence_number, 6);
66 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.element_id.id, 99);
67 1 : }
68 :
69 : BOOST_AUTO_TEST_SUITE_END()
|