summaryrefslogtreecommitdiff
path: root/tests/core
diff options
context:
space:
mode:
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/buf.c54
-rw-r--r--tests/core/dirent.c18
-rw-r--r--tests/core/env.c50
-rw-r--r--tests/core/filebuf.c10
-rw-r--r--tests/core/futils.c28
-rw-r--r--tests/core/gitstr.c (renamed from tests/core/buffer.c)793
-rw-r--r--tests/core/link.c119
-rw-r--r--tests/core/mkdir.c20
-rw-r--r--tests/core/path.c106
-rw-r--r--tests/core/posix.c12
-rw-r--r--tests/core/rmdir.c66
-rw-r--r--tests/core/sortedcache.c4
-rw-r--r--tests/core/stat.c6
-rw-r--r--tests/core/useragent.c4
-rw-r--r--tests/core/zstream.c35
15 files changed, 688 insertions, 637 deletions
diff --git a/tests/core/buf.c b/tests/core/buf.c
new file mode 100644
index 000000000..3959fa883
--- /dev/null
+++ b/tests/core/buf.c
@@ -0,0 +1,54 @@
+#include "clar_libgit2.h"
+#include "buf.h"
+
+void test_core_buf__sanitize(void)
+{
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_sanitize(&buf));
+ cl_assert_equal_s(buf.ptr, "");
+ cl_assert_equal_i(buf.reserved, 0);
+ cl_assert_equal_i(buf.size, 0);
+
+ git_buf_dispose(&buf);
+}
+
+void test_core_buf__tostr(void)
+{
+ git_str str = GIT_STR_INIT;
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_tostr(&str, &buf));
+
+ cl_assert_equal_s(buf.ptr, "");
+ cl_assert_equal_i(buf.reserved, 0);
+ cl_assert_equal_i(buf.size, 0);
+
+ cl_assert_equal_s(str.ptr, "");
+ cl_assert_equal_i(str.asize, 0);
+ cl_assert_equal_i(str.size, 0);
+
+ git_buf_dispose(&buf);
+ git_str_dispose(&str);
+}
+
+void test_core_buf__fromstr(void)
+{
+ git_str str = GIT_STR_INIT;
+ git_buf buf = { (char *)0x42, 0, 16 };
+
+ cl_git_pass(git_buf_tostr(&str, &buf));
+ cl_git_pass(git_str_puts(&str, "Hello, world."));
+ cl_git_pass(git_buf_fromstr(&buf, &str));
+
+ cl_assert(buf.reserved > 14);
+ cl_assert_equal_i(buf.size, 13);
+ cl_assert_equal_s(buf.ptr, "Hello, world.");
+
+ cl_assert_equal_s(str.ptr, "");
+ cl_assert_equal_i(str.asize, 0);
+ cl_assert_equal_i(str.size, 0);
+
+ git_buf_dispose(&buf);
+ git_str_dispose(&str);
+}
diff --git a/tests/core/dirent.c b/tests/core/dirent.c
index 08e0b11cf..ce93e0358 100644
--- a/tests/core/dirent.c
+++ b/tests/core/dirent.c
@@ -9,7 +9,7 @@ typedef struct name_data {
typedef struct walk_data {
char *sub; /* sub-directory name */
name_data *names; /* name state data */
- git_buf path;
+ git_str path;
} walk_data;
@@ -27,7 +27,7 @@ static void setup(walk_data *d)
if (strcmp(d->sub, ".") != 0)
cl_must_pass(p_mkdir(d->sub, 0777));
- cl_git_pass(git_buf_sets(&d->path, d->sub));
+ cl_git_pass(git_str_sets(&d->path, d->sub));
state_loc = d;
@@ -55,7 +55,7 @@ static void dirent_cleanup__cb(void *_d)
cl_must_pass(p_rmdir(top_dir));
- git_buf_dispose(&d->path);
+ git_str_dispose(&d->path);
}
static void check_counts(walk_data *d)
@@ -81,7 +81,7 @@ static int update_count(name_data *data, const char *name)
return GIT_ERROR;
}
-static int one_entry(void *state, git_buf *path)
+static int one_entry(void *state, git_str *path)
{
walk_data *d = (walk_data *) state;
@@ -104,7 +104,7 @@ static name_data dot_names[] = {
static walk_data dot = {
".",
dot_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that the '.' folder is not traversed */
@@ -128,7 +128,7 @@ static name_data sub_names[] = {
static walk_data sub = {
"sub",
sub_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* traverse a subfolder */
@@ -146,7 +146,7 @@ void test_core_dirent__traverse_subfolder(void)
static walk_data sub_slash = {
"sub/",
sub_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* traverse a slash-terminated subfolder */
@@ -167,7 +167,7 @@ static name_data empty_names[] = {
static walk_data empty = {
"empty",
empty_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that empty folders are not traversed */
@@ -195,7 +195,7 @@ static name_data odd_names[] = {
static walk_data odd = {
"odd",
odd_names,
- GIT_BUF_INIT
+ GIT_STR_INIT
};
/* make sure that strange looking filenames ('..c') are traversed */
diff --git a/tests/core/env.c b/tests/core/env.c
index 3c34b2c4d..9a3f0ae76 100644
--- a/tests/core/env.c
+++ b/tests/core/env.c
@@ -83,7 +83,7 @@ static void setenv_and_check(const char *name, const char *value)
void test_core_env__0(void)
{
- git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, found = GIT_STR_INIT;
char testfile[16], tidx = '0';
char **val;
const char *testname = "testfile";
@@ -110,9 +110,9 @@ void test_core_env__0(void)
* accidentally make this test pass...
*/
testfile[testlen] = tidx++;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
cl_git_mkfile(path.ptr, "find me");
- git_buf_rtruncate_at_char(&path, '/');
+ git_str_rtruncate_at_char(&path, '/');
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(&found, testfile));
@@ -162,14 +162,14 @@ void test_core_env__0(void)
(void)p_rmdir(*val);
}
- git_buf_dispose(&path);
- git_buf_dispose(&found);
+ git_str_dispose(&path);
+ git_str_dispose(&found);
}
void test_core_env__1(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(&path, "nonexistentfile"));
@@ -206,21 +206,21 @@ void test_core_env__1(void)
GIT_ENOTFOUND, git_sysdir_find_system_file(&path, "nonexistentfile"));
#endif
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void check_global_searchpath(
- const char *path, int position, const char *file, git_buf *temp)
+ const char *path, int position, const char *file, git_str *temp)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
/* build and set new path */
if (position < 0)
- cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH"));
+ cl_git_pass(git_str_join(temp, GIT_PATH_LIST_SEPARATOR, path, "$PATH"));
else if (position > 0)
- cl_git_pass(git_buf_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path));
+ cl_git_pass(git_str_join(temp, GIT_PATH_LIST_SEPARATOR, "$PATH", path));
else
- cl_git_pass(git_buf_sets(temp, path));
+ cl_git_pass(git_str_sets(temp, path));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, temp->ptr));
@@ -245,12 +245,12 @@ static void check_global_searchpath(
cl_assert_equal_i(
GIT_ENOTFOUND, git_sysdir_find_global_file(temp, file));
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
void test_core_env__2(void)
{
- git_buf path = GIT_BUF_INIT, found = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT, found = GIT_STR_INIT;
char testfile[16], tidx = '0';
char **val;
const char *testname = "alternate";
@@ -276,9 +276,9 @@ void test_core_env__2(void)
* deleting files won't accidentally make a test pass.
*/
testfile[testlen] = tidx++;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
cl_git_mkfile(path.ptr, "find me");
- git_buf_rtruncate_at_char(&path, '/');
+ git_str_rtruncate_at_char(&path, '/');
/* default should be NOTFOUND */
cl_assert_equal_i(
@@ -290,32 +290,32 @@ void test_core_env__2(void)
check_global_searchpath(path.ptr, 1, testfile, &found);
/* cleanup */
- cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, testfile));
(void)p_unlink(path.ptr);
(void)p_rmdir(*val);
}
- git_buf_dispose(&path);
- git_buf_dispose(&found);
+ git_str_dispose(&path);
+ git_str_dispose(&found);
}
void test_core_env__substitution(void)
{
- git_buf buf = GIT_BUF_INIT, expected = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT, expected = GIT_STR_INIT;
/* Set it to something non-default so we have controllable values */
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, "/tmp/a"));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf));
cl_assert_equal_s("/tmp/a", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b"));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b"));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, buf.ptr));
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf));
- cl_git_pass(git_buf_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b"));
+ cl_git_pass(git_str_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b"));
cl_assert_equal_s(expected.ptr, buf.ptr);
- git_buf_dispose(&expected);
- git_buf_dispose(&buf);
+ git_str_dispose(&expected);
+ git_str_dispose(&buf);
}
diff --git a/tests/core/filebuf.c b/tests/core/filebuf.c
index e527ce97c..6f654f523 100644
--- a/tests/core/filebuf.c
+++ b/tests/core/filebuf.c
@@ -189,13 +189,13 @@ void test_core_filebuf__symlink_follow(void)
void test_core_filebuf__symlink_follow_absolute_paths(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
- git_buf source = GIT_BUF_INIT, target = GIT_BUF_INIT;
+ git_str source = GIT_STR_INIT, target = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
cl_skip();
- cl_git_pass(git_buf_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
- cl_git_pass(git_buf_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
+ cl_git_pass(git_str_joinpath(&source, clar_sandbox_path(), "linkdir/link"));
+ cl_git_pass(git_str_joinpath(&target, clar_sandbox_path(), "linkdir/target"));
cl_git_pass(p_mkdir("linkdir", 0777));
cl_git_pass(p_symlink(target.ptr, source.ptr));
@@ -208,8 +208,8 @@ void test_core_filebuf__symlink_follow_absolute_paths(void)
cl_assert_equal_i(true, git_path_exists("linkdir/target"));
git_filebuf_cleanup(&file);
- git_buf_dispose(&source);
- git_buf_dispose(&target);
+ git_str_dispose(&source);
+ git_str_dispose(&target);
cl_git_pass(git_futils_rmdir_r("linkdir", NULL, GIT_RMDIR_REMOVE_FILES));
}
diff --git a/tests/core/futils.c b/tests/core/futils.c
index 2c8294c87..d08043b6e 100644
--- a/tests/core/futils.c
+++ b/tests/core/futils.c
@@ -14,27 +14,27 @@ void test_core_futils__cleanup(void)
void test_core_futils__writebuffer(void)
{
- git_buf out = GIT_BUF_INIT,
- append = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT,
+ append = GIT_STR_INIT;
/* create a new file */
- git_buf_puts(&out, "hello!\n");
- git_buf_printf(&out, "this is a %s\n", "test");
+ git_str_puts(&out, "hello!\n");
+ git_str_printf(&out, "this is a %s\n", "test");
cl_git_pass(git_futils_writebuffer(&out, "futils/test-file", O_RDWR|O_CREAT, 0666));
cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
/* append some more data */
- git_buf_puts(&append, "And some more!\n");
- git_buf_put(&out, append.ptr, append.size);
+ git_str_puts(&append, "And some more!\n");
+ git_str_put(&out, append.ptr, append.size);
cl_git_pass(git_futils_writebuffer(&append, "futils/test-file", O_RDWR|O_APPEND, 0666));
cl_assert_equal_file(out.ptr, out.size, "futils/test-file");
- git_buf_dispose(&out);
- git_buf_dispose(&append);
+ git_str_dispose(&out);
+ git_str_dispose(&append);
}
void test_core_futils__write_hidden_file(void)
@@ -42,17 +42,17 @@ void test_core_futils__write_hidden_file(void)
#ifndef GIT_WIN32
cl_skip();
#else
- git_buf out = GIT_BUF_INIT, append = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT, append = GIT_STR_INIT;
bool hidden;
- git_buf_puts(&out, "hidden file.\n");
+ git_str_puts(&out, "hidden file.\n");
git_futils_writebuffer(&out, "futils/test-file", O_RDWR | O_CREAT, 0666);
cl_git_pass(git_win32__set_hidden("futils/test-file", true));
/* append some more data */
- git_buf_puts(&append, "And some more!\n");
- git_buf_put(&out, append.ptr, append.size);
+ git_str_puts(&append, "And some more!\n");
+ git_str_put(&out, append.ptr, append.size);
cl_git_pass(git_futils_writebuffer(&append, "futils/test-file", O_RDWR | O_APPEND, 0666));
@@ -61,8 +61,8 @@ void test_core_futils__write_hidden_file(void)
cl_git_pass(git_win32__hidden(&hidden, "futils/test-file"));
cl_assert(hidden);
- git_buf_dispose(&out);
- git_buf_dispose(&append);
+ git_str_dispose(&out);
+ git_str_dispose(&append);
#endif
}
diff --git a/tests/core/buffer.c b/tests/core/gitstr.c
index 2af4a8712..0a624e28c 100644
--- a/tests/core/buffer.c
+++ b/tests/core/gitstr.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "git2/sys/hashsig.h"
#include "futils.h"
@@ -13,205 +12,205 @@ const char *test_4096 = TESTSTR_4096;
const char *test_8192 = TESTSTR_8192;
/* test basic data concatenation */
-void test_core_buffer__0(void)
+void test_core_gitstr__0(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_assert(buf.size == 0);
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string, git_buf_cstr(&buf));
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string_x2, git_buf_cstr(&buf));
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string_x2, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-/* test git_buf_printf */
-void test_core_buffer__1(void)
+/* test git_str_printf */
+void test_core_gitstr__1(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_printf(&buf, "%s %s %d ", "shoop", "da", 23);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("shoop da 23 ", git_buf_cstr(&buf));
+ git_str_printf(&buf, "%s %s %d ", "shoop", "da", 23);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("shoop da 23 ", git_str_cstr(&buf));
- git_buf_printf(&buf, "%s %d", "woop", 42);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("shoop da 23 woop 42", git_buf_cstr(&buf));
+ git_str_printf(&buf, "%s %d", "woop", 42);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("shoop da 23 woop 42", git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
/* more thorough test of concatenation options */
-void test_core_buffer__2(void)
+void test_core_gitstr__2(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int i;
char data[128];
cl_assert(buf.size == 0);
/* this must be safe to do */
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
cl_assert(buf.size == 0);
cl_assert(buf.asize == 0);
/* empty buffer should be empty string */
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ cl_assert_equal_s("", git_str_cstr(&buf));
cl_assert(buf.size == 0);
- /* cl_assert(buf.asize == 0); -- should not assume what git_buf does */
+ /* cl_assert(buf.asize == 0); -- should not assume what git_str does */
/* free should set us back to the beginning */
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
cl_assert(buf.size == 0);
cl_assert(buf.asize == 0);
/* add letter */
- git_buf_putc(&buf, '+');
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("+", git_buf_cstr(&buf));
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("+", git_str_cstr(&buf));
/* add letter again */
- git_buf_putc(&buf, '+');
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("++", git_buf_cstr(&buf));
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("++", git_str_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);
+ git_str_putc(&buf, '+');
+ cl_assert(git_str_oom(&buf) == 0);
}
- cl_assert_equal_s("++++++++++++++++++", git_buf_cstr(&buf));
+ cl_assert_equal_s("++++++++++++++++++", git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* add data */
- git_buf_put(&buf, "xo", 2);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("xo", git_buf_cstr(&buf));
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("xo", git_str_cstr(&buf));
/* add letter again */
- git_buf_put(&buf, "xo", 2);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s("xoxo", git_buf_cstr(&buf));
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s("xoxo", git_str_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);
+ git_str_put(&buf, "xo", 2);
+ cl_assert(git_str_oom(&buf) == 0);
}
cl_assert_equal_s("xoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxo",
- git_buf_cstr(&buf));
+ git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* set to string */
- git_buf_sets(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string, git_buf_cstr(&buf));
+ git_str_sets(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
/* append string */
- git_buf_puts(&buf, test_string);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_string_x2, git_buf_cstr(&buf));
+ git_str_puts(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string_x2, git_str_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_equal_s(test_string, git_buf_cstr(&buf));
+ git_str_sets(&buf, test_string);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_string, git_str_cstr(&buf));
/* test clear */
- git_buf_clear(&buf);
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ git_str_clear(&buf);
+ cl_assert_equal_s("", git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
/* test extracting data into buffer */
- git_buf_puts(&buf, REP4("0123456789"));
- cl_assert(git_buf_oom(&buf) == 0);
+ git_str_puts(&buf, REP4("0123456789"));
+ cl_assert(git_str_oom(&buf) == 0);
- git_buf_copy_cstr(data, sizeof(data), &buf);
+ git_str_copy_cstr(data, sizeof(data), &buf);
cl_assert_equal_s(REP4("0123456789"), data);
- git_buf_copy_cstr(data, 11, &buf);
+ git_str_copy_cstr(data, 11, &buf);
cl_assert_equal_s("0123456789", data);
- git_buf_copy_cstr(data, 3, &buf);
+ git_str_copy_cstr(data, 3, &buf);
cl_assert_equal_s("01", data);
- git_buf_copy_cstr(data, 1, &buf);
+ git_str_copy_cstr(data, 1, &buf);
cl_assert_equal_s("", data);
- git_buf_copy_cstr(data, sizeof(data), &buf);
+ git_str_copy_cstr(data, sizeof(data), &buf);
cl_assert_equal_s(REP4("0123456789"), data);
- git_buf_sets(&buf, REP256("x"));
- git_buf_copy_cstr(data, sizeof(data), &buf);
+ git_str_sets(&buf, REP256("x"));
+ git_str_copy_cstr(data, sizeof(data), &buf);
/* since sizeof(data) == 128, only 127 bytes should be copied */
cl_assert_equal_s(REP4(REP16("x")) REP16("x") REP16("x")
REP16("x") "xxxxxxxxxxxxxxx", data);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
- git_buf_copy_cstr(data, sizeof(data), &buf);
+ git_str_copy_cstr(data, sizeof(data), &buf);
cl_assert_equal_s("", data);
}
/* let's do some tests with larger buffers to push our limits */
-void test_core_buffer__3(void)
+void test_core_gitstr__3(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* set to string */
- git_buf_set(&buf, test_4096, 4096);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_4096, git_buf_cstr(&buf));
+ git_str_set(&buf, test_4096, 4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_4096, git_str_cstr(&buf));
/* append string */
- git_buf_puts(&buf, test_4096);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(test_8192, git_buf_cstr(&buf));
+ git_str_puts(&buf, test_4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_8192, git_str_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_equal_s(test_4096, git_buf_cstr(&buf));
+ git_str_set(&buf, test_4096, 4096);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(test_4096, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
/* let's try some producer/consumer tests */
-void test_core_buffer__4(void)
+void test_core_gitstr__4(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int i;
for (i = 0; i < 10; ++i) {
- git_buf_puts(&buf, "1234"); /* add 4 */
- cl_assert(git_buf_oom(&buf) == 0);
- git_buf_consume(&buf, buf.ptr + 2); /* eat the first two */
- cl_assert(strlen(git_buf_cstr(&buf)) == (size_t)((i + 1) * 2));
+ git_str_puts(&buf, "1234"); /* add 4 */
+ cl_assert(git_str_oom(&buf) == 0);
+ git_str_consume(&buf, buf.ptr + 2); /* eat the first two */
+ cl_assert(strlen(git_str_cstr(&buf)) == (size_t)((i + 1) * 2));
}
/* we have appended 1234 10x and removed the first 20 letters */
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, NULL);
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
+ git_str_consume(&buf, NULL);
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, "invalid pointer");
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
+ git_str_consume(&buf, "invalid pointer");
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, buf.ptr);
- cl_assert_equal_s("12341234123412341234", git_buf_cstr(&buf));
+ git_str_consume(&buf, buf.ptr);
+ cl_assert_equal_s("12341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, buf.ptr + 1);
- cl_assert_equal_s("2341234123412341234", git_buf_cstr(&buf));
+ git_str_consume(&buf, buf.ptr + 1);
+ cl_assert_equal_s("2341234123412341234", git_str_cstr(&buf));
- git_buf_consume(&buf, buf.ptr + buf.size);
- cl_assert_equal_s("", git_buf_cstr(&buf));
+ git_str_consume(&buf, buf.ptr + buf.size);
+ cl_assert_equal_s("", git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
@@ -223,18 +222,18 @@ check_buf_append(
size_t expected_size,
size_t expected_asize)
{
- git_buf tgt = GIT_BUF_INIT;
+ git_str tgt = GIT_STR_INIT;
- git_buf_sets(&tgt, data_a);
- cl_assert(git_buf_oom(&tgt) == 0);
- git_buf_puts(&tgt, data_b);
- cl_assert(git_buf_oom(&tgt) == 0);
- cl_assert_equal_s(expected_data, git_buf_cstr(&tgt));
+ git_str_sets(&tgt, data_a);
+ cl_assert(git_str_oom(&tgt) == 0);
+ git_str_puts(&tgt, data_b);
+ cl_assert(git_str_oom(&tgt) == 0);
+ cl_assert_equal_s(expected_data, git_str_cstr(&tgt));
cl_assert_equal_i(tgt.size, expected_size);
if (expected_asize > 0)
cl_assert_equal_i(tgt.asize, expected_asize);
- git_buf_dispose(&tgt);
+ git_str_dispose(&tgt);
}
static void
@@ -248,37 +247,37 @@ check_buf_append_abc(
const char* expected_abcab,
const char* expected_abcabc)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_sets(&buf, buf_a);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(buf_a, git_buf_cstr(&buf));
+ git_str_sets(&buf, buf_a);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(buf_a, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_ab, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_ab, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_c);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abc, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_c);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abc, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_a);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abca, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_a);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abca, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abcab, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abcab, git_str_cstr(&buf));
- git_buf_puts(&buf, buf_c);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected_abcabc, git_buf_cstr(&buf));
+ git_str_puts(&buf, buf_c);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected_abcabc, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
/* more variations on append tests */
-void test_core_buffer__5(void)
+void test_core_gitstr__5(void)
{
check_buf_append("", "", "", 0, 0);
check_buf_append("a", "", "a", 1, 0);
@@ -321,70 +320,70 @@ void test_core_buffer__5(void)
}
/* test swap */
-void test_core_buffer__6(void)
+void test_core_gitstr__6(void)
{
- git_buf a = GIT_BUF_INIT;
- git_buf b = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
+ git_str b = GIT_STR_INIT;
- git_buf_sets(&a, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- git_buf_sets(&b, "bar");
- cl_assert(git_buf_oom(&b) == 0);
+ git_str_sets(&a, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ git_str_sets(&b, "bar");
+ cl_assert(git_str_oom(&b) == 0);
- cl_assert_equal_s("foo", git_buf_cstr(&a));
- cl_assert_equal_s("bar", git_buf_cstr(&b));
+ cl_assert_equal_s("foo", git_str_cstr(&a));
+ cl_assert_equal_s("bar", git_str_cstr(&b));
- git_buf_swap(&a, &b);
+ git_str_swap(&a, &b);
- cl_assert_equal_s("bar", git_buf_cstr(&a));
- cl_assert_equal_s("foo", git_buf_cstr(&b));
+ cl_assert_equal_s("bar", git_str_cstr(&a));
+ cl_assert_equal_s("foo", git_str_cstr(&b));
- git_buf_dispose(&a);
- git_buf_dispose(&b);
+ git_str_dispose(&a);
+ git_str_dispose(&b);
}
/* test detach/attach data */
-void test_core_buffer__7(void)
+void test_core_gitstr__7(void)
{
const char *fun = "This is fun";
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
char *b = NULL;
- git_buf_sets(&a, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo", git_buf_cstr(&a));
+ git_str_sets(&a, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo", git_str_cstr(&a));
- b = git_buf_detach(&a);
+ b = git_str_detach(&a);
cl_assert_equal_s("foo", b);
cl_assert_equal_s("", a.ptr);
git__free(b);
- b = git_buf_detach(&a);
+ b = git_str_detach(&a);
cl_assert_equal_s(NULL, b);
cl_assert_equal_s("", a.ptr);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
b = git__strdup(fun);
- git_buf_attach(&a, b, 0);
+ git_str_attach(&a, b, 0);
cl_assert_equal_s(fun, a.ptr);
cl_assert(a.size == strlen(fun));
cl_assert(a.asize == strlen(fun) + 1);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
b = git__strdup(fun);
- git_buf_attach(&a, b, strlen(fun) + 1);
+ git_str_attach(&a, b, 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_dispose(&a);
+ git_str_dispose(&a);
}
@@ -395,12 +394,12 @@ check_joinbuf_2(
const char *expected)
{
char sep = '/';
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_join(&buf, sep, a, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_join(&buf, sep, a, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
}
static void
@@ -411,13 +410,13 @@ check_joinbuf_overlapped(
const char *expected)
{
char sep = '/';
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_sets(&buf, oldval);
- git_buf_join(&buf, sep, buf.ptr + ofs_a, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_sets(&buf, oldval);
+ git_str_join(&buf, sep, buf.ptr + ofs_a, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
}
static void
@@ -427,16 +426,16 @@ check_joinbuf_n_2(
const char *expected)
{
char sep = '/';
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_sets(&buf, a);
- cl_assert(git_buf_oom(&buf) == 0);
+ git_str_sets(&buf, a);
+ cl_assert(git_str_oom(&buf) == 0);
- git_buf_join_n(&buf, sep, 1, b);
- cl_assert(git_buf_oom(&buf) == 0);
- cl_assert_equal_s(expected, git_buf_cstr(&buf));
+ git_str_join_n(&buf, sep, 1, b);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
static void
@@ -448,31 +447,31 @@ check_joinbuf_n_4(
const char *expected)
{
char sep = ';';
- 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_equal_s(expected, git_buf_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str buf = GIT_STR_INIT;
+ git_str_join_n(&buf, sep, 4, a, b, c, d);
+ cl_assert(git_str_oom(&buf) == 0);
+ cl_assert_equal_s(expected, git_str_cstr(&buf));
+ git_str_dispose(&buf);
}
/* test join */
-void test_core_buffer__8(void)
+void test_core_gitstr__8(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
- git_buf_join_n(&a, '/', 1, "foo");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo", git_buf_cstr(&a));
+ git_str_join_n(&a, '/', 1, "foo");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo", git_str_cstr(&a));
- git_buf_join_n(&a, '/', 1, "bar");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo/bar", git_buf_cstr(&a));
+ git_str_join_n(&a, '/', 1, "bar");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo/bar", git_str_cstr(&a));
- git_buf_join_n(&a, '/', 1, "baz");
- cl_assert(git_buf_oom(&a) == 0);
- cl_assert_equal_s("foo/bar/baz", git_buf_cstr(&a));
+ git_str_join_n(&a, '/', 1, "baz");
+ cl_assert(git_str_oom(&a) == 0);
+ cl_assert_equal_s("foo/bar/baz", git_str_cstr(&a));
- git_buf_dispose(&a);
+ git_str_dispose(&a);
check_joinbuf_2(NULL, "", "");
check_joinbuf_2(NULL, "a", "a");
@@ -537,9 +536,9 @@ void test_core_buffer__8(void)
check_joinbuf_n_4(";abcd;", ";efgh;", ";ijkl;", ";mnop;", ";abcd;efgh;ijkl;mnop;");
}
-void test_core_buffer__9(void)
+void test_core_gitstr__9(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* just some exhaustive tests of various separator placement */
char *a[] = { "", "-", "a-", "-a", "-a-" };
@@ -570,68 +569,68 @@ 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]);
+ git_str_join(&buf, separator, a[i], b[j]);
cl_assert_equal_s(*expect, buf.ptr);
expect++;
}
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__10(void)
+void test_core_gitstr__10(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
- cl_git_pass(git_buf_join_n(&a, '/', 1, "test"));
+ cl_git_pass(git_str_join_n(&a, '/', 1, "test"));
cl_assert_equal_s(a.ptr, "test");
- cl_git_pass(git_buf_join_n(&a, '/', 1, "string"));
+ cl_git_pass(git_str_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"));
+ git_str_clear(&a);
+ cl_git_pass(git_str_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_git_pass(git_str_join_n(&a, '/', 2, a.ptr, "more"));
cl_assert_equal_s(a.ptr, "test/string/join/test/string/join/more");
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
-void test_core_buffer__join3(void)
+void test_core_gitstr__join3(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
- cl_git_pass(git_buf_join3(&a, '/', "test", "string", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "test", "string", "join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "string", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "test/", "string", "join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string", "join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string/", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string/", "join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "test/", "/string/", "/join"));
+ cl_git_pass(git_str_join3(&a, '/', "test/", "/string/", "/join"));
cl_assert_equal_s("test/string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "", "string", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "", "string", "join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "", "string/", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "", "string/", "join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "", "string/", "/join"));
+ cl_git_pass(git_str_join3(&a, '/', "", "string/", "/join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "string", "", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "string", "", "join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "string/", "", "join"));
+ cl_git_pass(git_str_join3(&a, '/', "string/", "", "join"));
cl_assert_equal_s("string/join", a.ptr);
- cl_git_pass(git_buf_join3(&a, '/', "string/", "", "/join"));
+ cl_git_pass(git_str_join3(&a, '/', "string/", "", "/join"));
cl_assert_equal_s("string/join", a.ptr);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
-void test_core_buffer__11(void)
+void test_core_gitstr__11(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
char *t1[] = { "nothing", "in", "common" };
char *t2[] = { "something", "something else", "some other" };
char *t3[] = { "something", "some fun", "no fun" };
@@ -640,89 +639,89 @@ void test_core_buffer__11(void)
char *t6[] = { "no", "nope", "" };
char *t7[] = { "", "doesn't matter" };
- cl_git_pass(git_buf_common_prefix(&a, t1, 3));
+ cl_git_pass(git_str_common_prefix(&a, t1, 3));
cl_assert_equal_s(a.ptr, "");
- cl_git_pass(git_buf_common_prefix(&a, t2, 3));
+ cl_git_pass(git_str_common_prefix(&a, t2, 3));
cl_assert_equal_s(a.ptr, "some");
- cl_git_pass(git_buf_common_prefix(&a, t3, 3));
+ cl_git_pass(git_str_common_prefix(&a, t3, 3));
cl_assert_equal_s(a.ptr, "");
- cl_git_pass(git_buf_common_prefix(&a, t4, 3));
+ cl_git_pass(git_str_common_prefix(&a, t4, 3));
cl_assert_equal_s(a.ptr, "happ");
- cl_git_pass(git_buf_common_prefix(&a, t5, 3));
+ cl_git_pass(git_str_common_prefix(&a, t5, 3));
cl_assert_equal_s(a.ptr, "happ");
- cl_git_pass(git_buf_common_prefix(&a, t6, 3));
+ cl_git_pass(git_str_common_prefix(&a, t6, 3));
cl_assert_equal_s(a.ptr, "");
- cl_git_pass(git_buf_common_prefix(&a, t7, 3));
+ cl_git_pass(git_str_common_prefix(&a, t7, 3));
cl_assert_equal_s(a.ptr, "");
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
-void test_core_buffer__rfind_variants(void)
+void test_core_gitstr__rfind_variants(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
ssize_t len;
- cl_git_pass(git_buf_sets(&a, "/this/is/it/"));
+ cl_git_pass(git_str_sets(&a, "/this/is/it/"));
- len = (ssize_t)git_buf_len(&a);
+ len = (ssize_t)git_str_len(&a);
- cl_assert(git_buf_rfind(&a, '/') == len - 1);
- cl_assert(git_buf_rfind_next(&a, '/') == len - 4);
+ cl_assert(git_str_rfind(&a, '/') == len - 1);
+ cl_assert(git_str_rfind_next(&a, '/') == len - 4);
- cl_assert(git_buf_rfind(&a, 'i') == len - 3);
- cl_assert(git_buf_rfind_next(&a, 'i') == len - 3);
+ cl_assert(git_str_rfind(&a, 'i') == len - 3);
+ cl_assert(git_str_rfind_next(&a, 'i') == len - 3);
- cl_assert(git_buf_rfind(&a, 'h') == 2);
- cl_assert(git_buf_rfind_next(&a, 'h') == 2);
+ cl_assert(git_str_rfind(&a, 'h') == 2);
+ cl_assert(git_str_rfind_next(&a, 'h') == 2);
- cl_assert(git_buf_rfind(&a, 'q') == -1);
- cl_assert(git_buf_rfind_next(&a, 'q') == -1);
+ cl_assert(git_str_rfind(&a, 'q') == -1);
+ cl_assert(git_str_rfind_next(&a, 'q') == -1);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
-void test_core_buffer__puts_escaped(void)
+void test_core_gitstr__puts_escaped(void)
{
- git_buf a = GIT_BUF_INIT;
+ git_str a = GIT_STR_INIT;
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "", ""));
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "", ""));
cl_assert_equal_s("this is a test", a.ptr);
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "t", "\\"));
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "t", "\\"));
cl_assert_equal_s("\\this is a \\tes\\t", a.ptr);
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escaped(&a, "this is a test", "i ", "__"));
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escaped(&a, "this is a test", "i ", "__"));
cl_assert_equal_s("th__is__ __is__ a__ test", a.ptr);
- git_buf_clear(&a);
- cl_git_pass(git_buf_puts_escape_regex(&a, "^match\\s*[A-Z]+.*"));
+ git_str_clear(&a);
+ cl_git_pass(git_str_puts_escape_regex(&a, "^match\\s*[A-Z]+.*"));
cl_assert_equal_s("\\^match\\\\s\\*\\[A-Z\\]\\+\\.\\*", a.ptr);
- git_buf_dispose(&a);
+ git_str_dispose(&a);
}
static void assert_unescape(char *expected, char *to_unescape) {
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&buf, to_unescape));
- git_buf_unescape(&buf);
+ cl_git_pass(git_str_sets(&buf, to_unescape));
+ git_str_unescape(&buf);
cl_assert_equal_s(expected, buf.ptr);
cl_assert_equal_sz(strlen(expected), buf.size);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__unescape(void)
+void test_core_gitstr__unescape(void)
{
assert_unescape("Escaped\\", "Es\\ca\\ped\\");
assert_unescape("Es\\caped\\", "Es\\\\ca\\ped\\\\");
@@ -731,9 +730,9 @@ void test_core_buffer__unescape(void)
assert_unescape("", "");
}
-void test_core_buffer__encode_base64(void)
+void test_core_gitstr__encode_base64(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* t h i s
* 0x 74 68 69 73
@@ -742,100 +741,100 @@ void test_core_buffer__encode_base64(void)
* 0x 1d 06 21 29 1c 30
* d G h p c w
*/
- cl_git_pass(git_buf_encode_base64(&buf, "this", 4));
+ cl_git_pass(git_str_encode_base64(&buf, "this", 4));
cl_assert_equal_s("dGhpcw==", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_encode_base64(&buf, "this!", 5));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_encode_base64(&buf, "this!", 5));
cl_assert_equal_s("dGhpcyE=", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_encode_base64(&buf, "this!\n", 6));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_encode_base64(&buf, "this!\n", 6));
cl_assert_equal_s("dGhpcyEK", buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__decode_base64(void)
+void test_core_gitstr__decode_base64(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcw==", 8));
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcw==", 8));
cl_assert_equal_s("this", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcyE=", 8));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcyE=", 8));
cl_assert_equal_s("this!", buf.ptr);
- git_buf_clear(&buf);
- cl_git_pass(git_buf_decode_base64(&buf, "dGhpcyEK", 8));
+ git_str_clear(&buf);
+ cl_git_pass(git_str_decode_base64(&buf, "dGhpcyEK", 8));
cl_assert_equal_s("this!\n", buf.ptr);
- cl_git_fail(git_buf_decode_base64(&buf, "This is not a valid base64 string!!!", 36));
+ cl_git_fail(git_str_decode_base64(&buf, "This is not a valid base64 string!!!", 36));
cl_assert_equal_s("this!\n", buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__encode_base85(void)
+void test_core_gitstr__encode_base85(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_encode_base85(&buf, "this", 4));
+ cl_git_pass(git_str_encode_base85(&buf, "this", 4));
cl_assert_equal_s("bZBXF", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- cl_git_pass(git_buf_encode_base85(&buf, "two rnds", 8));
+ cl_git_pass(git_str_encode_base85(&buf, "two rnds", 8));
cl_assert_equal_s("ba!tca&BaE", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- cl_git_pass(git_buf_encode_base85(&buf, "this is base 85 encoded",
+ cl_git_pass(git_str_encode_base85(&buf, "this is base 85 encoded",
strlen("this is base 85 encoded")));
cl_assert_equal_s("bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__decode_base85(void)
+void test_core_gitstr__decode_base85(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_decode_base85(&buf, "bZBXF", 5, 4));
+ cl_git_pass(git_str_decode_base85(&buf, "bZBXF", 5, 4));
cl_assert_equal_sz(4, buf.size);
cl_assert_equal_s("this", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- cl_git_pass(git_buf_decode_base85(&buf, "ba!tca&BaE", 10, 8));
+ cl_git_pass(git_str_decode_base85(&buf, "ba!tca&BaE", 10, 8));
cl_assert_equal_sz(8, buf.size);
cl_assert_equal_s("two rnds", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- cl_git_pass(git_buf_decode_base85(&buf, "bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", 30, 23));
+ cl_git_pass(git_str_decode_base85(&buf, "bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", 30, 23));
cl_assert_equal_sz(23, buf.size);
cl_assert_equal_s("this is base 85 encoded", buf.ptr);
- git_buf_clear(&buf);
+ git_str_clear(&buf);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__decode_base85_fails_gracefully(void)
+void test_core_gitstr__decode_base85_fails_gracefully(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_puts(&buf, "foobar");
+ git_str_puts(&buf, "foobar");
- cl_git_fail(git_buf_decode_base85(&buf, "invalid charsZZ", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "invalidchars__ ", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "overflowZZ~~~~~", 15, 42));
- cl_git_fail(git_buf_decode_base85(&buf, "truncated", 9, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "invalid charsZZ", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "invalidchars__ ", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "overflowZZ~~~~~", 15, 42));
+ cl_git_fail(git_str_decode_base85(&buf, "truncated", 9, 42));
cl_assert_equal_sz(6, buf.size);
cl_assert_equal_s("foobar", buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__classify_with_utf8(void)
+void test_core_gitstr__classify_with_utf8(void)
{
char *data0 = "Simple text\n";
size_t data0len = 12;
@@ -845,23 +844,23 @@ void test_core_buffer__classify_with_utf8(void)
size_t data2len = 29;
char *data3 = "\xef\xbb\xbfThis is UTF-8 with a BOM.\n";
size_t data3len = 20;
- git_buf b;
+ git_str b;
b.ptr = data0; b.size = b.asize = data0len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
b.ptr = data1; b.size = b.asize = data1len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
b.ptr = data2; b.size = b.asize = data2len;
- cl_assert(git_buf_is_binary(&b));
- cl_assert(git_buf_contains_nul(&b));
+ cl_assert(git_str_is_binary(&b));
+ cl_assert(git_str_contains_nul(&b));
b.ptr = data3; b.size = b.asize = data3len;
- cl_assert(!git_buf_is_binary(&b));
- cl_assert(!git_buf_contains_nul(&b));
+ cl_assert(!git_str_is_binary(&b));
+ cl_assert(!git_str_contains_nul(&b));
}
#define SIMILARITY_TEST_DATA_1 \
@@ -871,15 +870,15 @@ void test_core_buffer__classify_with_utf8(void)
"030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \
"040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n"
-void test_core_buffer__similarity_metric(void)
+void test_core_gitstr__similarity_metric(void)
{
git_hashsig *a, *b;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int sim;
/* in the first case, we compare data to itself and expect 100% match */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
@@ -890,9 +889,9 @@ void test_core_buffer__similarity_metric(void)
/* if we change just a single byte, how much does that change magnify? */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf,
+ cl_git_pass(git_str_sets(&buf,
"000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
"010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
"x020x\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \
@@ -910,9 +909,9 @@ void test_core_buffer__similarity_metric(void)
/* let's try comparing data to a superset of itself */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1
"050\n051\n052\n053\n054\n055\n056\n057\n058\n059\n"));
cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
@@ -926,9 +925,9 @@ void test_core_buffer__similarity_metric(void)
/* what if we keep about half the original data and add half new */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
- cl_git_pass(git_buf_sets(&buf,
+ cl_git_pass(git_str_sets(&buf,
"000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \
"010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \
"020x\n021\n022\n023\n024\n" \
@@ -948,7 +947,7 @@ void test_core_buffer__similarity_metric(void)
/* lastly, let's check that we can hash file content as well */
- cl_git_pass(git_buf_sets(&buf, SIMILARITY_TEST_DATA_1));
+ cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL));
cl_git_pass(git_futils_mkdir("scratch", 0755, GIT_MKDIR_PATH));
@@ -961,15 +960,15 @@ void test_core_buffer__similarity_metric(void)
git_hashsig_free(a);
git_hashsig_free(b);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
git_futils_rmdir_r("scratch", NULL, GIT_RMDIR_REMOVE_FILES);
}
-void test_core_buffer__similarity_metric_whitespace(void)
+void test_core_gitstr__similarity_metric_whitespace(void)
{
git_hashsig *a, *b;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
int sim, i, j;
git_hashsig_option_t opt;
const char *tabbed =
@@ -979,7 +978,7 @@ void test_core_buffer__similarity_metric_whitespace(void)
"\n"
" for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
" for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\n"
" cl_assert_equal_s(*expect, buf.ptr);\n"
" expect++;\n"
" }\n"
@@ -992,7 +991,7 @@ void test_core_buffer__similarity_metric_whitespace(void)
"\n"
" for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n"
" for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\n"
" cl_assert_equal_s(*expect, buf.ptr);\n"
" expect++;\n"
" }\n"
@@ -1005,7 +1004,7 @@ void test_core_buffer__similarity_metric_whitespace(void)
"\r\n"
" for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\r\n"
" for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\r\n"
- " git_buf_join(&buf, separator, a[i], b[j]);\r\n"
+ " git_str_join(&buf, separator, a[i], b[j]);\r\n"
" cl_assert_equal_s(*expect, buf.ptr);\r\n"
" expect++;\r\n"
" }\r\n"
@@ -1018,10 +1017,10 @@ void test_core_buffer__similarity_metric_whitespace(void)
for (opt = GIT_HASHSIG_NORMAL; opt <= GIT_HASHSIG_SMART_WHITESPACE; ++opt) {
for (i = 0; i < 3; ++i) {
for (j = 0; j < 3; ++j) {
- cl_git_pass(git_buf_sets(&buf, text[i]));
+ cl_git_pass(git_str_sets(&buf, text[i]));
cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, opt));
- cl_git_pass(git_buf_sets(&buf, text[j]));
+ cl_git_pass(git_str_sets(&buf, text[j]));
cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, opt));
sim = git_hashsig_compare(a, b);
@@ -1041,7 +1040,7 @@ void test_core_buffer__similarity_metric_whitespace(void)
}
}
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
#include "../filter/crlf.h"
@@ -1050,177 +1049,177 @@ void test_core_buffer__similarity_metric_whitespace(void)
cl_assert_equal_s(expected, buf.ptr); \
cl_assert_equal_sz(strlen(expected), buf.size); } while (0)
-void test_core_buffer__lf_and_crlf_conversions(void)
+void test_core_gitstr__lf_and_crlf_conversions(void)
{
- git_buf src = GIT_BUF_INIT, tgt = GIT_BUF_INIT;
+ git_str src = GIT_STR_INIT, tgt = GIT_STR_INIT;
/* LF source */
- git_buf_sets(&src, "lf\nlf\nlf\nlf\n");
+ git_str_sets(&src, "lf\nlf\nlf\nlf\n");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("lf\r\nlf\r\nlf\r\nlf\r\n", tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(src.ptr, tgt);
- git_buf_sets(&src, "\nlf\nlf\nlf\nlf\nlf");
+ git_str_sets(&src, "\nlf\nlf\nlf\nlf\nlf");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\r\nlf\r\nlf\r\nlf\r\nlf\r\nlf", tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(src.ptr, tgt);
/* CRLF source */
- git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
+ git_str_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n", tgt);
- git_buf_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
+ git_str_sets(&src, "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n");
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("crlf\ncrlf\ncrlf\ncrlf\n", tgt);
- git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
+ git_str_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf", tgt);
- git_buf_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
+ git_str_sets(&src, "\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf\r\ncrlf");
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\ncrlf\ncrlf\ncrlf\ncrlf\ncrlf", tgt);
/* CRLF in LF text */
- git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
+ git_str_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\r\nlf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\ncrlf\r\n", tgt);
- git_buf_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
+ git_str_sets(&src, "\nlf\nlf\ncrlf\r\nlf\nlf\ncrlf\r\n");
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\nlf\nlf\ncrlf\nlf\nlf\ncrlf\n", tgt);
/* LF in CRLF text */
- git_buf_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf");
+ git_str_sets(&src, "\ncrlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\r\ncrlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf", tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\ncrlf\ncrlf\nlf\ncrlf\ncrlf", tgt);
/* bare CR test */
- git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
+ git_str_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf("\rcrlf\r\nlf\r\nlf\r\ncr\rcrlf\r\nlf\r\ncr\r", tgt);
- git_buf_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
+ git_str_sets(&src, "\rcrlf\r\nlf\nlf\ncr\rcrlf\r\nlf\ncr\r");
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\rcrlf\nlf\nlf\ncr\rcrlf\nlf\ncr\r", tgt);
- git_buf_sets(&src, "\rcr\r");
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, "\rcr\r");
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(src.ptr, tgt);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf("\rcr\r", tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
/* blob correspondence tests */
- git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, ALL_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(ALL_CRLF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, ALL_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ git_str_sets(&src, ALL_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(ALL_CRLF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
- git_buf_sets(&src, ALL_LF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, ALL_LF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(ALL_LF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, ALL_LF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ git_str_sets(&src, ALL_LF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(ALL_LF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
- git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, MORE_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(MORE_CRLF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, MORE_CRLF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ git_str_sets(&src, MORE_CRLF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(MORE_CRLF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
- git_buf_sets(&src, MORE_LF_TEXT_RAW);
- cl_git_pass(git_buf_lf_to_crlf(&tgt, &src));
+ git_str_sets(&src, MORE_LF_TEXT_RAW);
+ cl_git_pass(git_str_lf_to_crlf(&tgt, &src));
check_buf(MORE_LF_TEXT_AS_CRLF, tgt);
- git_buf_sets(&src, MORE_LF_TEXT_RAW);
- cl_git_pass(git_buf_crlf_to_lf(&tgt, &src));
+ git_str_sets(&src, MORE_LF_TEXT_RAW);
+ cl_git_pass(git_str_crlf_to_lf(&tgt, &src));
check_buf(MORE_LF_TEXT_AS_LF, tgt);
- git_buf_dispose(&src);
- git_buf_dispose(&tgt);
+ git_str_dispose(&src);
+ git_str_dispose(&tgt);
}
-void test_core_buffer__dont_grow_borrowed(void)
+void test_core_gitstr__dont_grow_borrowed(void)
{
const char *somestring = "blah blah";
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- git_buf_attach_notowned(&buf, somestring, strlen(somestring) + 1);
+ git_str_attach_notowned(&buf, somestring, strlen(somestring) + 1);
cl_assert_equal_p(somestring, buf.ptr);
cl_assert_equal_i(0, buf.asize);
cl_assert_equal_i(strlen(somestring) + 1, buf.size);
- cl_git_fail_with(GIT_EINVALID, git_buf_grow(&buf, 1024));
+ cl_git_fail_with(GIT_EINVALID, git_str_grow(&buf, 1024));
}
-void test_core_buffer__dont_hit_infinite_loop_when_resizing(void)
+void test_core_gitstr__dont_hit_infinite_loop_when_resizing(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
- cl_git_pass(git_buf_puts(&buf, "foobar"));
+ cl_git_pass(git_str_puts(&buf, "foobar"));
/*
* We do not care whether this succeeds or fails, which
* would depend on platform-specific allocation
* semantics. We only want to know that the function
* actually returns.
*/
- (void)git_buf_try_grow(&buf, SIZE_MAX, true);
+ (void)git_str_try_grow(&buf, SIZE_MAX, true);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
-void test_core_buffer__avoid_printing_into_oom_buffer(void)
+void test_core_gitstr__avoid_printing_into_oom_buffer(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
/* Emulate OOM situation with a previous allocation */
buf.asize = 8;
- buf.ptr = git_buf__oom;
+ buf.ptr = git_str__oom;
/*
* Print the same string again. As the buffer still has
* an `asize` of 8 due to the previous print,
* `ENSURE_SIZE` would not try to reallocate the array at
- * all. As it didn't explicitly check for `git_buf__oom`
+ * all. As it didn't explicitly check for `git_str__oom`
* in earlier versions, this would've resulted in it
- * returning successfully and thus `git_buf_puts` would
- * just print into the `git_buf__oom` array.
+ * returning successfully and thus `git_str_puts` would
+ * just print into the `git_str__oom` array.
*/
- cl_git_fail(git_buf_puts(&buf, "foobar"));
+ cl_git_fail(git_str_puts(&buf, "foobar"));
}
diff --git a/tests/core/link.c b/tests/core/link.c
index 0493edf1d..6ab79b2a8 100644
--- a/tests/core/link.c
+++ b/tests/core/link.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "posix.h"
-#include "buffer.h"
#include "path.h"
#ifdef GIT_WIN32
@@ -82,7 +81,7 @@ static void do_junction(const char *old, const char *new)
{
GIT_REPARSE_DATA_BUFFER *reparse_buf;
HANDLE handle;
- git_buf unparsed_buf = GIT_BUF_INIT;
+ git_str unparsed_buf = GIT_STR_INIT;
wchar_t *subst_utf16, *print_utf16;
DWORD ioctl_ret;
int subst_utf16_len, subst_byte_len, print_utf16_len, print_byte_len, ret;
@@ -93,14 +92,14 @@ static void do_junction(const char *old, const char *new)
* backslashes instead of forward, and end in a trailing backslash.
* eg: \??\C:\Foo\
*/
- git_buf_puts(&unparsed_buf, "\\??\\");
+ git_str_puts(&unparsed_buf, "\\??\\");
for (i = 0; i < strlen(old); i++)
- git_buf_putc(&unparsed_buf, old[i] == '/' ? '\\' : old[i]);
+ git_str_putc(&unparsed_buf, old[i] == '/' ? '\\' : old[i]);
- git_buf_putc(&unparsed_buf, '\\');
+ git_str_putc(&unparsed_buf, '\\');
- subst_utf16_len = git__utf8_to_16(NULL, 0, git_buf_cstr(&unparsed_buf));
+ subst_utf16_len = git__utf8_to_16(NULL, 0, git_str_cstr(&unparsed_buf));
subst_byte_len = subst_utf16_len * sizeof(WCHAR);
print_utf16_len = subst_utf16_len - 4;
@@ -127,11 +126,11 @@ static void do_junction(const char *old, const char *new)
print_utf16 = subst_utf16 + subst_utf16_len + 1;
ret = git__utf8_to_16(subst_utf16, subst_utf16_len + 1,
- git_buf_cstr(&unparsed_buf));
+ git_str_cstr(&unparsed_buf));
cl_assert_equal_i(subst_utf16_len, ret);
ret = git__utf8_to_16(print_utf16,
- print_utf16_len + 1, git_buf_cstr(&unparsed_buf) + 4);
+ print_utf16_len + 1, git_str_cstr(&unparsed_buf) + 4);
cl_assert_equal_i(print_utf16_len, ret);
reparse_buf->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
@@ -147,7 +146,7 @@ static void do_junction(const char *old, const char *new)
CloseHandle(handle);
LocalFree(reparse_buf);
- git_buf_dispose(&unparsed_buf);
+ git_str_dispose(&unparsed_buf);
}
static void do_custom_reparse(const char *path)
@@ -300,7 +299,7 @@ void test_core_link__stat_dangling_symlink_directory(void)
void test_core_link__lstat_symlink(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
if (!should_run())
@@ -309,10 +308,10 @@ void test_core_link__lstat_symlink(void)
/* Windows always writes the canonical path as the link target, so
* write the full path on all platforms.
*/
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_target");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_target");
cl_git_rewritefile("lstat_target", "This is the target of a symbolic link.\n");
- do_symlink(git_buf_cstr(&target_path), "lstat_symlink", 0);
+ do_symlink(git_str_cstr(&target_path), "lstat_symlink", 0);
cl_must_pass(p_lstat("lstat_target", &st));
cl_assert(S_ISREG(st.st_mode));
@@ -320,32 +319,32 @@ void test_core_link__lstat_symlink(void)
cl_must_pass(p_lstat("lstat_symlink", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__lstat_symlink_directory(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_dirtarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_dirtarget");
p_mkdir("lstat_dirtarget", 0777);
- do_symlink(git_buf_cstr(&target_path), "lstat_dirlink", 1);
+ do_symlink(git_str_cstr(&target_path), "lstat_dirlink", 1);
cl_must_pass(p_lstat("lstat_dirtarget", &st));
cl_assert(S_ISDIR(st.st_mode));
cl_must_pass(p_lstat("lstat_dirlink", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__lstat_dangling_symlink(void)
@@ -383,13 +382,13 @@ void test_core_link__lstat_dangling_symlink_directory(void)
void test_core_link__stat_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "stat_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "stat_junctarget");
p_mkdir("stat_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "stat_junction");
+ do_junction(git_str_cstr(&target_path), "stat_junction");
cl_must_pass(p_stat("stat_junctarget", &st));
cl_assert(S_ISDIR(st.st_mode));
@@ -397,40 +396,40 @@ void test_core_link__stat_junction(void)
cl_must_pass(p_stat("stat_junction", &st));
cl_assert(S_ISDIR(st.st_mode));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__stat_dangling_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "stat_nonexistent_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "stat_nonexistent_junctarget");
p_mkdir("stat_nonexistent_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "stat_dangling_junction");
+ do_junction(git_str_cstr(&target_path), "stat_dangling_junction");
RemoveDirectory("stat_nonexistent_junctarget");
cl_must_fail(p_stat("stat_nonexistent_junctarget", &st));
cl_must_fail(p_stat("stat_dangling_junction", &st));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__lstat_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_junctarget");
p_mkdir("lstat_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "lstat_junction");
+ do_junction(git_str_cstr(&target_path), "lstat_junction");
cl_must_pass(p_lstat("lstat_junctarget", &st));
cl_assert(S_ISDIR(st.st_mode));
@@ -438,20 +437,20 @@ void test_core_link__lstat_junction(void)
cl_must_pass(p_lstat("lstat_junction", &st));
cl_assert(S_ISLNK(st.st_mode));
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
void test_core_link__lstat_dangling_junction(void)
{
#ifdef GIT_WIN32
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
struct stat st;
- git_buf_join(&target_path, '/', clar_sandbox_path(), "lstat_nonexistent_junctarget");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "lstat_nonexistent_junctarget");
p_mkdir("lstat_nonexistent_junctarget", 0777);
- do_junction(git_buf_cstr(&target_path), "lstat_dangling_junction");
+ do_junction(git_str_cstr(&target_path), "lstat_dangling_junction");
RemoveDirectory("lstat_nonexistent_junctarget");
@@ -459,9 +458,9 @@ void test_core_link__lstat_dangling_junction(void)
cl_must_pass(p_lstat("lstat_dangling_junction", &st));
cl_assert(S_ISLNK(st.st_mode));
- cl_assert_equal_i(git_buf_len(&target_path), st.st_size);
+ cl_assert_equal_i(git_str_len(&target_path), st.st_size);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
#endif
}
@@ -554,79 +553,79 @@ void test_core_link__readlink_normal_file(void)
void test_core_link__readlink_symlink(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_target");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_target");
cl_git_rewritefile("readlink_target", "This is the target of a symlink\n");
- do_symlink(git_buf_cstr(&target_path), "readlink_link", 0);
+ do_symlink(git_str_cstr(&target_path), "readlink_link", 0);
len = p_readlink("readlink_link", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&target_path), buf);
+ cl_assert_equal_s(git_str_cstr(&target_path), buf);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__readlink_dangling(void)
{
- git_buf target_path = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_nonexistent");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_nonexistent");
- do_symlink(git_buf_cstr(&target_path), "readlink_dangling", 0);
+ do_symlink(git_str_cstr(&target_path), "readlink_dangling", 0);
len = p_readlink("readlink_dangling", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&target_path), buf);
+ cl_assert_equal_s(git_str_cstr(&target_path), buf);
- git_buf_dispose(&target_path);
+ git_str_dispose(&target_path);
}
void test_core_link__readlink_multiple(void)
{
- git_buf target_path = GIT_BUF_INIT,
- path3 = GIT_BUF_INIT, path2 = GIT_BUF_INIT, path1 = GIT_BUF_INIT;
+ git_str target_path = GIT_STR_INIT,
+ path3 = GIT_STR_INIT, path2 = GIT_STR_INIT, path1 = GIT_STR_INIT;
int len;
char buf[2048];
if (!should_run())
clar__skip();
- git_buf_join(&target_path, '/', clar_sandbox_path(), "readlink_final");
- git_buf_join(&path3, '/', clar_sandbox_path(), "readlink_3");
- git_buf_join(&path2, '/', clar_sandbox_path(), "readlink_2");
- git_buf_join(&path1, '/', clar_sandbox_path(), "readlink_1");
+ git_str_join(&target_path, '/', clar_sandbox_path(), "readlink_final");
+ git_str_join(&path3, '/', clar_sandbox_path(), "readlink_3");
+ git_str_join(&path2, '/', clar_sandbox_path(), "readlink_2");
+ git_str_join(&path1, '/', clar_sandbox_path(), "readlink_1");
- do_symlink(git_buf_cstr(&target_path), git_buf_cstr(&path3), 0);
- do_symlink(git_buf_cstr(&path3), git_buf_cstr(&path2), 0);
- do_symlink(git_buf_cstr(&path2), git_buf_cstr(&path1), 0);
+ do_symlink(git_str_cstr(&target_path), git_str_cstr(&path3), 0);
+ do_symlink(git_str_cstr(&path3), git_str_cstr(&path2), 0);
+ do_symlink(git_str_cstr(&path2), git_str_cstr(&path1), 0);
len = p_readlink("readlink_1", buf, 2048);
cl_must_pass(len);
buf[len] = 0;
- cl_assert_equal_s(git_buf_cstr(&path2), buf);
+ cl_assert_equal_s(git_str_cstr(&path2), buf);
- git_buf_dispose(&path1);
- git_buf_dispose(&path2);
- git_buf_dispose(&path3);
- git_buf_dispose(&target_path);
+ git_str_dispose(&path1);
+ git_str_dispose(&path2);
+ git_str_dispose(&path3);
+ git_str_dispose(&target_path);
}
diff --git a/tests/core/mkdir.c b/tests/core/mkdir.c
index 3f04c2ad3..f0461ac1f 100644
--- a/tests/core/mkdir.c
+++ b/tests/core/mkdir.c
@@ -15,41 +15,41 @@ static void cleanup_basic_dirs(void *ref)
void test_core_mkdir__absolute(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(cleanup_basic_dirs, NULL);
- git_buf_joinpath(&path, clar_sandbox_path(), "d0");
+ git_str_joinpath(&path, clar_sandbox_path(), "d0");
/* make a directory */
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(git_path_isdir(path.ptr));
- git_buf_joinpath(&path, path.ptr, "subdir");
+ git_str_joinpath(&path, path.ptr, "subdir");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(git_path_isdir(path.ptr));
/* ensure mkdir_r works for a single subdir */
- git_buf_joinpath(&path, path.ptr, "another");
+ git_str_joinpath(&path, path.ptr, "another");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
cl_assert(git_path_isdir(path.ptr));
/* ensure mkdir_r works */
- git_buf_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf");
+ git_str_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf");
cl_assert(!git_path_isdir(path.ptr));
cl_git_pass(git_futils_mkdir_r(path.ptr, 0755));
cl_assert(git_path_isdir(path.ptr));
/* ensure we don't imply recursive */
- git_buf_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf");
+ git_str_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf");
cl_assert(!git_path_isdir(path.ptr));
cl_git_fail(git_futils_mkdir(path.ptr, 0755, 0));
cl_assert(!git_path_isdir(path.ptr));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_core_mkdir__basic(void)
@@ -230,7 +230,7 @@ void test_core_mkdir__chmods(void)
void test_core_mkdir__keeps_parent_symlinks(void)
{
#ifndef GIT_WIN32
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_set_cleanup(cleanup_basic_dirs, NULL);
@@ -250,14 +250,14 @@ void test_core_mkdir__keeps_parent_symlinks(void)
cl_must_pass(symlink("d0", "d2"));
cl_assert(git_path_islink("d2"));
- git_buf_joinpath(&path, clar_sandbox_path(), "d2/other/dir");
+ git_str_joinpath(&path, clar_sandbox_path(), "d2/other/dir");
cl_git_pass(git_futils_mkdir(path.ptr, 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS));
cl_assert(git_path_islink("d2"));
cl_assert(git_path_isdir("d2/other/dir"));
cl_assert(git_path_isdir("d0/other/dir"));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
#endif
}
diff --git a/tests/core/path.c b/tests/core/path.c
index eac3573fe..6decf23ea 100644
--- a/tests/core/path.c
+++ b/tests/core/path.c
@@ -4,12 +4,12 @@
static void
check_dirname(const char *A, const char *B)
{
- git_buf dir = GIT_BUF_INIT;
+ git_str dir = GIT_STR_INIT;
char *dir2;
cl_assert(git_path_dirname_r(&dir, A) >= 0);
cl_assert_equal_s(B, dir.ptr);
- git_buf_dispose(&dir);
+ git_str_dispose(&dir);
cl_assert((dir2 = git_path_dirname(A)) != NULL);
cl_assert_equal_s(B, dir2);
@@ -19,12 +19,12 @@ check_dirname(const char *A, const char *B)
static void
check_basename(const char *A, const char *B)
{
- git_buf base = GIT_BUF_INIT;
+ git_str base = GIT_STR_INIT;
char *base2;
cl_assert(git_path_basename_r(&base, A) >= 0);
cl_assert_equal_s(B, base.ptr);
- git_buf_dispose(&base);
+ git_str_dispose(&base);
cl_assert((base2 = git_path_basename(A)) != NULL);
cl_assert_equal_s(B, base2);
@@ -34,12 +34,12 @@ check_basename(const char *A, const char *B)
static void
check_joinpath(const char *path_a, const char *path_b, const char *expected_path)
{
- git_buf joined_path = GIT_BUF_INIT;
+ git_str joined_path = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&joined_path, path_a, path_b));
+ cl_git_pass(git_str_joinpath(&joined_path, path_a, path_b));
cl_assert_equal_s(expected_path, joined_path.ptr);
- git_buf_dispose(&joined_path);
+ git_str_dispose(&joined_path);
}
static void
@@ -50,13 +50,13 @@ check_joinpath_n(
const char *path_d,
const char *expected_path)
{
- git_buf joined_path = GIT_BUF_INIT;
+ git_str joined_path = GIT_STR_INIT;
- cl_git_pass(git_buf_join_n(&joined_path, '/', 4,
+ cl_git_pass(git_str_join_n(&joined_path, '/', 4,
path_a, path_b, path_c, path_d));
cl_assert_equal_s(expected_path, joined_path.ptr);
- git_buf_dispose(&joined_path);
+ git_str_dispose(&joined_path);
}
@@ -172,13 +172,13 @@ check_path_to_dir(
const char* path,
const char* expected)
{
- git_buf tgt = GIT_BUF_INIT;
+ git_str tgt = GIT_STR_INIT;
- git_buf_sets(&tgt, path);
+ git_str_sets(&tgt, path);
cl_git_pass(git_path_to_dir(&tgt));
cl_assert_equal_s(expected, tgt.ptr);
- git_buf_dispose(&tgt);
+ git_str_dispose(&tgt);
}
static void
@@ -231,46 +231,46 @@ void test_core_path__07_path_to_dir(void)
/* join path to itself */
void test_core_path__08_self_join(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
size_t asize = 0;
asize = path.asize;
- cl_git_pass(git_buf_sets(&path, "/foo"));
+ cl_git_pass(git_str_sets(&path, "/foo"));
cl_assert_equal_s(path.ptr, "/foo");
cl_assert(asize < path.asize);
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, "this is a new string"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, "this is a new string"));
cl_assert_equal_s(path.ptr, "/foo/this is a new string");
cl_assert(asize < path.asize);
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer"));
cl_assert_equal_s(path.ptr, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer");
cl_assert(asize < path.asize);
- git_buf_dispose(&path);
- cl_git_pass(git_buf_sets(&path, "/foo/bar"));
+ git_str_dispose(&path);
+ cl_git_pass(git_str_sets(&path, "/foo/bar"));
- cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "baz"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr + 4, "baz"));
cl_assert_equal_s(path.ptr, "/bar/baz");
asize = path.asize;
- cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc"));
+ cl_git_pass(git_str_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc"));
cl_assert_equal_s(path.ptr, "/baz/somethinglongenoughtorealloc");
cl_assert(asize < path.asize);
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
static void check_percent_decoding(const char *expected_result, const char *input)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_git_pass(git__percent_decode(&buf, input));
- cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_result, git_str_cstr(&buf));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_core_path__09_percent_decode(void)
@@ -289,17 +289,17 @@ void test_core_path__09_percent_decode(void)
static void check_fromurl(const char *expected_result, const char *input, int should_fail)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
assert(should_fail || expected_result);
if (!should_fail) {
cl_git_pass(git_path_fromurl(&buf, input));
- cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
+ cl_assert_equal_s(expected_result, git_str_cstr(&buf));
} else
cl_git_fail(git_path_fromurl(&buf, input));
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
#ifdef GIT_WIN32
@@ -353,7 +353,7 @@ static int check_one_walkup_step(void *ref, const char *path)
void test_core_path__11_walkup(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
char *expect[] = {
/* 1 */ "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL,
@@ -398,7 +398,7 @@ void test_core_path__11_walkup(void)
for (i = 0, j = 0; expect[i] != NULL; i++, j++) {
- git_buf_sets(&p, expect[i]);
+ git_str_sets(&p, expect[i]);
info.expect_idx = i;
cl_git_pass(
@@ -410,12 +410,12 @@ void test_core_path__11_walkup(void)
i = info.expect_idx;
}
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__11a_walkup_cancel(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
int cancel[] = { 3, 2, 1, 0 };
char *expect[] = {
"/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "[CANCEL]", NULL,
@@ -432,7 +432,7 @@ void test_core_path__11a_walkup_cancel(void)
for (i = 0, j = 0; expect[i] != NULL; i++, j++) {
- git_buf_sets(&p, expect[i]);
+ git_str_sets(&p, expect[i]);
info.cancel_after = cancel[j];
info.expect_idx = i;
@@ -446,7 +446,7 @@ void test_core_path__11a_walkup_cancel(void)
while (expect[i] != NULL) i++;
}
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__12_offset_to_path_root(void)
@@ -468,20 +468,20 @@ void test_core_path__12_offset_to_path_root(void)
void test_core_path__13_cannot_prettify_a_non_existing_file(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH), false);
cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH, NULL));
cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL));
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
void test_core_path__14_apply_relative(void)
{
- git_buf p = GIT_BUF_INIT;
+ git_str p = GIT_STR_INIT;
- cl_git_pass(git_buf_sets(&p, "/this/is/a/base"));
+ cl_git_pass(git_str_sets(&p, "/this/is/a/base"));
cl_git_pass(git_path_apply_relative(&p, "../test"));
cl_assert_equal_s("/this/is/a/test", p.ptr);
@@ -501,7 +501,7 @@ void test_core_path__14_apply_relative(void)
cl_git_fail(git_path_apply_relative(&p, "../../.."));
- cl_git_pass(git_buf_sets(&p, "d:/another/test"));
+ cl_git_pass(git_str_sets(&p, "d:/another/test"));
cl_git_pass(git_path_apply_relative(&p, "../.."));
cl_assert_equal_s("d:/", p.ptr);
@@ -510,7 +510,7 @@ void test_core_path__14_apply_relative(void)
cl_assert_equal_s("d:/from/here/and/back/", p.ptr);
- cl_git_pass(git_buf_sets(&p, "https://my.url.com/test.git"));
+ cl_git_pass(git_str_sets(&p, "https://my.url.com/test.git"));
cl_git_pass(git_path_apply_relative(&p, "../another.git"));
cl_assert_equal_s("https://my.url.com/another.git", p.ptr);
@@ -525,7 +525,7 @@ void test_core_path__14_apply_relative(void)
cl_assert_equal_s("https://", p.ptr);
- cl_git_pass(git_buf_sets(&p, "../../this/is/relative"));
+ cl_git_pass(git_str_sets(&p, "../../this/is/relative"));
cl_git_pass(git_path_apply_relative(&p, "../../preserves/the/prefix"));
cl_assert_equal_s("../../this/preserves/the/prefix", p.ptr);
@@ -535,20 +535,20 @@ void test_core_path__14_apply_relative(void)
cl_git_pass(git_path_apply_relative(&p, "../there"));
cl_assert_equal_s("../../there", p.ptr);
- git_buf_dispose(&p);
+ git_str_dispose(&p);
}
static void assert_resolve_relative(
- git_buf *buf, const char *expected, const char *path)
+ git_str *buf, const char *expected, const char *path)
{
- cl_git_pass(git_buf_sets(buf, path));
+ cl_git_pass(git_str_sets(buf, path));
cl_git_pass(git_path_resolve_relative(buf, 0));
cl_assert_equal_s(expected, buf->ptr);
}
void test_core_path__15_resolve_relative(void)
{
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
assert_resolve_relative(&buf, "", "");
assert_resolve_relative(&buf, "", ".");
@@ -595,22 +595,22 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "../../path", "../../test//../././path");
assert_resolve_relative(&buf, "../d", "a/b/../../../c/../d");
- cl_git_pass(git_buf_sets(&buf, "/.."));
+ cl_git_pass(git_str_sets(&buf, "/.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/./.."));
+ cl_git_pass(git_str_sets(&buf, "/./.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/.//.."));
+ cl_git_pass(git_str_sets(&buf, "/.//.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/../."));
+ cl_git_pass(git_str_sets(&buf, "/../."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "/../.././../a"));
+ cl_git_pass(git_str_sets(&buf, "/../.././../a"));
cl_git_fail(git_path_resolve_relative(&buf, 0));
- cl_git_pass(git_buf_sets(&buf, "////.."));
+ cl_git_pass(git_str_sets(&buf, "////.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
/* things that start with Windows network paths */
@@ -619,7 +619,7 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "//a/", "//a/b/..");
assert_resolve_relative(&buf, "//a/b/c", "//a/Q/../b/x/y/../../c");
- cl_git_pass(git_buf_sets(&buf, "//a/b/../.."));
+ cl_git_pass(git_str_sets(&buf, "//a/b/../.."));
cl_git_fail(git_path_resolve_relative(&buf, 0));
#else
assert_resolve_relative(&buf, "/a/b/c", "//a/b/c");
@@ -628,7 +628,7 @@ void test_core_path__15_resolve_relative(void)
assert_resolve_relative(&buf, "/", "//a/b/../..");
#endif
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
#define assert_common_dirlen(i, p, q) \
diff --git a/tests/core/posix.c b/tests/core/posix.c
index 1bb1e9c6b..247bd43f5 100644
--- a/tests/core/posix.c
+++ b/tests/core/posix.c
@@ -168,7 +168,7 @@ void test_core_posix__unlink_removes_symlink(void)
void test_core_posix__symlink_resolves_to_correct_type(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -187,12 +187,12 @@ void test_core_posix__symlink_resolves_to_correct_type(void)
cl_must_pass(p_rmdir("dir"));
cl_must_pass(p_rmdir("file"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_core_posix__relative_symlink(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -207,12 +207,12 @@ void test_core_posix__relative_symlink(void)
cl_must_pass(p_unlink("dir/link"));
cl_must_pass(p_rmdir("dir"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
void test_core_posix__symlink_to_file_across_dirs(void)
{
- git_buf contents = GIT_BUF_INIT;
+ git_str contents = GIT_STR_INIT;
if (!git_path_supports_symlinks(clar_sandbox_path()))
clar__skip();
@@ -234,5 +234,5 @@ void test_core_posix__symlink_to_file_across_dirs(void)
cl_must_pass(p_unlink("link"));
cl_must_pass(p_rmdir("dir"));
- git_buf_dispose(&contents);
+ git_str_dispose(&contents);
}
diff --git a/tests/core/rmdir.c b/tests/core/rmdir.c
index b436b97e0..56ea320be 100644
--- a/tests/core/rmdir.c
+++ b/tests/core/rmdir.c
@@ -5,26 +5,26 @@ static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
void test_core_rmdir__initialize(void)
{
- git_buf path = GIT_BUF_INIT;
+ git_str path = GIT_STR_INIT;
cl_must_pass(p_mkdir(empty_tmp_dir, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_one"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_one"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_two"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one/two_two/three"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/two"));
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/two"));
cl_must_pass(p_mkdir(path.ptr, 0777));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
void test_core_rmdir__cleanup(void)
@@ -36,25 +36,25 @@ void test_core_rmdir__cleanup(void)
/* make sure empty dir can be deleted recusively */
void test_core_rmdir__delete_recursive(void)
{
- git_buf path = GIT_BUF_INIT;
- cl_git_pass(git_buf_joinpath(&path, empty_tmp_dir, "/one"));
- cl_assert(git_path_exists(git_buf_cstr(&path)));
+ git_str path = GIT_STR_INIT;
+ cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one"));
+ cl_assert(git_path_exists(git_str_cstr(&path)));
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
- cl_assert(!git_path_exists(git_buf_cstr(&path)));
+ cl_assert(!git_path_exists(git_str_cstr(&path)));
- git_buf_dispose(&path);
+ git_str_dispose(&path);
}
/* make sure non-empty dir cannot be deleted recusively */
void test_core_rmdir__fail_to_delete_non_empty_dir(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
+ cl_git_pass(git_str_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
@@ -63,7 +63,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void)
cl_assert(!git_path_exists(empty_tmp_dir));
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
void test_core_rmdir__keep_base(void)
@@ -74,47 +74,47 @@ void test_core_rmdir__keep_base(void)
void test_core_rmdir__can_skip_non_empty_dir(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
- cl_git_pass(git_buf_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
+ cl_git_pass(git_str_joinpath(&file, empty_tmp_dir, "/two/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_NONEMPTY));
- cl_assert(git_path_exists(git_buf_cstr(&file)) == true);
+ cl_assert(git_path_exists(git_str_cstr(&file)) == true);
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(git_path_exists(empty_tmp_dir) == false);
- git_buf_dispose(&file);
+ git_str_dispose(&file);
}
void test_core_rmdir__can_remove_empty_parents(void)
{
- git_buf file = GIT_BUF_INIT;
+ git_str file = GIT_STR_INIT;
cl_git_pass(
- git_buf_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
- cl_git_mkfile(git_buf_cstr(&file), "dummy");
- cl_assert(git_path_isfile(git_buf_cstr(&file)));
+ git_str_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt"));
+ cl_git_mkfile(git_str_cstr(&file), "dummy");
+ cl_assert(git_path_isfile(git_str_cstr(&file)));
cl_git_pass(git_futils_rmdir_r("one/two_two/three/file.txt", empty_tmp_dir,
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_EMPTY_PARENTS));
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
- cl_assert(!git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */
+ cl_assert(!git_path_exists(git_str_cstr(&file)));
- git_buf_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
- cl_assert(git_path_exists(git_buf_cstr(&file)));
+ git_str_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */
+ cl_assert(git_path_exists(git_str_cstr(&file)));
cl_assert(git_path_exists(empty_tmp_dir) == true);
- git_buf_dispose(&file);
+ git_str_dispose(&file);
cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY));
}
diff --git a/tests/core/sortedcache.c b/tests/core/sortedcache.c
index d5bbcea19..cb4e34efa 100644
--- a/tests/core/sortedcache.c
+++ b/tests/core/sortedcache.c
@@ -241,7 +241,7 @@ void test_core_sortedcache__in_memory(void)
static void sortedcache_test_reload(git_sortedcache *sc)
{
int count = 0;
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
char *scan, *after;
sortedcache_test_struct *item;
@@ -266,7 +266,7 @@ static void sortedcache_test_reload(git_sortedcache *sc)
git_sortedcache_wunlock(sc);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
void test_core_sortedcache__on_disk(void)
diff --git a/tests/core/stat.c b/tests/core/stat.c
index 7f5d66753..56d141e98 100644
--- a/tests/core/stat.c
+++ b/tests/core/stat.c
@@ -98,17 +98,17 @@ void test_core_stat__0(void)
void test_core_stat__root(void)
{
const char *sandbox = clar_sandbox_path();
- git_buf root = GIT_BUF_INIT;
+ git_str root = GIT_STR_INIT;
int root_len;
struct stat st;
root_len = git_path_root(sandbox);
cl_assert(root_len >= 0);
- git_buf_set(&root, sandbox, root_len+1);
+ git_str_set(&root, sandbox, root_len+1);
cl_must_pass(p_stat(root.ptr, &st));
cl_assert(S_ISDIR(st.st_mode));
- git_buf_dispose(&root);
+ git_str_dispose(&root);
}
diff --git a/tests/core/useragent.c b/tests/core/useragent.c
index 2ce935bf5..a4ece902f 100644
--- a/tests/core/useragent.c
+++ b/tests/core/useragent.c
@@ -4,7 +4,7 @@
void test_core_useragent__get(void)
{
const char *custom_name = "super duper git";
- git_buf buf = GIT_BUF_INIT;
+ git_str buf = GIT_STR_INIT;
cl_assert_equal_p(NULL, git_libgit2__user_agent());
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_USER_AGENT, custom_name));
@@ -13,5 +13,5 @@ void test_core_useragent__get(void)
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_USER_AGENT, &buf));
cl_assert_equal_s(custom_name, buf.ptr);
- git_buf_dispose(&buf);
+ git_str_dispose(&buf);
}
diff --git a/tests/core/zstream.c b/tests/core/zstream.c
index 3cbcea168..c22e81008 100644
--- a/tests/core/zstream.c
+++ b/tests/core/zstream.c
@@ -1,5 +1,4 @@
#include "clar_libgit2.h"
-#include "buffer.h"
#include "zstream.h"
static const char *data = "This is a test test test of This is a test";
@@ -60,7 +59,7 @@ void test_core_zstream__basic(void)
void test_core_zstream__fails_on_trailing_garbage(void)
{
- git_buf deflated = GIT_BUF_INIT, inflated = GIT_BUF_INIT;
+ git_str deflated = GIT_STR_INIT, inflated = GIT_STR_INIT;
char i = 0;
/* compress a simple string */
@@ -68,29 +67,29 @@ void test_core_zstream__fails_on_trailing_garbage(void)
/* append some garbage */
for (i = 0; i < 10; i++) {
- git_buf_putc(&deflated, i);
+ git_str_putc(&deflated, i);
}
cl_git_fail(git_zstream_inflatebuf(&inflated, deflated.ptr, deflated.size));
- git_buf_dispose(&deflated);
- git_buf_dispose(&inflated);
+ git_str_dispose(&deflated);
+ git_str_dispose(&inflated);
}
void test_core_zstream__buffer(void)
{
- git_buf out = GIT_BUF_INIT;
+ git_str out = GIT_STR_INIT;
cl_git_pass(git_zstream_deflatebuf(&out, data, strlen(data) + 1));
assert_zlib_equal(data, strlen(data) + 1, out.ptr, out.size);
- git_buf_dispose(&out);
+ git_str_dispose(&out);
}
#define BIG_STRING_PART "Big Data IS Big - Long Data IS Long - We need a buffer larger than 1024 x 1024 to make sure we trigger chunked compression - Big Big Data IS Bigger than Big - Long Long Data IS Longer than Long"
-static void compress_and_decompress_input_various_ways(git_buf *input)
+static void compress_and_decompress_input_various_ways(git_str *input)
{
- git_buf out1 = GIT_BUF_INIT, out2 = GIT_BUF_INIT;
- git_buf inflated = GIT_BUF_INIT;
+ git_str out1 = GIT_STR_INIT, out2 = GIT_STR_INIT;
+ git_str inflated = GIT_STR_INIT;
size_t i, fixed_size = max(input->size / 2, 256);
char *fixed = git__malloc(fixed_size);
cl_assert(fixed);
@@ -119,7 +118,7 @@ static void compress_and_decompress_input_various_ways(git_buf *input)
while (!git_zstream_done(&zs)) {
size_t written = use_fixed_size;
cl_git_pass(git_zstream_get_output(fixed, &written, &zs));
- cl_git_pass(git_buf_put(&out2, fixed, written));
+ cl_git_pass(git_str_put(&out2, fixed, written));
}
git_zstream_free(&zs);
@@ -129,30 +128,30 @@ static void compress_and_decompress_input_various_ways(git_buf *input)
cl_assert_equal_sz(out1.size, out2.size);
cl_assert(!memcmp(out1.ptr, out2.ptr, out1.size));
- git_buf_dispose(&out2);
+ git_str_dispose(&out2);
}
cl_git_pass(git_zstream_inflatebuf(&inflated, out1.ptr, out1.size));
cl_assert_equal_i(input->size, inflated.size);
cl_assert(memcmp(input->ptr, inflated.ptr, inflated.size) == 0);
- git_buf_dispose(&out1);
- git_buf_dispose(&inflated);
+ git_str_dispose(&out1);
+ git_str_dispose(&inflated);
git__free(fixed);
}
void test_core_zstream__big_data(void)
{
- git_buf in = GIT_BUF_INIT;
+ git_str in = GIT_STR_INIT;
size_t scan, target;
for (target = 1024; target <= 1024 * 1024 * 4; target *= 8) {
/* make a big string that's easy to compress */
- git_buf_clear(&in);
+ git_str_clear(&in);
while (in.size < target)
cl_git_pass(
- git_buf_put(&in, BIG_STRING_PART, strlen(BIG_STRING_PART)));
+ git_str_put(&in, BIG_STRING_PART, strlen(BIG_STRING_PART)));
compress_and_decompress_input_various_ways(&in);
@@ -164,5 +163,5 @@ void test_core_zstream__big_data(void)
compress_and_decompress_input_various_ways(&in);
}
- git_buf_dispose(&in);
+ git_str_dispose(&in);
}