]> git.proxmox.com Git - libgit2.git/blob - tests/patch/print.c
New upstream version 1.1.0+dfsg.1
[libgit2.git] / tests / patch / print.c
1 #include "clar_libgit2.h"
2 #include "patch.h"
3 #include "patch_parse.h"
4
5 #include "patch_common.h"
6
7
8 /* sanity check the round-trip of patch parsing: ensure that we can parse
9 * and then print a variety of patch files.
10 */
11
12 void patch_print_from_patchfile(const char *data, size_t len)
13 {
14 git_patch *patch;
15 git_buf buf = GIT_BUF_INIT;
16
17 cl_git_pass(git_patch_from_buffer(&patch, data, len, NULL));
18 cl_git_pass(git_patch_to_buf(&buf, patch));
19
20 cl_assert_equal_s(data, buf.ptr);
21
22 git_patch_free(patch);
23 git_buf_dispose(&buf);
24 }
25
26 void test_patch_print__change_middle(void)
27 {
28 patch_print_from_patchfile(PATCH_ORIGINAL_TO_CHANGE_MIDDLE,
29 strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE));
30 }
31
32 void test_patch_print__change_middle_nocontext(void)
33 {
34 patch_print_from_patchfile(PATCH_ORIGINAL_TO_CHANGE_MIDDLE_NOCONTEXT,
35 strlen(PATCH_ORIGINAL_TO_CHANGE_MIDDLE_NOCONTEXT));
36 }
37
38 void test_patch_print__change_firstline(void)
39 {
40 patch_print_from_patchfile(PATCH_ORIGINAL_TO_CHANGE_FIRSTLINE,
41 strlen(PATCH_ORIGINAL_TO_CHANGE_FIRSTLINE));
42 }
43
44 void test_patch_print__change_lastline(void)
45 {
46 patch_print_from_patchfile(PATCH_ORIGINAL_TO_CHANGE_LASTLINE,
47 strlen(PATCH_ORIGINAL_TO_CHANGE_LASTLINE));
48 }
49
50 void test_patch_print__prepend(void)
51 {
52 patch_print_from_patchfile(PATCH_ORIGINAL_TO_PREPEND,
53 strlen(PATCH_ORIGINAL_TO_PREPEND));
54 }
55
56 void test_patch_print__prepend_nocontext(void)
57 {
58 patch_print_from_patchfile(PATCH_ORIGINAL_TO_PREPEND_NOCONTEXT,
59 strlen(PATCH_ORIGINAL_TO_PREPEND_NOCONTEXT));
60 }
61
62 void test_patch_print__append(void)
63 {
64 patch_print_from_patchfile(PATCH_ORIGINAL_TO_APPEND,
65 strlen(PATCH_ORIGINAL_TO_APPEND));
66 }
67
68 void test_patch_print__append_nocontext(void)
69 {
70 patch_print_from_patchfile(PATCH_ORIGINAL_TO_APPEND_NOCONTEXT,
71 strlen(PATCH_ORIGINAL_TO_APPEND_NOCONTEXT));
72 }
73
74 void test_patch_print__prepend_and_append(void)
75 {
76 patch_print_from_patchfile(PATCH_ORIGINAL_TO_PREPEND_AND_APPEND,
77 strlen(PATCH_ORIGINAL_TO_PREPEND_AND_APPEND));
78 }
79
80 void test_patch_print__to_empty_file(void)
81 {
82 patch_print_from_patchfile(PATCH_ORIGINAL_TO_EMPTY_FILE,
83 strlen(PATCH_ORIGINAL_TO_EMPTY_FILE));
84 }
85
86 void test_patch_print__from_empty_file(void)
87 {
88 patch_print_from_patchfile(PATCH_EMPTY_FILE_TO_ORIGINAL,
89 strlen(PATCH_EMPTY_FILE_TO_ORIGINAL));
90 }
91
92 void test_patch_print__add(void)
93 {
94 patch_print_from_patchfile(PATCH_ADD_ORIGINAL,
95 strlen(PATCH_ADD_ORIGINAL));
96 }
97
98 void test_patch_print__delete(void)
99 {
100 patch_print_from_patchfile(PATCH_DELETE_ORIGINAL,
101 strlen(PATCH_DELETE_ORIGINAL));
102 }
103
104 void test_patch_print__rename_exact(void)
105 {
106 patch_print_from_patchfile(PATCH_RENAME_EXACT,
107 strlen(PATCH_RENAME_EXACT));
108 }
109
110 void test_patch_print__rename_exact_with_mode(void)
111 {
112 patch_print_from_patchfile(PATCH_RENAME_EXACT_WITH_MODE,
113 strlen(PATCH_RENAME_EXACT_WITH_MODE));
114 }
115
116 void test_patch_print__rename_similar(void)
117 {
118 patch_print_from_patchfile(PATCH_RENAME_SIMILAR,
119 strlen(PATCH_RENAME_SIMILAR));
120 }
121
122 void test_patch_print__rename_exact_quotedname(void)
123 {
124 patch_print_from_patchfile(PATCH_RENAME_EXACT_QUOTEDNAME,
125 strlen(PATCH_RENAME_EXACT_QUOTEDNAME));
126 }
127
128 void test_patch_print__rename_similar_quotedname(void)
129 {
130 patch_print_from_patchfile(PATCH_RENAME_SIMILAR_QUOTEDNAME,
131 strlen(PATCH_RENAME_SIMILAR_QUOTEDNAME));
132 }
133
134 void test_patch_print__modechange_unchanged(void)
135 {
136 patch_print_from_patchfile(PATCH_MODECHANGE_UNCHANGED,
137 strlen(PATCH_MODECHANGE_UNCHANGED));
138 }
139
140 void test_patch_print__modechange_modified(void)
141 {
142 patch_print_from_patchfile(PATCH_MODECHANGE_MODIFIED,
143 strlen(PATCH_MODECHANGE_MODIFIED));
144 }
145
146 void test_patch_print__binary_literal(void)
147 {
148 patch_print_from_patchfile(PATCH_BINARY_LITERAL,
149 strlen(PATCH_BINARY_LITERAL));
150 }
151
152 void test_patch_print__binary_delta(void)
153 {
154 patch_print_from_patchfile(PATCH_BINARY_DELTA,
155 strlen(PATCH_BINARY_DELTA));
156 }
157
158 void test_patch_print__binary_add(void)
159 {
160 patch_print_from_patchfile(PATCH_BINARY_ADD,
161 strlen(PATCH_BINARY_ADD));
162 }
163
164 void test_patch_print__binary_delete(void)
165 {
166 patch_print_from_patchfile(PATCH_BINARY_DELETE,
167 strlen(PATCH_BINARY_DELETE));
168 }
169
170 void test_patch_print__not_reversible(void)
171 {
172 patch_print_from_patchfile(PATCH_BINARY_NOT_REVERSIBLE,
173 strlen(PATCH_BINARY_NOT_REVERSIBLE));
174 }
175
176 void test_patch_print__binary_not_shown(void)
177 {
178 patch_print_from_patchfile(PATCH_BINARY_NOT_PRINTED,
179 strlen(PATCH_BINARY_NOT_PRINTED));
180 }
181
182 void test_patch_print__binary_add_not_shown(void)
183 {
184 patch_print_from_patchfile(PATCH_ADD_BINARY_NOT_PRINTED,
185 strlen(PATCH_ADD_BINARY_NOT_PRINTED));
186 }