Message ID | 20240621115708.3626-12-chandrapratap3519@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/11] t: move reftable/record_test.c to the unit testing framework | expand |
Chandra Pratap <chandrapratap3519@gmail.com> writes: > 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> > --- > t/unit-tests/t-reftable-record.c | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > > diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c > index b949617c88..d480cc438a 100644 > --- a/t/unit-tests/t-reftable-record.c > +++ b/t/unit-tests/t-reftable-record.c > @@ -214,6 +214,30 @@ static void test_reftable_log_record_comparison(void) > reftable_record_release(&in[i]); > } > > +static void test_reftable_log_record_compare_key(void) > +{ > + struct reftable_log_record logs[14] = { 0 }; > + size_t N = ARRAY_SIZE(logs), i; > + > + for (i = 0; i < N; i++) { > + if (i < N / 2) { > + logs[i].refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i); > + logs[i].update_index = i; > + } else { > + logs[i].refname = xstrdup("refs/heads/master"); > + logs[i].update_index = i; > + } > + } > + > + QSORT(logs, N, reftable_log_record_compare_key); > + > + for (i = 1; i < N; i++) > + check(reftable_log_record_compare_key(&logs[i - 1], &logs[i]) < 0); > + > + for (i = 0; i < N; i++) > + reftable_log_record_release(&logs[i]); > +} > + Same comments as those from the previous commit. > static void test_reftable_log_record_roundtrip(void) > { > struct reftable_log_record in[] = { > @@ -519,6 +543,7 @@ int cmd_main(int argc, const char *argv[]) > 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_compare_key(), "reftable_log_record_compare_key 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"); > -- > 2.45.2.404.g9eaef5822c
diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c index b949617c88..d480cc438a 100644 --- a/t/unit-tests/t-reftable-record.c +++ b/t/unit-tests/t-reftable-record.c @@ -214,6 +214,30 @@ static void test_reftable_log_record_comparison(void) reftable_record_release(&in[i]); } +static void test_reftable_log_record_compare_key(void) +{ + struct reftable_log_record logs[14] = { 0 }; + size_t N = ARRAY_SIZE(logs), i; + + for (i = 0; i < N; i++) { + if (i < N / 2) { + logs[i].refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i); + logs[i].update_index = i; + } else { + logs[i].refname = xstrdup("refs/heads/master"); + logs[i].update_index = i; + } + } + + QSORT(logs, N, reftable_log_record_compare_key); + + for (i = 1; i < N; i++) + check(reftable_log_record_compare_key(&logs[i - 1], &logs[i]) < 0); + + for (i = 0; i < N; i++) + reftable_log_record_release(&logs[i]); +} + static void test_reftable_log_record_roundtrip(void) { struct reftable_log_record in[] = { @@ -519,6 +543,7 @@ int cmd_main(int argc, const char *argv[]) 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_compare_key(), "reftable_log_record_compare_key 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_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> --- t/unit-tests/t-reftable-record.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)