Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar/core/buffer.c')
-rw-r--r--tests-clar/core/buffer.c191
1 files changed, 129 insertions, 62 deletions
diff --git a/tests-clar/core/buffer.c b/tests-clar/core/buffer.c
index 740cd8578..6a718f459 100644
--- a/tests-clar/core/buffer.c
+++ b/tests-clar/core/buffer.c
@@ -19,11 +19,11 @@ void test_core_buffer__0(void)
git_buf_puts(&buf, test_string);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(test_string, git_buf_cstr(&buf));
+ cl_assert_equal_s(test_string, git_buf_cstr(&buf));
git_buf_puts(&buf, test_string);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(test_string_x2, git_buf_cstr(&buf));
+ cl_assert_equal_s(test_string_x2, git_buf_cstr(&buf));
git_buf_free(&buf);
}
@@ -35,11 +35,11 @@ void test_core_buffer__1(void)
git_buf_printf(&buf, "%s %s %d ", "shoop", "da", 23);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal("shoop da 23 ", git_buf_cstr(&buf));
+ cl_assert_equal_s("shoop da 23 ", git_buf_cstr(&buf));
git_buf_printf(&buf, "%s %d", "woop", 42);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal("shoop da 23 woop 42", git_buf_cstr(&buf));
+ cl_assert_equal_s("shoop da 23 woop 42", git_buf_cstr(&buf));
git_buf_free(&buf);
}
@@ -59,7 +59,7 @@ void test_core_buffer__2(void)
cl_assert(buf.asize == 0);
/* empty buffer should be empty string */
- cl_assert_strequal("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", git_buf_cstr(&buf));
cl_assert(buf.size == 0);
/* cl_assert(buf.asize == 0); -- should not assume what git_buf does */
@@ -71,38 +71,38 @@ void test_core_buffer__2(void)
/* add letter */
git_buf_putc(&buf, '+');
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal("+", git_buf_cstr(&buf));
+ cl_assert_equal_s("+", git_buf_cstr(&buf));
/* add letter again */
git_buf_putc(&buf, '+');
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal("++", git_buf_cstr(&buf));
+ cl_assert_equal_s("++", git_buf_cstr(&buf));
/* let's try that a few times */
for (i = 0; i < 16; ++i) {
git_buf_putc(&buf, '+');
cl_assert(git_buf_oom(&buf) == 0);
}
- cl_assert_strequal("++++++++++++++++++", git_buf_cstr(&buf));
+ cl_assert_equal_s("++++++++++++++++++", git_buf_cstr(&buf));
git_buf_free(&buf);
/* add data */
git_buf_put(&buf, "xo", 2);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal("xo", git_buf_cstr(&buf));
+ cl_assert_equal_s("xo", git_buf_cstr(&buf));
/* add letter again */
git_buf_put(&buf, "xo", 2);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal("xoxo", git_buf_cstr(&buf));
+ cl_assert_equal_s("xoxo", git_buf_cstr(&buf));
/* let's try that a few times */
for (i = 0; i < 16; ++i) {
git_buf_put(&buf, "xo", 2);
cl_assert(git_buf_oom(&buf) == 0);
}
- cl_assert_strequal("xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo",
+ cl_assert_equal_s("xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo",
git_buf_cstr(&buf));
git_buf_free(&buf);
@@ -110,21 +110,21 @@ void test_core_buffer__2(void)
/* set to string */
git_buf_sets(&buf, test_string);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(test_string, git_buf_cstr(&buf));
+ cl_assert_equal_s(test_string, git_buf_cstr(&buf));
/* append string */
git_buf_puts(&buf, test_string);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(test_string_x2, git_buf_cstr(&buf));
+ cl_assert_equal_s(test_string_x2, git_buf_cstr(&buf));
/* set to string again (should overwrite - not append) */
git_buf_sets(&buf, test_string);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(test_string, git_buf_cstr(&buf));
+ cl_assert_equal_s(test_string, git_buf_cstr(&buf));
/* test clear */
git_buf_clear(&buf);
- cl_assert_strequal("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", git_buf_cstr(&buf));
git_buf_free(&buf);
@@ -133,27 +133,27 @@ void test_core_buffer__2(void)
cl_assert(git_buf_oom(&buf) == 0);
git_buf_copy_cstr(data, sizeof(data), &buf);
- cl_assert_strequal(REP4("0123456789"), data);
+ cl_assert_equal_s(REP4("0123456789"), data);
git_buf_copy_cstr(data, 11, &buf);
- cl_assert_strequal("0123456789", data);
+ cl_assert_equal_s("0123456789", data);
git_buf_copy_cstr(data, 3, &buf);
- cl_assert_strequal("01", data);
+ cl_assert_equal_s("01", data);
git_buf_copy_cstr(data, 1, &buf);
- cl_assert_strequal("", data);
+ cl_assert_equal_s("", data);
git_buf_copy_cstr(data, sizeof(data), &buf);
- cl_assert_strequal(REP4("0123456789"), data);
+ cl_assert_equal_s(REP4("0123456789"), data);
git_buf_sets(&buf, REP256("x"));
git_buf_copy_cstr(data, sizeof(data), &buf);
/* since sizeof(data) == 128, only 127 bytes should be copied */
- cl_assert_strequal(REP4(REP16("x")) REP16("x") REP16("x")
+ cl_assert_equal_s(REP4(REP16("x")) REP16("x") REP16("x")
REP16("x") "xxxxxxxxxxxxxxx", data);
git_buf_free(&buf);
git_buf_copy_cstr(data, sizeof(data), &buf);
- cl_assert_strequal("", data);
+ cl_assert_equal_s("", data);
}
/* let's do some tests with larger buffers to push our limits */
@@ -164,17 +164,17 @@ void test_core_buffer__3(void)
/* set to string */
git_buf_set(&buf, test_4096, 4096);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(test_4096, git_buf_cstr(&buf));
+ cl_assert_equal_s(test_4096, git_buf_cstr(&buf));
/* append string */
git_buf_puts(&buf, test_4096);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(test_8192, git_buf_cstr(&buf));
+ cl_assert_equal_s(test_8192, git_buf_cstr(&buf));
/* set to string again (should overwrite - not append) */
git_buf_set(&buf, test_4096, 4096);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(test_4096, git_buf_cstr(&buf));
+ cl_assert_equal_s(test_4096, git_buf_cstr(&buf));
git_buf_free(&buf);
}
@@ -192,22 +192,22 @@ void test_core_buffer__4(void)
cl_assert(strlen(git_buf_cstr(&buf)) == (size_t)((i + 1) * 2));
}
/* we have appended 1234 10x and removed the first 20 letters */
- cl_assert_strequal("12341234123412341234", git_buf_cstr(&buf));
+ cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
git_buf_consume(&buf, NULL);
- cl_assert_strequal("12341234123412341234", git_buf_cstr(&buf));
+ cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
git_buf_consume(&buf, "invalid pointer");
- cl_assert_strequal("12341234123412341234", git_buf_cstr(&buf));
+ cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
git_buf_consume(&buf, buf.ptr);
- cl_assert_strequal("12341234123412341234", git_buf_cstr(&buf));
+ cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
git_buf_consume(&buf, buf.ptr + 1);
- cl_assert_strequal("2341234123412341234", git_buf_cstr(&buf));
+ cl_assert_equal_s("2341234123412341234", git_buf_cstr(&buf));
git_buf_consume(&buf, buf.ptr + buf.size);
- cl_assert_strequal("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", git_buf_cstr(&buf));
git_buf_free(&buf);
}
@@ -218,8 +218,8 @@ check_buf_append(
const char* data_a,
const char* data_b,
const char* expected_data,
- ssize_t expected_size,
- ssize_t expected_asize)
+ size_t expected_size,
+ size_t expected_asize)
{
git_buf tgt = GIT_BUF_INIT;
@@ -227,7 +227,7 @@ check_buf_append(
cl_assert(git_buf_oom(&tgt) == 0);
git_buf_puts(&tgt, data_b);
cl_assert(git_buf_oom(&tgt) == 0);
- cl_assert_strequal(expected_data, git_buf_cstr(&tgt));
+ cl_assert_equal_s(expected_data, git_buf_cstr(&tgt));
cl_assert(tgt.size == expected_size);
if (expected_asize > 0)
cl_assert(tgt.asize == expected_asize);
@@ -250,27 +250,27 @@ check_buf_append_abc(
git_buf_sets(&buf, buf_a);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(buf_a, git_buf_cstr(&buf));
+ cl_assert_equal_s(buf_a, git_buf_cstr(&buf));
git_buf_puts(&buf, buf_b);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(expected_ab, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_ab, git_buf_cstr(&buf));
git_buf_puts(&buf, buf_c);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(expected_abc, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_abc, git_buf_cstr(&buf));
git_buf_puts(&buf, buf_a);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(expected_abca, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_abca, git_buf_cstr(&buf));
git_buf_puts(&buf, buf_b);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(expected_abcab, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_abcab, git_buf_cstr(&buf));
git_buf_puts(&buf, buf_c);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(expected_abcabc, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_abcabc, git_buf_cstr(&buf));
git_buf_free(&buf);
}
@@ -330,13 +330,13 @@ void test_core_buffer__6(void)
git_buf_sets(&b, "bar");
cl_assert(git_buf_oom(&b) == 0);
- cl_assert_strequal("foo", git_buf_cstr(&a));
- cl_assert_strequal("bar", git_buf_cstr(&b));
+ cl_assert_equal_s("foo", git_buf_cstr(&a));
+ cl_assert_equal_s("bar", git_buf_cstr(&b));
git_buf_swap(&a, &b);
- cl_assert_strequal("bar", git_buf_cstr(&a));
- cl_assert_strequal("foo", git_buf_cstr(&b));
+ cl_assert_equal_s("bar", git_buf_cstr(&a));
+ cl_assert_equal_s("foo", git_buf_cstr(&b));
git_buf_free(&a);
git_buf_free(&b);
@@ -352,36 +352,36 @@ void test_core_buffer__7(void)
git_buf_sets(&a, "foo");
cl_assert(git_buf_oom(&a) == 0);
- cl_assert_strequal("foo", git_buf_cstr(&a));
+ cl_assert_equal_s("foo", git_buf_cstr(&a));
b = git_buf_detach(&a);
- cl_assert_strequal("foo", b);
- cl_assert_strequal("", a.ptr);
+ cl_assert_equal_s("foo", b);
+ cl_assert_equal_s("", a.ptr);
git__free(b);
b = git_buf_detach(&a);
- cl_assert_strequal(NULL, b);
- cl_assert_strequal("", a.ptr);
+ cl_assert_equal_s(NULL, b);
+ cl_assert_equal_s("", a.ptr);
git_buf_free(&a);
b = git__strdup(fun);
git_buf_attach(&a, b, 0);
- cl_assert_strequal(fun, a.ptr);
- cl_assert(a.size == (ssize_t)strlen(fun));
- cl_assert(a.asize == (ssize_t)strlen(fun) + 1);
+ cl_assert_equal_s(fun, a.ptr);
+ cl_assert(a.size == strlen(fun));
+ cl_assert(a.asize == strlen(fun) + 1);
git_buf_free(&a);
b = git__strdup(fun);
git_buf_attach(&a, b, strlen(fun) + 1);
- cl_assert_strequal(fun, a.ptr);
- cl_assert(a.size == (ssize_t)strlen(fun));
- cl_assert(a.asize == (ssize_t)strlen(fun) + 1);
+ cl_assert_equal_s(fun, a.ptr);
+ cl_assert(a.size == strlen(fun));
+ cl_assert(a.asize == strlen(fun) + 1);
git_buf_free(&a);
}
@@ -398,7 +398,7 @@ check_joinbuf_2(
git_buf_join(&buf, sep, a, b);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, git_buf_cstr(&buf));
git_buf_free(&buf);
}
@@ -416,7 +416,7 @@ check_joinbuf_n_2(
git_buf_join_n(&buf, sep, 1, b);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, git_buf_cstr(&buf));
git_buf_free(&buf);
}
@@ -433,7 +433,7 @@ check_joinbuf_n_4(
git_buf buf = GIT_BUF_INIT;
git_buf_join_n(&buf, sep, 4, a, b, c, d);
cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_strequal(expected, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected, git_buf_cstr(&buf));
git_buf_free(&buf);
}
@@ -444,15 +444,15 @@ void test_core_buffer__8(void)
git_buf_join_n(&a, '/', 1, "foo");
cl_assert(git_buf_oom(&a) == 0);
- cl_assert_strequal("foo", git_buf_cstr(&a));
+ cl_assert_equal_s("foo", git_buf_cstr(&a));
git_buf_join_n(&a, '/', 1, "bar");
cl_assert(git_buf_oom(&a) == 0);
- cl_assert_strequal("foo/bar", git_buf_cstr(&a));
+ cl_assert_equal_s("foo/bar", git_buf_cstr(&a));
git_buf_join_n(&a, '/', 1, "baz");
cl_assert(git_buf_oom(&a) == 0);
- cl_assert_strequal("foo/bar/baz", git_buf_cstr(&a));
+ cl_assert_equal_s("foo/bar/baz", git_buf_cstr(&a));
git_buf_free(&a);
@@ -536,7 +536,7 @@ void test_core_buffer__9(void)
for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {
for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {
git_buf_join(&buf, separator, a[i], b[j]);
- cl_assert_strequal(*expect, buf.ptr);
+ cl_assert_equal_s(*expect, buf.ptr);
expect++;
}
}
@@ -544,3 +544,70 @@ void test_core_buffer__9(void)
git_buf_free(&buf);
}
+
+void test_core_buffer__10(void)
+{
+ git_buf a = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_join_n(&a, '/', 1, "test"));
+ cl_assert_equal_s(a.ptr, "test");
+ cl_git_pass(git_buf_join_n(&a, '/', 1, "string"));
+ cl_assert_equal_s(a.ptr, "test/string");
+ git_buf_clear(&a);
+ cl_git_pass(git_buf_join_n(&a, '/', 3, "test", "string", "join"));
+ cl_assert_equal_s(a.ptr, "test/string/join");
+ cl_git_pass(git_buf_join_n(&a, '/', 2, a.ptr, "more"));
+ cl_assert_equal_s(a.ptr, "test/string/join/test/string/join/more");
+
+ git_buf_free(&a);
+}
+
+void test_core_buffer__11(void)
+{
+ git_buf a = GIT_BUF_INIT;
+ git_strarray t;
+ char *t1[] = { "nothing", "in", "common" };
+ char *t2[] = { "something", "something else", "some other" };
+ char *t3[] = { "something", "some fun", "no fun" };
+ char *t4[] = { "happy", "happier", "happiest" };
+ char *t5[] = { "happiest", "happier", "happy" };
+ char *t6[] = { "no", "nope", "" };
+ char *t7[] = { "", "doesn't matter" };
+
+ t.strings = t1;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "");
+
+ t.strings = t2;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "some");
+
+ t.strings = t3;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "");
+
+ t.strings = t4;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "happ");
+
+ t.strings = t5;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "happ");
+
+ t.strings = t6;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "");
+
+ t.strings = t7;
+ t.count = 3;
+ cl_git_pass(git_buf_common_prefix(&a, &t));
+ cl_assert_equal_s(a.ptr, "");
+
+ git_buf_free(&a);
+}