artdaq  v3_01_00
FragCounter_t.cc
1 #include "artdaq/DAQrate/detail/FragCounter.hh"
2 #include "canvas/Utilities/Exception.h"
3 
5 
6 #define BOOST_TEST_MODULE FragCounter_t
7 #include <boost/test/auto_unit_test.hpp>
8 
9 BOOST_AUTO_TEST_SUITE(FragCounter_test)
10 
11  BOOST_AUTO_TEST_CASE(Construct)
12  {
13  FragCounter f1;
14  }
15 
16  BOOST_AUTO_TEST_CASE(nSlots)
17  {
18  FragCounter f1;
19  BOOST_REQUIRE_EQUAL(f1.nSlots(), 0ul);
20  }
21 
22  BOOST_AUTO_TEST_CASE(Apply)
23  {
24  FragCounter f;
25  f.incSlot(0);
26  BOOST_REQUIRE_EQUAL(f.slotCount(0), 1ul);
27  f.incSlot(1, 4);
28  BOOST_REQUIRE_EQUAL(f.slotCount(1), 4ul);
29  f.incSlot(1);
30  BOOST_REQUIRE_EQUAL(f.slotCount(1), 5ul);
31  f.incSlot(1, 2);
32  BOOST_REQUIRE_EQUAL(f.slotCount(1), 7ul);
33  BOOST_REQUIRE_EQUAL(f.slotCount(2), 0ul);
34  BOOST_REQUIRE_EQUAL(f.count(), 8ul);
35  }
36 
37  BOOST_AUTO_TEST_CASE(ApplyWithOffset)
38  {
39  FragCounter f;
40  f.incSlot(4);
41  BOOST_REQUIRE_EQUAL(f.slotCount(4), 1ul);
42  f.incSlot(5, 4);
43  BOOST_REQUIRE_EQUAL(f.slotCount(5), 4ul);
44  f.incSlot(5);
45  BOOST_REQUIRE_EQUAL(f.slotCount(5), 5ul);
46  f.incSlot(5, 2);
47  BOOST_REQUIRE_EQUAL(f.slotCount(5), 7ul);
48  BOOST_REQUIRE_EQUAL(f.slotCount(6), 0ul);
49  BOOST_REQUIRE_EQUAL(f.count(), 8ul);
50  }
51 
52 BOOST_AUTO_TEST_SUITE_END()
Keep track of the count of Fragments received from a set of sources.
Definition: FragCounter.hh:20
void incSlot(size_t slot)
Increment the given slot by one.
Definition: FragCounter.hh:93
size_t nSlots() const
Get the number of slots this FragCounter instance is tracking.
Definition: FragCounter.hh:119
size_t slotCount(size_t slot) const
Get the current count for the requested slot.
Definition: FragCounter.hh:142
size_t count() const
Get the total number of Fragments received.
Definition: FragCounter.hh:128