t-reftable-record: add comparison tests for obj records
In the current testing setup for obj records, the comparison functions for obj records, reftable_obj_record_cmp_void() and reftable_obj_record_equal_void() are left untested. Add tests for the same by using the wrapper functions reftable_record_cmp() and reftable_record_equal() for reftable_index_record_cmp_void() and reftable_index_record_equal_void() respectively. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> Acked-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Chandra Pratap committed
Jul 2, 2024 at 12:52 UTC
abb1834f2af0c958f418968760abf4e4c62aef34
1 file changed
+39
t/unit-tests/t-reftable-record.c
+39
@@ -299,6 +299,44 @@ static void t_key_roundtrip(void)
299
strbuf_release(&roundtrip);
300
}
301
302
+static void t_reftable_obj_record_comparison(void)
303
+{
304
+
305
+ uint8_t id_bytes[] = { 0, 1, 2, 3, 4, 5, 6 };
306
+ uint64_t offsets[] = { 0, 16, 32, 48, 64, 80, 96, 112};
307
+ struct reftable_record in[3] = {
308
+ {
309
+ .type = BLOCK_TYPE_OBJ,
310
+ .u.obj.hash_prefix = id_bytes,
311
+ .u.obj.hash_prefix_len = 7,
312
+ .u.obj.offsets = offsets,
313
+ .u.obj.offset_len = 8,
314
+ },
315
+ {
316
+ .type = BLOCK_TYPE_OBJ,
317
+ .u.obj.hash_prefix = id_bytes,
318
+ .u.obj.hash_prefix_len = 7,
319
+ .u.obj.offsets = offsets,
320
+ .u.obj.offset_len = 5,
321
+ },
322
+ {
323
+ .type = BLOCK_TYPE_OBJ,
324
+ .u.obj.hash_prefix = id_bytes,
325
+ .u.obj.hash_prefix_len = 5,
326
+ },
327
+ };
328
+
329
+ check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
330
+ check(!reftable_record_cmp(&in[0], &in[1]));
331
+
332
+ check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
333
+ check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
334
+
335
+ in[1].u.obj.offset_len = in[0].u.obj.offset_len;
336
+ check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
337
+ check(!reftable_record_cmp(&in[0], &in[1]));
338
+}
339
+
340
static void t_reftable_obj_record_roundtrip(void)
341
{
342
uint8_t testHash1[GIT_SHA1_RAWSZ] = { 1, 2, 3, 4, 0 };
@@ -443,6 +481,7 @@ int cmd_main(int argc, const char *argv[])
481
TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
482
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
483
TEST(t_reftable_index_record_comparison(), "comparison operations work on index record");
484
+ TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record");
485
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
486
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
487
TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");