2 #include "test_helpers.h"
5 #include <git/commit.h>
7 static char *test_commits_broken
[] = {
13 "asd97sa9du902e9a0jdsuusad09as9du098709aweu8987sd\n",
16 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\r\n\
17 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\r\n\
18 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\r\n\
19 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\r\n\
21 a test commit with broken endlines\r\n",
24 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\
25 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\
26 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\
27 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\
29 another test commit with broken endlines",
32 "\ntree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
33 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
34 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
35 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
37 a test commit with a starting endline\n",
40 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
41 parent 05452d6349abcd67aa396df",
44 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
48 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
52 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
55 // FIXME: duplicated parents?
56 // It this supposed to pass?
58 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
59 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
60 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
61 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
62 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
69 static char *test_commits_working
[] = {
70 // simple commit with no message
71 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
72 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
73 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
76 // simple commit, no parent
77 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
78 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
79 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
81 a simple commit which works\n",
83 // simple commit, 1 parents
84 "tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
85 parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
86 author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
87 committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
89 a simple commit which works\n",
92 BEGIN_TEST(parse_oid_test
)
96 #define TEST_OID_PASS(string, header){ \
98 char *ptr_original = ptr;\
99 size_t len = strlen(ptr);\
100 must_pass(git_commit__parse_oid(&oid, &ptr, ptr + len, header));\
101 must_be_true(ptr == ptr_original + len);\
104 #define TEST_OID_FAIL(string, header){ \
106 size_t len = strlen(ptr);\
107 must_fail(git_commit__parse_oid(&oid, &ptr, ptr + len, header));\
110 TEST_OID_PASS("parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent ");
111 TEST_OID_PASS("tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree ");
112 TEST_OID_PASS("random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading ");
113 TEST_OID_PASS("stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading");
114 TEST_OID_PASS("tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree ");
115 TEST_OID_PASS("tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree ");
116 TEST_OID_PASS("tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree ");
117 TEST_OID_PASS("tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree ");
119 TEST_OID_FAIL("parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent ");
120 TEST_OID_FAIL("05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree ");
121 TEST_OID_FAIL("parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent ");
122 TEST_OID_FAIL("parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent ");
123 TEST_OID_FAIL("tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree ");
124 TEST_OID_FAIL("parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent ");
125 TEST_OID_FAIL("parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent ");
126 TEST_OID_FAIL("", "tree ");
127 TEST_OID_FAIL("", "");
134 BEGIN_TEST(parse_buffer_test
)
135 const int broken_commit_count
= sizeof(test_commits_broken
) / sizeof(*test_commits_broken
);
136 const int working_commit_count
= sizeof(test_commits_working
) / sizeof(*test_commits_working
);
139 for (i
= 0; i
< broken_commit_count
; ++i
) {
144 must_fail(git_commit__parse_buffer(
146 test_commits_broken
[i
],
147 strlen(test_commits_broken
[i
]))
151 for (i
= 0; i
< working_commit_count
; ++i
) {
156 must_pass(git_commit__parse_buffer(
158 test_commits_working
[i
],
159 strlen(test_commits_working
[i
]))