Line data Source code
1 : /**
2 : * @file TriggerDecision_test.cxx TriggerDecision 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 "dfmessages/TriggerDecision.hpp"
10 :
11 : /**
12 : * @brief Name of this test module
13 : */
14 : #define BOOST_TEST_MODULE TriggerDecision_test // NOLINT
15 :
16 : #include "TRACE/trace.h"
17 : #include "boost/test/unit_test.hpp"
18 :
19 : using namespace dunedaq::dfmessages;
20 :
21 : BOOST_AUTO_TEST_SUITE(TriggerDecision_test)
22 :
23 : /**
24 : * @brief Check that TriggerDecisions have appropriate Copy/Move semantics
25 : */
26 2 : BOOST_AUTO_TEST_CASE(CopyAndMoveSemantics)
27 : {
28 1 : BOOST_REQUIRE(std::is_copy_constructible_v<TriggerDecision>);
29 1 : BOOST_REQUIRE(std::is_copy_assignable_v<TriggerDecision>);
30 1 : BOOST_REQUIRE(std::is_move_constructible_v<TriggerDecision>);
31 1 : BOOST_REQUIRE(std::is_move_assignable_v<TriggerDecision>);
32 1 : }
33 :
34 2 : BOOST_AUTO_TEST_CASE(SerDes_MsgPack)
35 : {
36 1 : TriggerDecision td;
37 1 : td.trigger_number = 1;
38 1 : td.run_number = 2;
39 1 : td.trigger_timestamp = 3;
40 1 : td.trigger_type = 4;
41 1 : td.readout_type = ReadoutType::kLocalized;
42 :
43 1 : SourceID sid;
44 1 : sid.subsystem = SourceID::Subsystem::kDetectorReadout;
45 1 : sid.id= 1;
46 1 : ComponentRequest cr;
47 1 : cr.component = sid;
48 1 : cr.window_begin = 5;
49 1 : cr.window_end = 6;
50 :
51 1 : SourceID another_sid;
52 1 : another_sid.subsystem = SourceID::Subsystem::kDetectorReadout;
53 1 : another_sid.id= 2;
54 1 : ComponentRequest another_cr;
55 1 : another_cr.component = another_sid;
56 1 : another_cr.window_begin = 7;
57 1 : another_cr.window_end = 8;
58 :
59 1 : td.components.push_back(cr);
60 1 : td.components.push_back(another_cr);
61 :
62 1 : auto bytes = dunedaq::serialization::serialize(td, dunedaq::serialization::kMsgPack);
63 3 : TLOG(TLVL_INFO) << "MsgPack message size: " << bytes.size() << " bytes";
64 1 : TriggerDecision td_deserialized = dunedaq::serialization::deserialize<TriggerDecision>(bytes);
65 :
66 1 : BOOST_REQUIRE_EQUAL(td.trigger_number, td_deserialized.trigger_number);
67 1 : BOOST_REQUIRE_EQUAL(td.run_number, td_deserialized.run_number);
68 1 : BOOST_REQUIRE_EQUAL(td.trigger_timestamp, td_deserialized.trigger_timestamp);
69 1 : BOOST_REQUIRE_EQUAL(td.trigger_type, td_deserialized.trigger_type);
70 1 : BOOST_REQUIRE_EQUAL(static_cast<uint16_t>(td.readout_type), // NOLINT(build/unsigned)
71 : static_cast<uint16_t>(td_deserialized.readout_type)); // NOLINT(build/unsigned)
72 :
73 1 : BOOST_REQUIRE_EQUAL(td.components.size(), td_deserialized.components.size());
74 :
75 1 : BOOST_REQUIRE_EQUAL(td.components[0].component.subsystem, td_deserialized.components[0].component.subsystem);
76 1 : BOOST_REQUIRE_EQUAL(td.components[0].component.id, td_deserialized.components[0].component.id);
77 1 : BOOST_REQUIRE_EQUAL(td.components[0].window_begin, td_deserialized.components[0].window_begin);
78 1 : BOOST_REQUIRE_EQUAL(td.components[0].window_end, td_deserialized.components[0].window_end);
79 :
80 1 : BOOST_REQUIRE_EQUAL(td.components[1].component.subsystem, td_deserialized.components[1].component.subsystem);
81 1 : BOOST_REQUIRE_EQUAL(td.components[1].component.id, td_deserialized.components[1].component.id);
82 1 : BOOST_REQUIRE_EQUAL(td.components[1].window_begin, td_deserialized.components[1].window_begin);
83 1 : BOOST_REQUIRE_EQUAL(td.components[1].window_end, td_deserialized.components[1].window_end);
84 1 : }
85 :
86 : BOOST_AUTO_TEST_SUITE_END()
|