@@ -96,4 +96,73 @@ TEST(BitstreamReaderTest, jumpToPointer) {
96
96
}
97
97
}
98
98
99
+ TEST (BitstreamReaderTest, setArtificialByteLimit) {
100
+ uint8_t Bytes[] = {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
101
+ 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f };
102
+ BitstreamReader Reader (std::begin (Bytes), std::end (Bytes));
103
+ SimpleBitstreamCursor Cursor (Reader);
104
+
105
+ Cursor.setArtificialByteLimit (8 );
106
+ while (!Cursor.AtEndOfStream ())
107
+ (void )Cursor.Read (1 );
108
+
109
+ EXPECT_EQ (8u , Cursor.getCurrentByteNo ());
110
+ }
111
+
112
+ TEST (BitstreamReaderTest, setArtificialByteLimitNotWordBoundary) {
113
+ uint8_t Bytes[] = {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
114
+ 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f };
115
+ BitstreamReader Reader (std::begin (Bytes), std::end (Bytes));
116
+ SimpleBitstreamCursor Cursor (Reader);
117
+
118
+ Cursor.setArtificialByteLimit (5 );
119
+ while (!Cursor.AtEndOfStream ())
120
+ (void )Cursor.Read (1 );
121
+
122
+ EXPECT_EQ (8u , Cursor.getCurrentByteNo ());
123
+ }
124
+
125
+ TEST (BitstreamReaderTest, setArtificialByteLimitNot4ByteBoundary) {
126
+ uint8_t Bytes[] = {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
127
+ 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f };
128
+ BitstreamReader Reader (std::begin (Bytes), std::end (Bytes));
129
+ SimpleBitstreamCursor Cursor (Reader);
130
+
131
+ Cursor.setArtificialByteLimit (5 );
132
+ while (!Cursor.AtEndOfStream ())
133
+ (void )Cursor.Read (1 );
134
+
135
+ EXPECT_EQ (8u , Cursor.getCurrentByteNo ());
136
+ }
137
+
138
+ TEST (BitstreamReaderTest, setArtificialByteLimitPastTheEnd) {
139
+ uint8_t Bytes[] = {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
140
+ 0x08 , 0x09 , 0x0a , 0x0b };
141
+ BitstreamReader Reader (std::begin (Bytes), std::end (Bytes));
142
+ SimpleBitstreamCursor Cursor (Reader);
143
+
144
+ // The size of the memory object isn't known yet. Set it too high and
145
+ // confirm that we don't read too far.
146
+ Cursor.setArtificialByteLimit (20 );
147
+ while (!Cursor.AtEndOfStream ())
148
+ (void )Cursor.Read (1 );
149
+
150
+ EXPECT_EQ (12u , Cursor.getCurrentByteNo ());
151
+ }
152
+
153
+ TEST (BitstreamReaderTest, setArtificialByteLimitPastTheEndKnown) {
154
+ uint8_t Bytes[] = {0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
155
+ 0x08 , 0x09 , 0x0a , 0x0b };
156
+ BitstreamReader Reader (std::begin (Bytes), std::end (Bytes));
157
+ SimpleBitstreamCursor Cursor (Reader);
158
+
159
+ // Save the size of the memory object in the cursor.
160
+ while (!Cursor.AtEndOfStream ())
161
+ (void )Cursor.Read (1 );
162
+ EXPECT_EQ (12u , Cursor.getCurrentByteNo ());
163
+
164
+ Cursor.setArtificialByteLimit (20 );
165
+ EXPECT_TRUE (Cursor.AtEndOfStream ());
166
+ }
167
+
99
168
} // end anonymous namespace
0 commit comments