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.c2
-rw-r--r--t/unit-tests/t-example-decorate.c4
-rw-r--r--t/unit-tests/t-prio-queue.c2
-rw-r--r--t/unit-tests/t-reftable-readwrite.c49
-rw-r--r--t/unit-tests/t-reftable-stack.c10
-rw-r--r--t/unit-tests/t-trailer.c2
-rw-r--r--t/unit-tests/test-lib.c2
-rw-r--r--t/unit-tests/u-strvec.c10
8 files changed, 74 insertions, 7 deletions
diff --git a/t/unit-tests/lib-reftable.c b/t/unit-tests/lib-reftable.c
index d795dfb7c9..8a69612266 100644
--- a/t/unit-tests/lib-reftable.c
+++ b/t/unit-tests/lib-reftable.c
@@ -1,3 +1,5 @@
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
#include "lib-reftable.h"
#include "test-lib.h"
#include "reftable/constants.h"
diff --git a/t/unit-tests/t-example-decorate.c b/t/unit-tests/t-example-decorate.c
index 8bf0709c41..bfc776e223 100644
--- a/t/unit-tests/t-example-decorate.c
+++ b/t/unit-tests/t-example-decorate.c
@@ -42,9 +42,9 @@ static void t_lookup(struct test_vars *vars)
static void t_loop(struct test_vars *vars)
{
- int i, objects_noticed = 0;
+ int objects_noticed = 0;
- for (i = 0; i < vars->n.size; i++) {
+ for (size_t i = 0; i < vars->n.size; i++) {
if (vars->n.entries[i].base)
objects_noticed++;
}
diff --git a/t/unit-tests/t-prio-queue.c b/t/unit-tests/t-prio-queue.c
index fe6ae37935..a053635000 100644
--- a/t/unit-tests/t-prio-queue.c
+++ b/t/unit-tests/t-prio-queue.c
@@ -25,7 +25,7 @@ static void test_prio_queue(int *input, size_t input_size,
struct prio_queue pq = { intcmp };
int j = 0;
- for (int i = 0; i < input_size; i++) {
+ for (size_t i = 0; i < input_size; i++) {
void *peek, *get;
switch(input[i]) {
case GET:
diff --git a/t/unit-tests/t-reftable-readwrite.c b/t/unit-tests/t-reftable-readwrite.c
index 91c881aedf..6b75a419b9 100644
--- a/t/unit-tests/t-reftable-readwrite.c
+++ b/t/unit-tests/t-reftable-readwrite.c
@@ -6,6 +6,8 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
#include "test-lib.h"
#include "lib-reftable.h"
#include "reftable/basics.h"
@@ -91,7 +93,7 @@ static void t_log_buffer_size(void)
int i;
struct reftable_log_record
log = { .refname = (char *) "refs/heads/master",
- .update_index = 0xa,
+ .update_index = update_index,
.value_type = REFTABLE_LOG_UPDATE,
.value = { .update = {
.name = (char *) "Han-Wen Nienhuys",
@@ -128,7 +130,7 @@ static void t_log_overflow(void)
int err;
struct reftable_log_record log = {
.refname = (char *) "refs/heads/master",
- .update_index = 0xa,
+ .update_index = update_index,
.value_type = REFTABLE_LOG_UPDATE,
.value = {
.update = {
@@ -152,6 +154,48 @@ static void t_log_overflow(void)
reftable_buf_release(&buf);
}
+static void t_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_log_record log = {
+ .refname = (char *)"refs/head/master",
+ .update_index = 0,
+ .value_type = REFTABLE_LOG_UPDATE,
+ .value = {
+ .update = {
+ .old_hash = { 1 },
+ .new_hash = { 2 },
+ .name = (char *)"Han-Wen Nienhuys",
+ .email = (char *)"hanwen@google.com",
+ .tz_offset = 100,
+ .time = 0x5e430672,
+ },
+ },
+ };
+ 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);
+
+ /* 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);
+
+ /* 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);
+
+ reftable_writer_free(w);
+ reftable_buf_release(&buf);
+}
+
static void t_log_write_read(void)
{
struct reftable_write_options opts = {
@@ -918,6 +962,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
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");
diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c
index b2f6c1c37e..aeec195b2b 100644
--- a/t/unit-tests/t-reftable-stack.c
+++ b/t/unit-tests/t-reftable-stack.c
@@ -6,6 +6,8 @@ license that can be found in the LICENSE file or at
https://developers.google.com/open-source/licenses/bsd
*/
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
#include "test-lib.h"
#include "lib-reftable.h"
#include "dir.h"
@@ -773,8 +775,12 @@ static void t_reftable_stack_tombstone(void)
}
logs[i].refname = xstrdup(buf);
- /* update_index is part of the key. */
- logs[i].update_index = 42;
+ /*
+ * update_index is part of the key so should be constant.
+ * The value itself should be less than the writer's upper
+ * limit.
+ */
+ logs[i].update_index = 1;
if (i % 2 == 0) {
logs[i].value_type = REFTABLE_LOG_UPDATE;
t_reftable_set_hash(logs[i].value.update.new_hash, i,
diff --git a/t/unit-tests/t-trailer.c b/t/unit-tests/t-trailer.c
index e1c6ad7461..184593e73d 100644
--- a/t/unit-tests/t-trailer.c
+++ b/t/unit-tests/t-trailer.c
@@ -1,3 +1,5 @@
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
#include "test-lib.h"
#include "trailer.h"
diff --git a/t/unit-tests/test-lib.c b/t/unit-tests/test-lib.c
index fa1f95965c..87e1f5c201 100644
--- a/t/unit-tests/test-lib.c
+++ b/t/unit-tests/test-lib.c
@@ -1,3 +1,5 @@
+#define DISABLE_SIGN_COMPARE_WARNINGS
+
#include "test-lib.h"
enum result {
diff --git a/t/unit-tests/u-strvec.c b/t/unit-tests/u-strvec.c
index 855b602337..e66b7bbfae 100644
--- a/t/unit-tests/u-strvec.c
+++ b/t/unit-tests/u-strvec.c
@@ -88,6 +88,16 @@ void test_strvec__pushv(void)
strvec_clear(&vec);
}
+void test_strvec__splice_just_initialized_strvec(void)
+{
+ struct strvec vec = STRVEC_INIT;
+ const char *replacement[] = { "foo" };
+
+ strvec_splice(&vec, 0, 0, replacement, ARRAY_SIZE(replacement));
+ check_strvec(&vec, "foo", NULL);
+ strvec_clear(&vec);
+}
+
void test_strvec__splice_with_same_size_replacement(void)
{
struct strvec vec = STRVEC_INIT;