15 #pragma GCC diagnostic push 16 #pragma GCC diagnostic ignored "-Wsign-compare" 19 #define BOOST_TEST_MODULE(MilliSlice_t) 23 BOOST_AUTO_TEST_SUITE(MilliSlice_test)
27 const uint16_t CHANNEL_NUMBER = 123;
28 const uint32_t MILLISLICE_BUFFER_SIZE = 8192;
29 const uint32_t MICROSLICE_BUFFER_SIZE = 1024;
30 const uint32_t NANOSLICE_BUFFER_SIZE = 128;
31 const uint16_t SAMPLE1 = 0x1234;
32 const uint16_t SAMPLE2 = 0xc3c3;
33 const uint16_t SAMPLE3 = 0xbeef;
34 const uint16_t SAMPLE4 = 0xfe87;
35 const uint16_t SAMPLE5 = 0x5a5a;
36 std::vector<uint8_t> work_buffer(MILLISLICE_BUFFER_SIZE);
37 std::unique_ptr<dune::MicroSlice> microslice_ptr;
38 std::shared_ptr<dune::MicroSliceWriter> microslice_writer_ptr;
39 std::shared_ptr<dune::NanoSliceWriter> nanoslice_writer_ptr;
48 microslice_ptr = millislice_writer.
microSlice(0);
49 BOOST_REQUIRE(microslice_ptr.get() == 0);
50 microslice_ptr = millislice_writer.
microSlice(999);
51 BOOST_REQUIRE(microslice_ptr.get() == 0);
56 bool threw_exception =
false;
61 threw_exception =
true;
64 BOOST_REQUIRE_EQUAL(threw_exception,
true);
68 microslice_writer_ptr = millislice_writer.
reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
69 BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
70 BOOST_REQUIRE_EQUAL(millislice_writer.
size(),
73 if (microslice_writer_ptr.get() != 0) {
74 nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
75 BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
76 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
78 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
79 if (nanoslice_writer_ptr.get() != 0) {
80 nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER);
81 nanoslice_writer_ptr->addSample(SAMPLE1);
85 microslice_writer_ptr = millislice_writer.
reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
86 BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
89 sizeof(uint16_t) + MICROSLICE_BUFFER_SIZE);
91 if (microslice_writer_ptr.get() != 0) {
92 nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
93 BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
94 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
96 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
97 if (nanoslice_writer_ptr.get() != 0) {
98 nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+1);
99 nanoslice_writer_ptr->addSample(SAMPLE2);
102 nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
103 BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
106 NANOSLICE_BUFFER_SIZE);
107 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 2);
108 if (nanoslice_writer_ptr.get() != 0) {
109 nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+1);
110 nanoslice_writer_ptr->addSample(SAMPLE3);
114 microslice_writer_ptr = millislice_writer.
reserveMicroSlice(MICROSLICE_BUFFER_SIZE);
115 BOOST_REQUIRE(microslice_writer_ptr.get() != 0);
118 3*
sizeof(uint16_t) + MICROSLICE_BUFFER_SIZE);
120 if (microslice_writer_ptr.get() != 0) {
121 nanoslice_writer_ptr = microslice_writer_ptr->reserveNanoSlice(NANOSLICE_BUFFER_SIZE);
122 BOOST_REQUIRE(nanoslice_writer_ptr.get() != 0);
123 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->size(),
125 BOOST_REQUIRE_EQUAL(microslice_writer_ptr->nanoSliceCount(), 1);
126 if (nanoslice_writer_ptr.get() != 0) {
127 nanoslice_writer_ptr->setChannelNumber(CHANNEL_NUMBER+2);
128 nanoslice_writer_ptr->addSample(SAMPLE4);
129 nanoslice_writer_ptr->addSample(SAMPLE5);
136 int32_t size_diff = millislice_writer.
finalize();
137 BOOST_REQUIRE_EQUAL(size_diff, MILLISLICE_BUFFER_SIZE -
143 bool threw_exception =
false;
148 threw_exception =
true;
151 BOOST_REQUIRE_EQUAL(threw_exception,
true);
164 BOOST_REQUIRE(microslice_ptr.get() != 0);
165 if (microslice_ptr.get() != 0) {
166 BOOST_REQUIRE_EQUAL(microslice_ptr->nanoSliceCount(), 2);
167 std::unique_ptr<dune::NanoSlice> nanoslice_ptr = microslice_ptr->nanoSlice(1);
168 BOOST_REQUIRE(nanoslice_ptr.get() != 0);
169 if (nanoslice_ptr.get() != 0) {
170 BOOST_REQUIRE_EQUAL(nanoslice_ptr->sampleCount(), 1);
171 BOOST_REQUIRE(nanoslice_ptr->sampleValue(0, value));
172 BOOST_REQUIRE_EQUAL(value, SAMPLE3);
177 BOOST_REQUIRE(microslice_ptr.get() != 0);
178 if (microslice_ptr.get() != 0) {
179 BOOST_REQUIRE_EQUAL(microslice_ptr->nanoSliceCount(), 1);
180 std::unique_ptr<dune::NanoSlice> nanoslice_ptr = microslice_ptr->nanoSlice(0);
181 BOOST_REQUIRE(nanoslice_ptr.get() != 0);
182 if (nanoslice_ptr.get() != 0) {
183 BOOST_REQUIRE_EQUAL(nanoslice_ptr->sampleCount(), 2);
184 BOOST_REQUIRE(nanoslice_ptr->sampleValue(0, value));
185 BOOST_REQUIRE_EQUAL(value, SAMPLE4);
186 BOOST_REQUIRE(nanoslice_ptr->sampleValue(1, value));
187 BOOST_REQUIRE_EQUAL(value, SAMPLE5);
216 BOOST_AUTO_TEST_SUITE_END()
218 #pragma GCC diagnostic pop
std::unique_ptr< MicroSlice > microSlice(uint32_t index) const
Header::microslice_count_t microSliceCount() const
BOOST_AUTO_TEST_CASE(BaselineTest)
std::shared_ptr< MicroSliceWriter > reserveMicroSlice(uint32_t ms_max_bytes)
Header::millislice_size_t size() const
cet::coded_exception< error, detail::translate > exception