summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-01-26 16:03:37 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2014-01-27 04:44:05 +0100
commitb25d87c9cdef0bc09007c756d7e52f15eb4622d7 (patch)
tree6f95b302cac224f89739b223a14e3ec00da23731 /tests
parent7a3bd1e73215f8939f270092e0673d6c0f3f32af (diff)
downloadlibgit2-b25d87c9cdef0bc09007c756d7e52f15eb4622d7.tar.gz
branch: move to git_buf when outputting newly-allocated strings
Internally we already did everything with git_bufs, so this is just exposing those functions with public names.
Diffstat (limited to 'tests')
-rw-r--r--tests/clone/empty.c12
-rw-r--r--tests/refs/branches/remote.c39
-rw-r--r--tests/refs/branches/upstreamname.c10
3 files changed, 20 insertions, 41 deletions
diff --git a/tests/clone/empty.c b/tests/clone/empty.c
index 6d19244cc..78aef7dae 100644
--- a/tests/clone/empty.c
+++ b/tests/clone/empty.c
@@ -38,7 +38,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
char *local_name = "refs/heads/master";
const char *expected_tracked_branch_name = "refs/remotes/origin/master";
const char *expected_remote_name = "origin";
- char buffer[1024];
+ git_buf buf = GIT_BUF_INIT;
git_reference *ref;
cl_set_cleanup(&cleanup_repository, "./empty");
@@ -50,16 +50,14 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name));
/* ...one can still retrieve the name of the remote tracking reference */
- cl_assert_equal_i((int)strlen(expected_tracked_branch_name) + 1,
- git_branch_upstream_name(buffer, 1024, g_repo_cloned, local_name));
+ cl_git_pass(git_branch_upstream_name(&buf, g_repo_cloned, local_name));
- cl_assert_equal_s(expected_tracked_branch_name, buffer);
+ cl_assert_equal_s(expected_tracked_branch_name, buf.ptr);
/* ...and the name of the remote... */
- cl_assert_equal_i((int)strlen(expected_remote_name) + 1,
- git_branch_remote_name(buffer, 1024, g_repo_cloned, expected_tracked_branch_name));
+ cl_git_pass(git_branch_remote_name(&buf, g_repo_cloned, expected_tracked_branch_name));
- cl_assert_equal_s(expected_remote_name, buffer);
+ cl_assert_equal_s(expected_remote_name, buf.ptr);
/* ...even when the remote HEAD is unborn as well */
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned,
diff --git a/tests/refs/branches/remote.c b/tests/refs/branches/remote.c
index c110adb33..bac088454 100644
--- a/tests/refs/branches/remote.c
+++ b/tests/refs/branches/remote.c
@@ -21,53 +21,40 @@ void test_refs_branches_remote__cleanup(void)
void test_refs_branches_remote__can_get_remote_for_branch(void)
{
- char remotename[1024] = {0};
+ git_buf remotename = {0};
- cl_assert_equal_i(expected_remote_name_length,
- git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name));
+ cl_git_pass(git_branch_remote_name(&remotename, g_repo, remote_tracking_branch_name));
- cl_assert_equal_i(expected_remote_name_length,
- git_branch_remote_name(remotename, expected_remote_name_length, g_repo,
- remote_tracking_branch_name));
-
- cl_assert_equal_s("test", remotename);
-}
-
-void test_refs_branches_remote__insufficient_buffer_returns_error(void)
-{
- char remotename[1024] = {0};
-
- cl_assert_equal_i(expected_remote_name_length,
- git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name));
-
- cl_git_fail_with(git_branch_remote_name(remotename,
- expected_remote_name_length - 1, g_repo, remote_tracking_branch_name),
- expected_remote_name_length);
+ cl_assert_equal_s("test", remotename.ptr);
+ git_buf_free(&remotename);
}
void test_refs_branches_remote__no_matching_remote_returns_error(void)
{
const char *unknown = "refs/remotes/nonexistent/master";
+ git_buf buf;
giterr_clear();
- cl_git_fail_with(git_branch_remote_name(
- NULL, 0, g_repo, unknown), GIT_ENOTFOUND);
+ memset(&buf, 0, sizeof(git_buf));
+ cl_git_fail_with(git_branch_remote_name(&buf, g_repo, unknown), GIT_ENOTFOUND);
cl_assert(giterr_last() != NULL);
}
void test_refs_branches_remote__local_remote_returns_error(void)
{
const char *local = "refs/heads/master";
+ git_buf buf;
giterr_clear();
- cl_git_fail_with(git_branch_remote_name(
- NULL, 0, g_repo, local), GIT_ERROR);
+ memset(&buf, 0, sizeof(git_buf));
+ cl_git_fail_with(git_branch_remote_name(&buf, g_repo, local), GIT_ERROR);
cl_assert(giterr_last() != NULL);
}
void test_refs_branches_remote__ambiguous_remote_returns_error(void)
{
git_remote *remote;
+ git_buf buf;
/* Create the remote */
cl_git_pass(git_remote_create(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2"));
@@ -80,7 +67,7 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void)
git_remote_free(remote);
giterr_clear();
- cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo,
- remote_tracking_branch_name), GIT_EAMBIGUOUS);
+ memset(&buf, 0, sizeof(git_buf));
+ cl_git_fail_with(git_branch_remote_name(&buf, g_repo, remote_tracking_branch_name), GIT_EAMBIGUOUS);
cl_assert(giterr_last() != NULL);
}
diff --git a/tests/refs/branches/upstreamname.c b/tests/refs/branches/upstreamname.c
index f05607d44..d30002e08 100644
--- a/tests/refs/branches/upstreamname.c
+++ b/tests/refs/branches/upstreamname.c
@@ -21,7 +21,7 @@ void test_refs_branches_upstreamname__cleanup(void)
void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference_name_of_a_local_branch(void)
{
- cl_git_pass(git_branch_upstream__name(
+ cl_git_pass(git_branch_upstream_name(
&upstream_name, repo, "refs/heads/master"));
cl_assert_equal_s("refs/remotes/test/master", git_buf_cstr(&upstream_name));
@@ -29,14 +29,8 @@ void test_refs_branches_upstreamname__can_retrieve_the_remote_tracking_reference
void test_refs_branches_upstreamname__can_retrieve_the_local_upstream_reference_name_of_a_local_branch(void)
{
- cl_git_pass(git_branch_upstream__name(
+ cl_git_pass(git_branch_upstream_name(
&upstream_name, repo, "refs/heads/track-local"));
cl_assert_equal_s("refs/heads/master", git_buf_cstr(&upstream_name));
}
-
-void test_refs_branches_upstreamname__can_return_the_size_of_thelocal_upstream_reference_name_of_a_local_branch(void)
-{
- cl_assert_equal_i((int)strlen("refs/heads/master") + 1,
- git_branch_upstream_name(NULL, 0, repo, "refs/heads/track-local"));
-}