ud.bytes_left = sizeof(bytes);
struct bit_source source;
- init_bit_source(&source, custom_read, &ud);
+ init_bit_source(&source, custom_read, 0, &ud);
for (unsigned i = 0; i < sizeof(bytes) * 8 / 6; ++i) {
possibly_refill(&source, 6);
ud.bytes_left = sizeof(bytes);
struct bit_source source;
- init_bit_source(&source, custom_read_slow, &ud);
+ init_bit_source(&source, custom_read_slow, 0, &ud);
for (unsigned i = 0; i < sizeof(bytes) * 8 / 6; ++i) {
possibly_refill(&source, 6);
ud.bytes_left = sizeof(bytes);
struct bit_source source;
- init_bit_source(&source, custom_read, &ud);
+ init_bit_source(&source, custom_read, 0, &ud);
{
possibly_refill(&source, 4);
assert(ret == 0xf);
}
+ assert(ud.bytes_left == 0);
+}
+
+// Tests that padding bytes are properly added at the end, even crossing reads.
+void test_padding_reads()
+{
+ uint8_t bytes[] = { 0x01, 0x02 };
+
+ struct custom_read_userdata ud;
+ ud.bytes = bytes;
+ ud.bytes_left = sizeof(bytes);
+
+ struct bit_source source;
+ init_bit_source(&source, custom_read, 2, &ud);
+
+ {
+ possibly_refill(&source, 8);
+ unsigned ret = read_bits(&source, 8);
+ assert(ret == 0x01);
+ }
+ {
+ possibly_refill(&source, 12);
+ unsigned ret = read_bits(&source, 12);
+ assert(ret == 0x020);
+ }
+
assert(ud.bytes_left == 0);
}
printf("test_variable_size()\n");
test_variable_size();
+ printf("test_padding_reads()\n");
+ test_padding_reads();
+
printf("All tests pass.\n");
return 0;
}