Hash :
654cd5ff
Author :
Date :
2010-12-02T21:50:28
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#include "test_lib.h"
#include "test_helpers.h"
#include "index.h"
#include <git/odb.h>
#include <git/index.h>
#define TEST_INDEX_PATH "../t0600-objects/index"
/*
void print_entries(git_index *index)
{
unsigned int i;
for (i = 0; i < index->entries.length; ++i)
printf("%d: %s\n", i, index->entries[i].path);
}
*/
void randomize_entries(git_index *index)
{
unsigned int i, j;
git_index_entry *tmp;
git_index_entry **entries;
entries = (git_index_entry **)index->entries.contents;
srand((unsigned int)time(NULL));
for (i = 0; i < index->entries.length; ++i) {
j = rand() % index->entries.length;
tmp = entries[j];
entries[j] = entries[i];
entries[i] = tmp;
}
index->sorted = 0;
}
BEGIN_TEST(index_sort_test)
git_index *index;
unsigned int i;
git_index_entry **entries;
must_pass(git_index_open_bare(&index, TEST_INDEX_PATH));
must_pass(git_index_read(index));
randomize_entries(index);
git_index__sort(index);
must_be_true(index->sorted);
entries = (git_index_entry **)index->entries.contents;
for (i = 1; i < index->entries.length; ++i)
must_be_true(strcmp(entries[i - 1]->path, entries[i]->path) < 0);
git_index_free(index);
END_TEST
BEGIN_TEST(index_sort_empty_test)
git_index *index;
must_pass(git_index_open_bare(&index, "fake-index"));
git_index__sort(index);
must_be_true(index->sorted);
git_index_free(index);
END_TEST