Skip to content

Commit abb1834

Browse files
Chandra Pratapgitster
authored andcommitted
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 <[email protected]> Mentored-by: Christian Couder <[email protected]> Signed-off-by: Chandra Pratap <[email protected]> Acked-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 85ca39e commit abb1834

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

t/unit-tests/t-reftable-record.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,44 @@ static void t_key_roundtrip(void)
299299
strbuf_release(&roundtrip);
300300
}
301301

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+
302340
static void t_reftable_obj_record_roundtrip(void)
303341
{
304342
uint8_t testHash1[GIT_SHA1_RAWSZ] = { 1, 2, 3, 4, 0 };
@@ -443,6 +481,7 @@ int cmd_main(int argc, const char *argv[])
443481
TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
444482
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
445483
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");
446485
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
447486
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
448487
TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");

0 commit comments

Comments
 (0)