2 #include "test_helpers.h"
8 #define TEST_INDEX_PATH "../t0600-objects/index"
10 void print_entries(git_index
*index
)
14 for (i
= 0; i
< index
->entry_count
; ++i
)
15 printf("%d: %s\n", i
, index
->entries
[i
].path
);
18 void randomize_entries(git_index
*index
)
23 srand((unsigned int)time(NULL
));
25 for (i
= 0; i
< index
->entry_count
; ++i
) {
26 j
= rand() % index
->entry_count
;
27 memcpy(&tmp
, &index
->entries
[j
], sizeof(git_index_entry
));
28 memcpy(&index
->entries
[j
], &index
->entries
[i
], sizeof(git_index_entry
));
29 memcpy(&index
->entries
[i
], &tmp
, sizeof(git_index_entry
));
35 BEGIN_TEST(index_sort_test
)
39 index
= git_index_alloc(TEST_INDEX_PATH
);
40 must_be_true(index
!= NULL
);
41 must_pass(git_index_read(index
));
43 randomize_entries(index
);
45 git_index__sort(index
);
46 must_be_true(index
->sorted
);
48 for (i
= 1; i
< index
->entry_count
; ++i
)
49 must_be_true(strcmp(index
->entries
[i
- 1].path
,
50 index
->entries
[i
].path
) < 0);
52 git_index_free(index
);
55 BEGIN_TEST(index_sort_empty_test
)
57 index
= git_index_alloc("fake-index");
58 must_be_true(index
!= NULL
);
60 git_index__sort(index
);
61 must_be_true(index
->sorted
);
63 git_index_free(index
);