MCPcopy Index your code
hub / github.com/git/git / test_reftable_stack__iterator

Function test_reftable_stack__iterator

t/unit-tests/u-reftable-stack.c:585–668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

583}
584
585void test_reftable_stack__iterator(void)
586{
587 struct reftable_write_options opts = { 0 };
588 struct reftable_stack *st = NULL;
589 char *dir = get_tmp_dir(__LINE__);
590 struct reftable_ref_record refs[10] = { 0 };
591 struct reftable_log_record logs[10] = { 0 };
592 struct reftable_iterator it = { 0 };
593 size_t N = ARRAY_SIZE(refs), i;
594 int err;
595
596 cl_assert_equal_i(reftable_new_stack(&st, dir, &opts), 0);
597
598 for (i = 0; i < N; i++) {
599 refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
600 refs[i].update_index = i + 1;
601 refs[i].value_type = REFTABLE_REF_VAL1;
602 cl_reftable_set_hash(refs[i].value.val1, i,
603 REFTABLE_HASH_SHA1);
604
605 logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
606 logs[i].update_index = i + 1;
607 logs[i].value_type = REFTABLE_LOG_UPDATE;
608 logs[i].value.update.email = xstrdup("johndoe@invalid");
609 logs[i].value.update.message = xstrdup("commit\n");
610 cl_reftable_set_hash(logs[i].value.update.new_hash, i,
611 REFTABLE_HASH_SHA1);
612 }
613
614 for (i = 0; i < N; i++)
615 cl_assert_equal_i(reftable_stack_add(st, write_test_ref,
616 &refs[i], 0), 0);
617
618 for (i = 0; i < N; i++) {
619 struct write_log_arg arg = {
620 .log = &logs[i],
621 .update_index = reftable_stack_next_update_index(st),
622 };
623
624 cl_assert_equal_i(reftable_stack_add(st, write_test_log,
625 &arg, 0), 0);
626 }
627
628 reftable_stack_init_ref_iterator(st, &it);
629 reftable_iterator_seek_ref(&it, refs[0].refname);
630 for (i = 0; ; i++) {
631 struct reftable_ref_record ref = { 0 };
632
633 err = reftable_iterator_next_ref(&it, &ref);
634 if (err > 0)
635 break;
636 cl_assert(!err);
637 cl_assert(reftable_ref_record_equal(&ref, &refs[i],
638 REFTABLE_HASH_SIZE_SHA1) != 0);
639 reftable_ref_record_release(&ref);
640 }
641 cl_assert_equal_i(i, N);
642

Callers

nothing calls this directly

Calls 15

get_tmp_dirFunction · 0.85
reftable_new_stackFunction · 0.85
xstrfmtFunction · 0.85
cl_reftable_set_hashFunction · 0.85
xstrdupFunction · 0.85
reftable_stack_addFunction · 0.85

Tested by

no test coverage detected