Skip to content

Commit b942fda

Browse files
Chandra Pratapgitster
Chandra Pratap
authored andcommitted
t-reftable-record: add tests for reftable_log_record_compare_key()
reftable_log_record_compare_key() is a function defined by reftable/record.{c, h} and is used to compare the keys of two log records when sorting multiple log records using 'qsort'. In the current testing setup, this function is left unexercised. Add a testing function for the same. 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 f7ec13b commit b942fda

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,35 @@ static void t_reftable_log_record_comparison(void)
205205
check(!reftable_record_cmp(&in[0], &in[1]));
206206
}
207207

208+
static void t_reftable_log_record_compare_key(void)
209+
{
210+
struct reftable_log_record logs[3] = {
211+
{
212+
.refname = (char *) "refs/heads/a",
213+
.update_index = 1,
214+
},
215+
{
216+
.refname = (char *) "refs/heads/b",
217+
.update_index = 2,
218+
},
219+
{
220+
.refname = (char *) "refs/heads/a",
221+
.update_index = 3,
222+
},
223+
};
224+
225+
check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0);
226+
check_int(reftable_log_record_compare_key(&logs[1], &logs[0]), >, 0);
227+
228+
logs[1].update_index = logs[0].update_index;
229+
check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0);
230+
231+
check_int(reftable_log_record_compare_key(&logs[0], &logs[2]), >, 0);
232+
check_int(reftable_log_record_compare_key(&logs[2], &logs[0]), <, 0);
233+
logs[2].update_index = logs[0].update_index;
234+
check_int(reftable_log_record_compare_key(&logs[0], &logs[2]), ==, 0);
235+
}
236+
208237
static void t_reftable_log_record_roundtrip(void)
209238
{
210239
struct reftable_log_record in[] = {
@@ -510,6 +539,7 @@ int cmd_main(int argc, const char *argv[])
510539
TEST(t_reftable_index_record_comparison(), "comparison operations work on index record");
511540
TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record");
512541
TEST(t_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works");
542+
TEST(t_reftable_log_record_compare_key(), "reftable_log_record_compare_key works");
513543
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
514544
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
515545
TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");

0 commit comments

Comments
 (0)