]> git.proxmox.com Git - libgit2.git/blob - tests/graph/ahead_behind.c
77d7768afe416e7211220e3966398a8ad4f5fbc8
[libgit2.git] / tests / graph / ahead_behind.c
1 #include "clar_libgit2.h"
2
3 static git_repository *_repo;
4 static git_commit *commit;
5 static size_t ahead;
6 static size_t behind;
7
8 void test_graph_ahead_behind__initialize(void)
9 {
10 git_oid oid;
11 cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
12
13 cl_git_pass(git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
14 cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
15 }
16
17 void test_graph_ahead_behind__cleanup(void)
18 {
19 git_commit_free(commit);
20 commit = NULL;
21
22 git_repository_free(_repo);
23 _repo = NULL;
24 }
25
26 void test_graph_ahead_behind__returns_correct_result(void)
27 {
28 git_oid oid;
29 git_oid oid2;
30 git_commit *other;
31
32 cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d"));
33 cl_git_pass(git_oid_fromstr(&oid2, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"));
34
35 cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &oid, &oid2));
36 cl_assert_equal_sz(2, ahead);
37 cl_assert_equal_sz(6, behind);
38
39 cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(commit)));
40 cl_assert_equal_sz(ahead, behind);
41 cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 1));
42
43 cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(other)));
44 cl_assert_equal_sz(ahead, behind + 2);
45 cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(other), git_commit_id(commit)));
46 cl_assert_equal_sz(ahead + 2, behind);
47
48 git_commit_free(other);
49
50 cl_git_pass(git_commit_nth_gen_ancestor(&other, commit, 3));
51
52 cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(commit), git_commit_id(other)));
53 cl_assert_equal_sz(ahead, behind + 4);
54 cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, git_commit_id(other), git_commit_id(commit)));
55 cl_assert_equal_sz(ahead + 4, behind);
56
57 git_commit_free(other);
58 }