]> git.proxmox.com Git - libgit2.git/blob - tests/odb/foreach.c
Merge pull request #1962 from libgit2/rename-tests
[libgit2.git] / tests / odb / foreach.c
1 #include "clar_libgit2.h"
2 #include "odb.h"
3 #include "git2/odb_backend.h"
4 #include "pack.h"
5
6 static git_odb *_odb;
7 static git_repository *_repo;
8 static int nobj;
9
10 void test_odb_foreach__cleanup(void)
11 {
12 git_odb_free(_odb);
13 git_repository_free(_repo);
14
15 _odb = NULL;
16 _repo = NULL;
17 }
18
19 static int foreach_cb(const git_oid *oid, void *data)
20 {
21 GIT_UNUSED(data);
22 GIT_UNUSED(oid);
23
24 nobj++;
25
26 return 0;
27 }
28
29 /*
30 * $ git --git-dir tests/resources/testrepo.git count-objects --verbose
31 * count: 47
32 * size: 4
33 * in-pack: 1640
34 * packs: 3
35 * size-pack: 425
36 * prune-packable: 0
37 * garbage: 0
38 */
39 void test_odb_foreach__foreach(void)
40 {
41 cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
42 git_repository_odb(&_odb, _repo);
43
44 cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL));
45 cl_assert_equal_i(47 + 1640, nobj); /* count + in-pack */
46 }
47
48 void test_odb_foreach__one_pack(void)
49 {
50 git_odb_backend *backend = NULL;
51
52 cl_git_pass(git_odb_new(&_odb));
53 cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
54 cl_git_pass(git_odb_add_backend(_odb, backend, 1));
55 _repo = NULL;
56
57 nobj = 0;
58 cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL));
59 cl_assert(nobj == 1628);
60 }
61
62 static int foreach_stop_cb(const git_oid *oid, void *data)
63 {
64 GIT_UNUSED(data);
65 GIT_UNUSED(oid);
66
67 nobj++;
68
69 return (nobj == 1000);
70 }
71
72 void test_odb_foreach__interrupt_foreach(void)
73 {
74 nobj = 0;
75 cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
76 git_repository_odb(&_odb, _repo);
77
78 cl_assert_equal_i(GIT_EUSER, git_odb_foreach(_odb, foreach_stop_cb, NULL));
79 cl_assert(nobj == 1000);
80 }