Style: Do not use (C99) // comments
[libgit2/raj.git] / tests / t0501-walk.c
blob065d464e42f271efe08daf3f5b69dbe266266880
1 #include "test_lib.h"
2 #include "test_helpers.h"
3 #include "commit.h"
5 #include <git/odb.h>
6 #include <git/commit.h>
7 #include <git/revwalk.h>
9 static const char *odb_dir = "../t0501-objects";
11 $ git log --oneline --graph --decorate
12 * a4a7dce (HEAD, br2) Merge branch 'master' into br2
14 | * 9fd738e (master) a fourth commit
15 | * 4a202b3 a third commit
16 * | c47800c branch commit one
18 * 5b5b025 another commit
19 * 8496071 testing
21 static const char *commit_head = "a4a7dce85cf63874e984719f4fdd239f5145052f";
23 static const char *commit_ids[] = {
24 "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
25 "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
26 "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
27 "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
28 "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
29 "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
32 static const int commit_sorting_topo[] = {0, 1, 2, 3, 5, 4};
33 static const int commit_sorting_time[] = {0, 3, 1, 2, 5, 4};
34 static const int commit_sorting_topo_reverse[] = {4, 5, 3, 2, 1, 0};
35 static const int commit_sorting_time_reverse[] = {4, 5, 2, 1, 3, 0};
36 static const int commit_sorting_topo_time[] = {0};
38 BEGIN_TEST(simple_walk_test)
39 git_odb *db;
40 git_oid id;
41 git_revpool *pool;
42 git_commit *head = NULL;
44 must_pass(git_odb_open(&db, odb_dir));
46 pool = gitrp_alloc(db);
47 must_be_true(pool != NULL);
49 git_oid_mkstr(&id, commit_head);
51 head = git_commit_parse(pool, &id);
52 must_be_true(head != NULL);
54 gitrp_push(pool, head);
56 #define TEST_WALK(sort_flags, result_array) {\
57 char oid[40]; int i = 0;\
58 git_commit *commit = NULL;\
59 gitrp_sorting(pool, sort_flags);\
60 while ((commit = gitrp_next(pool)) != NULL) {\
61 git_oid_fmt(oid, &commit->object.id);\
62 must_be_true(memcmp(oid, commit_ids[result_array[i++]], 40) == 0);\
64 must_be_true(i == sizeof(result_array)/sizeof(int));\
65 gitrp_reset(pool);\
68 TEST_WALK(GIT_RPSORT_TIME, commit_sorting_time);
69 TEST_WALK(GIT_RPSORT_TOPOLOGICAL, commit_sorting_topo);
70 TEST_WALK(GIT_RPSORT_TIME | GIT_RPSORT_REVERSE, commit_sorting_time_reverse);
71 TEST_WALK(GIT_RPSORT_TOPOLOGICAL | GIT_RPSORT_REVERSE, commit_sorting_topo_reverse);
73 #undef TEST_WALK
75 gitrp_free(pool);
76 git_odb_close(db);
77 END_TEST