]> git.proxmox.com Git - libgit2.git/blobdiff - tests/apply/fromfile.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / apply / fromfile.c
index ec2b889b3dc8257a84015a5fe108367d76fc660a..8cde623928a89aed18a7cbfb62efc2c6fb507c1f 100644 (file)
@@ -2,8 +2,9 @@
 #include "git2/sys/repository.h"
 
 #include "apply.h"
+#include "patch.h"
+#include "patch_parse.h"
 #include "repository.h"
-#include "buf_text.h"
 
 #include "../patch/patch_common.h"
 
@@ -29,27 +30,28 @@ static int apply_patchfile(
        unsigned int mode_expected)
 {
        git_patch *patch;
-       git_buf result = GIT_BUF_INIT;
-       git_buf patchbuf = GIT_BUF_INIT;
+       git_str result = GIT_STR_INIT;
+       git_str patchbuf = GIT_STR_INIT;
        char *filename;
        unsigned int mode;
        int error;
 
-       cl_git_pass(git_patch_from_patchfile(&patch, patchfile, strlen(patchfile), NULL));
+       cl_git_pass(git_patch_from_buffer(&patch, patchfile, strlen(patchfile), NULL));
 
-       error = git_apply__patch(&result, &filename, &mode, old, old_len, patch);
+       error = git_apply__patch(&result, &filename, &mode, old, old_len, patch, NULL);
 
        if (error == 0) {
                cl_assert_equal_i(new_len, result.size);
-               cl_assert(memcmp(new, result.ptr, new_len) == 0);
+               if (new_len)
+                       cl_assert(memcmp(new, result.ptr, new_len) == 0);
 
                cl_assert_equal_s(filename_expected, filename);
                cl_assert_equal_i(mode_expected, mode);
        }
 
        git__free(filename);
-       git_buf_free(&result);
-       git_buf_free(&patchbuf);
+       git_str_dispose(&result);
+       git_str_dispose(&patchbuf);
        git_patch_free(patch);
 
        return error;
@@ -79,7 +81,7 @@ static int validate_and_apply_patchfile(
 
        error = apply_patchfile(old, old_len, new, new_len, patchfile, filename_expected, mode_expected);
 
-       git_buf_free(&validated);
+       git_buf_dispose(&validated);
        git_patch_free(patch_fromdiff);
 
        return error;
@@ -308,28 +310,28 @@ void test_apply_fromfile__noisy_nocontext(void)
 void test_apply_fromfile__fail_truncated_1(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_1,
+       cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_1,
                strlen(PATCH_TRUNCATED_1), NULL));
 }
 
 void test_apply_fromfile__fail_truncated_2(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_2,
+       cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_2,
                strlen(PATCH_TRUNCATED_2), NULL));
 }
 
 void test_apply_fromfile__fail_truncated_3(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch, PATCH_TRUNCATED_3,
+       cl_git_fail(git_patch_from_buffer(&patch, PATCH_TRUNCATED_3,
                strlen(PATCH_TRUNCATED_3), NULL));
 }
 
 void test_apply_fromfile__fail_corrupt_githeader(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch, PATCH_CORRUPT_GIT_HEADER,
+       cl_git_fail(git_patch_from_buffer(&patch, PATCH_CORRUPT_GIT_HEADER,
                strlen(PATCH_CORRUPT_GIT_HEADER), NULL));
 }
 
@@ -353,7 +355,7 @@ void test_apply_fromfile__append_no_nl(void)
 void test_apply_fromfile__fail_missing_new_file(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch,
+       cl_git_fail(git_patch_from_buffer(&patch,
                PATCH_CORRUPT_MISSING_NEW_FILE,
                strlen(PATCH_CORRUPT_MISSING_NEW_FILE), NULL));
 }
@@ -361,7 +363,7 @@ void test_apply_fromfile__fail_missing_new_file(void)
 void test_apply_fromfile__fail_missing_old_file(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch,
+       cl_git_fail(git_patch_from_buffer(&patch,
                PATCH_CORRUPT_MISSING_OLD_FILE,
                strlen(PATCH_CORRUPT_MISSING_OLD_FILE), NULL));
 }
@@ -369,7 +371,7 @@ void test_apply_fromfile__fail_missing_old_file(void)
 void test_apply_fromfile__fail_no_changes(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch,
+       cl_git_fail(git_patch_from_buffer(&patch,
                PATCH_CORRUPT_NO_CHANGES,
                strlen(PATCH_CORRUPT_NO_CHANGES), NULL));
 }
@@ -377,7 +379,7 @@ void test_apply_fromfile__fail_no_changes(void)
 void test_apply_fromfile__fail_missing_hunk_header(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch,
+       cl_git_fail(git_patch_from_buffer(&patch,
                PATCH_CORRUPT_MISSING_HUNK_HEADER,
                strlen(PATCH_CORRUPT_MISSING_HUNK_HEADER), NULL));
 }
@@ -385,7 +387,7 @@ void test_apply_fromfile__fail_missing_hunk_header(void)
 void test_apply_fromfile__fail_not_a_patch(void)
 {
        git_patch *patch;
-       cl_git_fail(git_patch_from_patchfile(&patch, PATCH_NOT_A_PATCH,
+       cl_git_fail(git_patch_from_buffer(&patch, PATCH_NOT_A_PATCH,
                strlen(PATCH_NOT_A_PATCH), NULL));
 }
 
@@ -442,6 +444,6 @@ void test_apply_fromfile__empty_file_not_allowed(void)
 {
        git_patch *patch;
 
-       cl_git_fail(git_patch_from_patchfile(&patch, "", 0, NULL));
-       cl_git_fail(git_patch_from_patchfile(&patch, NULL, 0, NULL));
+       cl_git_fail(git_patch_from_buffer(&patch, "", 0, NULL));
+       cl_git_fail(git_patch_from_buffer(&patch, NULL, 0, NULL));
 }