Merge branch 'sk/reftable-clarify-tests'
The reftable unit tests are now ported to the "clar" unit testing framework. * sk/reftable-clarify-tests: t/unit-tests: finalize migration of reftable-related tests t/unit-tests: convert reftable stack test to use clar t/unit-tests: convert reftable record test to use clar t/unit-tests: convert reftable readwrite test to use clar t/unit-tests: convert reftable table test to use clar t/unit-tests: convert reftable pq test to use clar t/unit-tests: convert reftable merged test to use clar t/unit-tests: convert reftable block test to use clar t/unit-tests: convert reftable basics test to use clar test framework t/unit-tests: implement clar specific reftable test helper functionsmaint
commit
80b80162fd
20
Makefile
20
Makefile
|
|
@ -1362,6 +1362,13 @@ CLAR_TEST_SUITES += u-oid-array
|
|||
CLAR_TEST_SUITES += u-oidmap
|
||||
CLAR_TEST_SUITES += u-oidtree
|
||||
CLAR_TEST_SUITES += u-prio-queue
|
||||
CLAR_TEST_SUITES += u-reftable-basics
|
||||
CLAR_TEST_SUITES += u-reftable-block
|
||||
CLAR_TEST_SUITES += u-reftable-merged
|
||||
CLAR_TEST_SUITES += u-reftable-pq
|
||||
CLAR_TEST_SUITES += u-reftable-readwrite
|
||||
CLAR_TEST_SUITES += u-reftable-stack
|
||||
CLAR_TEST_SUITES += u-reftable-table
|
||||
CLAR_TEST_SUITES += u-reftable-tree
|
||||
CLAR_TEST_SUITES += u-strbuf
|
||||
CLAR_TEST_SUITES += u-strcmp-offset
|
||||
|
|
@ -1372,20 +1379,11 @@ CLAR_TEST_SUITES += u-urlmatch-normalization
|
|||
CLAR_TEST_PROG = $(UNIT_TEST_BIN)/unit-tests$(X)
|
||||
CLAR_TEST_OBJS = $(patsubst %,$(UNIT_TEST_DIR)/%.o,$(CLAR_TEST_SUITES))
|
||||
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/clar/clar.o
|
||||
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
|
||||
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-oid.o
|
||||
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
|
||||
CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
|
||||
|
||||
UNIT_TEST_PROGRAMS += t-reftable-basics
|
||||
UNIT_TEST_PROGRAMS += t-reftable-block
|
||||
UNIT_TEST_PROGRAMS += t-reftable-merged
|
||||
UNIT_TEST_PROGRAMS += t-reftable-pq
|
||||
UNIT_TEST_PROGRAMS += t-reftable-readwrite
|
||||
UNIT_TEST_PROGRAMS += t-reftable-record
|
||||
UNIT_TEST_PROGRAMS += t-reftable-stack
|
||||
UNIT_TEST_PROGRAMS += t-reftable-table
|
||||
UNIT_TEST_PROGS = $(patsubst %,$(UNIT_TEST_BIN)/%$X,$(UNIT_TEST_PROGRAMS))
|
||||
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
|
||||
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/lib-reftable.o
|
||||
|
||||
# xdiff and reftable libs may in turn depend on what is in libgit.a
|
||||
GITLIBS = common-main.o $(LIB_FILE) $(XDIFF_LIB) $(REFTABLE_LIB) $(LIB_FILE)
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ check-meson:
|
|||
@mkdir -p mesontmp && \
|
||||
printf "%s\n" \
|
||||
"integration_tests t[0-9][0-9][0-9][0-9]-*.sh" \
|
||||
"unit_test_programs unit-tests/t-*.c" \
|
||||
"clar_test_suites unit-tests/u-*.c" | \
|
||||
while read -r variable pattern; do \
|
||||
awk "/^$$variable = \[\$$/ {flag=1 ; next } /^]$$/ { flag=0 } flag { gsub(/^ \047/, \"\"); gsub(/\047,\$$/, \"\"); print }" meson.build >mesontmp/meson.txt && \
|
||||
|
|
|
|||
|
|
@ -8,6 +8,14 @@ clar_test_suites = [
|
|||
'unit-tests/u-oidmap.c',
|
||||
'unit-tests/u-oidtree.c',
|
||||
'unit-tests/u-prio-queue.c',
|
||||
'unit-tests/u-reftable-basics.c',
|
||||
'unit-tests/u-reftable-block.c',
|
||||
'unit-tests/u-reftable-merged.c',
|
||||
'unit-tests/u-reftable-pq.c',
|
||||
'unit-tests/u-reftable-readwrite.c',
|
||||
'unit-tests/u-reftable-record.c',
|
||||
'unit-tests/u-reftable-stack.c',
|
||||
'unit-tests/u-reftable-table.c',
|
||||
'unit-tests/u-reftable-tree.c',
|
||||
'unit-tests/u-strbuf.c',
|
||||
'unit-tests/u-strcmp-offset.c',
|
||||
|
|
@ -20,7 +28,8 @@ clar_test_suites = [
|
|||
clar_sources = [
|
||||
'unit-tests/clar/clar.c',
|
||||
'unit-tests/unit-test.c',
|
||||
'unit-tests/lib-oid.c'
|
||||
'unit-tests/lib-oid.c',
|
||||
'unit-tests/lib-reftable.c'
|
||||
]
|
||||
|
||||
clar_decls_h = custom_target(
|
||||
|
|
@ -54,33 +63,6 @@ clar_unit_tests = executable('unit-tests',
|
|||
)
|
||||
test('unit-tests', clar_unit_tests, kwargs: test_kwargs)
|
||||
|
||||
unit_test_programs = [
|
||||
'unit-tests/t-reftable-basics.c',
|
||||
'unit-tests/t-reftable-block.c',
|
||||
'unit-tests/t-reftable-merged.c',
|
||||
'unit-tests/t-reftable-pq.c',
|
||||
'unit-tests/t-reftable-readwrite.c',
|
||||
'unit-tests/t-reftable-record.c',
|
||||
'unit-tests/t-reftable-stack.c',
|
||||
'unit-tests/t-reftable-table.c',
|
||||
]
|
||||
|
||||
foreach unit_test_program : unit_test_programs
|
||||
unit_test_name = fs.stem(unit_test_program)
|
||||
unit_test = executable(unit_test_name,
|
||||
sources: [
|
||||
'unit-tests/test-lib.c',
|
||||
'unit-tests/lib-reftable.c',
|
||||
unit_test_program,
|
||||
],
|
||||
dependencies: [libgit_commonmain],
|
||||
)
|
||||
test(unit_test_name, unit_test,
|
||||
workdir: meson.current_source_dir(),
|
||||
kwargs: test_kwargs,
|
||||
)
|
||||
endforeach
|
||||
|
||||
subdir('helper')
|
||||
|
||||
integration_tests = [
|
||||
|
|
@ -1163,8 +1145,6 @@ benchmarks = [
|
|||
# sufficient to catch missing test suites in our CI though.
|
||||
foreach glob, tests : {
|
||||
't[0-9][0-9][0-9][0-9]-*.sh': integration_tests,
|
||||
'perf/p[0-9][0-9][0-9][0-9]-*.sh': benchmarks,
|
||||
'unit-tests/t-*.c': unit_test_programs,
|
||||
'unit-tests/u-*.c': clar_test_suites,
|
||||
}
|
||||
actual_tests = run_command(shell, '-c', 'ls ' + glob,
|
||||
|
|
@ -1231,4 +1211,4 @@ if perl.found() and time.found()
|
|||
timeout: 0,
|
||||
)
|
||||
endforeach
|
||||
endif
|
||||
endif
|
||||
|
|
@ -1,12 +1,14 @@
|
|||
#define DISABLE_SIGN_COMPARE_WARNINGS
|
||||
|
||||
#include "unit-test.h"
|
||||
#include "lib-reftable.h"
|
||||
#include "test-lib.h"
|
||||
#include "hex.h"
|
||||
#include "parse-options.h"
|
||||
#include "reftable/constants.h"
|
||||
#include "reftable/writer.h"
|
||||
#include "strbuf.h"
|
||||
#include "string-list.h"
|
||||
#include "strvec.h"
|
||||
|
||||
void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
|
||||
void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
|
||||
{
|
||||
memset(p, (uint8_t)i, hash_size(id));
|
||||
}
|
||||
|
|
@ -22,17 +24,17 @@ static int strbuf_writer_flush(void *arg UNUSED)
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
|
||||
struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
|
||||
struct reftable_write_options *opts)
|
||||
{
|
||||
struct reftable_writer *writer;
|
||||
int ret = reftable_writer_new(&writer, &strbuf_writer_write, &strbuf_writer_flush,
|
||||
buf, opts);
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
return writer;
|
||||
}
|
||||
|
||||
void t_reftable_write_to_buf(struct reftable_buf *buf,
|
||||
void cl_reftable_write_to_buf(struct reftable_buf *buf,
|
||||
struct reftable_ref_record *refs,
|
||||
size_t nrefs,
|
||||
struct reftable_log_record *logs,
|
||||
|
|
@ -64,35 +66,36 @@ void t_reftable_write_to_buf(struct reftable_buf *buf,
|
|||
min = ui;
|
||||
}
|
||||
|
||||
writer = t_reftable_strbuf_writer(buf, &opts);
|
||||
reftable_writer_set_limits(writer, min, max);
|
||||
writer = cl_reftable_strbuf_writer(buf, &opts);
|
||||
ret = reftable_writer_set_limits(writer, min, max);
|
||||
cl_assert(!ret);
|
||||
|
||||
if (nrefs) {
|
||||
ret = reftable_writer_add_refs(writer, refs, nrefs);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
}
|
||||
|
||||
if (nlogs) {
|
||||
ret = reftable_writer_add_logs(writer, logs, nlogs);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
}
|
||||
|
||||
ret = reftable_writer_close(writer);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
stats = reftable_writer_stats(writer);
|
||||
for (size_t i = 0; i < stats->ref_stats.blocks; i++) {
|
||||
for (size_t i = 0; i < (size_t)stats->ref_stats.blocks; i++) {
|
||||
size_t off = i * (opts.block_size ? opts.block_size
|
||||
: DEFAULT_BLOCK_SIZE);
|
||||
if (!off)
|
||||
off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
|
||||
check_char(buf->buf[off], ==, 'r');
|
||||
cl_assert(buf->buf[off] == 'r');
|
||||
}
|
||||
|
||||
if (nrefs)
|
||||
check_int(stats->ref_stats.blocks, >, 0);
|
||||
cl_assert(stats->ref_stats.blocks > 0);
|
||||
if (nlogs)
|
||||
check_int(stats->log_stats.blocks, >, 0);
|
||||
cl_assert(stats->log_stats.blocks > 0);
|
||||
|
||||
reftable_writer_free(writer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
#ifndef LIB_REFTABLE_H
|
||||
#define LIB_REFTABLE_H
|
||||
|
||||
#include "git-compat-util.h"
|
||||
#include "clar/clar.h"
|
||||
#include "clar-decls.h"
|
||||
#include "git-compat-util.h"
|
||||
#include "reftable/reftable-writer.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
struct reftable_buf;
|
||||
|
||||
void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
|
||||
void cl_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
|
||||
|
||||
struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
|
||||
struct reftable_writer *cl_reftable_strbuf_writer(struct reftable_buf *buf,
|
||||
struct reftable_write_options *opts);
|
||||
|
||||
void t_reftable_write_to_buf(struct reftable_buf *buf,
|
||||
void cl_reftable_write_to_buf(struct reftable_buf *buf,
|
||||
struct reftable_ref_record *refs,
|
||||
size_t nrecords,
|
||||
struct reftable_log_record *logs,
|
||||
size_t nlogs,
|
||||
struct reftable_write_options *opts);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,219 +0,0 @@
|
|||
/*
|
||||
Copyright 2020 Google LLC
|
||||
|
||||
Use of this source code is governed by a BSD-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://developers.google.com/open-source/licenses/bsd
|
||||
*/
|
||||
|
||||
#include "test-lib.h"
|
||||
#include "reftable/basics.h"
|
||||
|
||||
struct integer_needle_lesseq_args {
|
||||
int needle;
|
||||
int *haystack;
|
||||
};
|
||||
|
||||
static int integer_needle_lesseq(size_t i, void *_args)
|
||||
{
|
||||
struct integer_needle_lesseq_args *args = _args;
|
||||
return args->needle <= args->haystack[i];
|
||||
}
|
||||
|
||||
static void *realloc_stub(void *p UNUSED, size_t size UNUSED)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
{
|
||||
if_test ("binary search with binsearch works") {
|
||||
int haystack[] = { 2, 4, 6, 8, 10 };
|
||||
struct {
|
||||
int needle;
|
||||
size_t expected_idx;
|
||||
} testcases[] = {
|
||||
{-9000, 0},
|
||||
{-1, 0},
|
||||
{0, 0},
|
||||
{2, 0},
|
||||
{3, 1},
|
||||
{4, 1},
|
||||
{7, 3},
|
||||
{9, 4},
|
||||
{10, 4},
|
||||
{11, 5},
|
||||
{9000, 5},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
|
||||
struct integer_needle_lesseq_args args = {
|
||||
.haystack = haystack,
|
||||
.needle = testcases[i].needle,
|
||||
};
|
||||
size_t idx;
|
||||
|
||||
idx = binsearch(ARRAY_SIZE(haystack),
|
||||
&integer_needle_lesseq, &args);
|
||||
check_int(idx, ==, testcases[i].expected_idx);
|
||||
}
|
||||
}
|
||||
|
||||
if_test ("names_length returns size of a NULL-terminated string array") {
|
||||
const char *a[] = { "a", "b", NULL };
|
||||
check_int(names_length(a), ==, 2);
|
||||
}
|
||||
|
||||
if_test ("names_equal compares NULL-terminated string arrays") {
|
||||
const char *a[] = { "a", "b", "c", NULL };
|
||||
const char *b[] = { "a", "b", "d", NULL };
|
||||
const char *c[] = { "a", "b", NULL };
|
||||
|
||||
check(names_equal(a, a));
|
||||
check(!names_equal(a, b));
|
||||
check(!names_equal(a, c));
|
||||
}
|
||||
|
||||
if_test ("parse_names works for basic input") {
|
||||
char in1[] = "line\n";
|
||||
char in2[] = "a\nb\nc";
|
||||
char **out = parse_names(in1, strlen(in1));
|
||||
check(out != NULL);
|
||||
check_str(out[0], "line");
|
||||
check(!out[1]);
|
||||
free_names(out);
|
||||
|
||||
out = parse_names(in2, strlen(in2));
|
||||
check(out != NULL);
|
||||
check_str(out[0], "a");
|
||||
check_str(out[1], "b");
|
||||
check_str(out[2], "c");
|
||||
check(!out[3]);
|
||||
free_names(out);
|
||||
}
|
||||
|
||||
if_test ("parse_names drops empty string") {
|
||||
char in[] = "a\n\nb\n";
|
||||
char **out = parse_names(in, strlen(in));
|
||||
check(out != NULL);
|
||||
check_str(out[0], "a");
|
||||
/* simply '\n' should be dropped as empty string */
|
||||
check_str(out[1], "b");
|
||||
check(!out[2]);
|
||||
free_names(out);
|
||||
}
|
||||
|
||||
if_test ("common_prefix_size works") {
|
||||
struct reftable_buf a = REFTABLE_BUF_INIT;
|
||||
struct reftable_buf b = REFTABLE_BUF_INIT;
|
||||
struct {
|
||||
const char *a, *b;
|
||||
int want;
|
||||
} cases[] = {
|
||||
{"abcdef", "abc", 3},
|
||||
{ "abc", "ab", 2 },
|
||||
{ "", "abc", 0 },
|
||||
{ "abc", "abd", 2 },
|
||||
{ "abc", "pqr", 0 },
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
|
||||
check(!reftable_buf_addstr(&a, cases[i].a));
|
||||
check(!reftable_buf_addstr(&b, cases[i].b));
|
||||
check_uint(common_prefix_size(&a, &b), ==, cases[i].want);
|
||||
reftable_buf_reset(&a);
|
||||
reftable_buf_reset(&b);
|
||||
}
|
||||
reftable_buf_release(&a);
|
||||
reftable_buf_release(&b);
|
||||
}
|
||||
|
||||
if_test ("reftable_put_be64 and reftable_get_be64 work") {
|
||||
uint64_t in = 0x1122334455667788;
|
||||
uint8_t dest[8];
|
||||
uint64_t out;
|
||||
reftable_put_be64(dest, in);
|
||||
out = reftable_get_be64(dest);
|
||||
check_int(in, ==, out);
|
||||
}
|
||||
|
||||
if_test ("reftable_put_be32 and reftable_get_be32 work") {
|
||||
uint32_t in = 0x11223344;
|
||||
uint8_t dest[4];
|
||||
uint32_t out;
|
||||
reftable_put_be32(dest, in);
|
||||
out = reftable_get_be32(dest);
|
||||
check_int(in, ==, out);
|
||||
}
|
||||
|
||||
if_test ("reftable_put_be24 and reftable_get_be24 work") {
|
||||
uint32_t in = 0x112233;
|
||||
uint8_t dest[3];
|
||||
uint32_t out;
|
||||
reftable_put_be24(dest, in);
|
||||
out = reftable_get_be24(dest);
|
||||
check_int(in, ==, out);
|
||||
}
|
||||
|
||||
if_test ("put_be16 and get_be16 work") {
|
||||
uint32_t in = 0xfef1;
|
||||
uint8_t dest[3];
|
||||
uint32_t out;
|
||||
reftable_put_be16(dest, in);
|
||||
out = reftable_get_be16(dest);
|
||||
check_int(in, ==, out);
|
||||
}
|
||||
|
||||
if_test ("REFTABLE_ALLOC_GROW works") {
|
||||
int *arr = NULL, *old_arr;
|
||||
size_t alloc = 0, old_alloc;
|
||||
|
||||
check(!REFTABLE_ALLOC_GROW(arr, 1, alloc));
|
||||
check(arr != NULL);
|
||||
check_uint(alloc, >=, 1);
|
||||
arr[0] = 42;
|
||||
|
||||
old_alloc = alloc;
|
||||
old_arr = arr;
|
||||
reftable_set_alloc(NULL, realloc_stub, NULL);
|
||||
check(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
|
||||
check(arr == old_arr);
|
||||
check_uint(alloc, ==, old_alloc);
|
||||
|
||||
old_alloc = alloc;
|
||||
reftable_set_alloc(NULL, NULL, NULL);
|
||||
check(!REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
|
||||
check(arr != NULL);
|
||||
check_uint(alloc, >, old_alloc);
|
||||
arr[alloc - 1] = 42;
|
||||
|
||||
reftable_free(arr);
|
||||
}
|
||||
|
||||
if_test ("REFTABLE_ALLOC_GROW_OR_NULL works") {
|
||||
int *arr = NULL;
|
||||
size_t alloc = 0, old_alloc;
|
||||
|
||||
REFTABLE_ALLOC_GROW_OR_NULL(arr, 1, alloc);
|
||||
check(arr != NULL);
|
||||
check_uint(alloc, >=, 1);
|
||||
arr[0] = 42;
|
||||
|
||||
old_alloc = alloc;
|
||||
REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
|
||||
check(arr != NULL);
|
||||
check_uint(alloc, >, old_alloc);
|
||||
arr[alloc - 1] = 42;
|
||||
|
||||
old_alloc = alloc;
|
||||
reftable_set_alloc(NULL, realloc_stub, NULL);
|
||||
REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
|
||||
check(arr == NULL);
|
||||
check_uint(alloc, ==, 0);
|
||||
reftable_set_alloc(NULL, NULL, NULL);
|
||||
|
||||
reftable_free(arr);
|
||||
}
|
||||
|
||||
return test_done();
|
||||
}
|
||||
|
|
@ -0,0 +1,227 @@
|
|||
/*
|
||||
Copyright 2020 Google LLC
|
||||
|
||||
Use of this source code is governed by a BSD-style
|
||||
license that can be found in the LICENSE file or at
|
||||
https://developers.google.com/open-source/licenses/bsd
|
||||
*/
|
||||
|
||||
#include "unit-test.h"
|
||||
#include "lib-reftable.h"
|
||||
#include "reftable/basics.h"
|
||||
|
||||
struct integer_needle_lesseq_args {
|
||||
int needle;
|
||||
int *haystack;
|
||||
};
|
||||
|
||||
static int integer_needle_lesseq(size_t i, void *_args)
|
||||
{
|
||||
struct integer_needle_lesseq_args *args = _args;
|
||||
return args->needle <= args->haystack[i];
|
||||
}
|
||||
|
||||
static void *realloc_stub(void *p UNUSED, size_t size UNUSED)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void test_reftable_basics__binsearch(void)
|
||||
{
|
||||
int haystack[] = { 2, 4, 6, 8, 10 };
|
||||
struct {
|
||||
int needle;
|
||||
size_t expected_idx;
|
||||
} testcases[] = {
|
||||
{-9000, 0},
|
||||
{-1, 0},
|
||||
{0, 0},
|
||||
{2, 0},
|
||||
{3, 1},
|
||||
{4, 1},
|
||||
{7, 3},
|
||||
{9, 4},
|
||||
{10, 4},
|
||||
{11, 5},
|
||||
{9000, 5},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(testcases); i++) {
|
||||
struct integer_needle_lesseq_args args = {
|
||||
.haystack = haystack,
|
||||
.needle = testcases[i].needle,
|
||||
};
|
||||
size_t idx;
|
||||
|
||||
idx = binsearch(ARRAY_SIZE(haystack),
|
||||
&integer_needle_lesseq, &args);
|
||||
cl_assert_equal_i(idx, testcases[i].expected_idx);
|
||||
}
|
||||
}
|
||||
|
||||
void test_reftable_basics__names_length(void)
|
||||
{
|
||||
const char *a[] = { "a", "b", NULL };
|
||||
cl_assert_equal_i(names_length(a), 2);
|
||||
}
|
||||
|
||||
void test_reftable_basics__names_equal(void)
|
||||
{
|
||||
const char *a[] = { "a", "b", "c", NULL };
|
||||
const char *b[] = { "a", "b", "d", NULL };
|
||||
const char *c[] = { "a", "b", NULL };
|
||||
|
||||
cl_assert(names_equal(a, a));
|
||||
cl_assert(!names_equal(a, b));
|
||||
cl_assert(!names_equal(a, c));
|
||||
}
|
||||
|
||||
void test_reftable_basics__parse_names(void)
|
||||
{
|
||||
char in1[] = "line\n";
|
||||
char in2[] = "a\nb\nc";
|
||||
char **out = parse_names(in1, strlen(in1));
|
||||
cl_assert(out != NULL);
|
||||
cl_assert_equal_s(out[0], "line");
|
||||
cl_assert(!out[1]);
|
||||
free_names(out);
|
||||
|
||||
out = parse_names(in2, strlen(in2));
|
||||
cl_assert(out != NULL);
|
||||
cl_assert_equal_s(out[0], "a");
|
||||
cl_assert_equal_s(out[1], "b");
|
||||
cl_assert_equal_s(out[2], "c");
|
||||
cl_assert(!out[3]);
|
||||
free_names(out);
|
||||
}
|
||||
|
||||
void test_reftable_basics__parse_names_drop_empty_string(void)
|
||||
{
|
||||
char in[] = "a\n\nb\n";
|
||||
char **out = parse_names(in, strlen(in));
|
||||
cl_assert(out != NULL);
|
||||
cl_assert_equal_s(out[0], "a");
|
||||
/* simply '\n' should be dropped as empty string */
|
||||
cl_assert_equal_s(out[1], "b");
|
||||
cl_assert(out[2] == NULL);
|
||||
free_names(out);
|
||||
}
|
||||
|
||||
void test_reftable_basics__common_prefix_size(void)
|
||||
{
|
||||
struct reftable_buf a = REFTABLE_BUF_INIT;
|
||||
struct reftable_buf b = REFTABLE_BUF_INIT;
|
||||
struct {
|
||||
const char *a, *b;
|
||||
int want;
|
||||
} cases[] = {
|
||||
{"abcdef", "abc", 3},
|
||||
{ "abc", "ab", 2 },
|
||||
{ "", "abc", 0 },
|
||||
{ "abc", "abd", 2 },
|
||||
{ "abc", "pqr", 0 },
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
|
||||
cl_assert_equal_i(reftable_buf_addstr(&a, cases[i].a), 0);
|
||||
cl_assert_equal_i(reftable_buf_addstr(&b, cases[i].b), 0);
|
||||
cl_assert_equal_i(common_prefix_size(&a, &b), cases[i].want);
|
||||
reftable_buf_reset(&a);
|
||||
reftable_buf_reset(&b);
|
||||
}
|
||||
reftable_buf_release(&a);
|
||||
reftable_buf_release(&b);
|
||||
}
|
||||
|
||||
void test_reftable_basics__put_get_be64(void)
|
||||
{
|
||||
uint64_t in = 0x1122334455667788;
|
||||
uint8_t dest[8];
|
||||
uint64_t out;
|
||||
reftable_put_be64(dest, in);
|
||||
out = reftable_get_be64(dest);
|
||||
cl_assert(in == out);
|
||||
}
|
||||
|
||||
void test_reftable_basics__put_get_be32(void)
|
||||
{
|
||||
uint32_t in = 0x11223344;
|
||||
uint8_t dest[4];
|
||||
uint32_t out;
|
||||
reftable_put_be32(dest, in);
|
||||
out = reftable_get_be32(dest);
|
||||
cl_assert_equal_i(in, out);
|
||||
}
|
||||
|
||||
void test_reftable_basics__put_get_be24(void)
|
||||
{
|
||||
uint32_t in = 0x112233;
|
||||
uint8_t dest[3];
|
||||
uint32_t out;
|
||||
reftable_put_be24(dest, in);
|
||||
out = reftable_get_be24(dest);
|
||||
cl_assert_equal_i(in, out);
|
||||
}
|
||||
|
||||
void test_reftable_basics__put_get_be16(void)
|
||||
{
|
||||
uint32_t in = 0xfef1;
|
||||
uint8_t dest[3];
|
||||
uint32_t out;
|
||||
reftable_put_be16(dest, in);
|
||||
out = reftable_get_be16(dest);
|
||||
cl_assert_equal_i(in, out);
|
||||
}
|
||||
|
||||
void test_reftable_basics__alloc_grow(void)
|
||||
{
|
||||
int *arr = NULL, *old_arr;
|
||||
size_t alloc = 0, old_alloc;
|
||||
|
||||
cl_assert_equal_i(REFTABLE_ALLOC_GROW(arr, 1, alloc), 0);
|
||||
cl_assert(arr != NULL);
|
||||
cl_assert(alloc >= 1);
|
||||
arr[0] = 42;
|
||||
|
||||
old_alloc = alloc;
|
||||
old_arr = arr;
|
||||
reftable_set_alloc(NULL, realloc_stub, NULL);
|
||||
cl_assert(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc));
|
||||
cl_assert(arr == old_arr);
|
||||
cl_assert_equal_i(alloc, old_alloc);
|
||||
|
||||
old_alloc = alloc;
|
||||
reftable_set_alloc(NULL, NULL, NULL);
|
||||
cl_assert_equal_i(REFTABLE_ALLOC_GROW(arr, old_alloc + 1, alloc), 0);
|
||||
cl_assert(arr != NULL);
|
||||
cl_assert(alloc > old_alloc);
|
||||
arr[alloc - 1] = 42;
|
||||
|
||||
reftable_free(arr);
|
||||
}
|
||||
|
||||
void test_reftable_basics__alloc_grow_or_null(void)
|
||||
{
|
||||
int *arr = NULL;
|
||||
size_t alloc = 0, old_alloc;
|
||||
|
||||
REFTABLE_ALLOC_GROW_OR_NULL(arr, 1, alloc);
|
||||
cl_assert(arr != NULL);
|
||||
cl_assert(alloc >= 1);
|
||||
arr[0] = 42;
|
||||
|
||||
old_alloc = alloc;
|
||||
REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
|
||||
cl_assert(arr != NULL);
|
||||
cl_assert(alloc > old_alloc);
|
||||
arr[alloc - 1] = 42;
|
||||
|
||||
old_alloc = alloc;
|
||||
reftable_set_alloc(NULL, realloc_stub, NULL);
|
||||
REFTABLE_ALLOC_GROW_OR_NULL(arr, old_alloc + 1, alloc);
|
||||
cl_assert(arr == NULL);
|
||||
cl_assert_equal_i(alloc, 0);
|
||||
reftable_set_alloc(NULL, NULL, NULL);
|
||||
|
||||
reftable_free(arr);
|
||||
}
|
||||
|
|
@ -6,14 +6,15 @@ license that can be found in the LICENSE file or at
|
|||
https://developers.google.com/open-source/licenses/bsd
|
||||
*/
|
||||
|
||||
#include "test-lib.h"
|
||||
#include "unit-test.h"
|
||||
#include "lib-reftable.h"
|
||||
#include "reftable/block.h"
|
||||
#include "reftable/blocksource.h"
|
||||
#include "reftable/constants.h"
|
||||
#include "reftable/reftable-error.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
static void t_ref_block_read_write(void)
|
||||
void test_reftable_block__read_write(void)
|
||||
{
|
||||
const int header_off = 21; /* random */
|
||||
struct reftable_record recs[30];
|
||||
|
|
@ -34,17 +35,18 @@ static void t_ref_block_read_write(void)
|
|||
struct reftable_buf block_data = REFTABLE_BUF_INIT;
|
||||
|
||||
REFTABLE_CALLOC_ARRAY(block_data.buf, block_size);
|
||||
check(block_data.buf != NULL);
|
||||
cl_assert(block_data.buf != NULL);
|
||||
block_data.len = block_size;
|
||||
|
||||
ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_REF, (uint8_t *) block_data.buf, block_size,
|
||||
ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_REF,
|
||||
(uint8_t *) block_data.buf, block_size,
|
||||
header_off, hash_size(REFTABLE_HASH_SHA1));
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
rec.u.ref.refname = (char *) "";
|
||||
rec.u.ref.value_type = REFTABLE_REF_DELETION;
|
||||
ret = block_writer_add(&bw, &rec);
|
||||
check_int(ret, ==, REFTABLE_API_ERROR);
|
||||
cl_assert_equal_i(ret, REFTABLE_API_ERROR);
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
rec.u.ref.refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
|
||||
|
|
@ -55,11 +57,11 @@ static void t_ref_block_read_write(void)
|
|||
ret = block_writer_add(&bw, &rec);
|
||||
rec.u.ref.refname = NULL;
|
||||
rec.u.ref.value_type = REFTABLE_REF_DELETION;
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
}
|
||||
|
||||
ret = block_writer_finish(&bw);
|
||||
check_int(ret, >, 0);
|
||||
cl_assert(ret > 0);
|
||||
|
||||
block_writer_release(&bw);
|
||||
|
||||
|
|
@ -71,32 +73,32 @@ static void t_ref_block_read_write(void)
|
|||
|
||||
for (i = 0; ; i++) {
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, >=, 0);
|
||||
cl_assert(ret >= 0);
|
||||
if (ret > 0) {
|
||||
check_int(i, ==, N);
|
||||
cl_assert_equal_i(i, N);
|
||||
break;
|
||||
}
|
||||
check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
reftable_record_key(&recs[i], &want);
|
||||
|
||||
ret = block_iter_seek_key(&it, &want);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
|
||||
want.len--;
|
||||
ret = block_iter_seek_key(&it, &want);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, ==, 0);
|
||||
check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(ret, 0);
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
}
|
||||
|
||||
reftable_block_release(&block);
|
||||
|
|
@ -108,7 +110,7 @@ static void t_ref_block_read_write(void)
|
|||
reftable_record_release(&recs[i]);
|
||||
}
|
||||
|
||||
static void t_log_block_read_write(void)
|
||||
void test_reftable_block__log_read_write(void)
|
||||
{
|
||||
const int header_off = 21;
|
||||
struct reftable_record recs[30];
|
||||
|
|
@ -129,12 +131,12 @@ static void t_log_block_read_write(void)
|
|||
struct reftable_buf block_data = REFTABLE_BUF_INIT;
|
||||
|
||||
REFTABLE_CALLOC_ARRAY(block_data.buf, block_size);
|
||||
check(block_data.buf != NULL);
|
||||
cl_assert(block_data.buf != NULL);
|
||||
block_data.len = block_size;
|
||||
|
||||
ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_LOG, (uint8_t *) block_data.buf, block_size,
|
||||
header_off, hash_size(REFTABLE_HASH_SHA1));
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
rec.u.log.refname = xstrfmt("branch%02"PRIuMAX , (uintmax_t)i);
|
||||
|
|
@ -145,11 +147,11 @@ static void t_log_block_read_write(void)
|
|||
ret = block_writer_add(&bw, &rec);
|
||||
rec.u.log.refname = NULL;
|
||||
rec.u.log.value_type = REFTABLE_LOG_DELETION;
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
}
|
||||
|
||||
ret = block_writer_finish(&bw);
|
||||
check_int(ret, >, 0);
|
||||
cl_assert(ret > 0);
|
||||
|
||||
block_writer_release(&bw);
|
||||
|
||||
|
|
@ -161,33 +163,33 @@ static void t_log_block_read_write(void)
|
|||
|
||||
for (i = 0; ; i++) {
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, >=, 0);
|
||||
cl_assert(ret >= 0);
|
||||
if (ret > 0) {
|
||||
check_int(i, ==, N);
|
||||
cl_assert_equal_i(i, N);
|
||||
break;
|
||||
}
|
||||
check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
reftable_buf_reset(&want);
|
||||
check(!reftable_buf_addstr(&want, recs[i].u.log.refname));
|
||||
cl_assert(reftable_buf_addstr(&want, recs[i].u.log.refname) == 0);
|
||||
|
||||
ret = block_iter_seek_key(&it, &want);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
|
||||
want.len--;
|
||||
ret = block_iter_seek_key(&it, &want);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, ==, 0);
|
||||
check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(ret, 0);
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
}
|
||||
|
||||
reftable_block_release(&block);
|
||||
|
|
@ -199,7 +201,7 @@ static void t_log_block_read_write(void)
|
|||
reftable_record_release(&recs[i]);
|
||||
}
|
||||
|
||||
static void t_obj_block_read_write(void)
|
||||
void test_reftable_block__obj_read_write(void)
|
||||
{
|
||||
const int header_off = 21;
|
||||
struct reftable_record recs[30];
|
||||
|
|
@ -220,12 +222,12 @@ static void t_obj_block_read_write(void)
|
|||
struct reftable_buf block_data = REFTABLE_BUF_INIT;
|
||||
|
||||
REFTABLE_CALLOC_ARRAY(block_data.buf, block_size);
|
||||
check(block_data.buf != NULL);
|
||||
cl_assert(block_data.buf != NULL);
|
||||
block_data.len = block_size;
|
||||
|
||||
ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_OBJ, (uint8_t *) block_data.buf, block_size,
|
||||
header_off, hash_size(REFTABLE_HASH_SHA1));
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
uint8_t bytes[] = { i, i + 1, i + 2, i + 3, i + 5 }, *allocated;
|
||||
|
|
@ -238,11 +240,11 @@ static void t_obj_block_read_write(void)
|
|||
ret = block_writer_add(&bw, &rec);
|
||||
rec.u.obj.hash_prefix = NULL;
|
||||
rec.u.obj.hash_prefix_len = 0;
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
}
|
||||
|
||||
ret = block_writer_finish(&bw);
|
||||
check_int(ret, >, 0);
|
||||
cl_assert(ret > 0);
|
||||
|
||||
block_writer_release(&bw);
|
||||
|
||||
|
|
@ -254,24 +256,24 @@ static void t_obj_block_read_write(void)
|
|||
|
||||
for (i = 0; ; i++) {
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, >=, 0);
|
||||
cl_assert(ret >= 0);
|
||||
if (ret > 0) {
|
||||
check_int(i, ==, N);
|
||||
cl_assert_equal_i(i, N);
|
||||
break;
|
||||
}
|
||||
check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
reftable_record_key(&recs[i], &want);
|
||||
|
||||
ret = block_iter_seek_key(&it, &want);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
}
|
||||
|
||||
reftable_block_release(&block);
|
||||
|
|
@ -283,7 +285,7 @@ static void t_obj_block_read_write(void)
|
|||
reftable_record_release(&recs[i]);
|
||||
}
|
||||
|
||||
static void t_index_block_read_write(void)
|
||||
void test_reftable_block__ref_read_write(void)
|
||||
{
|
||||
const int header_off = 21;
|
||||
struct reftable_record recs[30];
|
||||
|
|
@ -305,12 +307,12 @@ static void t_index_block_read_write(void)
|
|||
struct reftable_buf block_data = REFTABLE_BUF_INIT;
|
||||
|
||||
REFTABLE_CALLOC_ARRAY(block_data.buf, block_size);
|
||||
check(block_data.buf != NULL);
|
||||
cl_assert(block_data.buf != NULL);
|
||||
block_data.len = block_size;
|
||||
|
||||
ret = block_writer_init(&bw, REFTABLE_BLOCK_TYPE_INDEX, (uint8_t *) block_data.buf, block_size,
|
||||
header_off, hash_size(REFTABLE_HASH_SHA1));
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
char buf[128];
|
||||
|
|
@ -319,15 +321,15 @@ static void t_index_block_read_write(void)
|
|||
|
||||
reftable_buf_init(&recs[i].u.idx.last_key);
|
||||
recs[i].type = REFTABLE_BLOCK_TYPE_INDEX;
|
||||
check(!reftable_buf_addstr(&recs[i].u.idx.last_key, buf));
|
||||
cl_assert(!reftable_buf_addstr(&recs[i].u.idx.last_key, buf));
|
||||
recs[i].u.idx.offset = i;
|
||||
|
||||
ret = block_writer_add(&bw, &recs[i]);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
}
|
||||
|
||||
ret = block_writer_finish(&bw);
|
||||
check_int(ret, >, 0);
|
||||
cl_assert(ret > 0);
|
||||
|
||||
block_writer_release(&bw);
|
||||
|
||||
|
|
@ -339,32 +341,32 @@ static void t_index_block_read_write(void)
|
|||
|
||||
for (i = 0; ; i++) {
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, >=, 0);
|
||||
cl_assert(ret >= 0);
|
||||
if (ret > 0) {
|
||||
check_int(i, ==, N);
|
||||
cl_assert_equal_i(i, N);
|
||||
break;
|
||||
}
|
||||
check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
reftable_record_key(&recs[i], &want);
|
||||
|
||||
ret = block_iter_seek_key(&it, &want);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
|
||||
want.len--;
|
||||
ret = block_iter_seek_key(&it, &want);
|
||||
check_int(ret, ==, 0);
|
||||
cl_assert_equal_i(ret, 0);
|
||||
|
||||
ret = block_iter_next(&it, &rec);
|
||||
check_int(ret, ==, 0);
|
||||
check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(ret, 0);
|
||||
cl_assert_equal_i(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
}
|
||||
|
||||
reftable_block_release(&block);
|
||||
|
|
@ -376,7 +378,7 @@ static void t_index_block_read_write(void)
|
|||
reftable_record_release(&recs[i]);
|
||||
}
|
||||
|
||||
static void t_block_iterator(void)
|
||||
void test_reftable_block__iterator(void)
|
||||
{
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct block_writer writer = {
|
||||
|
|
@ -391,11 +393,12 @@ static void t_block_iterator(void)
|
|||
|
||||
data.len = 1024;
|
||||
REFTABLE_CALLOC_ARRAY(data.buf, data.len);
|
||||
check(data.buf != NULL);
|
||||
cl_assert(data.buf != NULL);
|
||||
|
||||
err = block_writer_init(&writer, REFTABLE_BLOCK_TYPE_REF, (uint8_t *) data.buf, data.len,
|
||||
err = block_writer_init(&writer, REFTABLE_BLOCK_TYPE_REF,
|
||||
(uint8_t *) data.buf, data.len,
|
||||
0, hash_size(REFTABLE_HASH_SHA1));
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(expected_refs); i++) {
|
||||
expected_refs[i] = (struct reftable_record) {
|
||||
|
|
@ -408,42 +411,42 @@ static void t_block_iterator(void)
|
|||
memset(expected_refs[i].u.ref.value.val1, i, REFTABLE_HASH_SIZE_SHA1);
|
||||
|
||||
err = block_writer_add(&writer, &expected_refs[i]);
|
||||
check_int(err, ==, 0);
|
||||
cl_assert_equal_i(err, 0);
|
||||
}
|
||||
|
||||
err = block_writer_finish(&writer);
|
||||
check_int(err, >, 0);
|
||||
cl_assert(err > 0);
|
||||
|
||||
block_source_from_buf(&source, &data);
|
||||
reftable_block_init(&block, &source, 0, 0, data.len,
|
||||
REFTABLE_HASH_SIZE_SHA1, REFTABLE_BLOCK_TYPE_REF);
|
||||
|
||||
err = reftable_block_init_iterator(&block, &it);
|
||||
check_int(err, ==, 0);
|
||||
cl_assert_equal_i(err, 0);
|
||||
|
||||
for (size_t i = 0; ; i++) {
|
||||
err = reftable_iterator_next_ref(&it, &ref);
|
||||
if (err > 0) {
|
||||
check_int(i, ==, ARRAY_SIZE(expected_refs));
|
||||
cl_assert_equal_i(i, ARRAY_SIZE(expected_refs));
|
||||
break;
|
||||
}
|
||||
check_int(err, ==, 0);
|
||||
cl_assert_equal_i(err, 0);
|
||||
|
||||
check(reftable_ref_record_equal(&ref, &expected_refs[i].u.ref,
|
||||
REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_ref_record_equal(&ref,
|
||||
&expected_refs[i].u.ref, REFTABLE_HASH_SIZE_SHA1));
|
||||
}
|
||||
|
||||
err = reftable_iterator_seek_ref(&it, "refs/heads/does-not-exist");
|
||||
check_int(err, ==, 0);
|
||||
cl_assert_equal_i(err, 0);
|
||||
err = reftable_iterator_next_ref(&it, &ref);
|
||||
check_int(err, ==, 1);
|
||||
cl_assert_equal_i(err, 1);
|
||||
|
||||
err = reftable_iterator_seek_ref(&it, "refs/heads/branch-13");
|
||||
check_int(err, ==, 0);
|
||||
cl_assert_equal_i(err, 0);
|
||||
err = reftable_iterator_next_ref(&it, &ref);
|
||||
check_int(err, ==, 0);
|
||||
check(reftable_ref_record_equal(&ref, &expected_refs[13].u.ref,
|
||||
REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert_equal_i(err, 0);
|
||||
cl_assert(reftable_ref_record_equal(&ref,
|
||||
&expected_refs[13].u.ref,REFTABLE_HASH_SIZE_SHA1));
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(expected_refs); i++)
|
||||
reftable_free(expected_refs[i].u.ref.refname);
|
||||
|
|
@ -453,14 +456,3 @@ static void t_block_iterator(void)
|
|||
block_writer_release(&writer);
|
||||
reftable_buf_release(&data);
|
||||
}
|
||||
|
||||
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
{
|
||||
TEST(t_index_block_read_write(), "read-write operations on index blocks work");
|
||||
TEST(t_log_block_read_write(), "read-write operations on log blocks work");
|
||||
TEST(t_obj_block_read_write(), "read-write operations on obj blocks work");
|
||||
TEST(t_ref_block_read_write(), "read-write operations on ref blocks work");
|
||||
TEST(t_block_iterator(), "block iterator works");
|
||||
|
||||
return test_done();
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ license that can be found in the LICENSE file or at
|
|||
https://developers.google.com/open-source/licenses/bsd
|
||||
*/
|
||||
|
||||
#include "test-lib.h"
|
||||
#include "unit-test.h"
|
||||
#include "lib-reftable.h"
|
||||
#include "reftable/blocksource.h"
|
||||
#include "reftable/constants.h"
|
||||
|
|
@ -29,21 +29,21 @@ merged_table_from_records(struct reftable_ref_record **refs,
|
|||
int err;
|
||||
|
||||
REFTABLE_CALLOC_ARRAY(*tables, n);
|
||||
check(*tables != NULL);
|
||||
cl_assert(*tables != NULL);
|
||||
REFTABLE_CALLOC_ARRAY(*source, n);
|
||||
check(*source != NULL);
|
||||
cl_assert(*source != NULL);
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
t_reftable_write_to_buf(&buf[i], refs[i], sizes[i], NULL, 0, &opts);
|
||||
cl_reftable_write_to_buf(&buf[i], refs[i], sizes[i], NULL, 0, &opts);
|
||||
block_source_from_buf(&(*source)[i], &buf[i]);
|
||||
|
||||
err = reftable_table_new(&(*tables)[i], &(*source)[i],
|
||||
"name");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
}
|
||||
|
||||
err = reftable_merged_table_new(&mt, *tables, n, REFTABLE_HASH_SHA1);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
return mt;
|
||||
}
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ static void tables_destroy(struct reftable_table **tables, const size_t n)
|
|||
reftable_free(tables);
|
||||
}
|
||||
|
||||
static void t_merged_single_record(void)
|
||||
void test_reftable_merged__single_record(void)
|
||||
{
|
||||
struct reftable_ref_record r1[] = { {
|
||||
.refname = (char *) "b",
|
||||
|
|
@ -85,13 +85,14 @@ static void t_merged_single_record(void)
|
|||
int err;
|
||||
|
||||
err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, "a");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_iterator_next_ref(&it, &ref);
|
||||
check(!err);
|
||||
check(reftable_ref_record_equal(&r2[0], &ref, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(!err);
|
||||
cl_assert(reftable_ref_record_equal(&r2[0], &ref,
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
reftable_ref_record_release(&ref);
|
||||
reftable_iterator_destroy(&it);
|
||||
tables_destroy(tables, 3);
|
||||
|
|
@ -101,7 +102,7 @@ static void t_merged_single_record(void)
|
|||
reftable_free(bs);
|
||||
}
|
||||
|
||||
static void t_merged_refs(void)
|
||||
void test_reftable_merged__refs(void)
|
||||
{
|
||||
struct reftable_ref_record r1[] = {
|
||||
{
|
||||
|
|
@ -165,12 +166,12 @@ static void t_merged_refs(void)
|
|||
size_t i;
|
||||
|
||||
err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, "a");
|
||||
check(!err);
|
||||
check_int(reftable_merged_table_hash_id(mt), ==, REFTABLE_HASH_SHA1);
|
||||
check_int(reftable_merged_table_min_update_index(mt), ==, 1);
|
||||
check_int(reftable_merged_table_max_update_index(mt), ==, 3);
|
||||
cl_assert(err == 0);
|
||||
cl_assert_equal_i(reftable_merged_table_hash_id(mt), REFTABLE_HASH_SHA1);
|
||||
cl_assert_equal_i(reftable_merged_table_min_update_index(mt), 1);
|
||||
cl_assert_equal_i(reftable_merged_table_max_update_index(mt), 3);
|
||||
|
||||
while (len < 100) { /* cap loops/recursion. */
|
||||
struct reftable_ref_record ref = { 0 };
|
||||
|
|
@ -178,15 +179,15 @@ static void t_merged_refs(void)
|
|||
if (err > 0)
|
||||
break;
|
||||
|
||||
check(!REFTABLE_ALLOC_GROW(out, len + 1, cap));
|
||||
cl_assert(REFTABLE_ALLOC_GROW(out, len + 1, cap) == 0);
|
||||
out[len++] = ref;
|
||||
}
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
check_int(ARRAY_SIZE(want), ==, len);
|
||||
cl_assert_equal_i(ARRAY_SIZE(want), len);
|
||||
for (i = 0; i < len; i++)
|
||||
check(reftable_ref_record_equal(want[i], &out[i],
|
||||
REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_ref_record_equal(want[i], &out[i],
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
for (i = 0; i < len; i++)
|
||||
reftable_ref_record_release(&out[i]);
|
||||
reftable_free(out);
|
||||
|
|
@ -198,7 +199,7 @@ static void t_merged_refs(void)
|
|||
reftable_free(bs);
|
||||
}
|
||||
|
||||
static void t_merged_seek_multiple_times(void)
|
||||
void test_reftable_merged__seek_multiple_times(void)
|
||||
{
|
||||
struct reftable_ref_record r1[] = {
|
||||
{
|
||||
|
|
@ -248,20 +249,17 @@ static void t_merged_seek_multiple_times(void)
|
|||
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
int err = reftable_iterator_seek_ref(&it, "c");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_iterator_next_ref(&it, &rec);
|
||||
check(!err);
|
||||
err = reftable_ref_record_equal(&rec, &r1[1], REFTABLE_HASH_SIZE_SHA1);
|
||||
check(err == 1);
|
||||
cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
|
||||
cl_assert_equal_i(reftable_ref_record_equal(&rec, &r1[1],
|
||||
REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
|
||||
err = reftable_iterator_next_ref(&it, &rec);
|
||||
check(!err);
|
||||
err = reftable_ref_record_equal(&rec, &r2[1], REFTABLE_HASH_SIZE_SHA1);
|
||||
check(err == 1);
|
||||
cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
|
||||
cl_assert_equal_i(reftable_ref_record_equal(&rec, &r2[1],
|
||||
REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
|
||||
err = reftable_iterator_next_ref(&it, &rec);
|
||||
check(err > 0);
|
||||
cl_assert(reftable_iterator_next_ref(&it, &rec) > 0);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(bufs); i++)
|
||||
|
|
@ -273,7 +271,7 @@ static void t_merged_seek_multiple_times(void)
|
|||
reftable_free(sources);
|
||||
}
|
||||
|
||||
static void t_merged_seek_multiple_times_without_draining(void)
|
||||
void test_reftable_merged__seek_multiple_times_no_drain(void)
|
||||
{
|
||||
struct reftable_ref_record r1[] = {
|
||||
{
|
||||
|
|
@ -317,24 +315,19 @@ static void t_merged_seek_multiple_times_without_draining(void)
|
|||
struct reftable_ref_record rec = { 0 };
|
||||
struct reftable_iterator it = { 0 };
|
||||
struct reftable_merged_table *mt;
|
||||
int err;
|
||||
|
||||
mt = merged_table_from_records(refs, &sources, &tables, sizes, bufs, 2);
|
||||
merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_REF);
|
||||
|
||||
err = reftable_iterator_seek_ref(&it, "b");
|
||||
check(!err);
|
||||
err = reftable_iterator_next_ref(&it, &rec);
|
||||
check(!err);
|
||||
err = reftable_ref_record_equal(&rec, &r2[0], REFTABLE_HASH_SIZE_SHA1);
|
||||
check(err == 1);
|
||||
cl_assert(reftable_iterator_seek_ref(&it, "b") == 0);
|
||||
cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
|
||||
cl_assert_equal_i(reftable_ref_record_equal(&rec, &r2[0],
|
||||
REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
|
||||
err = reftable_iterator_seek_ref(&it, "a");
|
||||
check(!err);
|
||||
err = reftable_iterator_next_ref(&it, &rec);
|
||||
check(!err);
|
||||
err = reftable_ref_record_equal(&rec, &r1[0], REFTABLE_HASH_SIZE_SHA1);
|
||||
check(err == 1);
|
||||
cl_assert(reftable_iterator_seek_ref(&it, "a") == 0);
|
||||
cl_assert(reftable_iterator_next_ref(&it, &rec) == 0);
|
||||
cl_assert_equal_i(reftable_ref_record_equal(&rec, &r1[0],
|
||||
REFTABLE_HASH_SIZE_SHA1), 1);
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(bufs); i++)
|
||||
reftable_buf_release(&bufs[i]);
|
||||
|
|
@ -359,25 +352,25 @@ merged_table_from_log_records(struct reftable_log_record **logs,
|
|||
int err;
|
||||
|
||||
REFTABLE_CALLOC_ARRAY(*tables, n);
|
||||
check(*tables != NULL);
|
||||
cl_assert(*tables != NULL);
|
||||
REFTABLE_CALLOC_ARRAY(*source, n);
|
||||
check(*source != NULL);
|
||||
cl_assert(*source != NULL);
|
||||
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
t_reftable_write_to_buf(&buf[i], NULL, 0, logs[i], sizes[i], &opts);
|
||||
cl_reftable_write_to_buf(&buf[i], NULL, 0, logs[i], sizes[i], &opts);
|
||||
block_source_from_buf(&(*source)[i], &buf[i]);
|
||||
|
||||
err = reftable_table_new(&(*tables)[i], &(*source)[i],
|
||||
"name");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
}
|
||||
|
||||
err = reftable_merged_table_new(&mt, *tables, n, REFTABLE_HASH_SHA1);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
return mt;
|
||||
}
|
||||
|
||||
static void t_merged_logs(void)
|
||||
void test_reftable_merged__logs(void)
|
||||
{
|
||||
struct reftable_log_record r1[] = {
|
||||
{
|
||||
|
|
@ -439,19 +432,19 @@ static void t_merged_logs(void)
|
|||
struct reftable_merged_table *mt = merged_table_from_log_records(
|
||||
logs, &bs, &tables, sizes, bufs, 3);
|
||||
struct reftable_iterator it = { 0 };
|
||||
int err;
|
||||
struct reftable_log_record *out = NULL;
|
||||
size_t len = 0;
|
||||
size_t cap = 0;
|
||||
size_t i;
|
||||
int err;
|
||||
|
||||
err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_LOG);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_log(&it, "a");
|
||||
check(!err);
|
||||
check_int(reftable_merged_table_hash_id(mt), ==, REFTABLE_HASH_SHA1);
|
||||
check_int(reftable_merged_table_min_update_index(mt), ==, 1);
|
||||
check_int(reftable_merged_table_max_update_index(mt), ==, 3);
|
||||
cl_assert(!err);
|
||||
cl_assert_equal_i(reftable_merged_table_hash_id(mt), REFTABLE_HASH_SHA1);
|
||||
cl_assert_equal_i(reftable_merged_table_min_update_index(mt), 1);
|
||||
cl_assert_equal_i(reftable_merged_table_max_update_index(mt), 3);
|
||||
|
||||
while (len < 100) { /* cap loops/recursion. */
|
||||
struct reftable_log_record log = { 0 };
|
||||
|
|
@ -459,24 +452,24 @@ static void t_merged_logs(void)
|
|||
if (err > 0)
|
||||
break;
|
||||
|
||||
check(!REFTABLE_ALLOC_GROW(out, len + 1, cap));
|
||||
cl_assert(REFTABLE_ALLOC_GROW(out, len + 1, cap) == 0);
|
||||
out[len++] = log;
|
||||
}
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
check_int(ARRAY_SIZE(want), ==, len);
|
||||
cl_assert_equal_i(ARRAY_SIZE(want), len);
|
||||
for (i = 0; i < len; i++)
|
||||
check(reftable_log_record_equal(want[i], &out[i],
|
||||
REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_log_record_equal(want[i], &out[i],
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
|
||||
err = merged_table_init_iter(mt, &it, REFTABLE_BLOCK_TYPE_LOG);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_log_at(&it, "a", 2);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
reftable_log_record_release(&out[0]);
|
||||
err = reftable_iterator_next_log(&it, &out[0]);
|
||||
check(!err);
|
||||
check(reftable_log_record_equal(&out[0], &r3[0], REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_iterator_next_log(&it, &out[0]) == 0);
|
||||
cl_assert(reftable_log_record_equal(&out[0], &r3[0],
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
|
|
@ -490,11 +483,11 @@ static void t_merged_logs(void)
|
|||
reftable_free(bs);
|
||||
}
|
||||
|
||||
static void t_default_write_opts(void)
|
||||
void test_reftable_merged__default_write_opts(void)
|
||||
{
|
||||
struct reftable_write_options opts = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_ref_record rec = {
|
||||
.refname = (char *) "master",
|
||||
.update_index = 1,
|
||||
|
|
@ -507,40 +500,25 @@ static void t_default_write_opts(void)
|
|||
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
|
||||
err = reftable_writer_add_ref(w, &rec);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(w, &rec), 0);
|
||||
|
||||
err = reftable_writer_close(w);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_close(w), 0);
|
||||
reftable_writer_free(w);
|
||||
|
||||
block_source_from_buf(&source, &buf);
|
||||
|
||||
err = reftable_table_new(&table, &source, "filename");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
hash_id = reftable_table_hash_id(table);
|
||||
check_int(hash_id, ==, REFTABLE_HASH_SHA1);
|
||||
cl_assert_equal_i(hash_id, REFTABLE_HASH_SHA1);
|
||||
|
||||
err = reftable_merged_table_new(&merged, &table, 1, REFTABLE_HASH_SHA256);
|
||||
check_int(err, ==, REFTABLE_FORMAT_ERROR);
|
||||
cl_assert_equal_i(err, REFTABLE_FORMAT_ERROR);
|
||||
err = reftable_merged_table_new(&merged, &table, 1, REFTABLE_HASH_SHA1);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
reftable_table_decref(table);
|
||||
reftable_merged_table_free(merged);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
|
||||
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
{
|
||||
TEST(t_default_write_opts(), "merged table with default write opts");
|
||||
TEST(t_merged_logs(), "merged table with multiple log updates for same ref");
|
||||
TEST(t_merged_refs(), "merged table with multiple updates to same ref");
|
||||
TEST(t_merged_seek_multiple_times(), "merged table can seek multiple times");
|
||||
TEST(t_merged_seek_multiple_times_without_draining(), "merged table can seek multiple times without draining");
|
||||
TEST(t_merged_single_record(), "ref occurring in only one record can be fetched");
|
||||
|
||||
return test_done();
|
||||
}
|
||||
|
|
@ -6,7 +6,8 @@ license that can be found in the LICENSE file or at
|
|||
https://developers.google.com/open-source/licenses/bsd
|
||||
*/
|
||||
|
||||
#include "test-lib.h"
|
||||
#include "unit-test.h"
|
||||
#include "lib-reftable.h"
|
||||
#include "reftable/constants.h"
|
||||
#include "reftable/pq.h"
|
||||
#include "strbuf.h"
|
||||
|
|
@ -15,18 +16,18 @@ static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)
|
|||
{
|
||||
for (size_t i = 1; i < pq->len; i++) {
|
||||
size_t parent = (i - 1) / 2;
|
||||
check(pq_less(&pq->heap[parent], &pq->heap[i]));
|
||||
cl_assert(pq_less(&pq->heap[parent], &pq->heap[i]) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
static int pq_entry_equal(struct pq_entry *a, struct pq_entry *b)
|
||||
{
|
||||
int cmp;
|
||||
check(!reftable_record_cmp(a->rec, b->rec, &cmp));
|
||||
cl_assert_equal_i(reftable_record_cmp(a->rec, b->rec, &cmp), 0);
|
||||
return !cmp && (a->index == b->index);
|
||||
}
|
||||
|
||||
static void t_pq_record(void)
|
||||
void test_reftable_pq__record(void)
|
||||
{
|
||||
struct merged_iter_pqueue pq = { 0 };
|
||||
struct reftable_record recs[54];
|
||||
|
|
@ -34,7 +35,8 @@ static void t_pq_record(void)
|
|||
char *last = NULL;
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
|
||||
cl_assert(!reftable_record_init(&recs[i],
|
||||
REFTABLE_BLOCK_TYPE_REF));
|
||||
recs[i].u.ref.refname = xstrfmt("%02"PRIuMAX, (uintmax_t)i);
|
||||
}
|
||||
|
||||
|
|
@ -53,13 +55,13 @@ static void t_pq_record(void)
|
|||
struct pq_entry top = merged_iter_pqueue_top(pq);
|
||||
struct pq_entry e;
|
||||
|
||||
check(!merged_iter_pqueue_remove(&pq, &e));
|
||||
cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
|
||||
merged_iter_pqueue_check(&pq);
|
||||
|
||||
check(pq_entry_equal(&top, &e));
|
||||
check(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
|
||||
cl_assert(pq_entry_equal(&top, &e));
|
||||
cl_assert(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
|
||||
if (last)
|
||||
check_int(strcmp(last, e.rec->u.ref.refname), <, 0);
|
||||
cl_assert(strcmp(last, e.rec->u.ref.refname) < 0);
|
||||
last = e.rec->u.ref.refname;
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +70,7 @@ static void t_pq_record(void)
|
|||
merged_iter_pqueue_release(&pq);
|
||||
}
|
||||
|
||||
static void t_pq_index(void)
|
||||
void test_reftable_pq__index(void)
|
||||
{
|
||||
struct merged_iter_pqueue pq = { 0 };
|
||||
struct reftable_record recs[13];
|
||||
|
|
@ -76,7 +78,8 @@ static void t_pq_index(void)
|
|||
size_t N = ARRAY_SIZE(recs), i;
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
|
||||
cl_assert(!reftable_record_init(&recs[i],
|
||||
REFTABLE_BLOCK_TYPE_REF));
|
||||
recs[i].u.ref.refname = (char *) "refs/heads/master";
|
||||
}
|
||||
|
||||
|
|
@ -96,28 +99,29 @@ static void t_pq_index(void)
|
|||
struct pq_entry top = merged_iter_pqueue_top(pq);
|
||||
struct pq_entry e;
|
||||
|
||||
check(!merged_iter_pqueue_remove(&pq, &e));
|
||||
cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
|
||||
merged_iter_pqueue_check(&pq);
|
||||
|
||||
check(pq_entry_equal(&top, &e));
|
||||
check(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
|
||||
check_int(e.index, ==, i);
|
||||
cl_assert(pq_entry_equal(&top, &e));
|
||||
cl_assert(reftable_record_type(e.rec) == REFTABLE_BLOCK_TYPE_REF);
|
||||
cl_assert_equal_i(e.index, i);
|
||||
if (last)
|
||||
check_str(last, e.rec->u.ref.refname);
|
||||
cl_assert_equal_s(last, e.rec->u.ref.refname);
|
||||
last = e.rec->u.ref.refname;
|
||||
}
|
||||
|
||||
merged_iter_pqueue_release(&pq);
|
||||
}
|
||||
|
||||
static void t_merged_iter_pqueue_top(void)
|
||||
void test_reftable_pq__merged_iter_pqueue_top(void)
|
||||
{
|
||||
struct merged_iter_pqueue pq = { 0 };
|
||||
struct reftable_record recs[13];
|
||||
size_t N = ARRAY_SIZE(recs), i;
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
check(!reftable_record_init(&recs[i], REFTABLE_BLOCK_TYPE_REF));
|
||||
cl_assert(!reftable_record_init(&recs[i],
|
||||
REFTABLE_BLOCK_TYPE_REF));
|
||||
recs[i].u.ref.refname = (char *) "refs/heads/master";
|
||||
}
|
||||
|
||||
|
|
@ -137,25 +141,16 @@ static void t_merged_iter_pqueue_top(void)
|
|||
struct pq_entry top = merged_iter_pqueue_top(pq);
|
||||
struct pq_entry e;
|
||||
|
||||
check(!merged_iter_pqueue_remove(&pq, &e));
|
||||
cl_assert_equal_i(merged_iter_pqueue_remove(&pq, &e), 0);
|
||||
|
||||
merged_iter_pqueue_check(&pq);
|
||||
check(pq_entry_equal(&top, &e));
|
||||
check(reftable_record_equal(top.rec, &recs[i], REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(pq_entry_equal(&top, &e) != 0);
|
||||
cl_assert(reftable_record_equal(top.rec, &recs[i], REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
for (size_t j = 0; i < pq.len; j++) {
|
||||
check(pq_less(&top, &pq.heap[j]));
|
||||
check_int(top.index, >, j);
|
||||
cl_assert(pq_less(&top, &pq.heap[j]) != 0);
|
||||
cl_assert(top.index > j);
|
||||
}
|
||||
}
|
||||
|
||||
merged_iter_pqueue_release(&pq);
|
||||
}
|
||||
|
||||
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
{
|
||||
TEST(t_pq_record(), "pq works with record-based comparison");
|
||||
TEST(t_pq_index(), "pq works with index-based comparison");
|
||||
TEST(t_merged_iter_pqueue_top(), "merged_iter_pqueue_top works");
|
||||
|
||||
return test_done();
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@ https://developers.google.com/open-source/licenses/bsd
|
|||
|
||||
#define DISABLE_SIGN_COMPARE_WARNINGS
|
||||
|
||||
#include "test-lib.h"
|
||||
#include "unit-test.h"
|
||||
#include "lib-reftable.h"
|
||||
#include "reftable/basics.h"
|
||||
#include "reftable/blocksource.h"
|
||||
|
|
@ -19,24 +19,24 @@ https://developers.google.com/open-source/licenses/bsd
|
|||
|
||||
static const int update_index = 5;
|
||||
|
||||
static void t_buffer(void)
|
||||
void test_reftable_readwrite__buffer(void)
|
||||
{
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct reftable_block_data out = { 0 };
|
||||
int n;
|
||||
uint8_t in[] = "hello";
|
||||
check(!reftable_buf_add(&buf, in, sizeof(in)));
|
||||
cl_assert_equal_i(reftable_buf_add(&buf, in, sizeof(in)), 0);
|
||||
block_source_from_buf(&source, &buf);
|
||||
check_int(block_source_size(&source), ==, 6);
|
||||
cl_assert_equal_i(block_source_size(&source), 6);
|
||||
n = block_source_read_data(&source, &out, 0, sizeof(in));
|
||||
check_int(n, ==, sizeof(in));
|
||||
check(!memcmp(in, out.data, n));
|
||||
cl_assert_equal_i(n, sizeof(in));
|
||||
cl_assert(!memcmp(in, out.data, n));
|
||||
block_source_release_data(&out);
|
||||
|
||||
n = block_source_read_data(&source, &out, 1, 2);
|
||||
check_int(n, ==, 2);
|
||||
check(!memcmp(out.data, "el", 2));
|
||||
cl_assert_equal_i(n, 2);
|
||||
cl_assert(!memcmp(out.data, "el", 2));
|
||||
|
||||
block_source_release_data(&out);
|
||||
block_source_close(&source);
|
||||
|
|
@ -55,41 +55,41 @@ static void write_table(char ***names, struct reftable_buf *buf, int N,
|
|||
int i;
|
||||
|
||||
REFTABLE_CALLOC_ARRAY(*names, N + 1);
|
||||
check(*names != NULL);
|
||||
cl_assert(*names != NULL);
|
||||
REFTABLE_CALLOC_ARRAY(refs, N);
|
||||
check(refs != NULL);
|
||||
cl_assert(refs != NULL);
|
||||
REFTABLE_CALLOC_ARRAY(logs, N);
|
||||
check(logs != NULL);
|
||||
cl_assert(logs != NULL);
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
refs[i].refname = (*names)[i] = xstrfmt("refs/heads/branch%02d", i);
|
||||
refs[i].update_index = update_index;
|
||||
refs[i].value_type = REFTABLE_REF_VAL1;
|
||||
t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
|
||||
cl_reftable_set_hash(refs[i].value.val1, i,
|
||||
REFTABLE_HASH_SHA1);
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
logs[i].refname = (*names)[i];
|
||||
logs[i].update_index = update_index;
|
||||
logs[i].value_type = REFTABLE_LOG_UPDATE;
|
||||
t_reftable_set_hash(logs[i].value.update.new_hash, i,
|
||||
REFTABLE_HASH_SHA1);
|
||||
cl_reftable_set_hash(logs[i].value.update.new_hash, i,
|
||||
REFTABLE_HASH_SHA1);
|
||||
logs[i].value.update.message = (char *) "message";
|
||||
}
|
||||
|
||||
t_reftable_write_to_buf(buf, refs, N, logs, N, &opts);
|
||||
cl_reftable_write_to_buf(buf, refs, N, logs, N, &opts);
|
||||
|
||||
reftable_free(refs);
|
||||
reftable_free(logs);
|
||||
}
|
||||
|
||||
static void t_log_buffer_size(void)
|
||||
void test_reftable_readwrite__log_buffer_size(void)
|
||||
{
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_write_options opts = {
|
||||
.block_size = 4096,
|
||||
};
|
||||
int err;
|
||||
int i;
|
||||
struct reftable_log_record
|
||||
log = { .refname = (char *) "refs/heads/master",
|
||||
|
|
@ -102,7 +102,8 @@ static void t_log_buffer_size(void)
|
|||
.time = 0x5e430672,
|
||||
.message = (char *) "commit: 9\n",
|
||||
} } };
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
|
||||
&opts);
|
||||
|
||||
/* This tests buffer extension for log compression. Must use a random
|
||||
hash, to ensure that the compressed part is larger than the original.
|
||||
|
|
@ -112,22 +113,19 @@ static void t_log_buffer_size(void)
|
|||
log.value.update.new_hash[i] = (uint8_t)(git_rand(0) % 256);
|
||||
}
|
||||
reftable_writer_set_limits(w, update_index, update_index);
|
||||
err = reftable_writer_add_log(w, &log);
|
||||
check(!err);
|
||||
err = reftable_writer_close(w);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
|
||||
cl_assert_equal_i(reftable_writer_close(w), 0);
|
||||
reftable_writer_free(w);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_log_overflow(void)
|
||||
void test_reftable_readwrite__log_overflow(void)
|
||||
{
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
char msg[256] = { 0 };
|
||||
struct reftable_write_options opts = {
|
||||
.block_size = ARRAY_SIZE(msg),
|
||||
};
|
||||
int err;
|
||||
struct reftable_log_record log = {
|
||||
.refname = (char *) "refs/heads/master",
|
||||
.update_index = update_index,
|
||||
|
|
@ -144,21 +142,22 @@ static void t_log_overflow(void)
|
|||
},
|
||||
},
|
||||
};
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
|
||||
&opts);
|
||||
|
||||
memset(msg, 'x', sizeof(msg) - 1);
|
||||
reftable_writer_set_limits(w, update_index, update_index);
|
||||
err = reftable_writer_add_log(w, &log);
|
||||
check_int(err, ==, REFTABLE_ENTRY_TOO_BIG_ERROR);
|
||||
cl_assert_equal_i(reftable_writer_add_log(w, &log), REFTABLE_ENTRY_TOO_BIG_ERROR);
|
||||
reftable_writer_free(w);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_log_write_limits(void)
|
||||
void test_reftable_readwrite__log_write_limits(void)
|
||||
{
|
||||
struct reftable_write_options opts = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
|
||||
&opts);
|
||||
struct reftable_log_record log = {
|
||||
.refname = (char *)"refs/head/master",
|
||||
.update_index = 0,
|
||||
|
|
@ -174,29 +173,25 @@ static void t_log_write_limits(void)
|
|||
},
|
||||
},
|
||||
};
|
||||
int err;
|
||||
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
|
||||
/* write with update_index (0) below set limits (1, 1) */
|
||||
err = reftable_writer_add_log(w, &log);
|
||||
check_int(err, ==, 0);
|
||||
cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
|
||||
|
||||
/* write with update_index (1) in the set limits (1, 1) */
|
||||
log.update_index = 1;
|
||||
err = reftable_writer_add_log(w, &log);
|
||||
check_int(err, ==, 0);
|
||||
cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
|
||||
|
||||
/* write with update_index (3) above set limits (1, 1) */
|
||||
log.update_index = 3;
|
||||
err = reftable_writer_add_log(w, &log);
|
||||
check_int(err, ==, REFTABLE_API_ERROR);
|
||||
cl_assert_equal_i(reftable_writer_add_log(w, &log), REFTABLE_API_ERROR);
|
||||
|
||||
reftable_writer_free(w);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_log_write_read(void)
|
||||
void test_reftable_readwrite__log_write_read(void)
|
||||
{
|
||||
struct reftable_write_options opts = {
|
||||
.block_size = 256,
|
||||
|
|
@ -207,13 +202,14 @@ static void t_log_write_read(void)
|
|||
struct reftable_table *table;
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
|
||||
const struct reftable_stats *stats = NULL;
|
||||
int N = 2, err, i, n;
|
||||
int N = 2, i;
|
||||
char **names;
|
||||
int err;
|
||||
|
||||
names = reftable_calloc(N + 1, sizeof(*names));
|
||||
check(names != NULL);
|
||||
cl_assert(names != NULL);
|
||||
|
||||
reftable_writer_set_limits(w, 0, N);
|
||||
|
||||
|
|
@ -225,8 +221,7 @@ static void t_log_write_read(void)
|
|||
ref.refname = name;
|
||||
ref.update_index = i;
|
||||
|
||||
err = reftable_writer_add_ref(w, &ref);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(w, &ref), 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
|
|
@ -235,60 +230,57 @@ static void t_log_write_read(void)
|
|||
log.refname = names[i];
|
||||
log.update_index = i;
|
||||
log.value_type = REFTABLE_LOG_UPDATE;
|
||||
t_reftable_set_hash(log.value.update.old_hash, i,
|
||||
REFTABLE_HASH_SHA1);
|
||||
t_reftable_set_hash(log.value.update.new_hash, i + 1,
|
||||
REFTABLE_HASH_SHA1);
|
||||
cl_reftable_set_hash(log.value.update.old_hash, i,
|
||||
REFTABLE_HASH_SHA1);
|
||||
cl_reftable_set_hash(log.value.update.new_hash, i + 1,
|
||||
REFTABLE_HASH_SHA1);
|
||||
|
||||
err = reftable_writer_add_log(w, &log);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
|
||||
}
|
||||
|
||||
n = reftable_writer_close(w);
|
||||
check_int(n, ==, 0);
|
||||
cl_assert_equal_i(reftable_writer_close(w), 0);
|
||||
|
||||
stats = reftable_writer_stats(w);
|
||||
check_int(stats->log_stats.blocks, >, 0);
|
||||
cl_assert(stats->log_stats.blocks > 0);
|
||||
reftable_writer_free(w);
|
||||
w = NULL;
|
||||
|
||||
block_source_from_buf(&source, &buf);
|
||||
|
||||
err = reftable_table_new(&table, &source, "file.log");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_table_init_ref_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_iterator_seek_ref(&it, names[N - 1]);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_iterator_next_ref(&it, &ref);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
/* end of iteration. */
|
||||
err = reftable_iterator_next_ref(&it, &ref);
|
||||
check_int(err, >, 0);
|
||||
cl_assert(reftable_iterator_next_ref(&it, &ref) > 0);
|
||||
|
||||
reftable_iterator_destroy(&it);
|
||||
reftable_ref_record_release(&ref);
|
||||
|
||||
err = reftable_table_init_log_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_log(&it, "");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
int err = reftable_iterator_next_log(&it, &log);
|
||||
if (err > 0)
|
||||
break;
|
||||
check(!err);
|
||||
check_str(names[i], log.refname);
|
||||
check_int(i, ==, log.update_index);
|
||||
cl_assert(!err);
|
||||
cl_assert_equal_s(names[i], log.refname);
|
||||
cl_assert_equal_i(i, log.update_index);
|
||||
reftable_log_record_release(&log);
|
||||
}
|
||||
|
||||
check_int(i, ==, N);
|
||||
cl_assert_equal_i(i, N);
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
/* cleanup. */
|
||||
|
|
@ -297,7 +289,7 @@ static void t_log_write_read(void)
|
|||
reftable_table_decref(table);
|
||||
}
|
||||
|
||||
static void t_log_zlib_corruption(void)
|
||||
void test_reftable_readwrite__log_zlib_corruption(void)
|
||||
{
|
||||
struct reftable_write_options opts = {
|
||||
.block_size = 256,
|
||||
|
|
@ -306,10 +298,12 @@ static void t_log_zlib_corruption(void)
|
|||
struct reftable_table *table;
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
|
||||
&opts);
|
||||
const struct reftable_stats *stats = NULL;
|
||||
char message[100] = { 0 };
|
||||
int err, i, n;
|
||||
int i;
|
||||
int err;
|
||||
struct reftable_log_record log = {
|
||||
.refname = (char *) "refname",
|
||||
.value_type = REFTABLE_LOG_UPDATE,
|
||||
|
|
@ -329,14 +323,11 @@ static void t_log_zlib_corruption(void)
|
|||
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
|
||||
err = reftable_writer_add_log(w, &log);
|
||||
check(!err);
|
||||
|
||||
n = reftable_writer_close(w);
|
||||
check_int(n, ==, 0);
|
||||
cl_assert_equal_i(reftable_writer_add_log(w, &log), 0);
|
||||
cl_assert_equal_i(reftable_writer_close(w), 0);
|
||||
|
||||
stats = reftable_writer_stats(w);
|
||||
check_int(stats->log_stats.blocks, >, 0);
|
||||
cl_assert(stats->log_stats.blocks > 0);
|
||||
reftable_writer_free(w);
|
||||
w = NULL;
|
||||
|
||||
|
|
@ -346,12 +337,12 @@ static void t_log_zlib_corruption(void)
|
|||
block_source_from_buf(&source, &buf);
|
||||
|
||||
err = reftable_table_new(&table, &source, "file.log");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_table_init_log_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_log(&it, "refname");
|
||||
check_int(err, ==, REFTABLE_ZLIB_ERROR);
|
||||
cl_assert_equal_i(err, REFTABLE_ZLIB_ERROR);
|
||||
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
|
|
@ -360,7 +351,7 @@ static void t_log_zlib_corruption(void)
|
|||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_table_read_write_sequential(void)
|
||||
void test_reftable_readwrite__table_read_write_sequential(void)
|
||||
{
|
||||
char **names;
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
|
|
@ -376,24 +367,24 @@ static void t_table_read_write_sequential(void)
|
|||
block_source_from_buf(&source, &buf);
|
||||
|
||||
err = reftable_table_new(&table, &source, "file.ref");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_table_init_ref_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, "");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
for (j = 0; ; j++) {
|
||||
struct reftable_ref_record ref = { 0 };
|
||||
int r = reftable_iterator_next_ref(&it, &ref);
|
||||
check_int(r, >=, 0);
|
||||
cl_assert(r >= 0);
|
||||
if (r > 0)
|
||||
break;
|
||||
check_str(names[j], ref.refname);
|
||||
check_int(update_index, ==, ref.update_index);
|
||||
cl_assert_equal_s(names[j], ref.refname);
|
||||
cl_assert_equal_i(update_index, ref.update_index);
|
||||
reftable_ref_record_release(&ref);
|
||||
}
|
||||
check_int(j, ==, N);
|
||||
cl_assert_equal_i(j, N);
|
||||
|
||||
reftable_iterator_destroy(&it);
|
||||
reftable_table_decref(table);
|
||||
|
|
@ -401,42 +392,42 @@ static void t_table_read_write_sequential(void)
|
|||
free_names(names);
|
||||
}
|
||||
|
||||
static void t_table_write_small_table(void)
|
||||
void test_reftable_readwrite__table_write_small_table(void)
|
||||
{
|
||||
char **names;
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
int N = 1;
|
||||
write_table(&names, &buf, N, 4096, REFTABLE_HASH_SHA1);
|
||||
check_int(buf.len, <, 200);
|
||||
cl_assert(buf.len < 200);
|
||||
reftable_buf_release(&buf);
|
||||
free_names(names);
|
||||
}
|
||||
|
||||
static void t_table_read_api(void)
|
||||
void test_reftable_readwrite__table_read_api(void)
|
||||
{
|
||||
char **names;
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
int N = 50;
|
||||
struct reftable_table *table;
|
||||
struct reftable_block_source source = { 0 };
|
||||
int err;
|
||||
struct reftable_log_record log = { 0 };
|
||||
struct reftable_iterator it = { 0 };
|
||||
int err;
|
||||
|
||||
write_table(&names, &buf, N, 256, REFTABLE_HASH_SHA1);
|
||||
|
||||
block_source_from_buf(&source, &buf);
|
||||
|
||||
err = reftable_table_new(&table, &source, "file.ref");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_table_init_ref_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, names[0]);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_iterator_next_log(&it, &log);
|
||||
check_int(err, ==, REFTABLE_API_ERROR);
|
||||
cl_assert_equal_i(err, REFTABLE_API_ERROR);
|
||||
|
||||
reftable_buf_release(&buf);
|
||||
free_names(names);
|
||||
|
|
@ -464,42 +455,43 @@ static void t_table_read_write_seek(int index, enum reftable_hash hash_id)
|
|||
block_source_from_buf(&source, &buf);
|
||||
|
||||
err = reftable_table_new(&table, &source, "file.ref");
|
||||
check(!err);
|
||||
check_int(hash_id, ==, reftable_table_hash_id(table));
|
||||
cl_assert(!err);
|
||||
cl_assert_equal_i(hash_id, reftable_table_hash_id(table));
|
||||
|
||||
if (!index) {
|
||||
table->ref_offsets.index_offset = 0;
|
||||
} else {
|
||||
check_int(table->ref_offsets.index_offset, >, 0);
|
||||
cl_assert(table->ref_offsets.index_offset > 0);
|
||||
}
|
||||
|
||||
for (i = 1; i < N; i++) {
|
||||
err = reftable_table_init_ref_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, names[i]);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_next_ref(&it, &ref);
|
||||
check(!err);
|
||||
check_str(names[i], ref.refname);
|
||||
check_int(REFTABLE_REF_VAL1, ==, ref.value_type);
|
||||
check_int(i, ==, ref.value.val1[0]);
|
||||
cl_assert(!err);
|
||||
cl_assert_equal_s(names[i], ref.refname);
|
||||
cl_assert_equal_i(REFTABLE_REF_VAL1, ref.value_type);
|
||||
cl_assert_equal_i(i, ref.value.val1[0]);
|
||||
|
||||
reftable_ref_record_release(&ref);
|
||||
reftable_iterator_destroy(&it);
|
||||
}
|
||||
|
||||
check(!reftable_buf_addstr(&pastLast, names[N - 1]));
|
||||
check(!reftable_buf_addstr(&pastLast, "/"));
|
||||
cl_assert_equal_i(reftable_buf_addstr(&pastLast, names[N - 1]),
|
||||
0);
|
||||
cl_assert_equal_i(reftable_buf_addstr(&pastLast, "/"), 0);
|
||||
|
||||
err = reftable_table_init_ref_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, pastLast.buf);
|
||||
if (err == 0) {
|
||||
struct reftable_ref_record ref = { 0 };
|
||||
int err = reftable_iterator_next_ref(&it, &ref);
|
||||
check_int(err, >, 0);
|
||||
cl_assert(err > 0);
|
||||
} else {
|
||||
check_int(err, >, 0);
|
||||
cl_assert(err > 0);
|
||||
}
|
||||
|
||||
reftable_buf_release(&pastLast);
|
||||
|
|
@ -510,17 +502,17 @@ static void t_table_read_write_seek(int index, enum reftable_hash hash_id)
|
|||
reftable_table_decref(table);
|
||||
}
|
||||
|
||||
static void t_table_read_write_seek_linear(void)
|
||||
void test_reftable_readwrite__table_read_write_seek_linear(void)
|
||||
{
|
||||
t_table_read_write_seek(0, REFTABLE_HASH_SHA1);
|
||||
}
|
||||
|
||||
static void t_table_read_write_seek_linear_sha256(void)
|
||||
void test_reftable_readwrite__table_read_write_seek_linear_sha256(void)
|
||||
{
|
||||
t_table_read_write_seek(0, REFTABLE_HASH_SHA256);
|
||||
}
|
||||
|
||||
static void t_table_read_write_seek_index(void)
|
||||
void test_reftable_readwrite__table_read_write_seek_index(void)
|
||||
{
|
||||
t_table_read_write_seek(1, REFTABLE_HASH_SHA1);
|
||||
}
|
||||
|
|
@ -538,14 +530,16 @@ static void t_table_refs_for(int indexed)
|
|||
struct reftable_table *table;
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf,
|
||||
&opts);
|
||||
struct reftable_iterator it = { 0 };
|
||||
int N = 50, n, j, err, i;
|
||||
int N = 50, j, i;
|
||||
int err;
|
||||
|
||||
want_names = reftable_calloc(N + 1, sizeof(*want_names));
|
||||
check(want_names != NULL);
|
||||
cl_assert(want_names != NULL);
|
||||
|
||||
t_reftable_set_hash(want_hash, 4, REFTABLE_HASH_SHA1);
|
||||
cl_reftable_set_hash(want_hash, 4, REFTABLE_HASH_SHA1);
|
||||
|
||||
for (i = 0; i < N; i++) {
|
||||
uint8_t hash[REFTABLE_HASH_SIZE_SHA1];
|
||||
|
|
@ -561,24 +555,22 @@ static void t_table_refs_for(int indexed)
|
|||
ref.refname = name;
|
||||
|
||||
ref.value_type = REFTABLE_REF_VAL2;
|
||||
t_reftable_set_hash(ref.value.val2.value, i / 4,
|
||||
REFTABLE_HASH_SHA1);
|
||||
t_reftable_set_hash(ref.value.val2.target_value, 3 + i / 4,
|
||||
REFTABLE_HASH_SHA1);
|
||||
cl_reftable_set_hash(ref.value.val2.value, i / 4,
|
||||
REFTABLE_HASH_SHA1);
|
||||
cl_reftable_set_hash(ref.value.val2.target_value,
|
||||
3 + i / 4, REFTABLE_HASH_SHA1);
|
||||
|
||||
/* 80 bytes / entry, so 3 entries per block. Yields 17
|
||||
*/
|
||||
/* blocks. */
|
||||
n = reftable_writer_add_ref(w, &ref);
|
||||
check_int(n, ==, 0);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(w, &ref), 0);
|
||||
|
||||
if (!memcmp(ref.value.val2.value, want_hash, REFTABLE_HASH_SIZE_SHA1) ||
|
||||
!memcmp(ref.value.val2.target_value, want_hash, REFTABLE_HASH_SIZE_SHA1))
|
||||
want_names[want_names_len++] = xstrdup(name);
|
||||
}
|
||||
|
||||
n = reftable_writer_close(w);
|
||||
check_int(n, ==, 0);
|
||||
cl_assert_equal_i(reftable_writer_close(w), 0);
|
||||
|
||||
reftable_writer_free(w);
|
||||
w = NULL;
|
||||
|
|
@ -586,29 +578,29 @@ static void t_table_refs_for(int indexed)
|
|||
block_source_from_buf(&source, &buf);
|
||||
|
||||
err = reftable_table_new(&table, &source, "file.ref");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
if (!indexed)
|
||||
table->obj_offsets.is_present = 0;
|
||||
|
||||
err = reftable_table_init_ref_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, "");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
reftable_iterator_destroy(&it);
|
||||
|
||||
err = reftable_table_refs_for(table, &it, want_hash);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
for (j = 0; ; j++) {
|
||||
int err = reftable_iterator_next_ref(&it, &ref);
|
||||
check_int(err, >=, 0);
|
||||
cl_assert(err >= 0);
|
||||
if (err > 0)
|
||||
break;
|
||||
check_int(j, <, want_names_len);
|
||||
check_str(ref.refname, want_names[j]);
|
||||
cl_assert(j < want_names_len);
|
||||
cl_assert_equal_s(ref.refname, want_names[j]);
|
||||
reftable_ref_record_release(&ref);
|
||||
}
|
||||
check_int(j, ==, want_names_len);
|
||||
cl_assert_equal_i(j, want_names_len);
|
||||
|
||||
reftable_buf_release(&buf);
|
||||
free_names(want_names);
|
||||
|
|
@ -616,21 +608,21 @@ static void t_table_refs_for(int indexed)
|
|||
reftable_table_decref(table);
|
||||
}
|
||||
|
||||
static void t_table_refs_for_no_index(void)
|
||||
void test_reftable_readwrite__table_refs_for_no_index(void)
|
||||
{
|
||||
t_table_refs_for(0);
|
||||
}
|
||||
|
||||
static void t_table_refs_for_obj_index(void)
|
||||
void test_reftable_readwrite__table_refs_for_obj_index(void)
|
||||
{
|
||||
t_table_refs_for(1);
|
||||
}
|
||||
|
||||
static void t_write_empty_table(void)
|
||||
void test_reftable_readwrite__write_empty_table(void)
|
||||
{
|
||||
struct reftable_write_options opts = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct reftable_table *table = NULL;
|
||||
struct reftable_ref_record rec = { 0 };
|
||||
|
|
@ -639,43 +631,41 @@ static void t_write_empty_table(void)
|
|||
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
|
||||
err = reftable_writer_close(w);
|
||||
check_int(err, ==, REFTABLE_EMPTY_TABLE_ERROR);
|
||||
cl_assert_equal_i(reftable_writer_close(w), REFTABLE_EMPTY_TABLE_ERROR);
|
||||
reftable_writer_free(w);
|
||||
|
||||
check_uint(buf.len, ==, header_size(1) + footer_size(1));
|
||||
cl_assert_equal_i(buf.len, header_size(1) + footer_size(1));
|
||||
|
||||
block_source_from_buf(&source, &buf);
|
||||
|
||||
err = reftable_table_new(&table, &source, "filename");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_table_init_ref_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, "");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
err = reftable_iterator_next_ref(&it, &rec);
|
||||
check_int(err, >, 0);
|
||||
cl_assert(err > 0);
|
||||
|
||||
reftable_iterator_destroy(&it);
|
||||
reftable_table_decref(table);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_write_object_id_min_length(void)
|
||||
void test_reftable_readwrite__write_object_id_min_length(void)
|
||||
{
|
||||
struct reftable_write_options opts = {
|
||||
.block_size = 75,
|
||||
};
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_ref_record ref = {
|
||||
.update_index = 1,
|
||||
.value_type = REFTABLE_REF_VAL1,
|
||||
.value.val1 = {42},
|
||||
};
|
||||
int err;
|
||||
int i;
|
||||
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
|
|
@ -686,30 +676,27 @@ static void t_write_object_id_min_length(void)
|
|||
char name[256];
|
||||
snprintf(name, sizeof(name), "ref%05d", i);
|
||||
ref.refname = name;
|
||||
err = reftable_writer_add_ref(w, &ref);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(w, &ref), 0);
|
||||
}
|
||||
|
||||
err = reftable_writer_close(w);
|
||||
check(!err);
|
||||
check_int(reftable_writer_stats(w)->object_id_len, ==, 2);
|
||||
cl_assert_equal_i(reftable_writer_close(w), 0);
|
||||
cl_assert_equal_i(reftable_writer_stats(w)->object_id_len, 2);
|
||||
reftable_writer_free(w);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_write_object_id_length(void)
|
||||
void test_reftable_readwrite__write_object_id_length(void)
|
||||
{
|
||||
struct reftable_write_options opts = {
|
||||
.block_size = 75,
|
||||
};
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_ref_record ref = {
|
||||
.update_index = 1,
|
||||
.value_type = REFTABLE_REF_VAL1,
|
||||
.value.val1 = {42},
|
||||
};
|
||||
int err;
|
||||
int i;
|
||||
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
|
|
@ -721,44 +708,39 @@ static void t_write_object_id_length(void)
|
|||
snprintf(name, sizeof(name), "ref%05d", i);
|
||||
ref.refname = name;
|
||||
ref.value.val1[15] = i;
|
||||
err = reftable_writer_add_ref(w, &ref);
|
||||
check(!err);
|
||||
cl_assert(reftable_writer_add_ref(w, &ref) == 0);
|
||||
}
|
||||
|
||||
err = reftable_writer_close(w);
|
||||
check(!err);
|
||||
check_int(reftable_writer_stats(w)->object_id_len, ==, 16);
|
||||
cl_assert_equal_i(reftable_writer_close(w), 0);
|
||||
cl_assert_equal_i(reftable_writer_stats(w)->object_id_len, 16);
|
||||
reftable_writer_free(w);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_write_empty_key(void)
|
||||
void test_reftable_readwrite__write_empty_key(void)
|
||||
{
|
||||
struct reftable_write_options opts = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_ref_record ref = {
|
||||
.refname = (char *) "",
|
||||
.update_index = 1,
|
||||
.value_type = REFTABLE_REF_DELETION,
|
||||
};
|
||||
int err;
|
||||
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
err = reftable_writer_add_ref(w, &ref);
|
||||
check_int(err, ==, REFTABLE_API_ERROR);
|
||||
|
||||
err = reftable_writer_close(w);
|
||||
check_int(err, ==, REFTABLE_EMPTY_TABLE_ERROR);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(w, &ref), REFTABLE_API_ERROR);
|
||||
cl_assert_equal_i(reftable_writer_close(w),
|
||||
REFTABLE_EMPTY_TABLE_ERROR);
|
||||
reftable_writer_free(w);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_write_key_order(void)
|
||||
void test_reftable_readwrite__write_key_order(void)
|
||||
{
|
||||
struct reftable_write_options opts = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_writer *w = t_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_writer *w = cl_reftable_strbuf_writer(&buf, &opts);
|
||||
struct reftable_ref_record refs[2] = {
|
||||
{
|
||||
.refname = (char *) "b",
|
||||
|
|
@ -776,24 +758,21 @@ static void t_write_key_order(void)
|
|||
},
|
||||
}
|
||||
};
|
||||
int err;
|
||||
|
||||
reftable_writer_set_limits(w, 1, 1);
|
||||
err = reftable_writer_add_ref(w, &refs[0]);
|
||||
check(!err);
|
||||
err = reftable_writer_add_ref(w, &refs[1]);
|
||||
check_int(err, ==, REFTABLE_API_ERROR);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(w, &refs[0]), 0);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(w, &refs[1]),
|
||||
REFTABLE_API_ERROR);
|
||||
|
||||
refs[0].update_index = 2;
|
||||
err = reftable_writer_add_ref(w, &refs[0]);
|
||||
check_int(err, ==, REFTABLE_API_ERROR);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(w, &refs[0]), REFTABLE_API_ERROR);
|
||||
|
||||
reftable_writer_close(w);
|
||||
reftable_writer_free(w);
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_write_multiple_indices(void)
|
||||
void test_reftable_readwrite__write_multiple_indices(void)
|
||||
{
|
||||
struct reftable_write_options opts = {
|
||||
.block_size = 100,
|
||||
|
|
@ -805,9 +784,10 @@ static void t_write_multiple_indices(void)
|
|||
struct reftable_writer *writer;
|
||||
struct reftable_table *table;
|
||||
char buf[128];
|
||||
int err, i;
|
||||
int i;
|
||||
int err;
|
||||
|
||||
writer = t_reftable_strbuf_writer(&writer_buf, &opts);
|
||||
writer = cl_reftable_strbuf_writer(&writer_buf, &opts);
|
||||
reftable_writer_set_limits(writer, 1, 1);
|
||||
for (i = 0; i < 100; i++) {
|
||||
struct reftable_ref_record ref = {
|
||||
|
|
@ -819,8 +799,7 @@ static void t_write_multiple_indices(void)
|
|||
snprintf(buf, sizeof(buf), "refs/heads/%04d", i);
|
||||
ref.refname = buf;
|
||||
|
||||
err = reftable_writer_add_ref(writer, &ref);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(writer, &ref), 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
|
|
@ -836,8 +815,7 @@ static void t_write_multiple_indices(void)
|
|||
snprintf(buf, sizeof(buf), "refs/heads/%04d", i);
|
||||
log.refname = buf;
|
||||
|
||||
err = reftable_writer_add_log(writer, &log);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_add_log(writer, &log), 0);
|
||||
}
|
||||
|
||||
reftable_writer_close(writer);
|
||||
|
|
@ -847,22 +825,22 @@ static void t_write_multiple_indices(void)
|
|||
* for each of the block types.
|
||||
*/
|
||||
stats = reftable_writer_stats(writer);
|
||||
check_int(stats->ref_stats.index_offset, >, 0);
|
||||
check_int(stats->obj_stats.index_offset, >, 0);
|
||||
check_int(stats->log_stats.index_offset, >, 0);
|
||||
cl_assert(stats->ref_stats.index_offset > 0);
|
||||
cl_assert(stats->obj_stats.index_offset > 0);
|
||||
cl_assert(stats->log_stats.index_offset > 0);
|
||||
|
||||
block_source_from_buf(&source, &writer_buf);
|
||||
err = reftable_table_new(&table, &source, "filename");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
/*
|
||||
* Seeking the log uses the log index now. In case there is any
|
||||
* confusion regarding indices we would notice here.
|
||||
*/
|
||||
err = reftable_table_init_log_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_log(&it, "");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
reftable_iterator_destroy(&it);
|
||||
reftable_writer_free(writer);
|
||||
|
|
@ -870,7 +848,7 @@ static void t_write_multiple_indices(void)
|
|||
reftable_buf_release(&writer_buf);
|
||||
}
|
||||
|
||||
static void t_write_multi_level_index(void)
|
||||
void test_reftable_readwrite__write_multi_level_index(void)
|
||||
{
|
||||
struct reftable_write_options opts = {
|
||||
.block_size = 100,
|
||||
|
|
@ -883,7 +861,7 @@ static void t_write_multi_level_index(void)
|
|||
struct reftable_table *table;
|
||||
int err;
|
||||
|
||||
writer = t_reftable_strbuf_writer(&writer_buf, &opts);
|
||||
writer = cl_reftable_strbuf_writer(&writer_buf, &opts);
|
||||
reftable_writer_set_limits(writer, 1, 1);
|
||||
for (size_t i = 0; i < 200; i++) {
|
||||
struct reftable_ref_record ref = {
|
||||
|
|
@ -896,8 +874,7 @@ static void t_write_multi_level_index(void)
|
|||
snprintf(buf, sizeof(buf), "refs/heads/%03" PRIuMAX, (uintmax_t)i);
|
||||
ref.refname = buf;
|
||||
|
||||
err = reftable_writer_add_ref(writer, &ref);
|
||||
check(!err);
|
||||
cl_assert_equal_i(reftable_writer_add_ref(writer, &ref), 0);
|
||||
}
|
||||
reftable_writer_close(writer);
|
||||
|
||||
|
|
@ -906,19 +883,19 @@ static void t_write_multi_level_index(void)
|
|||
* multi-level index.
|
||||
*/
|
||||
stats = reftable_writer_stats(writer);
|
||||
check_int(stats->ref_stats.max_index_level, ==, 2);
|
||||
cl_assert_equal_i(stats->ref_stats.max_index_level, 2);
|
||||
|
||||
block_source_from_buf(&source, &writer_buf);
|
||||
err = reftable_table_new(&table, &source, "filename");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
/*
|
||||
* Seeking the last ref should work as expected.
|
||||
*/
|
||||
err = reftable_table_init_ref_iterator(table, &it);
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
err = reftable_iterator_seek_ref(&it, "refs/heads/199");
|
||||
check(!err);
|
||||
cl_assert(!err);
|
||||
|
||||
reftable_iterator_destroy(&it);
|
||||
reftable_writer_free(writer);
|
||||
|
|
@ -927,7 +904,7 @@ static void t_write_multi_level_index(void)
|
|||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
static void t_corrupt_table_empty(void)
|
||||
void test_reftable_readwrite__corrupt_table_empty(void)
|
||||
{
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_block_source source = { 0 };
|
||||
|
|
@ -936,50 +913,22 @@ static void t_corrupt_table_empty(void)
|
|||
|
||||
block_source_from_buf(&source, &buf);
|
||||
err = reftable_table_new(&table, &source, "file.log");
|
||||
check_int(err, ==, REFTABLE_FORMAT_ERROR);
|
||||
cl_assert_equal_i(err, REFTABLE_FORMAT_ERROR);
|
||||
}
|
||||
|
||||
static void t_corrupt_table(void)
|
||||
void test_reftable_readwrite__corrupt_table(void)
|
||||
{
|
||||
uint8_t zeros[1024] = { 0 };
|
||||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct reftable_table *table;
|
||||
int err;
|
||||
check(!reftable_buf_add(&buf, zeros, sizeof(zeros)));
|
||||
|
||||
cl_assert(!reftable_buf_add(&buf, zeros, sizeof(zeros)));
|
||||
|
||||
block_source_from_buf(&source, &buf);
|
||||
err = reftable_table_new(&table, &source, "file.log");
|
||||
check_int(err, ==, REFTABLE_FORMAT_ERROR);
|
||||
cl_assert_equal_i(err, REFTABLE_FORMAT_ERROR);
|
||||
|
||||
reftable_buf_release(&buf);
|
||||
}
|
||||
|
||||
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
{
|
||||
TEST(t_buffer(), "strbuf works as blocksource");
|
||||
TEST(t_corrupt_table(), "read-write on corrupted table");
|
||||
TEST(t_corrupt_table_empty(), "read-write on an empty table");
|
||||
TEST(t_log_buffer_size(), "buffer extension for log compression");
|
||||
TEST(t_log_overflow(), "log overflow returns expected error");
|
||||
TEST(t_log_write_limits(), "writer limits for writing log records");
|
||||
TEST(t_log_write_read(), "read-write on log records");
|
||||
TEST(t_log_zlib_corruption(), "reading corrupted log record returns expected error");
|
||||
TEST(t_table_read_api(), "read on a table");
|
||||
TEST(t_table_read_write_seek_index(), "read-write on a table with index");
|
||||
TEST(t_table_read_write_seek_linear(), "read-write on a table without index (SHA1)");
|
||||
TEST(t_table_read_write_seek_linear_sha256(), "read-write on a table without index (SHA256)");
|
||||
TEST(t_table_read_write_sequential(), "sequential read-write on a table");
|
||||
TEST(t_table_refs_for_no_index(), "refs-only table with no index");
|
||||
TEST(t_table_refs_for_obj_index(), "refs-only table with index");
|
||||
TEST(t_table_write_small_table(), "write_table works");
|
||||
TEST(t_write_empty_key(), "write on refs with empty keys");
|
||||
TEST(t_write_empty_table(), "read-write on empty tables");
|
||||
TEST(t_write_key_order(), "refs must be written in increasing order");
|
||||
TEST(t_write_multi_level_index(), "table with multi-level index");
|
||||
TEST(t_write_multiple_indices(), "table with indices for multiple block types");
|
||||
TEST(t_write_object_id_length(), "prefix compression on writing refs");
|
||||
TEST(t_write_object_id_min_length(), "prefix compression on writing refs");
|
||||
|
||||
return test_done();
|
||||
}
|
||||
|
|
@ -6,7 +6,8 @@
|
|||
https://developers.google.com/open-source/licenses/bsd
|
||||
*/
|
||||
|
||||
#include "test-lib.h"
|
||||
#include "unit-test.h"
|
||||
#include "lib-reftable.h"
|
||||
#include "reftable/basics.h"
|
||||
#include "reftable/constants.h"
|
||||
#include "reftable/record.h"
|
||||
|
|
@ -17,16 +18,17 @@ static void t_copy(struct reftable_record *rec)
|
|||
uint8_t typ;
|
||||
|
||||
typ = reftable_record_type(rec);
|
||||
check(!reftable_record_init(©, typ));
|
||||
cl_assert_equal_i(reftable_record_init(©, typ), 0);
|
||||
reftable_record_copy_from(©, rec, REFTABLE_HASH_SIZE_SHA1);
|
||||
/* do it twice to catch memory leaks */
|
||||
reftable_record_copy_from(©, rec, REFTABLE_HASH_SIZE_SHA1);
|
||||
check(reftable_record_equal(rec, ©, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_record_equal(rec, ©,
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
|
||||
reftable_record_release(©);
|
||||
}
|
||||
|
||||
static void t_varint_roundtrip(void)
|
||||
void test_reftable_record__varint_roundtrip(void)
|
||||
{
|
||||
uint64_t inputs[] = { 0,
|
||||
1,
|
||||
|
|
@ -49,16 +51,16 @@ static void t_varint_roundtrip(void)
|
|||
int n = put_var_int(&out, in);
|
||||
uint64_t got = 0;
|
||||
|
||||
check_int(n, >, 0);
|
||||
cl_assert(n > 0);
|
||||
out.len = n;
|
||||
n = get_var_int(&got, &out);
|
||||
check_int(n, >, 0);
|
||||
cl_assert(n > 0);
|
||||
|
||||
check_int(got, ==, in);
|
||||
cl_assert_equal_i(got, in);
|
||||
}
|
||||
}
|
||||
|
||||
static void t_varint_overflow(void)
|
||||
void test_reftable_record__varint_overflow(void)
|
||||
{
|
||||
unsigned char buf[] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
|
@ -70,8 +72,7 @@ static void t_varint_overflow(void)
|
|||
.len = sizeof(buf),
|
||||
};
|
||||
uint64_t value;
|
||||
int err = get_var_int(&value, &view);
|
||||
check_int(err, ==, -1);
|
||||
cl_assert_equal_i(get_var_int(&value, &view), -1);
|
||||
}
|
||||
|
||||
static void set_hash(uint8_t *h, int j)
|
||||
|
|
@ -80,7 +81,7 @@ static void set_hash(uint8_t *h, int j)
|
|||
h[i] = (j >> i) & 0xff;
|
||||
}
|
||||
|
||||
static void t_reftable_ref_record_comparison(void)
|
||||
void test_reftable_record__ref_record_comparison(void)
|
||||
{
|
||||
struct reftable_record in[3] = {
|
||||
{
|
||||
|
|
@ -102,21 +103,23 @@ static void t_reftable_ref_record_comparison(void)
|
|||
};
|
||||
int cmp;
|
||||
|
||||
check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[0], &in[1], &cmp));
|
||||
check(!cmp);
|
||||
cl_assert(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1) == 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
|
||||
cl_assert(!cmp);
|
||||
|
||||
check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[1], &in[2], &cmp));
|
||||
check_int(cmp, >, 0);
|
||||
cl_assert(reftable_record_equal(&in[1], &in[2],
|
||||
REFTABLE_HASH_SIZE_SHA1) == 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[1], &in[2], &cmp), 0);
|
||||
cl_assert(cmp > 0);
|
||||
|
||||
in[1].u.ref.value_type = in[0].u.ref.value_type;
|
||||
check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[0], &in[1], &cmp));
|
||||
check(!cmp);
|
||||
cl_assert(reftable_record_equal(&in[0], &in[1],
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
|
||||
cl_assert(!cmp);
|
||||
}
|
||||
|
||||
static void t_reftable_ref_record_compare_name(void)
|
||||
void test_reftable_record__ref_record_compare_name(void)
|
||||
{
|
||||
struct reftable_ref_record recs[3] = {
|
||||
{
|
||||
|
|
@ -130,12 +133,15 @@ static void t_reftable_ref_record_compare_name(void)
|
|||
},
|
||||
};
|
||||
|
||||
check_int(reftable_ref_record_compare_name(&recs[0], &recs[1]), <, 0);
|
||||
check_int(reftable_ref_record_compare_name(&recs[1], &recs[0]), >, 0);
|
||||
check_int(reftable_ref_record_compare_name(&recs[0], &recs[2]), ==, 0);
|
||||
cl_assert(reftable_ref_record_compare_name(&recs[0],
|
||||
&recs[1]) < 0);
|
||||
cl_assert(reftable_ref_record_compare_name(&recs[1],
|
||||
&recs[0]) > 0);
|
||||
cl_assert_equal_i(reftable_ref_record_compare_name(&recs[0],
|
||||
&recs[2]), 0);
|
||||
}
|
||||
|
||||
static void t_reftable_ref_record_roundtrip(void)
|
||||
void test_reftable_record__ref_record_roundtrip(void)
|
||||
{
|
||||
struct reftable_buf scratch = REFTABLE_BUF_INIT;
|
||||
|
||||
|
|
@ -172,19 +178,21 @@ static void t_reftable_ref_record_roundtrip(void)
|
|||
|
||||
t_copy(&in);
|
||||
|
||||
check_int(reftable_record_val_type(&in), ==, i);
|
||||
check_int(reftable_record_is_deletion(&in), ==, i == REFTABLE_REF_DELETION);
|
||||
cl_assert_equal_i(reftable_record_val_type(&in), i);
|
||||
cl_assert_equal_i(reftable_record_is_deletion(&in),
|
||||
i == REFTABLE_REF_DELETION);
|
||||
|
||||
reftable_record_key(&in, &key);
|
||||
n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
|
||||
check_int(n, >, 0);
|
||||
cl_assert(n > 0);
|
||||
|
||||
/* decode into a non-zero reftable_record to test for leaks. */
|
||||
m = reftable_record_decode(&out, key, i, dest, REFTABLE_HASH_SIZE_SHA1, &scratch);
|
||||
check_int(n, ==, m);
|
||||
cl_assert_equal_i(n, m);
|
||||
|
||||
check(reftable_ref_record_equal(&in.u.ref, &out.u.ref,
|
||||
REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_ref_record_equal(&in.u.ref,
|
||||
&out.u.ref,
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
reftable_record_release(&in);
|
||||
|
||||
reftable_buf_release(&key);
|
||||
|
|
@ -194,7 +202,7 @@ static void t_reftable_ref_record_roundtrip(void)
|
|||
reftable_buf_release(&scratch);
|
||||
}
|
||||
|
||||
static void t_reftable_log_record_comparison(void)
|
||||
void test_reftable_record__log_record_comparison(void)
|
||||
{
|
||||
struct reftable_record in[3] = {
|
||||
{
|
||||
|
|
@ -215,21 +223,24 @@ static void t_reftable_log_record_comparison(void)
|
|||
};
|
||||
int cmp;
|
||||
|
||||
check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[1], &in[2], &cmp));
|
||||
check_int(cmp, >, 0);
|
||||
cl_assert_equal_i(reftable_record_equal(&in[0], &in[1],
|
||||
REFTABLE_HASH_SIZE_SHA1), 0);
|
||||
cl_assert_equal_i(reftable_record_equal(&in[1], &in[2],
|
||||
REFTABLE_HASH_SIZE_SHA1), 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[1], &in[2], &cmp), 0);
|
||||
cl_assert(cmp > 0);
|
||||
/* comparison should be reversed for equal keys, because
|
||||
* comparison is now performed on the basis of update indices */
|
||||
check(!reftable_record_cmp(&in[0], &in[1], &cmp));
|
||||
check_int(cmp, <, 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
|
||||
cl_assert(cmp < 0);
|
||||
|
||||
in[1].u.log.update_index = in[0].u.log.update_index;
|
||||
check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[0], &in[1], &cmp));
|
||||
cl_assert(reftable_record_equal(&in[0], &in[1],
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
|
||||
}
|
||||
|
||||
static void t_reftable_log_record_compare_key(void)
|
||||
void test_reftable_record__log_record_compare_key(void)
|
||||
{
|
||||
struct reftable_log_record logs[3] = {
|
||||
{
|
||||
|
|
@ -246,19 +257,24 @@ static void t_reftable_log_record_compare_key(void)
|
|||
},
|
||||
};
|
||||
|
||||
check_int(reftable_log_record_compare_key(&logs[0], &logs[1]), <, 0);
|
||||
check_int(reftable_log_record_compare_key(&logs[1], &logs[0]), >, 0);
|
||||
cl_assert(reftable_log_record_compare_key(&logs[0],
|
||||
&logs[1]) < 0);
|
||||
cl_assert(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);
|
||||
cl_assert(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);
|
||||
cl_assert(reftable_log_record_compare_key(&logs[0],
|
||||
&logs[2]) > 0);
|
||||
cl_assert(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);
|
||||
cl_assert_equal_i(reftable_log_record_compare_key(&logs[0], &logs[2]), 0);
|
||||
}
|
||||
|
||||
static void t_reftable_log_record_roundtrip(void)
|
||||
void test_reftable_record__log_record_roundtrip(void)
|
||||
{
|
||||
struct reftable_log_record in[] = {
|
||||
{
|
||||
|
|
@ -292,9 +308,9 @@ static void t_reftable_log_record_roundtrip(void)
|
|||
set_hash(in[2].value.update.new_hash, 3);
|
||||
set_hash(in[2].value.update.old_hash, 4);
|
||||
|
||||
check(!reftable_log_record_is_deletion(&in[0]));
|
||||
check(reftable_log_record_is_deletion(&in[1]));
|
||||
check(!reftable_log_record_is_deletion(&in[2]));
|
||||
cl_assert_equal_i(reftable_log_record_is_deletion(&in[0]), 0);
|
||||
cl_assert(reftable_log_record_is_deletion(&in[1]) != 0);
|
||||
cl_assert_equal_i(reftable_log_record_is_deletion(&in[2]), 0);
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(in); i++) {
|
||||
struct reftable_record rec = { .type = REFTABLE_BLOCK_TYPE_LOG };
|
||||
|
|
@ -328,14 +344,14 @@ static void t_reftable_log_record_roundtrip(void)
|
|||
reftable_record_key(&rec, &key);
|
||||
|
||||
n = reftable_record_encode(&rec, dest, REFTABLE_HASH_SIZE_SHA1);
|
||||
check_int(n, >=, 0);
|
||||
cl_assert(n >= 0);
|
||||
valtype = reftable_record_val_type(&rec);
|
||||
m = reftable_record_decode(&out, key, valtype, dest,
|
||||
REFTABLE_HASH_SIZE_SHA1, &scratch);
|
||||
check_int(n, ==, m);
|
||||
cl_assert_equal_i(n, m);
|
||||
|
||||
check(reftable_log_record_equal(&in[i], &out.u.log,
|
||||
REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_log_record_equal(&in[i], &out.u.log,
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
reftable_log_record_release(&in[i]);
|
||||
reftable_buf_release(&key);
|
||||
reftable_record_release(&out);
|
||||
|
|
@ -344,7 +360,7 @@ static void t_reftable_log_record_roundtrip(void)
|
|||
reftable_buf_release(&scratch);
|
||||
}
|
||||
|
||||
static void t_key_roundtrip(void)
|
||||
void test_reftable_record__key_roundtrip(void)
|
||||
{
|
||||
uint8_t buffer[1024] = { 0 };
|
||||
struct string_view dest = {
|
||||
|
|
@ -359,25 +375,28 @@ static void t_key_roundtrip(void)
|
|||
int n, m;
|
||||
uint8_t rt_extra;
|
||||
|
||||
check(!reftable_buf_addstr(&last_key, "refs/heads/master"));
|
||||
check(!reftable_buf_addstr(&key, "refs/tags/bla"));
|
||||
cl_assert_equal_i(reftable_buf_addstr(&last_key,
|
||||
"refs/heads/master"), 0);
|
||||
cl_assert_equal_i(reftable_buf_addstr(&key,
|
||||
"refs/tags/bla"), 0);
|
||||
extra = 6;
|
||||
n = reftable_encode_key(&restart, dest, last_key, key, extra);
|
||||
check(!restart);
|
||||
check_int(n, >, 0);
|
||||
cl_assert(!restart);
|
||||
cl_assert(n > 0);
|
||||
|
||||
check(!reftable_buf_addstr(&roundtrip, "refs/heads/master"));
|
||||
cl_assert_equal_i(reftable_buf_addstr(&roundtrip,
|
||||
"refs/heads/master"), 0);
|
||||
m = reftable_decode_key(&roundtrip, &rt_extra, dest);
|
||||
check_int(n, ==, m);
|
||||
check(!reftable_buf_cmp(&key, &roundtrip));
|
||||
check_int(rt_extra, ==, extra);
|
||||
cl_assert_equal_i(n, m);
|
||||
cl_assert_equal_i(reftable_buf_cmp(&key, &roundtrip), 0);
|
||||
cl_assert_equal_i(rt_extra, extra);
|
||||
|
||||
reftable_buf_release(&last_key);
|
||||
reftable_buf_release(&key);
|
||||
reftable_buf_release(&roundtrip);
|
||||
}
|
||||
|
||||
static void t_reftable_obj_record_comparison(void)
|
||||
void test_reftable_record__obj_record_comparison(void)
|
||||
{
|
||||
|
||||
uint8_t id_bytes[] = { 0, 1, 2, 3, 4, 5, 6 };
|
||||
|
|
@ -405,21 +424,23 @@ static void t_reftable_obj_record_comparison(void)
|
|||
};
|
||||
int cmp;
|
||||
|
||||
check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[0], &in[1], &cmp));
|
||||
check(!cmp);
|
||||
cl_assert_equal_i(reftable_record_equal(&in[0], &in[1],
|
||||
REFTABLE_HASH_SIZE_SHA1), 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
|
||||
cl_assert(!cmp);
|
||||
|
||||
check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[1], &in[2], &cmp));
|
||||
check_int(cmp, >, 0);
|
||||
cl_assert_equal_i(reftable_record_equal(&in[1], &in[2],
|
||||
REFTABLE_HASH_SIZE_SHA1), 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[1], &in[2], &cmp), 0);
|
||||
cl_assert(cmp > 0);
|
||||
|
||||
in[1].u.obj.offset_len = in[0].u.obj.offset_len;
|
||||
check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[0], &in[1], &cmp));
|
||||
check(!cmp);
|
||||
cl_assert(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
|
||||
cl_assert(!cmp);
|
||||
}
|
||||
|
||||
static void t_reftable_obj_record_roundtrip(void)
|
||||
void test_reftable_record__obj_record_roundtrip(void)
|
||||
{
|
||||
uint8_t testHash1[REFTABLE_HASH_SIZE_SHA1] = { 1, 2, 3, 4, 0 };
|
||||
uint64_t till9[] = { 1, 2, 3, 4, 500, 600, 700, 800, 9000 };
|
||||
|
|
@ -460,17 +481,18 @@ static void t_reftable_obj_record_roundtrip(void)
|
|||
int n, m;
|
||||
uint8_t extra;
|
||||
|
||||
check(!reftable_record_is_deletion(&in));
|
||||
cl_assert_equal_i(reftable_record_is_deletion(&in), 0);
|
||||
t_copy(&in);
|
||||
reftable_record_key(&in, &key);
|
||||
n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
|
||||
check_int(n, >, 0);
|
||||
cl_assert(n > 0);
|
||||
extra = reftable_record_val_type(&in);
|
||||
m = reftable_record_decode(&out, key, extra, dest,
|
||||
REFTABLE_HASH_SIZE_SHA1, &scratch);
|
||||
check_int(n, ==, m);
|
||||
cl_assert_equal_i(n, m);
|
||||
|
||||
check(reftable_record_equal(&in, &out, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_record_equal(&in, &out,
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
reftable_buf_release(&key);
|
||||
reftable_record_release(&out);
|
||||
}
|
||||
|
|
@ -478,7 +500,7 @@ static void t_reftable_obj_record_roundtrip(void)
|
|||
reftable_buf_release(&scratch);
|
||||
}
|
||||
|
||||
static void t_reftable_index_record_comparison(void)
|
||||
void test_reftable_record__index_record_comparison(void)
|
||||
{
|
||||
struct reftable_record in[3] = {
|
||||
{
|
||||
|
|
@ -499,28 +521,33 @@ static void t_reftable_index_record_comparison(void)
|
|||
};
|
||||
int cmp;
|
||||
|
||||
check(!reftable_buf_addstr(&in[0].u.idx.last_key, "refs/heads/master"));
|
||||
check(!reftable_buf_addstr(&in[1].u.idx.last_key, "refs/heads/master"));
|
||||
check(!reftable_buf_addstr(&in[2].u.idx.last_key, "refs/heads/branch"));
|
||||
cl_assert_equal_i(reftable_buf_addstr(&in[0].u.idx.last_key,
|
||||
"refs/heads/master"), 0);
|
||||
cl_assert_equal_i(reftable_buf_addstr(&in[1].u.idx.last_key, "refs/heads/master"), 0);
|
||||
cl_assert(reftable_buf_addstr(&in[2].u.idx.last_key,
|
||||
"refs/heads/branch") == 0);
|
||||
|
||||
check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[0], &in[1], &cmp));
|
||||
check(!cmp);
|
||||
cl_assert_equal_i(reftable_record_equal(&in[0], &in[1],
|
||||
REFTABLE_HASH_SIZE_SHA1), 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
|
||||
cl_assert(!cmp);
|
||||
|
||||
check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[1], &in[2], &cmp));
|
||||
check_int(cmp, >, 0);
|
||||
cl_assert_equal_i(reftable_record_equal(&in[1], &in[2],
|
||||
REFTABLE_HASH_SIZE_SHA1), 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[1], &in[2], &cmp), 0);
|
||||
cl_assert(cmp > 0);
|
||||
|
||||
in[1].u.idx.offset = in[0].u.idx.offset;
|
||||
check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
|
||||
check(!reftable_record_cmp(&in[0], &in[1], &cmp));
|
||||
check(!cmp);
|
||||
cl_assert(reftable_record_equal(&in[0], &in[1],
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
cl_assert_equal_i(reftable_record_cmp(&in[0], &in[1], &cmp), 0);
|
||||
cl_assert(!cmp);
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(in); i++)
|
||||
reftable_record_release(&in[i]);
|
||||
}
|
||||
|
||||
static void t_reftable_index_record_roundtrip(void)
|
||||
void test_reftable_record__index_record_roundtrip(void)
|
||||
{
|
||||
struct reftable_record in = {
|
||||
.type = REFTABLE_BLOCK_TYPE_INDEX,
|
||||
|
|
@ -543,43 +570,26 @@ static void t_reftable_index_record_roundtrip(void)
|
|||
int n, m;
|
||||
uint8_t extra;
|
||||
|
||||
check(!reftable_buf_addstr(&in.u.idx.last_key, "refs/heads/master"));
|
||||
cl_assert_equal_i(reftable_buf_addstr(&in.u.idx.last_key,
|
||||
"refs/heads/master"), 0);
|
||||
reftable_record_key(&in, &key);
|
||||
t_copy(&in);
|
||||
|
||||
check(!reftable_record_is_deletion(&in));
|
||||
check(!reftable_buf_cmp(&key, &in.u.idx.last_key));
|
||||
cl_assert_equal_i(reftable_record_is_deletion(&in), 0);
|
||||
cl_assert_equal_i(reftable_buf_cmp(&key, &in.u.idx.last_key), 0);
|
||||
n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
|
||||
check_int(n, >, 0);
|
||||
cl_assert(n > 0);
|
||||
|
||||
extra = reftable_record_val_type(&in);
|
||||
m = reftable_record_decode(&out, key, extra, dest, REFTABLE_HASH_SIZE_SHA1,
|
||||
&scratch);
|
||||
check_int(m, ==, n);
|
||||
m = reftable_record_decode(&out, key, extra, dest,
|
||||
REFTABLE_HASH_SIZE_SHA1, &scratch);
|
||||
cl_assert_equal_i(m, n);
|
||||
|
||||
check(reftable_record_equal(&in, &out, REFTABLE_HASH_SIZE_SHA1));
|
||||
cl_assert(reftable_record_equal(&in, &out,
|
||||
REFTABLE_HASH_SIZE_SHA1) != 0);
|
||||
|
||||
reftable_record_release(&out);
|
||||
reftable_buf_release(&key);
|
||||
reftable_buf_release(&scratch);
|
||||
reftable_buf_release(&in.u.idx.last_key);
|
||||
}
|
||||
|
||||
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
{
|
||||
TEST(t_reftable_ref_record_comparison(), "comparison operations work on ref record");
|
||||
TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
|
||||
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");
|
||||
TEST(t_varint_overflow(), "get_var_int notices an integer overflow");
|
||||
TEST(t_key_roundtrip(), "reftable_encode_key and reftable_decode_key work");
|
||||
TEST(t_reftable_obj_record_roundtrip(), "record operations work on obj record");
|
||||
TEST(t_reftable_index_record_roundtrip(), "record operations work on index record");
|
||||
|
||||
return test_done();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,4 +1,4 @@
|
|||
#include "test-lib.h"
|
||||
#include "unit-test.h"
|
||||
#include "lib-reftable.h"
|
||||
#include "reftable/blocksource.h"
|
||||
#include "reftable/constants.h"
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
#include "reftable/table.h"
|
||||
#include "strbuf.h"
|
||||
|
||||
static int t_table_seek_once(void)
|
||||
void test_reftable_table__seek_once(void)
|
||||
{
|
||||
struct reftable_ref_record records[] = {
|
||||
{
|
||||
|
|
@ -22,32 +22,32 @@ static int t_table_seek_once(void)
|
|||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
int ret;
|
||||
|
||||
t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
|
||||
cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
|
||||
block_source_from_buf(&source, &buf);
|
||||
|
||||
ret = reftable_table_new(&table, &source, "name");
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
reftable_table_init_ref_iterator(table, &it);
|
||||
ret = reftable_iterator_seek_ref(&it, "");
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
ret = reftable_iterator_next_ref(&it, &ref);
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
|
||||
check_int(ret, ==, 1);
|
||||
ret = reftable_ref_record_equal(&ref, &records[0],
|
||||
REFTABLE_HASH_SIZE_SHA1);
|
||||
cl_assert_equal_i(ret, 1);
|
||||
|
||||
ret = reftable_iterator_next_ref(&it, &ref);
|
||||
check_int(ret, ==, 1);
|
||||
cl_assert_equal_i(ret, 1);
|
||||
|
||||
reftable_ref_record_release(&ref);
|
||||
reftable_iterator_destroy(&it);
|
||||
reftable_table_decref(table);
|
||||
reftable_buf_release(&buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int t_table_reseek(void)
|
||||
void test_reftable_table__reseek(void)
|
||||
{
|
||||
struct reftable_ref_record records[] = {
|
||||
{
|
||||
|
|
@ -63,35 +63,35 @@ static int t_table_reseek(void)
|
|||
struct reftable_buf buf = REFTABLE_BUF_INIT;
|
||||
int ret;
|
||||
|
||||
t_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records), NULL, 0, NULL);
|
||||
cl_reftable_write_to_buf(&buf, records, ARRAY_SIZE(records),
|
||||
NULL, 0, NULL);
|
||||
block_source_from_buf(&source, &buf);
|
||||
|
||||
ret = reftable_table_new(&table, &source, "name");
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
reftable_table_init_ref_iterator(table, &it);
|
||||
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
ret = reftable_iterator_seek_ref(&it, "");
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
ret = reftable_iterator_next_ref(&it, &ref);
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
|
||||
check_int(ret, ==, 1);
|
||||
cl_assert_equal_i(ret, 1);
|
||||
|
||||
ret = reftable_iterator_next_ref(&it, &ref);
|
||||
check_int(ret, ==, 1);
|
||||
cl_assert_equal_i(ret, 1);
|
||||
}
|
||||
|
||||
reftable_ref_record_release(&ref);
|
||||
reftable_iterator_destroy(&it);
|
||||
reftable_table_decref(table);
|
||||
reftable_buf_release(&buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int t_table_block_iterator(void)
|
||||
void test_reftable_table__block_iterator(void)
|
||||
{
|
||||
struct reftable_block_source source = { 0 };
|
||||
struct reftable_table_iterator it = { 0 };
|
||||
|
|
@ -147,14 +147,14 @@ static int t_table_block_iterator(void)
|
|||
(uintmax_t) i);
|
||||
}
|
||||
|
||||
t_reftable_write_to_buf(&buf, records, nrecords, NULL, 0, NULL);
|
||||
cl_reftable_write_to_buf(&buf, records, nrecords, NULL, 0, NULL);
|
||||
block_source_from_buf(&source, &buf);
|
||||
|
||||
ret = reftable_table_new(&table, &source, "name");
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
ret = reftable_table_iterator_init(&it, table);
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(expected_blocks); i++) {
|
||||
struct reftable_iterator record_it = { 0 };
|
||||
|
|
@ -163,22 +163,26 @@ static int t_table_block_iterator(void)
|
|||
};
|
||||
|
||||
ret = reftable_table_iterator_next(&it, &block);
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
check_int(block->block_type, ==, expected_blocks[i].block_type);
|
||||
check_int(block->header_off, ==, expected_blocks[i].header_off);
|
||||
check_int(block->restart_count, ==, expected_blocks[i].restart_count);
|
||||
cl_assert_equal_i(block->block_type,
|
||||
expected_blocks[i].block_type);
|
||||
cl_assert_equal_i(block->header_off,
|
||||
expected_blocks[i].header_off);
|
||||
cl_assert_equal_i(block->restart_count,
|
||||
expected_blocks[i].restart_count);
|
||||
|
||||
ret = reftable_block_init_iterator(block, &record_it);
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
|
||||
for (size_t j = 0; ; j++) {
|
||||
ret = iterator_next(&record_it, &record);
|
||||
if (ret > 0) {
|
||||
check_int(j, ==, expected_blocks[i].record_count);
|
||||
cl_assert_equal_i(j,
|
||||
expected_blocks[i].record_count);
|
||||
break;
|
||||
}
|
||||
check(!ret);
|
||||
cl_assert(!ret);
|
||||
}
|
||||
|
||||
reftable_iterator_destroy(&record_it);
|
||||
|
|
@ -186,7 +190,7 @@ static int t_table_block_iterator(void)
|
|||
}
|
||||
|
||||
ret = reftable_table_iterator_next(&it, &block);
|
||||
check_int(ret, ==, 1);
|
||||
cl_assert_equal_i(ret, 1);
|
||||
|
||||
for (size_t i = 0; i < nrecords; i++)
|
||||
reftable_free(records[i].refname);
|
||||
|
|
@ -194,13 +198,4 @@ static int t_table_block_iterator(void)
|
|||
reftable_table_decref(table);
|
||||
reftable_buf_release(&buf);
|
||||
reftable_free(records);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
||||
{
|
||||
TEST(t_table_seek_once(), "table can seek once");
|
||||
TEST(t_table_reseek(), "table can reseek multiple times");
|
||||
TEST(t_table_block_iterator(), "table can iterate through blocks");
|
||||
return test_done();
|
||||
}
|
||||
Loading…
Reference in New Issue