Project
Loading...
Searching...
No Matches
test_BitstreamReader.cxx
Go to the documentation of this file.
1
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3
// All rights not expressly granted are reserved.
4
//
5
// This software is distributed under the terms of the GNU General Public
6
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7
//
8
// In applying this license CERN does not waive the privileges and immunities
9
// granted to it by virtue of its status as an Intergovernmental Organization
10
// or submit itself to any jurisdiction.
11
16
17
#define BOOST_TEST_MODULE Algorithm BitstreamReader unit test
18
#define BOOST_TEST_MAIN
19
#define BOOST_TEST_DYN_LINK
20
#include <boost/test/unit_test.hpp>
21
#include <iostream>
22
#include <iomanip>
23
#include <array>
24
#include <vector>
25
#include <bitset>
26
#include "../include/Algorithm/BitstreamReader.h"
27
28
namespace
o2
29
{
30
namespace
algorithm
31
{
32
33
BOOST_AUTO_TEST_CASE
(test_BitstreamReader_basic)
34
{
35
std::array<uint8_t, 8>
data
= {
'd'
,
'e'
,
'a'
,
'd'
,
'b'
,
'e'
,
'e'
,
'f'
};
36
std::array<uint8_t, 10> expected7bit = {0x32, 0x19, 0x2c, 0x16, 0x23, 0x09, 0x4a, 0x65, 0x33, 0x0};
37
auto
reference
= expected7bit.begin();
38
constexpr
size_t
totalBits =
data
.size() *
sizeof
(
decltype
(
data
)::value_type) * 8;
39
size_t
bitsRead = 0;
40
41
BitstreamReader<uint8_t>
reader(
data
.data(),
data
.data() +
data
.size());
42
while
(bitsRead < totalBits) {
43
BOOST_REQUIRE(
reference
!= expected7bit.end());
44
BOOST_CHECK
(reader.
eof
() ==
false
);
45
uint8_t
value
;
46
reader.
peek
(
value
);
47
// we use 7 bits of the data
48
value
>>= 1;
49
reader.
seek
(7);
50
bitsRead += 7;
51
// in the last call should there is not enough data
52
BOOST_CHECK
(reader.
good
() == (bitsRead <= totalBits));
53
BOOST_REQUIRE(
reference
!= expected7bit.end());
54
//std::cout << "value " << (int)value << " expected " << (int)*reference << std::endl;
55
BOOST_CHECK
(
value
== *
reference
);
56
++
reference
;
57
}
58
}
59
60
BOOST_AUTO_TEST_CASE
(test_BitstreamReader_operator)
61
{
62
std::array<uint8_t, 8>
data
= {
'd'
,
'e'
,
'a'
,
'd'
,
'b'
,
'e'
,
'e'
,
'f'
};
63
std::array<uint8_t, 10> expected7bit = {0x32, 0x19, 0x2c, 0x16, 0x23, 0x09, 0x4a, 0x65, 0x33, 0x0};
64
auto
reference
= expected7bit.begin();
65
constexpr
size_t
totalBits =
data
.size() *
sizeof
(
decltype
(
data
)::value_type) * 8;
66
size_t
bitsRead = 0;
67
68
BitstreamReader<uint8_t>
reader(
data
.data(),
data
.data() +
data
.size());
69
while
(bitsRead < totalBits) {
70
BOOST_REQUIRE(
reference
!= expected7bit.end());
71
BOOST_CHECK
(reader.
eof
() ==
false
);
72
{
73
decltype
(reader)::Bits<uint8_t>
value
;
74
reader >>
value
;
75
// we use 7 bits of the data
76
*
value
>>= 1;
77
value
.markUsed(7);
78
//std::cout << "value " << (int)*value << " expected " << (int)*reference << std::endl;
79
BOOST_CHECK
(*
value
== *
reference
);
80
}
81
bitsRead += 7;
82
// in the last call should there is not enough data
83
BOOST_CHECK
(reader.
good
() == (bitsRead <= totalBits));
84
BOOST_REQUIRE(
reference
!= expected7bit.end());
85
++
reference
;
86
}
87
}
88
89
BOOST_AUTO_TEST_CASE
(test_BitstreamReader_bitset)
90
{
91
std::array<uint8_t, 8>
data
= {
'd'
,
'e'
,
'a'
,
'd'
,
'b'
,
'e'
,
'e'
,
'f'
};
92
std::array<uint8_t, 10> expected7bit = {0x32, 0x19, 0x2c, 0x16, 0x23, 0x09, 0x4a, 0x65, 0x33, 0x0};
93
auto
reference
= expected7bit.begin();
94
constexpr
size_t
totalBits =
data
.size() *
sizeof
(
decltype
(
data
)::value_type) * 8;
95
size_t
bitsRead = 0;
96
97
BitstreamReader<uint8_t>
reader(
data
.data(),
data
.data() +
data
.size());
98
while
(bitsRead < totalBits) {
99
BOOST_REQUIRE(
reference
!= expected7bit.end());
100
BOOST_CHECK
(reader.
eof
() ==
false
);
101
std::bitset<13>
value
;
102
reader.
peek
(
value
,
value
.size());
103
// we use 7 bits of the data
104
value
>>=
value
.size() - 7;
105
reader.
seek
(7);
106
bitsRead += 7;
107
// in the last call should there is not enough data
108
BOOST_CHECK
(reader.
good
() == (bitsRead <= totalBits));
109
BOOST_REQUIRE(
reference
!= expected7bit.end());
110
BOOST_CHECK_MESSAGE(
value
.to_ulong() == *
reference
, std::string(
"mismatch: value "
) <<
value
.to_ulong() <<
", expected "
<< (
int
)*
reference
);
111
++
reference
;
112
}
113
114
reader.
reset
();
115
std::bitset<16> aBitset;
116
reader >> aBitset;
117
BOOST_CHECK_MESSAGE(aBitset.to_ulong() == 0x6465, std::string(
"mismatch: value 0x"
) << std::hex << aBitset.to_ulong() <<
", expected 0x6465"
);
118
}
119
120
}
// namespace algorithm
121
}
// namespace o2
int
o2::algorithm::BitstreamReader
Definition
BitstreamReader.h:50
o2::algorithm::BitstreamReader::seek
void seek(size_t bitlength)
Definition
BitstreamReader.h:113
o2::algorithm::BitstreamReader::good
bool good() const
Definition
BitstreamReader.h:67
o2::algorithm::BitstreamReader::peek
size_t peek(T &v)
Definition
BitstreamReader.h:94
o2::algorithm::BitstreamReader::reset
void reset()
Reset the reader, start over at beginning.
Definition
BitstreamReader.h:80
o2::algorithm::BitstreamReader::eof
bool eof() const
Definition
BitstreamReader.h:74
reference
GLint reference
Definition
glcorearb.h:5487
value
GLsizei const GLfloat * value
Definition
glcorearb.h:819
data
GLboolean * data
Definition
glcorearb.h:298
o2::algorithm::BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_BitstreamReader_basic)
Definition
test_BitstreamReader.cxx:33
o2
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Definition
BitstreamReader.h:24
BOOST_CHECK
BOOST_CHECK(tree)
Algorithm
test
test_BitstreamReader.cxx
Generated on Tue Feb 25 2025 17:02:49 for Project by
1.9.8