Line data Source code
1 : /**
2 : * @file TimeSliceHeader_test.cxx TimeSliceHeader 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/TimeSliceHeader.hpp"
10 :
11 : /**
12 : * @brief Name of this test module
13 : */
14 : #define BOOST_TEST_MODULE TimeSliceHeader_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(TimeSliceHeader_test)
24 :
25 : /**
26 : * @brief Test that TimeSliceHeader::operator<< functions as expected
27 : */
28 2 : BOOST_AUTO_TEST_CASE(StreamOperator)
29 : {
30 1 : TimeSliceHeader header;
31 1 : header.timeslice_number = 1;
32 1 : header.run_number = 2;
33 1 : SourceID sid(SourceID::Subsystem::kTRBuilder, 55);
34 1 : header.element_id = sid;
35 :
36 1 : std::ostringstream ostr;
37 1 : ostr << header;
38 1 : std::string output = ostr.str();
39 1 : BOOST_TEST_MESSAGE("Stream operator: " << output);
40 :
41 1 : BOOST_REQUIRE(!output.empty());
42 1 : auto pos = output.find("timeslice_number: 1,");
43 1 : BOOST_REQUIRE(pos != std::string::npos);
44 1 : pos = output.find("run_number: 2");
45 1 : BOOST_REQUIRE(pos != std::string::npos);
46 :
47 1 : std::istringstream istr(output);
48 1 : TimeSliceHeader reconstituted_header;
49 1 : istr >> reconstituted_header;
50 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.timeslice_number, 1);
51 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.run_number, 2);
52 1 : BOOST_REQUIRE_EQUAL(reconstituted_header.element_id.id, 55);
53 1 : }
54 :
55 : BOOST_AUTO_TEST_SUITE_END()
|