summaryrefslogtreecommitdiff
path: root/tests/odb/foreach.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/odb/foreach.c')
-rw-r--r--tests/odb/foreach.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/tests/odb/foreach.c b/tests/odb/foreach.c
index ebb8866f7..256ae9cd7 100644
--- a/tests/odb/foreach.c
+++ b/tests/odb/foreach.c
@@ -5,7 +5,6 @@
static git_odb *_odb;
static git_repository *_repo;
-static int nobj;
void test_odb_foreach__cleanup(void)
{
@@ -18,10 +17,10 @@ void test_odb_foreach__cleanup(void)
static int foreach_cb(const git_oid *oid, void *data)
{
- GIT_UNUSED(data);
- GIT_UNUSED(oid);
+ int *nobj = data;
+ (*nobj)++;
- nobj++;
+ GIT_UNUSED(oid);
return 0;
}
@@ -38,43 +37,46 @@ static int foreach_cb(const git_oid *oid, void *data)
*/
void test_odb_foreach__foreach(void)
{
+ int nobj = 0;
+
cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
git_repository_odb(&_odb, _repo);
- cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL));
+ cl_git_pass(git_odb_foreach(_odb, foreach_cb, &nobj));
cl_assert_equal_i(47 + 1640, nobj); /* count + in-pack */
}
void test_odb_foreach__one_pack(void)
{
git_odb_backend *backend = NULL;
+ int nobj = 0;
cl_git_pass(git_odb_new(&_odb));
cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx")));
cl_git_pass(git_odb_add_backend(_odb, backend, 1));
_repo = NULL;
- nobj = 0;
- cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL));
+ cl_git_pass(git_odb_foreach(_odb, foreach_cb, &nobj));
cl_assert(nobj == 1628);
}
static int foreach_stop_cb(const git_oid *oid, void *data)
{
- GIT_UNUSED(data);
- GIT_UNUSED(oid);
+ int *nobj = data;
+ (*nobj)++;
- nobj++;
+ GIT_UNUSED(oid);
- return (nobj == 1000);
+ return (*nobj == 1000) ? -321 : 0;
}
void test_odb_foreach__interrupt_foreach(void)
{
- nobj = 0;
+ int nobj = 0;
+
cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
git_repository_odb(&_odb, _repo);
- cl_assert_equal_i(GIT_EUSER, git_odb_foreach(_odb, foreach_stop_cb, NULL));
+ cl_assert_equal_i(-321, git_odb_foreach(_odb, foreach_stop_cb, &nobj));
cl_assert(nobj == 1000);
}