6 #include "cetlib_except/exception.h" 15 #pragma GCC diagnostic push 16 #pragma GCC diagnostic ignored "-Wsign-compare" 19 #define BOOST_TEST_MODULE(MicroSlice_t) 22 BOOST_AUTO_TEST_SUITE(MicroSlice_test)
26 const uint16_t CHANNEL_NUMBER = 123;
27 const uint32_t MS_BUFFER_SIZE = 4096;
28 const uint32_t NS_BUFFER_SIZE = 1024;
29 const uint16_t SAMPLE1 = 0x1234;
30 const uint16_t SAMPLE2 = 0xc3c3;
31 const uint16_t SAMPLE3 = 0xbeef;
32 const uint16_t SAMPLE4 = 0xfe87;
33 const uint16_t SAMPLE5 = 0x5a5a;
34 std::vector<uint8_t> work_buffer(MS_BUFFER_SIZE);
35 std::unique_ptr<dune::NanoSlice> nslice_ptr;
36 std::shared_ptr<dune::NanoSliceWriter> ns_writer_ptr;
46 BOOST_REQUIRE(nslice_ptr.get() == 0);
48 BOOST_REQUIRE(nslice_ptr.get() == 0);
51 BOOST_REQUIRE(ns_writer_ptr.get() != 0);
52 BOOST_REQUIRE_EQUAL(ms_writer.
size(),
55 if (ns_writer_ptr.get() != 0) {
56 ns_writer_ptr->setChannelNumber(CHANNEL_NUMBER);
57 ns_writer_ptr->addSample(SAMPLE1);
58 ns_writer_ptr->addSample(SAMPLE2);
59 ns_writer_ptr->addSample(SAMPLE3);
60 ns_writer_ptr->addSample(SAMPLE4);
61 ns_writer_ptr->addSample(SAMPLE5);
63 uint32_t size_diff = ms_writer.
finalize();
68 BOOST_REQUIRE(nslice_ptr.get() == 0);
70 BOOST_REQUIRE(nslice_ptr.get() != 0);
71 if (nslice_ptr.get() != 0) {
72 BOOST_REQUIRE_EQUAL(nslice_ptr->size(),
74 BOOST_REQUIRE_EQUAL(nslice_ptr->sampleCount(), 5);
75 BOOST_REQUIRE(nslice_ptr->sampleValue(0, value));
76 BOOST_REQUIRE_EQUAL(value, SAMPLE1);
77 BOOST_REQUIRE(nslice_ptr->sampleValue(1, value));
78 BOOST_REQUIRE_EQUAL(value, SAMPLE2);
79 BOOST_REQUIRE(nslice_ptr->sampleValue(2, value));
80 BOOST_REQUIRE_EQUAL(value, SAMPLE3);
81 BOOST_REQUIRE(nslice_ptr->sampleValue(3, value));
82 BOOST_REQUIRE_EQUAL(value, SAMPLE4);
83 BOOST_REQUIRE(nslice_ptr->sampleValue(4, value));
84 BOOST_REQUIRE_EQUAL(value, SAMPLE5);
91 const uint16_t CHANNEL_NUMBER = 123;
92 const uint32_t MS_BUFFER_SIZE = 4096;
93 const uint32_t NS_BUFFER_SIZE = 1024;
94 const uint16_t SAMPLE1 = 0x1234;
95 const uint16_t SAMPLE2 = 0xc3c3;
96 const uint16_t SAMPLE3 = 0xbeef;
97 const uint16_t SAMPLE4 = 0xfe87;
98 const uint16_t SAMPLE5 = 0x5a5a;
99 std::vector<uint8_t> work_buffer(MS_BUFFER_SIZE);
100 std::unique_ptr<dune::NanoSlice> nslice_ptr;
101 std::shared_ptr<dune::NanoSliceWriter> ns_writer_ptr;
109 BOOST_REQUIRE(ns_writer_ptr.get() != 0);
110 BOOST_REQUIRE_EQUAL(ms_writer.
size(),
113 if (ns_writer_ptr.get() != 0) {
114 ns_writer_ptr->setChannelNumber(CHANNEL_NUMBER);
115 ns_writer_ptr->addSample(SAMPLE1);
116 ns_writer_ptr->addSample(SAMPLE2);
117 ns_writer_ptr->addSample(SAMPLE3);
118 ns_writer_ptr->addSample(SAMPLE4);
119 ns_writer_ptr->addSample(SAMPLE5);
122 BOOST_REQUIRE(nslice_ptr.get() == 0);
124 BOOST_REQUIRE(nslice_ptr.get() != 0);
130 BOOST_REQUIRE(ns_writer_ptr.get() != 0);
135 if (ns_writer_ptr.get() != 0) {
136 ns_writer_ptr->setChannelNumber(CHANNEL_NUMBER+1);
137 ns_writer_ptr->addSample(SAMPLE5);
138 ns_writer_ptr->addSample(SAMPLE3);
139 ns_writer_ptr->addSample(SAMPLE1);
142 BOOST_REQUIRE(nslice_ptr.get() == 0);
144 BOOST_REQUIRE(nslice_ptr.get() == 0);
146 BOOST_REQUIRE(nslice_ptr.get() != 0);
148 BOOST_REQUIRE(nslice_ptr.get() != 0);
154 BOOST_REQUIRE(ns_writer_ptr.get() != 0);
159 if (ns_writer_ptr.get() != 0) {
160 ns_writer_ptr->setChannelNumber(CHANNEL_NUMBER+2);
161 ns_writer_ptr->addSample(SAMPLE4);
162 ns_writer_ptr->addSample(SAMPLE5);
165 BOOST_REQUIRE(nslice_ptr.get() == 0);
167 BOOST_REQUIRE(nslice_ptr.get() == 0);
169 BOOST_REQUIRE(nslice_ptr.get() != 0);
171 BOOST_REQUIRE(nslice_ptr.get() != 0);
173 BOOST_REQUIRE(nslice_ptr.get() != 0);
179 int32_t size_diff = ms_writer.
finalize();
184 bool threw_exception =
false;
189 threw_exception =
true;
192 BOOST_REQUIRE_EQUAL(threw_exception,
true);
204 BOOST_REQUIRE(nslice_ptr.get() != 0);
207 BOOST_REQUIRE_EQUAL(nslice_ptr->channelNumber(), CHANNEL_NUMBER);
208 BOOST_REQUIRE_EQUAL(nslice_ptr->sampleCount(), 5);
209 BOOST_REQUIRE(nslice_ptr->sampleValue(0, value));
210 BOOST_REQUIRE_EQUAL(value, SAMPLE1);
211 BOOST_REQUIRE(nslice_ptr->sampleValue(1, value));
212 BOOST_REQUIRE_EQUAL(value, SAMPLE2);
213 BOOST_REQUIRE(nslice_ptr->sampleValue(2, value));
214 BOOST_REQUIRE_EQUAL(value, SAMPLE3);
215 BOOST_REQUIRE(nslice_ptr->sampleValue(3, value));
216 BOOST_REQUIRE_EQUAL(value, SAMPLE4);
217 BOOST_REQUIRE(nslice_ptr->sampleValue(4, value));
218 BOOST_REQUIRE_EQUAL(value, SAMPLE5);
219 BOOST_REQUIRE(! nslice_ptr->sampleValue(5, value));
220 BOOST_REQUIRE(! nslice_ptr->sampleValue(567, value));
223 BOOST_REQUIRE(nslice_ptr.get() != 0);
226 BOOST_REQUIRE_EQUAL(nslice_ptr->channelNumber(), CHANNEL_NUMBER+1);
227 BOOST_REQUIRE_EQUAL(nslice_ptr->sampleCount(), 3);
228 BOOST_REQUIRE(nslice_ptr->sampleValue(0, value));
229 BOOST_REQUIRE_EQUAL(value, SAMPLE5);
230 BOOST_REQUIRE(nslice_ptr->sampleValue(1, value));
231 BOOST_REQUIRE_EQUAL(value, SAMPLE3);
232 BOOST_REQUIRE(nslice_ptr->sampleValue(2, value));
233 BOOST_REQUIRE_EQUAL(value, SAMPLE1);
234 BOOST_REQUIRE(! nslice_ptr->sampleValue(3, value));
237 BOOST_REQUIRE(nslice_ptr.get() != 0);
240 BOOST_REQUIRE_EQUAL(nslice_ptr->channelNumber(), CHANNEL_NUMBER+2);
241 BOOST_REQUIRE_EQUAL(nslice_ptr->sampleCount(), 2);
242 BOOST_REQUIRE(nslice_ptr->sampleValue(0, value));
243 BOOST_REQUIRE_EQUAL(value, SAMPLE4);
244 BOOST_REQUIRE(nslice_ptr->sampleValue(1, value));
245 BOOST_REQUIRE_EQUAL(value, SAMPLE5);
246 BOOST_REQUIRE(! nslice_ptr->sampleValue(2, value));
281 BOOST_AUTO_TEST_SUITE_END()
283 #pragma GCC diagnostic pop
Header::nanoslice_count_t nanoSliceCount() const
Header::microslice_size_t size() const
BOOST_AUTO_TEST_CASE(BaselineTest)
std::unique_ptr< NanoSlice > nanoSlice(uint32_t index) const
cet::coded_exception< error, detail::translate > exception
std::shared_ptr< NanoSliceWriter > reserveNanoSlice(uint32_t ns_max_bytes)