diff options
Diffstat (limited to 'tests/t05-revwalk.c')
| -rw-r--r-- | tests/t05-revwalk.c | 114 |
1 files changed, 19 insertions, 95 deletions
diff --git a/tests/t05-revwalk.c b/tests/t05-revwalk.c index fd009fac1..cfcf01066 100644 --- a/tests/t05-revwalk.c +++ b/tests/t05-revwalk.c @@ -25,8 +25,6 @@ #include "test_lib.h" #include "test_helpers.h" -#include "revwalk.h" - /* $ git log --oneline --graph --decorate * a4a7dce (HEAD, br2) Merge branch 'master' into br2 @@ -70,12 +68,12 @@ static const int commit_sorting_time_reverse[][6] = { static const int result_bytes = 24; -static int get_commit_index(git_commit *commit) +static int get_commit_index(git_oid *raw_oid) { int i; char oid[40]; - git_oid_fmt(oid, &commit->object.id); + git_oid_fmt(oid, raw_oid); for (i = 0; i < commit_count; ++i) if (memcmp(oid, commit_ids[i], 40) == 0) @@ -84,23 +82,31 @@ static int get_commit_index(git_commit *commit) return -1; } -static int test_walk(git_revwalk *walk, git_commit *start_from, +static int test_walk(git_revwalk *walk, const git_oid *root, int flags, const int possible_results[][6], int results_count) { - git_commit *commit = NULL; + git_oid oid; int i; int result_array[commit_count]; git_revwalk_sorting(walk, flags); - git_revwalk_push(walk, start_from); + git_revwalk_push(walk, root); for (i = 0; i < commit_count; ++i) result_array[i] = -1; i = 0; - while (git_revwalk_next(&commit, walk) == GIT_SUCCESS) - result_array[i++] = get_commit_index(commit); + + while (git_revwalk_next(&oid, walk) == GIT_SUCCESS) { + result_array[i++] = get_commit_index(&oid); + /*{ + char str[41]; + git_oid_fmt(str, &oid); + str[40] = 0; + printf(" %d) %s\n", i, str); + }*/ + } for (i = 0; i < results_count; ++i) if (memcmp(possible_results[i], @@ -114,103 +120,21 @@ BEGIN_TEST(walk0, "do a simple walk on a repo with different sorting modes") git_oid id; git_repository *repo; git_revwalk *walk; - git_commit *head = NULL; must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_revwalk_new(&walk, repo)); git_oid_mkstr(&id, commit_head); - must_pass(git_commit_lookup(&head, repo, &id)); - - must_pass(test_walk(walk, head, - GIT_SORT_TIME, - commit_sorting_time, 1)); - - must_pass(test_walk(walk, head, - GIT_SORT_TOPOLOGICAL, - commit_sorting_topo, 2)); - - must_pass(test_walk(walk, head, - GIT_SORT_TIME | GIT_SORT_REVERSE, - commit_sorting_time_reverse, 1)); - - must_pass(test_walk(walk, head, - GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE, - commit_sorting_topo_reverse, 2)); - + must_pass(test_walk(walk, &id, GIT_SORT_TIME, commit_sorting_time, 1)); + must_pass(test_walk(walk, &id, GIT_SORT_TOPOLOGICAL, commit_sorting_topo, 2)); + must_pass(test_walk(walk, &id, GIT_SORT_TIME | GIT_SORT_REVERSE, commit_sorting_time_reverse, 1)); + must_pass(test_walk(walk, &id, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE, commit_sorting_topo_reverse, 2)); git_revwalk_free(walk); git_repository_free(repo); END_TEST -BEGIN_TEST(list0, "check that a commit list is properly sorted by time") - - git_revwalk_list list; - git_revwalk_listnode *n; - int i, t; - time_t previous_time; - -#define TEST_SORTED() \ - previous_time = INT_MAX;\ - for (n = list.head; n != NULL; n = n->next) {\ - must_be_true(n->walk_commit->commit_object->committer->when.time <= previous_time);\ - previous_time = n->walk_commit->commit_object->committer->when.time;\ - } - -#define CLEAR_LIST() \ - for (n = list.head; n != NULL; n = n->next) {\ - git_signature_free(n->walk_commit->commit_object->committer);\ - free(n->walk_commit->commit_object);\ - free(n->walk_commit);\ - }\ - git_revwalk_list_clear(&list); - - memset(&list, 0x0, sizeof(git_revwalk_list)); - srand((unsigned int)time(NULL)); - - for (t = 0; t < 20; ++t) { - const int test_size = rand() % 500 + 500; - - /* Purely random sorting test */ - for (i = 0; i < test_size; ++i) { - git_commit *c = git__malloc(sizeof(git_commit)); - git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit)); - - c->committer = git_signature_new("", "", (time_t)rand(), 0); - rc->commit_object = c; - - git_revwalk_list_push_back(&list, rc); - } - - git_revwalk_list_timesort(&list); - TEST_SORTED(); - CLEAR_LIST(); - } - - /* Try to sort list with all dates equal. */ - for (i = 0; i < 200; ++i) { - git_commit *c = git__malloc(sizeof(git_commit)); - git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit)); - - c->committer = git_signature_new("", "", 0, 0); - rc->commit_object = c; - - git_revwalk_list_push_back(&list, rc); - } - - git_revwalk_list_timesort(&list); - TEST_SORTED(); - CLEAR_LIST(); - - /* Try to sort empty list */ - git_revwalk_list_timesort(&list); - TEST_SORTED(); - -END_TEST - BEGIN_SUITE(revwalk) ADD_TEST(walk0); - ADD_TEST(list0); END_SUITE |
