libgit-thin: Introduces git_revlist_exclude()
[git/libgit-gsoc.git] / libgit-thin / tests / simple.c
blob4e271414d7878baff0c33afd7fc2d5470abf43d8
1 #include "tests.h"
2 #include "simple.h"
3 #include "misc.h"
5 const char *git_repository_dir2;
7 START_TEST(git_revlist_three_commits_test)
9 int ret;
10 size_t len;
11 char *msg_spec;
12 const char *msg;
13 struct git_commit *commit;
14 struct git_revlist_opt *opt;
15 unsigned char sha1[GIT_SHA1_SIZE];
17 ret = git_repo_open(git_repository_dir2);
18 fail_unless(ret == 0, "Can't initialize repository [%d]\n", ret);
20 commit = git_commit_init();
21 fail_unless(commit != NULL, "commit is NULL\n");
23 opt = git_revlist_init();
24 fail_unless(opt != NULL, "opt is NULL\n");
26 ret = git_repo_head(sha1);
27 fail_unless(ret == 0, "git_hex_to_sha1() failed: %s", strerror(errno));
29 ret = git_revlist_include(opt, sha1);
30 fail_unless(ret == 0, "git_revlist_include() failed: %d", ret);
33 * Get the top commit
35 ret = git_revlist_next(opt, commit);
36 fail_unless(ret == 1, "No commit to get (ret is 0)\n");
38 spec_file_get_checked("TEST_FILE3_COMMIT3", &msg_spec, &len);
39 msg = git_commit_message(commit);
40 fail_unless(msg != NULL, "msg is NULL\n");
41 /* FIXME: spec_file_get() doesn't the trailing '\n' */
42 fail_unless(!memcmp(msg_spec, msg, len-1), "%s != %s\n", msg_spec, msg);
43 free(msg_spec);
46 * Get the next commit
48 ret = git_revlist_next(opt, commit);
49 fail_unless(ret == 1, "No commit to get (ret is 0)\n");
51 spec_file_get_checked("TEST_FILE2_COMMIT2", &msg_spec, &len);
52 msg = git_commit_message(commit);
53 fail_unless(msg != NULL, "msg is NULL\n");
54 /* FIXME: spec_file_get() doesn't the trailing '\n' */
55 fail_unless(!memcmp(msg_spec, msg, len-1), "%s != %s\n", msg_spec, msg);
56 free(msg_spec);
59 * Get the last commit
61 ret = git_revlist_next(opt, commit);
62 fail_unless(ret == 1, "No commit to get (ret is 0)\n");
64 spec_file_get_checked("TEST_FILE2_COMMIT1", &msg_spec, &len);
65 msg = git_commit_message(commit);
66 fail_unless(msg != NULL, "msg is NULL\n");
67 /* FIXME: spec_file_get() doesn't the trailing '\n' */
68 fail_unless(!memcmp(msg_spec, msg, len-1), "%s != %s\n", msg_spec, msg);
69 free(msg_spec);
72 * The end...
74 ret = git_revlist_next(opt, commit);
75 fail_unless(ret == 0, "There should be only three commits [%d]\n",ret);
77 git_commit_free(commit);
78 git_revlist_free(opt);
80 END_TEST
82 START_TEST(git_revlist_exclude_test)
84 int ret;
85 size_t len;
86 const char *msg;
87 char *msg_spec, *hex_spec;
88 struct git_commit *commit;
89 struct git_revlist_opt *opt;
90 unsigned char sha1[GIT_SHA1_SIZE];
91 unsigned char sha2[GIT_SHA1_SIZE];
93 ret = git_repo_open(git_repository_dir2);
94 fail_unless(ret == 0, "Can't initialize repository [%d]\n", ret);
96 commit = git_commit_init();
97 fail_unless(commit != NULL, "commit is NULL\n");
99 opt = git_revlist_init();
100 fail_unless(opt != NULL, "opt is NULL\n");
102 ret = git_repo_head(sha1);
103 fail_unless(ret == 0, "git_hex_to_sha1() failed: %s", strerror(errno));
105 ret = git_revlist_include(opt, sha1);
106 fail_unless(ret == 0, "git_revlist_include() failed: %d", ret);
108 spec_file_get_checked("TEST_FILE2_COMMIT_ID", &hex_spec, &len);
109 ret = git_hex_to_sha1(hex_spec, sha2);
110 fail_unless(ret == 0, "git_hex_to_sha1() failed: %d", ret);
112 ret = git_revlist_exclude(opt, sha2);
113 fail_unless(ret == 0, "git_revlist_exclude() failed: %d", ret);
116 * Get the top commit
118 ret = git_revlist_next(opt, commit);
119 fail_unless(ret == 1, "No commit to get (ret is 0)\n");
121 spec_file_get_checked("TEST_FILE3_COMMIT3", &msg_spec, &len);
122 msg = git_commit_message(commit);
123 fail_unless(msg != NULL, "msg is NULL\n");
124 /* FIXME: spec_file_get() doesn't the trailing '\n' */
125 fail_unless(!memcmp(msg_spec, msg, len-1), "%s != %s\n", msg_spec, msg);
126 free(msg_spec);
128 #warning "There's a #if 0 here"
129 #if 0
130 Check _exclude() semantics with Shawn
132 * Get the next (last) commit
134 ret = git_revlist_next(opt, commit);
135 fail_unless(ret == 1, "No commit to get (ret is 0)\n");
137 spec_file_get_checked("TEST_FILE2_COMMIT1", &msg_spec, &len);
138 msg = git_commit_message(commit);
139 fail_unless(msg != NULL, "msg is NULL\n");
140 /* FIXME: spec_file_get() doesn't the trailing '\n' */
141 fail_unless(!memcmp(msg_spec, msg, len-1), "%s != %s\n", msg_spec, msg);
142 free(msg_spec);
143 #endif
146 * The end...
148 ret = git_revlist_next(opt, commit);
149 fail_unless(ret == 0, "There should be only three commits [%d]\n",ret);
151 git_commit_free(commit);
152 git_revlist_free(opt);
154 END_TEST
157 * Simple test-suite: Performs tests based on simple real-life
158 * scenarios.
160 * The tests cases in this suite performs what one would expect from
161 * common usage scenarios.
163 Suite *test_suite_simple(void)
165 Suite *s;
166 TCase *tc_revlist;
168 s = suite_create("Simple");
170 tc_revlist = tcase_create("Three commits revlist");
171 suite_add_tcase(s, tc_revlist);
172 tcase_add_test(tc_revlist, git_revlist_three_commits_test);
173 tcase_add_test(tc_revlist, git_revlist_exclude_test);
175 return s;