diff options
| author | Vicent Martà <tanoku@gmail.com> | 2012-01-02 09:58:39 +0100 |
|---|---|---|
| committer | Vicent Martà <tanoku@gmail.com> | 2012-01-02 09:58:39 +0100 |
| commit | 7a704309ae012b8e92eb6103b0d14dd3c22a1cb5 (patch) | |
| tree | a0e917d553db5fc4475be2fff7004268dc36d13d /tests-clay/object | |
| parent | 9191a6d2466d0f3c187a66f65757c95c1c3f772d (diff) | |
| parent | 0fb3fba123d8fbd99a9e1f9f47c192c704daee24 (diff) | |
| download | libgit2-7a704309ae012b8e92eb6103b0d14dd3c22a1cb5.tar.gz | |
Merge remote-tracking branch 'drizzd/diff-index-tests' into development
Conflicts:
tests-clay/clay.h
tests-clay/clay_main.c
Diffstat (limited to 'tests-clay/object')
| -rw-r--r-- | tests-clay/object/tree/diff.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/tests-clay/object/tree/diff.c b/tests-clay/object/tree/diff.c index 471e46544..b2c7f6913 100644 --- a/tests-clay/object/tree/diff.c +++ b/tests-clay/object/tree/diff.c @@ -2,8 +2,8 @@ #include "tree.h" #include "repository.h" -static unsigned int expect_idx; static git_repository *repo; +static git_index *theindex; static git_tree *atree, *btree; static git_oid aoid, boid; @@ -27,9 +27,18 @@ static int diff_cb(const git_tree_diff_data *diff, void *data) return GIT_SUCCESS; } +static void test_diff(git_tree *a, git_tree *b, git_tree_diff_cb cb, void *data) +{ + cl_must_pass(git_tree_diff(a, b, cb, data)); + + cl_git_pass(git_index_read_tree(theindex, b)); + cl_git_pass(git_tree_diff_index_recursive(a, theindex, cb, data)); +} + void test_object_tree_diff__initialize(void) { cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); + cl_git_pass(git_repository_index(&theindex, repo)); } void test_object_tree_diff__cleanup(void) @@ -58,7 +67,7 @@ void test_object_tree_diff__addition(void) cl_must_pass(git_tree_lookup(&atree, repo, &aoid)); cl_must_pass(git_tree_lookup(&btree, repo, &boid)); - cl_must_pass(git_tree_diff(atree, btree, diff_cb, &expect)); + test_diff(atree, btree, diff_cb, &expect); } void test_object_tree_diff__deletion(void) @@ -79,7 +88,7 @@ void test_object_tree_diff__deletion(void) cl_must_pass(git_tree_lookup(&atree, repo, &aoid)); cl_must_pass(git_tree_lookup(&btree, repo, &boid)); - cl_must_pass(git_tree_diff(atree, btree, diff_cb, &expect)); + test_diff(atree, btree, diff_cb, &expect); } void test_object_tree_diff__modification(void) @@ -101,13 +110,20 @@ void test_object_tree_diff__modification(void) cl_must_pass(git_tree_lookup(&atree, repo, &aoid)); cl_must_pass(git_tree_lookup(&btree, repo, &boid)); - cl_must_pass(git_tree_diff(atree, btree, diff_cb, &expect)); + test_diff(atree, btree, diff_cb, &expect); } +struct diff_more_data { + git_tree_diff_data expect[3]; + int expect_idx; +}; + static int diff_more_cb(const git_tree_diff_data *diff, void *data) { - git_tree_diff_data *expect = (git_tree_diff_data *) data; - diff_cmp(diff, &expect[expect_idx++]); + struct diff_more_data *more_data = data; + diff_cmp(diff, &more_data->expect[more_data->expect_idx]); + + more_data->expect_idx = (more_data->expect_idx + 1) % ARRAY_SIZE(more_data->expect); return GIT_SUCCESS; } @@ -116,9 +132,10 @@ void test_object_tree_diff__more(void) { char *astr = "814889a078c031f61ed08ab5fa863aea9314344d"; char *bstr = "75057dd4114e74cca1d750d0aee1647c903cb60a"; - git_tree_diff_data expect[3]; + struct diff_more_data more_data; + git_tree_diff_data *expect = more_data.expect; - memset(expect, 0x0, 3 * sizeof(git_tree_diff_data)); + memset(&more_data, 0x0, sizeof(struct diff_more_data)); /* M README */ expect[0].old_attr = 0100644; expect[0].new_attr = 0100644; @@ -146,5 +163,5 @@ void test_object_tree_diff__more(void) cl_must_pass(git_tree_lookup(&atree, repo, &aoid)); cl_must_pass(git_tree_lookup(&btree, repo, &boid)); - cl_must_pass(git_tree_diff(atree, btree, diff_more_cb, expect)); + test_diff(atree, btree, diff_more_cb, &more_data); } |
