Hash :
1795f879
Author :
Date :
2010-11-05T03:20:17
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
#include "test_lib.h"
#include "test_helpers.h"
#include "index.h"
#include <git/odb.h>
#include <git/index.h>
#define TEST_INDEX_PATH "../resources/testrepo.git/index"
#define TEST_INDEX2_PATH "../resources/gitgit.index"
#define TEST_INDEX_ENTRY_COUNT 109
#define TEST_INDEX2_ENTRY_COUNT 1437
struct test_entry {
unsigned int index;
char path[128];
size_t file_size;
uint32_t mtime;
};
struct test_entry TEST_ENTRIES[] = {
{4, "Makefile", 5064, 0x4C3F7F33},
{62, "tests/Makefile", 2631, 0x4C3F7F33},
{36, "src/index.c", 10014, 0x4C43368D},
{6, "git.git-authors", 2709, 0x4C3F7F33},
{48, "src/revobject.h", 1448, 0x4C3F7FE2}
};
BEGIN_TEST(index_loadempty_test)
git_index *index;
must_pass(git_index_open(&index, "in-memory-index", NULL));
must_be_true(index->on_disk == 0);
must_pass(git_index_read(index));
must_be_true(index->on_disk == 0);
must_be_true(index->entry_count == 0);
must_be_true(index->sorted);
git_index_free(index);
END_TEST
BEGIN_TEST(index_load_test)
git_index *index;
unsigned int i;
must_pass(git_index_open(&index, TEST_INDEX_PATH, NULL));
must_be_true(index->on_disk);
must_pass(git_index_read(index));
must_be_true(index->on_disk);
must_be_true(index->entry_count == TEST_INDEX_ENTRY_COUNT);
must_be_true(index->sorted);
for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) {
git_index_entry *e = &index->entries[TEST_ENTRIES[i].index];
must_be_true(strcmp(e->path, TEST_ENTRIES[i].path) == 0);
must_be_true(e->mtime.seconds == TEST_ENTRIES[i].mtime);
must_be_true(e->file_size == TEST_ENTRIES[i].file_size);
}
git_index_free(index);
END_TEST
BEGIN_TEST(index2_load_test)
git_index *index;
must_pass(git_index_open(&index, TEST_INDEX2_PATH, NULL));
must_be_true(index->on_disk);
must_pass(git_index_read(index));
must_be_true(index->on_disk);
must_be_true(index->entry_count == TEST_INDEX2_ENTRY_COUNT);
must_be_true(index->sorted);
must_be_true(index->tree != NULL);
git_index_free(index);
END_TEST
BEGIN_TEST(index_find_test)
git_index *index;
unsigned int i;
must_pass(git_index_open(&index, TEST_INDEX_PATH, NULL));
must_pass(git_index_read(index));
for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) {
int idx = git_index_find(index, TEST_ENTRIES[i].path);
must_be_true((unsigned int)idx == TEST_ENTRIES[i].index);
}
git_index_free(index);
END_TEST
BEGIN_TEST(index_findempty_test)
git_index *index;
unsigned int i;
must_pass(git_index_open(&index, "fake-index", NULL));
for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) {
int idx = git_index_find(index, TEST_ENTRIES[i].path);
must_be_true(idx == GIT_ENOTFOUND);
}
git_index_free(index);
END_TEST