1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include <cxxtest/TestSuite.h>
#include "common/bitstream.h"
#include "common/memstream.h"
class BitStreamTestSuite : public CxxTest::TestSuite
{
public:
void test_get_bit() {
byte contents[] = { 'a' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8MSB bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.getBit(), 0u);
TS_ASSERT_EQUALS(bs.getBit(), 1u);
TS_ASSERT_EQUALS(bs.getBit(), 1u);
TS_ASSERT_EQUALS(bs.pos(), 3u);
TS_ASSERT(!bs.eos());
}
void test_get_bits() {
byte contents[] = { 'a', 'b' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8MSB bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.getBits(3), 3u);
TS_ASSERT_EQUALS(bs.pos(), 3u);
TS_ASSERT_EQUALS(bs.getBits(8), 11u);
TS_ASSERT_EQUALS(bs.pos(), 11u);
TS_ASSERT(!bs.eos());
}
void test_skip() {
byte contents[] = { 'a', 'b' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8MSB bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
bs.skip(5);
TS_ASSERT_EQUALS(bs.pos(), 5u);
bs.skip(4);
TS_ASSERT_EQUALS(bs.pos(), 9u);
TS_ASSERT_EQUALS(bs.getBits(3), 6u);
TS_ASSERT(!bs.eos());
}
void test_rewind() {
byte contents[] = { 'a' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8MSB bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
bs.skip(5);
TS_ASSERT_EQUALS(bs.pos(), 5u);
bs.rewind();
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.getBits(3), 3u);
TS_ASSERT(!bs.eos());
TS_ASSERT_EQUALS(bs.size(), 8u);
}
void test_peek_bit() {
byte contents[] = { 'a' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8MSB bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.peekBit(), 0u);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.getBit(), 0u);
TS_ASSERT_EQUALS(bs.pos(), 1u);
TS_ASSERT_EQUALS(bs.peekBit(), 1u);
TS_ASSERT_EQUALS(bs.pos(), 1u);
TS_ASSERT(!bs.eos());
}
void test_peek_bits() {
byte contents[] = { 'a', 'b' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8MSB bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.peekBits(3), 3u);
TS_ASSERT_EQUALS(bs.pos(), 0u);
bs.skip(3);
TS_ASSERT_EQUALS(bs.pos(), 3u);
TS_ASSERT_EQUALS(bs.peekBits(8), 11u);
TS_ASSERT_EQUALS(bs.pos(), 3u);
bs.skip(8);
TS_ASSERT_EQUALS(bs.pos(), 11u);
TS_ASSERT_EQUALS(bs.peekBits(5), 2u);
TS_ASSERT(!bs.eos());
}
void test_eos() {
byte contents[] = { 'a', 'b' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8MSB bs(ms);
bs.skip(11);
TS_ASSERT_EQUALS(bs.pos(), 11u);
TS_ASSERT_EQUALS(bs.getBits(5), 2u);
TS_ASSERT(bs.eos());
bs.rewind();
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT(!bs.eos());
}
void test_get_bits_lsb() {
byte contents[] = { 'a', 'b' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8LSB bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.getBits(3), 1u);
TS_ASSERT_EQUALS(bs.pos(), 3u);
TS_ASSERT_EQUALS(bs.getBits(8), 76u);
TS_ASSERT_EQUALS(bs.pos(), 11u);
TS_ASSERT(!bs.eos());
}
void test_peek_bits_lsb() {
byte contents[] = { 'a', 'b' };
Common::MemoryReadStream ms(contents, sizeof(contents));
Common::BitStream8LSB bs(ms);
TS_ASSERT_EQUALS(bs.pos(), 0u);
TS_ASSERT_EQUALS(bs.peekBits(3), 1u);
TS_ASSERT_EQUALS(bs.pos(), 0u);
bs.skip(3);
TS_ASSERT_EQUALS(bs.pos(), 3u);
TS_ASSERT_EQUALS(bs.peekBits(8), 76u);
TS_ASSERT_EQUALS(bs.pos(), 3u);
bs.skip(8);
TS_ASSERT_EQUALS(bs.pos(), 11u);
TS_ASSERT_EQUALS(bs.peekBits(5), 12u);
TS_ASSERT(!bs.eos());
}
};
|