summaryrefslogtreecommitdiff
path: root/t/unit-tests
diff options
context:
space:
mode:
Diffstat (limited to 't/unit-tests')
-rw-r--r--t/unit-tests/lib-reftable.c5
-rw-r--r--t/unit-tests/lib-reftable.h2
-rw-r--r--t/unit-tests/t-reftable-block.c41
-rw-r--r--t/unit-tests/t-reftable-merged.c26
-rw-r--r--t/unit-tests/t-reftable-pq.c3
-rw-r--r--t/unit-tests/t-reftable-reader.c4
-rw-r--r--t/unit-tests/t-reftable-readwrite.c41
-rw-r--r--t/unit-tests/t-reftable-record.c59
-rw-r--r--t/unit-tests/t-reftable-stack.c37
9 files changed, 113 insertions, 105 deletions
diff --git a/t/unit-tests/lib-reftable.c b/t/unit-tests/lib-reftable.c
index 2ddf480588..d795dfb7c9 100644
--- a/t/unit-tests/lib-reftable.c
+++ b/t/unit-tests/lib-reftable.c
@@ -2,8 +2,9 @@
#include "test-lib.h"
#include "reftable/constants.h"
#include "reftable/writer.h"
+#include "strbuf.h"
-void t_reftable_set_hash(uint8_t *p, int i, uint32_t id)
+void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
{
memset(p, (uint8_t)i, hash_size(id));
}
@@ -82,7 +83,7 @@ void t_reftable_write_to_buf(struct reftable_buf *buf,
size_t off = i * (opts.block_size ? opts.block_size
: DEFAULT_BLOCK_SIZE);
if (!off)
- off = header_size(opts.hash_id == GIT_SHA256_FORMAT_ID ? 2 : 1);
+ off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
check_char(buf->buf[off], ==, 'r');
}
diff --git a/t/unit-tests/lib-reftable.h b/t/unit-tests/lib-reftable.h
index d4950fed3d..e4c360fa7e 100644
--- a/t/unit-tests/lib-reftable.h
+++ b/t/unit-tests/lib-reftable.h
@@ -6,7 +6,7 @@
struct reftable_buf;
-void t_reftable_set_hash(uint8_t *p, int i, uint32_t id);
+void t_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_write_options *opts);
diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c
index f9af907117..22040aeefa 100644
--- a/t/unit-tests/t-reftable-block.c
+++ b/t/unit-tests/t-reftable-block.c
@@ -11,6 +11,7 @@ https://developers.google.com/open-source/licenses/bsd
#include "reftable/blocksource.h"
#include "reftable/constants.h"
#include "reftable/reftable-error.h"
+#include "strbuf.h"
static void t_ref_block_read_write(void)
{
@@ -36,7 +37,7 @@ static void t_ref_block_read_write(void)
block.len = block_size;
block_source_from_buf(&block.source ,&buf);
ret = block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
- header_off, hash_size(GIT_SHA1_FORMAT_ID));
+ header_off, hash_size(REFTABLE_HASH_SHA1));
check(!ret);
rec.u.ref.refname = (char *) "";
@@ -47,7 +48,7 @@ static void t_ref_block_read_write(void)
for (i = 0; i < N; i++) {
rec.u.ref.refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
rec.u.ref.value_type = REFTABLE_REF_VAL1;
- memset(rec.u.ref.value.val1, i, GIT_SHA1_RAWSZ);
+ memset(rec.u.ref.value.val1, i, REFTABLE_HASH_SIZE_SHA1);
recs[i] = rec;
ret = block_writer_add(&bw, &rec);
@@ -61,7 +62,7 @@ static void t_ref_block_read_write(void)
block_writer_release(&bw);
- block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ);
+ block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
block_iter_seek_start(&it, &br);
@@ -72,7 +73,7 @@ static void t_ref_block_read_write(void)
check_int(i, ==, N);
break;
}
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
}
for (i = 0; i < N; i++) {
@@ -85,7 +86,7 @@ static void t_ref_block_read_write(void)
ret = block_iter_next(&it, &rec);
check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
want.len--;
ret = block_iter_seek_key(&it, &br, &want);
@@ -93,7 +94,7 @@ static void t_ref_block_read_write(void)
ret = block_iter_next(&it, &rec);
check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
}
block_reader_release(&br);
@@ -130,7 +131,7 @@ static void t_log_block_read_write(void)
block.len = block_size;
block_source_from_buf(&block.source ,&buf);
ret = block_writer_init(&bw, BLOCK_TYPE_LOG, block.data, block_size,
- header_off, hash_size(GIT_SHA1_FORMAT_ID));
+ header_off, hash_size(REFTABLE_HASH_SHA1));
check(!ret);
for (i = 0; i < N; i++) {
@@ -150,7 +151,7 @@ static void t_log_block_read_write(void)
block_writer_release(&bw);
- block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ);
+ block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
block_iter_seek_start(&it, &br);
@@ -161,7 +162,7 @@ static void t_log_block_read_write(void)
check_int(i, ==, N);
break;
}
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
}
for (i = 0; i < N; i++) {
@@ -175,7 +176,7 @@ static void t_log_block_read_write(void)
ret = block_iter_next(&it, &rec);
check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
want.len--;
ret = block_iter_seek_key(&it, &br, &want);
@@ -183,7 +184,7 @@ static void t_log_block_read_write(void)
ret = block_iter_next(&it, &rec);
check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
}
block_reader_release(&br);
@@ -220,7 +221,7 @@ static void t_obj_block_read_write(void)
block.len = block_size;
block_source_from_buf(&block.source, &buf);
ret = block_writer_init(&bw, BLOCK_TYPE_OBJ, block.data, block_size,
- header_off, hash_size(GIT_SHA1_FORMAT_ID));
+ header_off, hash_size(REFTABLE_HASH_SHA1));
check(!ret);
for (i = 0; i < N; i++) {
@@ -242,7 +243,7 @@ static void t_obj_block_read_write(void)
block_writer_release(&bw);
- block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ);
+ block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
block_iter_seek_start(&it, &br);
@@ -253,7 +254,7 @@ static void t_obj_block_read_write(void)
check_int(i, ==, N);
break;
}
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
}
for (i = 0; i < N; i++) {
@@ -266,7 +267,7 @@ static void t_obj_block_read_write(void)
ret = block_iter_next(&it, &rec);
check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
}
block_reader_release(&br);
@@ -304,7 +305,7 @@ static void t_index_block_read_write(void)
block.len = block_size;
block_source_from_buf(&block.source, &buf);
ret = block_writer_init(&bw, BLOCK_TYPE_INDEX, block.data, block_size,
- header_off, hash_size(GIT_SHA1_FORMAT_ID));
+ header_off, hash_size(REFTABLE_HASH_SHA1));
check(!ret);
for (i = 0; i < N; i++) {
@@ -326,7 +327,7 @@ static void t_index_block_read_write(void)
block_writer_release(&bw);
- block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ);
+ block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
block_iter_seek_start(&it, &br);
@@ -337,7 +338,7 @@ static void t_index_block_read_write(void)
check_int(i, ==, N);
break;
}
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
}
for (i = 0; i < N; i++) {
@@ -350,7 +351,7 @@ static void t_index_block_read_write(void)
ret = block_iter_next(&it, &rec);
check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
want.len--;
ret = block_iter_seek_key(&it, &br, &want);
@@ -358,7 +359,7 @@ static void t_index_block_read_write(void)
ret = block_iter_next(&it, &rec);
check_int(ret, ==, 0);
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
}
block_reader_release(&br);
diff --git a/t/unit-tests/t-reftable-merged.c b/t/unit-tests/t-reftable-merged.c
index 4c25ee5334..2591b5e597 100644
--- a/t/unit-tests/t-reftable-merged.c
+++ b/t/unit-tests/t-reftable-merged.c
@@ -42,7 +42,7 @@ merged_table_from_records(struct reftable_ref_record **refs,
check(!err);
}
- err = reftable_merged_table_new(&mt, *readers, n, GIT_SHA1_FORMAT_ID);
+ err = reftable_merged_table_new(&mt, *readers, n, REFTABLE_HASH_SHA1);
check(!err);
return mt;
}
@@ -91,7 +91,7 @@ static void t_merged_single_record(void)
err = reftable_iterator_next_ref(&it, &ref);
check(!err);
- check(reftable_ref_record_equal(&r2[0], &ref, GIT_SHA1_RAWSZ));
+ check(reftable_ref_record_equal(&r2[0], &ref, REFTABLE_HASH_SIZE_SHA1));
reftable_ref_record_release(&ref);
reftable_iterator_destroy(&it);
readers_destroy(readers, 3);
@@ -168,7 +168,7 @@ static void t_merged_refs(void)
check(!err);
err = reftable_iterator_seek_ref(&it, "a");
check(!err);
- check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID);
+ 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);
@@ -186,7 +186,7 @@ static void t_merged_refs(void)
check_int(ARRAY_SIZE(want), ==, len);
for (i = 0; i < len; i++)
check(reftable_ref_record_equal(want[i], &out[i],
- GIT_SHA1_RAWSZ));
+ REFTABLE_HASH_SIZE_SHA1));
for (i = 0; i < len; i++)
reftable_ref_record_release(&out[i]);
reftable_free(out);
@@ -252,12 +252,12 @@ static void t_merged_seek_multiple_times(void)
err = reftable_iterator_next_ref(&it, &rec);
check(!err);
- err = reftable_ref_record_equal(&rec, &r1[1], GIT_SHA1_RAWSZ);
+ err = reftable_ref_record_equal(&rec, &r1[1], REFTABLE_HASH_SIZE_SHA1);
check(err == 1);
err = reftable_iterator_next_ref(&it, &rec);
check(!err);
- err = reftable_ref_record_equal(&rec, &r2[1], GIT_SHA1_RAWSZ);
+ err = reftable_ref_record_equal(&rec, &r2[1], REFTABLE_HASH_SIZE_SHA1);
check(err == 1);
err = reftable_iterator_next_ref(&it, &rec);
@@ -300,7 +300,7 @@ merged_table_from_log_records(struct reftable_log_record **logs,
check(!err);
}
- err = reftable_merged_table_new(&mt, *readers, n, GIT_SHA1_FORMAT_ID);
+ err = reftable_merged_table_new(&mt, *readers, n, REFTABLE_HASH_SHA1);
check(!err);
return mt;
}
@@ -377,7 +377,7 @@ static void t_merged_logs(void)
check(!err);
err = reftable_iterator_seek_log(&it, "a");
check(!err);
- check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID);
+ 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);
@@ -395,7 +395,7 @@ static void t_merged_logs(void)
check_int(ARRAY_SIZE(want), ==, len);
for (i = 0; i < len; i++)
check(reftable_log_record_equal(want[i], &out[i],
- GIT_SHA1_RAWSZ));
+ REFTABLE_HASH_SIZE_SHA1));
err = merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
check(!err);
@@ -404,7 +404,7 @@ static void t_merged_logs(void)
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], GIT_SHA1_RAWSZ));
+ check(reftable_log_record_equal(&out[0], &r3[0], REFTABLE_HASH_SIZE_SHA1));
reftable_iterator_destroy(&it);
for (i = 0; i < len; i++)
@@ -448,11 +448,11 @@ static void t_default_write_opts(void)
check(!err);
hash_id = reftable_reader_hash_id(rd);
- check_int(hash_id, ==, GIT_SHA1_FORMAT_ID);
+ check_int(hash_id, ==, REFTABLE_HASH_SHA1);
- err = reftable_merged_table_new(&merged, &rd, 1, GIT_SHA256_FORMAT_ID);
+ err = reftable_merged_table_new(&merged, &rd, 1, REFTABLE_HASH_SHA256);
check_int(err, ==, REFTABLE_FORMAT_ERROR);
- err = reftable_merged_table_new(&merged, &rd, 1, GIT_SHA1_FORMAT_ID);
+ err = reftable_merged_table_new(&merged, &rd, 1, REFTABLE_HASH_SHA1);
check(!err);
reftable_reader_decref(rd);
diff --git a/t/unit-tests/t-reftable-pq.c b/t/unit-tests/t-reftable-pq.c
index ada4c19f18..f3f8a0cdf3 100644
--- a/t/unit-tests/t-reftable-pq.c
+++ b/t/unit-tests/t-reftable-pq.c
@@ -9,6 +9,7 @@ https://developers.google.com/open-source/licenses/bsd
#include "test-lib.h"
#include "reftable/constants.h"
#include "reftable/pq.h"
+#include "strbuf.h"
static void merged_iter_pqueue_check(const struct merged_iter_pqueue *pq)
{
@@ -132,7 +133,7 @@ static void t_merged_iter_pqueue_top(void)
merged_iter_pqueue_check(&pq);
check(pq_entry_equal(&top, &e));
- check(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(top.rec, &recs[i], REFTABLE_HASH_SIZE_SHA1));
for (size_t j = 0; i < pq.len; j++) {
check(pq_less(&top, &pq.heap[j]));
check_int(top.index, >, j);
diff --git a/t/unit-tests/t-reftable-reader.c b/t/unit-tests/t-reftable-reader.c
index 19cb53b641..546df6005e 100644
--- a/t/unit-tests/t-reftable-reader.c
+++ b/t/unit-tests/t-reftable-reader.c
@@ -31,7 +31,7 @@ static int t_reader_seek_once(void)
ret = reftable_iterator_next_ref(&it, &ref);
check(!ret);
- ret = reftable_ref_record_equal(&ref, &records[0], GIT_SHA1_RAWSZ);
+ ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
check_int(ret, ==, 1);
ret = reftable_iterator_next_ref(&it, &ref);
@@ -74,7 +74,7 @@ static int t_reader_reseek(void)
ret = reftable_iterator_next_ref(&it, &ref);
check(!ret);
- ret = reftable_ref_record_equal(&ref, &records[0], GIT_SHA1_RAWSZ);
+ ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
check_int(ret, ==, 1);
ret = reftable_iterator_next_ref(&it, &ref);
diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/t-reftable-readwrite.c
index d279b86df0..91c881aedf 100644
--- a/t/unit-tests/t-reftable-readwrite.c
+++ b/t/unit-tests/t-reftable-readwrite.c
@@ -13,6 +13,7 @@ https://developers.google.com/open-source/licenses/bsd
#include "reftable/reader.h"
#include "reftable/reftable-error.h"
#include "reftable/reftable-writer.h"
+#include "strbuf.h"
static const int update_index = 5;
@@ -41,7 +42,7 @@ static void t_buffer(void)
}
static void write_table(char ***names, struct reftable_buf *buf, int N,
- int block_size, uint32_t hash_id)
+ int block_size, enum reftable_hash hash_id)
{
struct reftable_write_options opts = {
.block_size = block_size,
@@ -62,7 +63,7 @@ static void write_table(char ***names, struct reftable_buf *buf, int N,
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, GIT_SHA1_FORMAT_ID);
+ t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
}
for (i = 0; i < N; i++) {
@@ -70,7 +71,7 @@ static void write_table(char ***names, struct reftable_buf *buf, int N,
logs[i].update_index = update_index;
logs[i].value_type = REFTABLE_LOG_UPDATE;
t_reftable_set_hash(logs[i].value.update.new_hash, i,
- GIT_SHA1_FORMAT_ID);
+ REFTABLE_HASH_SHA1);
logs[i].value.update.message = (char *) "message";
}
@@ -104,7 +105,7 @@ static void t_log_buffer_size(void)
/* This tests buffer extension for log compression. Must use a random
hash, to ensure that the compressed part is larger than the original.
*/
- for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
+ for (i = 0; i < REFTABLE_HASH_SIZE_SHA1; i++) {
log.value.update.old_hash[i] = (uint8_t)(git_rand() % 256);
log.value.update.new_hash[i] = (uint8_t)(git_rand() % 256);
}
@@ -191,9 +192,9 @@ static void t_log_write_read(void)
log.update_index = i;
log.value_type = REFTABLE_LOG_UPDATE;
t_reftable_set_hash(log.value.update.old_hash, i,
- GIT_SHA1_FORMAT_ID);
+ REFTABLE_HASH_SHA1);
t_reftable_set_hash(log.value.update.new_hash, i + 1,
- GIT_SHA1_FORMAT_ID);
+ REFTABLE_HASH_SHA1);
err = reftable_writer_add_log(w, &log);
check(!err);
@@ -326,7 +327,7 @@ static void t_table_read_write_sequential(void)
int err = 0;
int j = 0;
- write_table(&names, &buf, N, 256, GIT_SHA1_FORMAT_ID);
+ write_table(&names, &buf, N, 256, REFTABLE_HASH_SHA1);
block_source_from_buf(&source, &buf);
@@ -361,7 +362,7 @@ static void t_table_write_small_table(void)
char **names;
struct reftable_buf buf = REFTABLE_BUF_INIT;
int N = 1;
- write_table(&names, &buf, N, 4096, GIT_SHA1_FORMAT_ID);
+ write_table(&names, &buf, N, 4096, REFTABLE_HASH_SHA1);
check_int(buf.len, <, 200);
reftable_buf_release(&buf);
free_names(names);
@@ -378,7 +379,7 @@ static void t_table_read_api(void)
struct reftable_log_record log = { 0 };
struct reftable_iterator it = { 0 };
- write_table(&names, &buf, N, 256, GIT_SHA1_FORMAT_ID);
+ write_table(&names, &buf, N, 256, REFTABLE_HASH_SHA1);
block_source_from_buf(&source, &buf);
@@ -400,7 +401,7 @@ static void t_table_read_api(void)
reftable_buf_release(&buf);
}
-static void t_table_read_write_seek(int index, int hash_id)
+static void t_table_read_write_seek(int index, enum reftable_hash hash_id)
{
char **names;
struct reftable_buf buf = REFTABLE_BUF_INIT;
@@ -467,24 +468,24 @@ static void t_table_read_write_seek(int index, int hash_id)
static void t_table_read_write_seek_linear(void)
{
- t_table_read_write_seek(0, GIT_SHA1_FORMAT_ID);
+ t_table_read_write_seek(0, REFTABLE_HASH_SHA1);
}
static void t_table_read_write_seek_linear_sha256(void)
{
- t_table_read_write_seek(0, GIT_SHA256_FORMAT_ID);
+ t_table_read_write_seek(0, REFTABLE_HASH_SHA256);
}
static void t_table_read_write_seek_index(void)
{
- t_table_read_write_seek(1, GIT_SHA1_FORMAT_ID);
+ t_table_read_write_seek(1, REFTABLE_HASH_SHA1);
}
static void t_table_refs_for(int indexed)
{
char **want_names;
int want_names_len = 0;
- uint8_t want_hash[GIT_SHA1_RAWSZ];
+ uint8_t want_hash[REFTABLE_HASH_SIZE_SHA1];
struct reftable_write_options opts = {
.block_size = 256,
@@ -500,10 +501,10 @@ static void t_table_refs_for(int indexed)
want_names = reftable_calloc(N + 1, sizeof(*want_names));
check(want_names != NULL);
- t_reftable_set_hash(want_hash, 4, GIT_SHA1_FORMAT_ID);
+ t_reftable_set_hash(want_hash, 4, REFTABLE_HASH_SHA1);
for (i = 0; i < N; i++) {
- uint8_t hash[GIT_SHA1_RAWSZ];
+ uint8_t hash[REFTABLE_HASH_SIZE_SHA1];
char fill[51] = { 0 };
char name[100];
struct reftable_ref_record ref = { 0 };
@@ -517,9 +518,9 @@ static void t_table_refs_for(int indexed)
ref.value_type = REFTABLE_REF_VAL2;
t_reftable_set_hash(ref.value.val2.value, i / 4,
- GIT_SHA1_FORMAT_ID);
+ REFTABLE_HASH_SHA1);
t_reftable_set_hash(ref.value.val2.target_value, 3 + i / 4,
- GIT_SHA1_FORMAT_ID);
+ REFTABLE_HASH_SHA1);
/* 80 bytes / entry, so 3 entries per block. Yields 17
*/
@@ -527,8 +528,8 @@ static void t_table_refs_for(int indexed)
n = reftable_writer_add_ref(w, &ref);
check_int(n, ==, 0);
- if (!memcmp(ref.value.val2.value, want_hash, GIT_SHA1_RAWSZ) ||
- !memcmp(ref.value.val2.target_value, want_hash, GIT_SHA1_RAWSZ))
+ 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);
}
diff --git a/t/unit-tests/t-reftable-record.c b/t/unit-tests/t-reftable-record.c
index eb98bf2da9..42bc64cec8 100644
--- a/t/unit-tests/t-reftable-record.c
+++ b/t/unit-tests/t-reftable-record.c
@@ -7,6 +7,7 @@
*/
#include "test-lib.h"
+#include "reftable/basics.h"
#include "reftable/constants.h"
#include "reftable/record.h"
@@ -17,10 +18,10 @@ static void t_copy(struct reftable_record *rec)
typ = reftable_record_type(rec);
reftable_record_init(&copy, typ);
- reftable_record_copy_from(&copy, rec, GIT_SHA1_RAWSZ);
+ reftable_record_copy_from(&copy, rec, REFTABLE_HASH_SIZE_SHA1);
/* do it twice to catch memory leaks */
- reftable_record_copy_from(&copy, rec, GIT_SHA1_RAWSZ);
- check(reftable_record_equal(rec, &copy, GIT_SHA1_RAWSZ));
+ reftable_record_copy_from(&copy, rec, REFTABLE_HASH_SIZE_SHA1);
+ check(reftable_record_equal(rec, &copy, REFTABLE_HASH_SIZE_SHA1));
reftable_record_release(&copy);
}
@@ -59,7 +60,7 @@ static void t_varint_roundtrip(void)
static void set_hash(uint8_t *h, int j)
{
- for (int i = 0; i < hash_size(GIT_SHA1_FORMAT_ID); i++)
+ for (int i = 0; i < hash_size(REFTABLE_HASH_SHA1); i++)
h[i] = (j >> i) & 0xff;
}
@@ -84,14 +85,14 @@ static void t_reftable_ref_record_comparison(void)
},
};
- check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+ check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
check(!reftable_record_cmp(&in[0], &in[1]));
- check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
+ check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
in[1].u.ref.value_type = in[0].u.ref.value_type;
- check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
check(!reftable_record_cmp(&in[0], &in[1]));
}
@@ -155,15 +156,15 @@ static void t_reftable_ref_record_roundtrip(void)
check_int(reftable_record_is_deletion(&in), ==, i == REFTABLE_REF_DELETION);
reftable_record_key(&in, &key);
- n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ);
+ n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
check_int(n, >, 0);
/* decode into a non-zero reftable_record to test for leaks. */
- m = reftable_record_decode(&out, key, i, dest, GIT_SHA1_RAWSZ, &scratch);
+ m = reftable_record_decode(&out, key, i, dest, REFTABLE_HASH_SIZE_SHA1, &scratch);
check_int(n, ==, m);
check(reftable_ref_record_equal(&in.u.ref, &out.u.ref,
- GIT_SHA1_RAWSZ));
+ REFTABLE_HASH_SIZE_SHA1));
reftable_record_release(&in);
reftable_buf_release(&key);
@@ -193,15 +194,15 @@ static void t_reftable_log_record_comparison(void)
},
};
- check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
- check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
+ 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_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
/* comparison should be reversed for equal keys, because
* comparison is now performed on the basis of update indices */
check_int(reftable_record_cmp(&in[0], &in[1]), <, 0);
in[1].u.log.update_index = in[0].u.log.update_index;
- check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
check(!reftable_record_cmp(&in[0], &in[1]));
}
@@ -303,15 +304,15 @@ static void t_reftable_log_record_roundtrip(void)
reftable_record_key(&rec, &key);
- n = reftable_record_encode(&rec, dest, GIT_SHA1_RAWSZ);
+ n = reftable_record_encode(&rec, dest, REFTABLE_HASH_SIZE_SHA1);
check_int(n, >=, 0);
valtype = reftable_record_val_type(&rec);
m = reftable_record_decode(&out, key, valtype, dest,
- GIT_SHA1_RAWSZ, &scratch);
+ REFTABLE_HASH_SIZE_SHA1, &scratch);
check_int(n, ==, m);
check(reftable_log_record_equal(&in[i], &out.u.log,
- GIT_SHA1_RAWSZ));
+ REFTABLE_HASH_SIZE_SHA1));
reftable_log_record_release(&in[i]);
reftable_buf_release(&key);
reftable_record_release(&out);
@@ -380,20 +381,20 @@ static void t_reftable_obj_record_comparison(void)
},
};
- check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+ check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
check(!reftable_record_cmp(&in[0], &in[1]));
- check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
+ check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
in[1].u.obj.offset_len = in[0].u.obj.offset_len;
- check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
check(!reftable_record_cmp(&in[0], &in[1]));
}
static void t_reftable_obj_record_roundtrip(void)
{
- uint8_t testHash1[GIT_SHA1_RAWSZ] = { 1, 2, 3, 4, 0 };
+ uint8_t testHash1[REFTABLE_HASH_SIZE_SHA1] = { 1, 2, 3, 4, 0 };
uint64_t till9[] = { 1, 2, 3, 4, 500, 600, 700, 800, 9000 };
struct reftable_obj_record recs[3] = {
{
@@ -435,14 +436,14 @@ static void t_reftable_obj_record_roundtrip(void)
check(!reftable_record_is_deletion(&in));
t_copy(&in);
reftable_record_key(&in, &key);
- n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ);
+ n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
check_int(n, >, 0);
extra = reftable_record_val_type(&in);
m = reftable_record_decode(&out, key, extra, dest,
- GIT_SHA1_RAWSZ, &scratch);
+ REFTABLE_HASH_SIZE_SHA1, &scratch);
check_int(n, ==, m);
- check(reftable_record_equal(&in, &out, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&in, &out, REFTABLE_HASH_SIZE_SHA1));
reftable_buf_release(&key);
reftable_record_release(&out);
}
@@ -473,14 +474,14 @@ static void t_reftable_index_record_comparison(void)
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"));
- check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+ check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
check(!reftable_record_cmp(&in[0], &in[1]));
- check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
+ check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
in[1].u.idx.offset = in[0].u.idx.offset;
- check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
check(!reftable_record_cmp(&in[0], &in[1]));
for (size_t i = 0; i < ARRAY_SIZE(in); i++)
@@ -516,15 +517,15 @@ static void t_reftable_index_record_roundtrip(void)
check(!reftable_record_is_deletion(&in));
check(!reftable_buf_cmp(&key, &in.u.idx.last_key));
- n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ);
+ n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
check_int(n, >, 0);
extra = reftable_record_val_type(&in);
- m = reftable_record_decode(&out, key, extra, dest, GIT_SHA1_RAWSZ,
+ m = reftable_record_decode(&out, key, extra, dest, REFTABLE_HASH_SIZE_SHA1,
&scratch);
check_int(m, ==, n);
- check(reftable_record_equal(&in, &out, GIT_SHA1_RAWSZ));
+ check(reftable_record_equal(&in, &out, REFTABLE_HASH_SIZE_SHA1));
reftable_record_release(&out);
reftable_buf_release(&key);
diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c
index 72f6747064..b2f6c1c37e 100644
--- a/t/unit-tests/t-reftable-stack.c
+++ b/t/unit-tests/t-reftable-stack.c
@@ -8,10 +8,13 @@ https://developers.google.com/open-source/licenses/bsd
#include "test-lib.h"
#include "lib-reftable.h"
+#include "dir.h"
#include "reftable/merged.h"
#include "reftable/reader.h"
#include "reftable/reftable-error.h"
#include "reftable/stack.h"
+#include "strbuf.h"
+#include "tempfile.h"
#include <dirent.h>
static void clear_dir(const char *dirname)
@@ -120,7 +123,7 @@ static void write_n_ref_tables(struct reftable_stack *st,
snprintf(buf, sizeof(buf), "refs/heads/branch-%04"PRIuMAX, (uintmax_t)i);
ref.refname = buf;
- t_reftable_set_hash(ref.value.val1, i, GIT_SHA1_FORMAT_ID);
+ t_reftable_set_hash(ref.value.val1, i, REFTABLE_HASH_SHA1);
err = reftable_stack_add(st, &write_test_ref, &ref);
check(!err);
@@ -168,7 +171,7 @@ static void t_reftable_stack_add_one(void)
err = reftable_stack_read_ref(st, ref.refname, &dest);
check(!err);
- check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
+ check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
check_int(st->readers_len, >, 0);
#ifndef GIT_WINDOWS_NATIVE
@@ -279,7 +282,7 @@ static void t_reftable_stack_transaction_api(void)
err = reftable_stack_read_ref(st, ref.refname, &dest);
check(!err);
check_int(REFTABLE_REF_SYMREF, ==, dest.value_type);
- check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
+ check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
reftable_ref_record_release(&dest);
reftable_stack_destroy(st);
@@ -339,7 +342,7 @@ static void t_reftable_stack_transaction_with_reload(void)
for (size_t i = 0; i < ARRAY_SIZE(refs); i++) {
err = reftable_stack_read_ref(st2, refs[i].refname, &ref);
check(!err);
- check(reftable_ref_record_equal(&refs[i], &ref, GIT_SHA1_RAWSZ));
+ check(reftable_ref_record_equal(&refs[i], &ref, REFTABLE_HASH_SIZE_SHA1));
}
reftable_ref_record_release(&ref);
@@ -529,13 +532,13 @@ static void t_reftable_stack_add(void)
refs[i].refname = xstrdup(buf);
refs[i].update_index = i + 1;
refs[i].value_type = REFTABLE_REF_VAL1;
- t_reftable_set_hash(refs[i].value.val1, i, GIT_SHA1_FORMAT_ID);
+ t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
logs[i].refname = xstrdup(buf);
logs[i].update_index = N + i + 1;
logs[i].value_type = REFTABLE_LOG_UPDATE;
logs[i].value.update.email = xstrdup("identity@invalid");
- t_reftable_set_hash(logs[i].value.update.new_hash, i, GIT_SHA1_FORMAT_ID);
+ t_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
}
for (i = 0; i < N; i++) {
@@ -561,7 +564,7 @@ static void t_reftable_stack_add(void)
int err = reftable_stack_read_ref(st, refs[i].refname, &dest);
check(!err);
check(reftable_ref_record_equal(&dest, refs + i,
- GIT_SHA1_RAWSZ));
+ REFTABLE_HASH_SIZE_SHA1));
reftable_ref_record_release(&dest);
}
@@ -570,7 +573,7 @@ static void t_reftable_stack_add(void)
int err = reftable_stack_read_log(st, refs[i].refname, &dest);
check(!err);
check(reftable_log_record_equal(&dest, logs + i,
- GIT_SHA1_RAWSZ));
+ REFTABLE_HASH_SIZE_SHA1));
reftable_log_record_release(&dest);
}
@@ -621,14 +624,14 @@ static void t_reftable_stack_iterator(void)
refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
refs[i].update_index = i + 1;
refs[i].value_type = REFTABLE_REF_VAL1;
- t_reftable_set_hash(refs[i].value.val1, i, GIT_SHA1_FORMAT_ID);
+ t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
logs[i].update_index = i + 1;
logs[i].value_type = REFTABLE_LOG_UPDATE;
logs[i].value.update.email = xstrdup("johndoe@invalid");
logs[i].value.update.message = xstrdup("commit\n");
- t_reftable_set_hash(logs[i].value.update.new_hash, i, GIT_SHA1_FORMAT_ID);
+ t_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
}
for (i = 0; i < N; i++) {
@@ -655,7 +658,7 @@ static void t_reftable_stack_iterator(void)
if (err > 0)
break;
check(!err);
- check(reftable_ref_record_equal(&ref, &refs[i], GIT_SHA1_RAWSZ));
+ check(reftable_ref_record_equal(&ref, &refs[i], REFTABLE_HASH_SIZE_SHA1));
reftable_ref_record_release(&ref);
}
check_int(i, ==, N);
@@ -673,7 +676,7 @@ static void t_reftable_stack_iterator(void)
if (err > 0)
break;
check(!err);
- check(reftable_log_record_equal(&log, &logs[i], GIT_SHA1_RAWSZ));
+ check(reftable_log_record_equal(&log, &logs[i], REFTABLE_HASH_SIZE_SHA1));
reftable_log_record_release(&log);
}
check_int(i, ==, N);
@@ -766,7 +769,7 @@ static void t_reftable_stack_tombstone(void)
if (i % 2 == 0) {
refs[i].value_type = REFTABLE_REF_VAL1;
t_reftable_set_hash(refs[i].value.val1, i,
- GIT_SHA1_FORMAT_ID);
+ REFTABLE_HASH_SHA1);
}
logs[i].refname = xstrdup(buf);
@@ -775,7 +778,7 @@ static void t_reftable_stack_tombstone(void)
if (i % 2 == 0) {
logs[i].value_type = REFTABLE_LOG_UPDATE;
t_reftable_set_hash(logs[i].value.update.new_hash, i,
- GIT_SHA1_FORMAT_ID);
+ REFTABLE_HASH_SHA1);
logs[i].value.update.email =
xstrdup("identity@invalid");
}
@@ -835,7 +838,7 @@ static void t_reftable_stack_hash_id(void)
.value.symref = (char *) "target",
.update_index = 1,
};
- struct reftable_write_options opts32 = { .hash_id = GIT_SHA256_FORMAT_ID };
+ struct reftable_write_options opts32 = { .hash_id = REFTABLE_HASH_SHA256 };
struct reftable_stack *st32 = NULL;
struct reftable_write_options opts_default = { 0 };
struct reftable_stack *st_default = NULL;
@@ -858,7 +861,7 @@ static void t_reftable_stack_hash_id(void)
err = reftable_stack_read_ref(st_default, "master", &dest);
check(!err);
- check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
+ check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
reftable_ref_record_release(&dest);
reftable_stack_destroy(st);
reftable_stack_destroy(st_default);
@@ -908,7 +911,7 @@ static void t_reflog_expire(void)
logs[i].value.update.time = i;
logs[i].value.update.email = xstrdup("identity@invalid");
t_reftable_set_hash(logs[i].value.update.new_hash, i,
- GIT_SHA1_FORMAT_ID);
+ REFTABLE_HASH_SHA1);
}
for (i = 1; i <= N; i++) {