@@ -123,6 +123,20 @@ append_vector_packed_bit_from_packed_array (
123
123
ASSERT (bson_iter_next (& copy_iter ));
124
124
uint8_t packed_byte = (uint8_t ) bson_iter_as_int64 (& copy_iter );
125
125
ASSERT (bson_vector_packed_bit_view_write_packed (view , & packed_byte , 1 , i ));
126
+
127
+ // Read back the packed byte, interpret any masking as a conversion failure.
128
+ uint8_t packed_byte_check ;
129
+ ASSERT (bson_vector_packed_bit_view_read_packed (view , & packed_byte_check , 1 , i ));
130
+ if (packed_byte != packed_byte_check ) {
131
+ bson_set_error (error ,
132
+ TEST_ERROR_DOMAIN ,
133
+ TEST_ERROR_CODE ,
134
+ "byte at index %zu with value 0x%02X included write to masked bits (reads as 0x%02X)" ,
135
+ i ,
136
+ packed_byte ,
137
+ packed_byte_check );
138
+ return false;
139
+ }
126
140
}
127
141
return true;
128
142
} else {
@@ -159,17 +173,6 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
159
173
bson_error_t vector_from_array_error ;
160
174
bool vector_from_array_ok ;
161
175
162
- // (Spec test improvement TODO) Patch test cases that have unused bits set to '1' when '0' is required.
163
- if (0 == strcmp ("PACKED_BIT with padding" , test_case -> test_description )) {
164
- bson_iter_t iter ;
165
- ASSERT (bson_iter_init_find (& iter , & expected_bson , test_case -> scenario_test_key ));
166
- uint32_t binary_len ;
167
- uint8_t * binary ;
168
- bson_iter_overwrite_binary (& iter , BSON_SUBTYPE_VECTOR , & binary_len , & binary );
169
- ASSERT (binary_len > BSON_VECTOR_HEADER_LEN );
170
- binary [binary_len - 1 ] &= (uint8_t ) 0xFF << bson_vector_padding_from_header_byte_1 (binary [1 ]);
171
- }
172
-
173
176
// Try a format conversion from array to the indicated vector format.
174
177
// The spec calls the first header byte "dtype" (combining the element type and element size fields)
175
178
if (0 == strcmp ("0x03" , test_case -> test_dtype_hex_str )) {
@@ -336,14 +339,6 @@ test_bson_vector_json_case (vector_json_test_case_t *test_case)
336
339
test_error ("test-vector array element %d has unexpected type, should be int." , (int ) byte_count );
337
340
}
338
341
339
- // (Spec test improvement TODO) Packed writes can't set unused bits to '1' in libbson, but the spec
340
- // tests allow padding bits to take on undefined values. Modify the expected values to keep padding bits
341
- // zeroed.
342
- if (0 == strcmp ("PACKED_BIT with padding" , test_case -> test_description ) &&
343
- byte_count == bson_vector_packed_bit_const_view_length_bytes (actual_view ) - 1u ) {
344
- expected_byte &= ((int64_t ) 0xFF << * test_case -> test_padding ) & 0xFF ;
345
- }
346
-
347
342
// Note, the zero initializer is only needed due to a false positive -Wmaybe-uninitialized warning in
348
343
// uncommon configurations where the compiler does not have visibility into memcpy().
349
344
uint8_t actual_byte = 0 ;
0 commit comments