@@ -98,6 +98,26 @@ static void test_reftable_ref_record_comparison(void)
check(!reftable_record_cmp(&in[0], &in[1]));
}
+static void test_reftable_ref_record_compare_name(void)
+{
+ struct reftable_ref_record recs[14] = { 0 };
+ size_t N = ARRAY_SIZE(recs), i;
+ char refname[100];
+
+ for (i = 0; i < N; i++) {
+ xsnprintf(refname, sizeof(refname), "%02"PRIuMAX, (uintmax_t)i);
+ recs[i].refname = xstrdup(refname);
+ }
+
+ QSORT(recs, N, reftable_ref_record_compare_name);
+
+ for (i = 1; i < N; i++)
+ check(reftable_ref_record_compare_name(&recs[i - 1], &recs[i]) < 0);
+
+ for (i = 0; i < N; i++)
+ reftable_ref_record_release(&recs[i]);
+}
+
static void test_reftable_ref_record_roundtrip(void)
{
struct strbuf scratch = STRBUF_INIT;
@@ -495,6 +515,7 @@ int cmd_main(int argc, const char *argv[])
TEST(test_reftable_log_record_comparison(), "comparison operations work on log record");
TEST(test_reftable_index_record_comparison(), "comparison operations work on index record");
TEST(test_reftable_obj_record_comparison(), "comparison operations work on obj record");
+ TEST(test_reftable_ref_record_compare_name(), "reftable_ref_record_compare_name works");
TEST(test_reftable_log_record_roundtrip(), "record operations work on log record");
TEST(test_reftable_ref_record_roundtrip(), "record operations work on ref record");
TEST(test_varint_roundtrip(), "put_var_int and get_var_int work");
reftable_ref_record_compare_name() is a function defined by reftable/record.{c, h} and is used to compare the refname of two ref records when sorting multiple ref 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> --- t/unit-tests/t-reftable-record.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)