]>
git.proxmox.com Git - libgit2.git/blob - tests/t0401-parse.c
2 #include "test_helpers.h"
5 #include <git/commit.h>
6 #include <git/revwalk.h>
8 static char *test_commits_broken
[] = {
14 "asd97sa9du902e9a0jdsuusad09as9du098709aweu8987sd\n",
16 /* broken endlines 1 */
17 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\r\n\
18 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\r\n\
19 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\r\n\
20 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\r\n\
22 a test commit with broken endlines\r\n",
24 /* broken endlines 2 */
25 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\
26 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\
27 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\
28 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\
30 another test commit with broken endlines",
32 /* starting endlines */
33 "\ntree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
34 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
35 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
36 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
38 a test commit with a starting endline\n",
40 /* corrupted commit 1 */
41 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
42 parent 05452d6349abcd67aa396df",
44 /* corrupted commit 2 */
45 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
48 /* corrupted commit 3 */
49 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
52 /* corrupted commit 4 */
53 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
59 static char *test_commits_working
[] = {
60 /* simple commit with no message */
61 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
62 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
63 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
66 /* simple commit, no parent */
67 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
68 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
69 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
71 a simple commit which works\n",
73 /* simple commit, 1 parents */
74 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
75 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
76 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
77 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
79 a simple commit which works\n",
82 BEGIN_TEST(parse_oid_test
)
86 #define TEST_OID_PASS(string, header) { \
88 char *ptr_original = ptr;\
89 size_t len = strlen(ptr);\
90 must_pass(git__parse_oid(&oid, &ptr, ptr + len, header));\
91 must_be_true(ptr == ptr_original + len);\
94 #define TEST_OID_FAIL(string, header) { \
96 size_t len = strlen(ptr);\
97 must_fail(git__parse_oid(&oid, &ptr, ptr + len, header));\
100 TEST_OID_PASS("parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent ");
101 TEST_OID_PASS("tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree ");
102 TEST_OID_PASS("random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading ");
103 TEST_OID_PASS("stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading");
104 TEST_OID_PASS("tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree ");
105 TEST_OID_PASS("tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree ");
106 TEST_OID_PASS("tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree ");
107 TEST_OID_PASS("tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree ");
109 TEST_OID_FAIL("parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent ");
110 TEST_OID_FAIL("05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree ");
111 TEST_OID_FAIL("parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent ");
112 TEST_OID_FAIL("parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent ");
113 TEST_OID_FAIL("tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree ");
114 TEST_OID_FAIL("parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent ");
115 TEST_OID_FAIL("parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent ");
116 TEST_OID_FAIL("", "tree ");
117 TEST_OID_FAIL("", "");
124 BEGIN_TEST(parse_person_test
)
126 #define TEST_PERSON_PASS(_string, _header, _name, _email, _time) { \
127 char *ptr = _string; \
128 size_t len = strlen(_string);\
130 must_pass(git__parse_person(&person, &ptr, ptr + len, _header));\
131 must_be_true(strncmp(_name, person.name, 63) == 0);\
132 must_be_true(strncmp(_email, person.email, 63) == 0);\
133 must_be_true(_time == person.time);\
136 #define TEST_PERSON_FAIL(_string, _header) { \
137 char *ptr = _string; \
138 size_t len = strlen(_string);\
140 must_fail(git__parse_person(&person, &ptr, ptr + len, _header));\
144 "author Vicent Marti <tanoku@gmail.com> 12345 \n",
151 "author Vicent Marti <> 12345 \n",
158 "author Vicent Marti <tanoku@gmail.com> 231301 +2020\n",
165 "author Vicent Marti with an outrageously long name \
166 which will probably overflow the buffer <tanoku@gmail.com> 12345 \n",
168 "Vicent Marti with an outrageously long name \
169 which will probably overflow the buffer",
174 "author Vicent Marti <tanokuwithaveryveryverylongemail\
175 whichwillprobablyvoverflowtheemailbuffer@gmail.com> 12345 \n",
178 "tanokuwithaveryveryverylongemail\
179 whichwillprobablyvoverflowtheemailbuffer@gmail.com",
183 "author Vicent Marti <tanoku@gmail.com> 12345 \n",
187 "author Vicent Marti <tanoku@gmail.com> 12345 \n",
191 "author Vicent Marti 12345 \n",
195 "author Vicent Marti <broken@email 12345 \n",
199 "author Vicent Marti <tanoku@gmail.com> notime \n",
203 "author Vicent Marti <tanoku@gmail.com>\n",
210 #undef TEST_PERSON_PASS
211 #undef TESt_PERSON_FAIL
215 BEGIN_TEST(parse_buffer_test
)
216 const int broken_commit_count
= sizeof(test_commits_broken
) / sizeof(*test_commits_broken
);
217 const int working_commit_count
= sizeof(test_commits_working
) / sizeof(*test_commits_working
);
219 const unsigned int default_flags
= 0xFF; /* parse everything */
223 git_revpool
*pool
= gitrp_alloc(NULL
);
225 for (i
= 0; i
< broken_commit_count
; ++i
) {
227 commit
= git__malloc(sizeof(git_commit
));
228 memset(commit
, 0x0, sizeof(git_commit
));
229 commit
->object
.pool
= pool
;
231 must_fail(git_commit__parse_buffer(
233 test_commits_broken
[i
],
234 strlen(test_commits_broken
[i
]),
238 git_commit__free(commit
);
241 for (i
= 0; i
< working_commit_count
; ++i
) {
243 commit
= git__malloc(sizeof(git_commit
));
244 memset(commit
, 0x0, sizeof(git_commit
));
245 commit
->object
.pool
= pool
;
247 must_pass(git_commit__parse_buffer(
249 test_commits_working
[i
],
250 strlen(test_commits_working
[i
]),
254 git_commit__free(commit
);