+ 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);
+ }
+