diff options
author | Chandra Pratap <chandrapratap3519@gmail.com> | 2024-07-02 12:52:24 +0530 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-07-02 08:12:26 -0700 |
commit | b942fda6702994dc1a7ed91d33faceea68aedbc9 (patch) | |
tree | 6ae6fe84dbff8b1252894cdf17c2ff18440c4df7 /t/unit-tests | |
parent | f7ec13b53896966c233514c3906c284a40b00c3c (diff) |
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 <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>
Diffstat (limited to 't/unit-tests')
-rw-r--r-- | t/unit-tests/t-reftable-record.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index c0668cd8b4..cb649ee419 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -205,6 +205,35 @@ static void t_reftable_log_record_comparison(void) check(!reftable_record_cmp(&in[0], &in[1])); } +static void t_reftable_log_record_compare_key(void) +{ + struct reftable_log_record logs[3] = { + { + .refname = (char *) "refs/heads/a", + .update_index = 1, + }, + { + .refname = (char *) "refs/heads/b", + .update_index = 2, + }, + { + .refname = (char *) "refs/heads/a", + .update_index = 3, + }, + }; + + check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0); + check_int(reftable_log_record_compare_key(&logs[1], &logs[0]), >, 0); + + logs[1].update_index = logs[0].update_index; + check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0); + + check_int(reftable_log_record_compare_key(&logs[0], &logs[2]), >, 0); + check_int(reftable_log_record_compare_key(&logs[2], &logs[0]), <, 0); + logs[2].update_index = logs[0].update_index; + check_int(reftable_log_record_compare_key(&logs[0], &logs[2]), ==, 0); +} + static void t_reftable_log_record_roundtrip(void) { struct reftable_log_record in[] = { @@ -510,6 +539,7 @@ int cmd_main(int argc, const char *argv[]) TEST(t_reftable_index_record_comparison(), "comparison operations work on index record"); TEST(t_reftable_obj_record_comparison(), "comparison operations work on obj record"); TEST(t_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works"); + TEST(t_reftable_log_record_compare_key(), "reftable_log_record_compare_key works"); TEST(t_reftable_log_record_roundtrip(), "record operations work on log record"); TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record"); TEST(t_varint_roundtrip(), "put_var_int and get_var_int work"); |