Commit 9297b6e0 by Ben Straub

Removing test suites that have been ported to Clar:

* t00 / 6e86fb3 (mentioned in #406)
* t01 / fc60c4a (mentioned in #406)
* t03 / bcbabe61
* t04 / PR #606
* t05 / d96f2c3
* t06 / 6c106eec
* t07 / 2ef582b4
* t08 / b482c420
* t09 / 9a39a364
* t10 / 00a48934
* t12 / 7c3a4a7f
* t13 / 1cb9b31e
* t17 / cdaa6ff (mentioned in #406)
* t18 / efabc08
parent 8e82600e
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "fileops.h"
#include "odb.h"
static char *odb_dir = "test-objects";
#include "t03-data.h"
static int make_odb_dir(void)
{
if (p_mkdir(odb_dir, GIT_OBJECT_DIR_MODE) < 0) {
int err = errno;
fprintf(stderr, "can't make directory \"%s\"", odb_dir);
if (err == EEXIST)
fprintf(stderr, " (already exists)");
fprintf(stderr, "\n");
return -1;
}
return 0;
}
static int check_object_files(object_data *d)
{
if (git_path_exists(d->dir) < 0)
return -1;
if (git_path_exists(d->file) < 0)
return -1;
return 0;
}
static int cmp_objects(git_rawobj *o1, git_rawobj *o2)
{
if (o1->type != o2->type)
return -1;
if (o1->len != o2->len)
return -1;
if ((o1->len > 0) && (memcmp(o1->data, o2->data, o1->len) != 0))
return -1;
return 0;
}
static int remove_object_files(object_data *d)
{
if (p_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1;
}
if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove directory \"%s\"\n", d->dir);
return -1;
}
if (p_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir);
return -1;
}
return 0;
}
static int streaming_write(git_oid *oid, git_odb *odb, git_rawobj *raw)
{
git_odb_stream *stream;
int error;
if ((error = git_odb_open_wstream(&stream, odb, raw->len, raw->type)) < GIT_SUCCESS)
return error;
stream->write(stream, raw->data, raw->len);
error = stream->finalize_write(oid, stream);
stream->free(stream);
return error;
}
BEGIN_TEST(write0, "write loose commit object")
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_fromstr(&id1, commit.id));
must_pass(streaming_write(&id2, db, &commit_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&commit));
must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj->raw, &commit_obj));
git_odb_object_free(obj);
git_odb_free(db);
must_pass(remove_object_files(&commit));
END_TEST
BEGIN_TEST(write1, "write loose tree object")
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_fromstr(&id1, tree.id));
must_pass(streaming_write(&id2, db, &tree_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&tree));
must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj->raw, &tree_obj));
git_odb_object_free(obj);
git_odb_free(db);
must_pass(remove_object_files(&tree));
END_TEST
BEGIN_TEST(write2, "write loose tag object")
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_fromstr(&id1, tag.id));
must_pass(streaming_write(&id2, db, &tag_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&tag));
must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj->raw, &tag_obj));
git_odb_object_free(obj);
git_odb_free(db);
must_pass(remove_object_files(&tag));
END_TEST
BEGIN_TEST(write3, "write zero-length object")
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_fromstr(&id1, zero.id));
must_pass(streaming_write(&id2, db, &zero_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&zero));
must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj->raw, &zero_obj));
git_odb_object_free(obj);
git_odb_free(db);
must_pass(remove_object_files(&zero));
END_TEST
BEGIN_TEST(write4, "write one-byte long object")
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_fromstr(&id1, one.id));
must_pass(streaming_write(&id2, db, &one_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&one));
must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj->raw, &one_obj));
git_odb_object_free(obj);
git_odb_free(db);
must_pass(remove_object_files(&one));
END_TEST
BEGIN_TEST(write5, "write two-byte long object")
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_fromstr(&id1, two.id));
must_pass(streaming_write(&id2, db, &two_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&two));
must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj->raw, &two_obj));
git_odb_object_free(obj);
git_odb_free(db);
must_pass(remove_object_files(&two));
END_TEST
BEGIN_TEST(write6, "write an object which is several bytes long")
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
must_pass(make_odb_dir());
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_fromstr(&id1, some.id));
must_pass(streaming_write(&id2, db, &some_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
must_pass(check_object_files(&some));
must_pass(git_odb_read(&obj, db, &id1));
must_pass(cmp_objects(&obj->raw, &some_obj));
git_odb_object_free(obj);
git_odb_free(db);
must_pass(remove_object_files(&some));
END_TEST
BEGIN_SUITE(objwrite)
ADD_TEST(write0);
ADD_TEST(write1);
ADD_TEST(write2);
ADD_TEST(write3);
ADD_TEST(write4);
ADD_TEST(write5);
ADD_TEST(write6);
END_SUITE
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "test_helpers.h"
/*
$ git log --oneline --graph --decorate
* a4a7dce (HEAD, br2) Merge branch 'master' into br2
|\
| * 9fd738e (master) a fourth commit
| * 4a202b3 a third commit
* | c47800c branch commit one
|/
* 5b5b025 another commit
* 8496071 testing
*/
static const char *commit_head = "a4a7dce85cf63874e984719f4fdd239f5145052f";
static const char *commit_ids[] = {
"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
"9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
};
/* Careful: there are two possible topological sorts */
static const int commit_sorting_topo[][6] = {
{0, 1, 2, 3, 5, 4}, {0, 3, 1, 2, 5, 4}
};
static const int commit_sorting_time[][6] = {
{0, 3, 1, 2, 5, 4}
};
static const int commit_sorting_topo_reverse[][6] = {
{4, 5, 3, 2, 1, 0}, {4, 5, 2, 1, 3, 0}
};
static const int commit_sorting_time_reverse[][6] = {
{4, 5, 2, 1, 3, 0}
};
#define commit_count 6
static const int result_bytes = 24;
static int get_commit_index(git_oid *raw_oid)
{
int i;
char oid[40];
git_oid_fmt(oid, raw_oid);
for (i = 0; i < commit_count; ++i)
if (memcmp(oid, commit_ids[i], 40) == 0)
return i;
return -1;
}
static int test_walk(git_revwalk *walk, const git_oid *root,
int flags, const int possible_results[][6], int results_count)
{
git_oid oid;
int i;
int result_array[commit_count];
git_revwalk_sorting(walk, flags);
git_revwalk_push(walk, root);
for (i = 0; i < commit_count; ++i)
result_array[i] = -1;
i = 0;
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],
result_array, result_bytes) == 0)
return GIT_SUCCESS;
return GIT_ERROR;
}
BEGIN_TEST(walk0, "do a simple walk on a repo with different sorting modes")
git_oid id;
git_repository *repo;
git_revwalk *walk;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_revwalk_new(&walk, repo));
git_oid_fromstr(&id, commit_head);
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_SUITE(revwalk)
ADD_TEST(walk0);
END_SUITE
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "test_helpers.h"
#include "index.h"
#define TEST_INDEX_ENTRY_COUNT 109
#define TEST_INDEX2_ENTRY_COUNT 1437
struct test_entry {
unsigned int index;
char path[128];
git_off_t file_size;
git_time_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(read0, "load an empty index")
git_index *index;
must_pass(git_index_open(&index, "in-memory-index"));
must_be_true(index->on_disk == 0);
must_be_true(git_index_entrycount(index) == 0);
must_be_true(index->entries.sorted);
git_index_free(index);
END_TEST
BEGIN_TEST(read1, "load a standard index (default test index)")
git_index *index;
unsigned int i;
git_index_entry **entries;
must_pass(git_index_open(&index, TEST_INDEX_PATH));
must_be_true(index->on_disk);
must_be_true(git_index_entrycount(index) == TEST_INDEX_ENTRY_COUNT);
must_be_true(index->entries.sorted);
entries = (git_index_entry **)index->entries.contents;
for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) {
git_index_entry *e = 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(read2, "load a standard index (git.git index)")
git_index *index;
must_pass(git_index_open(&index, TEST_INDEX2_PATH));
must_be_true(index->on_disk);
must_be_true(git_index_entrycount(index) == TEST_INDEX2_ENTRY_COUNT);
must_be_true(index->entries.sorted);
must_be_true(index->tree != NULL);
git_index_free(index);
END_TEST
BEGIN_TEST(find0, "find an entry on an index")
git_index *index;
unsigned int i;
must_pass(git_index_open(&index, TEST_INDEX_PATH));
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(find1, "find an entry in an empty index")
git_index *index;
unsigned int i;
must_pass(git_index_open(&index, "fake-index"));
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
BEGIN_TEST(write0, "write an index back to disk")
git_index *index;
must_pass(copy_file(TEST_INDEXBIG_PATH, "index_rewrite"));
must_pass(git_index_open(&index, "index_rewrite"));
must_be_true(index->on_disk);
must_pass(git_index_write(index));
must_pass(cmp_files(TEST_INDEXBIG_PATH, "index_rewrite"));
git_index_free(index);
p_unlink("index_rewrite");
END_TEST
BEGIN_TEST(sort0, "sort the entires in an index")
/*
* TODO: This no longer applies:
* index sorting in Git uses some specific changes to the way
* directories are sorted.
*
* We need to specificially check for this by creating a new
* index, adding entries in random order and then
* checking for consistency
*/
END_TEST
BEGIN_TEST(sort1, "sort the entires in an empty index")
git_index *index;
must_pass(git_index_open(&index, "fake-index"));
/* FIXME: this test is slightly dumb */
must_be_true(index->entries.sorted);
git_index_free(index);
END_TEST
BEGIN_TEST(add0, "add a new file to the index")
git_index *index;
git_filebuf file = GIT_FILEBUF_INIT;
git_repository *repo;
git_index_entry *entry;
git_oid id1;
/* Intialize a new repository */
must_pass(git_repository_init(&repo, TEMP_REPO_FOLDER "myrepo", 0));
/* Ensure we're the only guy in the room */
must_pass(git_repository_index(&index, repo));
must_pass(git_index_entrycount(index) == 0);
/* Create a new file in the working directory */
must_pass(git_futils_mkpath2file(TEMP_REPO_FOLDER "myrepo/test.txt", 0777));
must_pass(git_filebuf_open(&file, TEMP_REPO_FOLDER "myrepo/test.txt", 0));
must_pass(git_filebuf_write(&file, "hey there\n", 10));
must_pass(git_filebuf_commit(&file, 0666));
/* Store the expected hash of the file/blob
* This has been generated by executing the following
* $ echo "hey there" | git hash-object --stdin
*/
must_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"));
/* Add the new file to the index */
must_pass(git_index_add(index, "test.txt", 0));
/* Wow... it worked! */
must_pass(git_index_entrycount(index) == 1);
entry = git_index_get(index, 0);
/* And the built-in hashing mechanism worked as expected */
must_be_true(git_oid_cmp(&id1, &entry->oid) == 0);
git_index_free(index);
git_repository_free(repo);
must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
END_TEST
BEGIN_SUITE(index)
ADD_TEST(read0);
ADD_TEST(read1);
ADD_TEST(read2);
ADD_TEST(find0);
ADD_TEST(find1);
ADD_TEST(write0);
ADD_TEST(sort0);
ADD_TEST(sort1);
ADD_TEST(add0);
END_SUITE
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "test_helpers.h"
#include "hashtable.h"
#include "hash.h"
typedef struct _aux_object {
int __bulk;
git_oid id;
int visited;
} table_item;
static uint32_t hash_func(const void *key, int hash_id)
{
uint32_t r;
const git_oid *id = key;
memcpy(&r, id->id + (hash_id * sizeof(uint32_t)), sizeof(r));
return r;
}
static int hash_cmpkey(const void *a, const void *b)
{
return git_oid_cmp(a, b);
}
BEGIN_TEST(table0, "create a new hashtable")
git_hashtable *table = NULL;
table = git_hashtable_alloc(55, hash_func, hash_cmpkey);
must_be_true(table != NULL);
must_be_true(table->size_mask + 1 == 64);
git_hashtable_free(table);
END_TEST
BEGIN_TEST(table1, "fill the hashtable with random entries")
const int objects_n = 32;
int i;
table_item *objects;
git_hashtable *table = NULL;
table = git_hashtable_alloc(objects_n * 2, hash_func, hash_cmpkey);
must_be_true(table != NULL);
objects = git__malloc(objects_n * sizeof(table_item));
memset(objects, 0x0, objects_n * sizeof(table_item));
/* populate the hash table */
for (i = 0; i < objects_n; ++i) {
git_hash_buf(&(objects[i].id), &i, sizeof(int));
must_pass(git_hashtable_insert(table, &(objects[i].id), &(objects[i])));
}
/* make sure all the inserted objects can be found */
for (i = 0; i < objects_n; ++i) {
git_oid id;
table_item *ob;
git_hash_buf(&id, &i, sizeof(int));
ob = (table_item *)git_hashtable_lookup(table, &id);
must_be_true(ob != NULL);
must_be_true(ob == &(objects[i]));
}
/* make sure we cannot find inexisting objects */
for (i = 0; i < 50; ++i) {
int hash_id;
git_oid id;
hash_id = (rand() % 50000) + objects_n;
git_hash_buf(&id, &hash_id, sizeof(int));
must_be_true(git_hashtable_lookup(table, &id) == NULL);
}
git_hashtable_free(table);
git__free(objects);
END_TEST
BEGIN_TEST(table2, "make sure the table resizes automatically")
const int objects_n = 64;
int i;
unsigned int old_size;
table_item *objects;
git_hashtable *table = NULL;
table = git_hashtable_alloc(objects_n, hash_func, hash_cmpkey);
must_be_true(table != NULL);
objects = git__malloc(objects_n * sizeof(table_item));
memset(objects, 0x0, objects_n * sizeof(table_item));
old_size = table->size_mask + 1;
/* populate the hash table -- should be automatically resized */
for (i = 0; i < objects_n; ++i) {
git_hash_buf(&(objects[i].id), &i, sizeof(int));
must_pass(git_hashtable_insert(table, &(objects[i].id), &(objects[i])));
}
must_be_true(table->size_mask > old_size);
/* make sure all the inserted objects can be found */
for (i = 0; i < objects_n; ++i) {
git_oid id;
table_item *ob;
git_hash_buf(&id, &i, sizeof(int));
ob = (table_item *)git_hashtable_lookup(table, &id);
must_be_true(ob != NULL);
must_be_true(ob == &(objects[i]));
}
git_hashtable_free(table);
git__free(objects);
END_TEST
BEGIN_TEST(tableit0, "iterate through all the contents of the table")
const int objects_n = 32;
int i;
table_item *objects, *ob;
git_hashtable *table = NULL;
table = git_hashtable_alloc(objects_n * 2, hash_func, hash_cmpkey);
must_be_true(table != NULL);
objects = git__malloc(objects_n * sizeof(table_item));
memset(objects, 0x0, objects_n * sizeof(table_item));
/* populate the hash table */
for (i = 0; i < objects_n; ++i) {
git_hash_buf(&(objects[i].id), &i, sizeof(int));
must_pass(git_hashtable_insert(table, &(objects[i].id), &(objects[i])));
}
GIT_HASHTABLE_FOREACH_VALUE(table, ob, ob->visited = 1);
/* make sure all nodes have been visited */
for (i = 0; i < objects_n; ++i)
must_be_true(objects[i].visited);
git_hashtable_free(table);
git__free(objects);
END_TEST
BEGIN_SUITE(hashtable)
ADD_TEST(table0);
ADD_TEST(table1);
ADD_TEST(table2);
ADD_TEST(tableit0);
END_SUITE
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "test_helpers.h"
#include "tree.h"
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
static const char *blob_oid = "fa49b077972391ad58037050f2a75f74e3671e92";
static const char *first_tree = "181037049a54a1eb5fab404658a3a250b44335d7";
static const char *second_tree = "f60079018b664e4e79329a7ef9559c8d9e0378d1";
static const char *third_tree = "eb86d8b81d6adbd5290a935d6c9976882de98488";
#if 0
static int print_tree(git_repository *repo, const git_oid *tree_oid, int depth)
{
static const char *indent = " ";
git_tree *tree;
unsigned int i;
if (git_tree_lookup(&tree, repo, tree_oid) < GIT_SUCCESS)
return GIT_ERROR;
for (i = 0; i < git_tree_entrycount(tree); ++i) {
const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
char entry_oid[40];
git_oid_fmt(entry_oid, &entry->oid);
printf("%.*s%o [%.*s] %s\n", depth*2, indent, entry->attr, 40, entry_oid, entry->filename);
if (entry->attr == S_IFDIR) {
if (print_tree(repo, &entry->oid, depth + 1) < GIT_SUCCESS) {
git_tree_free(tree);
return GIT_ERROR;
}
}
}
git_tree_free(tree);
return GIT_SUCCESS;
}
#endif
BEGIN_TEST(read0, "acces randomly the entries on a loaded tree")
git_oid id;
git_repository *repo;
git_tree *tree;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_fromstr(&id, tree_oid);
must_pass(git_tree_lookup(&tree, repo, &id));
must_be_true(git_tree_entry_byname(tree, "README") != NULL);
must_be_true(git_tree_entry_byname(tree, "NOTEXISTS") == NULL);
must_be_true(git_tree_entry_byname(tree, "") == NULL);
must_be_true(git_tree_entry_byindex(tree, 0) != NULL);
must_be_true(git_tree_entry_byindex(tree, 2) != NULL);
must_be_true(git_tree_entry_byindex(tree, 3) == NULL);
must_be_true(git_tree_entry_byindex(tree, (unsigned int)-1) == NULL);
git_tree_free(tree);
git_repository_free(repo);
END_TEST
BEGIN_TEST(read1, "read a tree from the repository")
git_oid id;
git_repository *repo;
git_tree *tree;
const git_tree_entry *entry;
git_object *obj;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_fromstr(&id, tree_oid);
must_pass(git_tree_lookup(&tree, repo, &id));
must_be_true(git_tree_entrycount(tree) == 3);
/* GH-86: git_object_lookup() should also check the type if the object comes from the cache */
must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_TREE) == 0);
must_be_true(obj != NULL);
git_object_free(obj);
obj = NULL;
must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_BLOB) == GIT_EINVALIDTYPE);
must_be_true(obj == NULL);
entry = git_tree_entry_byname(tree, "README");
must_be_true(entry != NULL);
must_be_true(strcmp(git_tree_entry_name(entry), "README") == 0);
must_pass(git_tree_entry_2object(&obj, repo, entry));
must_be_true(obj != NULL);
git_object_free(obj);
git_tree_free(tree);
git_repository_free(repo);
END_TEST
#if 0
BEGIN_TEST(write0, "write a tree from an index")
git_repository *repo;
git_index *index;
git_oid tree_oid;
must_pass(git_repository_open(&repo, "/tmp/redtmp/.git"));
must_pass(git_repository_index(&index, repo));
must_pass(git_tree_create_fromindex(&tree_oid, index));
must_pass(print_tree(repo, &tree_oid, 0));
git_repository_free(repo);
END_TEST
#endif
BEGIN_TEST(write2, "write a tree from a memory")
git_repository *repo;
git_treebuilder *builder;
git_tree *tree;
git_oid id, bid, rid, id2;
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
git_oid_fromstr(&id, first_tree);
git_oid_fromstr(&id2, second_tree);
git_oid_fromstr(&bid, blob_oid);
//create a second tree from first tree using `git_treebuilder_insert` on REPOSITORY_FOLDER.
must_pass(git_tree_lookup(&tree, repo, &id));
must_pass(git_treebuilder_create(&builder, tree));
must_fail(git_treebuilder_insert(NULL, builder, "", &bid, 0100644));
must_fail(git_treebuilder_insert(NULL, builder, "/", &bid, 0100644));
must_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt", &bid, 0100644));
must_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644));
must_pass(git_treebuilder_write(&rid,repo,builder));
must_be_true(git_oid_cmp(&rid, &id2) == 0);
git_treebuilder_free(builder);
git_tree_free(tree);
close_temp_repo(repo);
END_TEST
BEGIN_TEST(write3, "write a hierarchical tree from a memory")
git_repository *repo;
git_treebuilder *builder;
git_tree *tree;
git_oid id, bid, subtree_id, id2, id3;
git_oid id_hiearar;
must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER));
git_oid_fromstr(&id, first_tree);
git_oid_fromstr(&id2, second_tree);
git_oid_fromstr(&id3, third_tree);
git_oid_fromstr(&bid, blob_oid);
//create subtree
must_pass(git_treebuilder_create(&builder, NULL));
must_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644));
must_pass(git_treebuilder_write(&subtree_id,repo,builder));
git_treebuilder_free(builder);
// create parent tree
must_pass(git_tree_lookup(&tree, repo, &id));
must_pass(git_treebuilder_create(&builder, tree));
must_pass(git_treebuilder_insert(NULL,builder,"new",&subtree_id,040000));
must_pass(git_treebuilder_write(&id_hiearar,repo,builder));
git_treebuilder_free(builder);
git_tree_free(tree);
must_be_true(git_oid_cmp(&id_hiearar, &id3) == 0);
// check data is correct
must_pass(git_tree_lookup(&tree, repo, &id_hiearar));
must_be_true(2 == git_tree_entrycount(tree));
#ifndef GIT_WIN32
must_be_true((loose_object_dir_mode(TEMP_REPO_FOLDER, (git_object *)tree) & 0777) == GIT_OBJECT_DIR_MODE);
must_be_true((loose_object_mode(TEMP_REPO_FOLDER, (git_object *)tree) & 0777) == GIT_OBJECT_FILE_MODE);
#endif
git_tree_free(tree);
close_temp_repo(repo);
END_TEST
BEGIN_SUITE(tree)
//ADD_TEST(print0);
ADD_TEST(read0);
ADD_TEST(read1);
//ADD_TEST(write0);
//ADD_TEST(write1);
ADD_TEST(write2);
ADD_TEST(write3);
END_SUITE
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "test_helpers.h"
#include "odb.h"
#include "git2/odb_backend.h"
#include "repository.h"
#define EMPTY_BARE_REPOSITORY_FOLDER TEST_RESOURCES "/empty_bare.git/"
#define DISCOVER_FOLDER TEMP_REPO_FOLDER "discover.git"
#define SUB_REPOSITORY_FOLDER_NAME "sub_repo"
#define SUB_REPOSITORY_FOLDER DISCOVER_FOLDER "/" SUB_REPOSITORY_FOLDER_NAME
#define SUB_REPOSITORY_FOLDER_SUB SUB_REPOSITORY_FOLDER "/sub"
#define SUB_REPOSITORY_FOLDER_SUB_SUB SUB_REPOSITORY_FOLDER_SUB "/subsub"
#define SUB_REPOSITORY_FOLDER_SUB_SUB_SUB SUB_REPOSITORY_FOLDER_SUB_SUB "/subsubsub"
#define REPOSITORY_ALTERNATE_FOLDER DISCOVER_FOLDER "/alternate_sub_repo"
#define REPOSITORY_ALTERNATE_FOLDER_SUB REPOSITORY_ALTERNATE_FOLDER "/sub"
#define REPOSITORY_ALTERNATE_FOLDER_SUB_SUB REPOSITORY_ALTERNATE_FOLDER_SUB "/subsub"
#define REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/subsubsub"
#define ALTERNATE_MALFORMED_FOLDER1 DISCOVER_FOLDER "/alternate_malformed_repo1"
#define ALTERNATE_MALFORMED_FOLDER2 DISCOVER_FOLDER "/alternate_malformed_repo2"
#define ALTERNATE_MALFORMED_FOLDER3 DISCOVER_FOLDER "/alternate_malformed_repo3"
#define ALTERNATE_NOT_FOUND_FOLDER DISCOVER_FOLDER "/alternate_not_found_repo"
static int ensure_repository_discover(const char *start_path, const char *ceiling_dirs, const char *expected_path)
{
int error;
char found_path[GIT_PATH_MAX];
error = git_repository_discover(found_path, sizeof(found_path), start_path, 0, ceiling_dirs);
//across_fs is always 0 as we can't automate the filesystem change tests
if (error < GIT_SUCCESS)
return error;
return strcmp(found_path, expected_path) ? GIT_ERROR : GIT_SUCCESS;
}
static int write_file(const char *path, const char *content)
{
int error;
git_file file;
if (git_path_exists(path) == GIT_SUCCESS) {
error = p_unlink(path);
if (error < GIT_SUCCESS)
return error;
}
file = git_futils_creat_withpath(path, 0777, 0666);
if (file < GIT_SUCCESS)
return file;
error = p_write(file, content, strlen(content) * sizeof(char));
p_close(file);
return error;
}
//no check is performed on ceiling_dirs length, so be sure it's long enough
static int append_ceiling_dir(git_buf *ceiling_dirs, const char *path)
{
git_buf pretty_path = GIT_BUF_INIT;
int error;
char ceiling_separator[2] = { GIT_PATH_LIST_SEPARATOR, '\0' };
error = git_path_prettify_dir(&pretty_path, path, NULL);
if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to append ceiling directory.");
if (ceiling_dirs->size > 0)
git_buf_puts(ceiling_dirs, ceiling_separator);
git_buf_puts(ceiling_dirs, pretty_path.ptr);
git_buf_free(&pretty_path);
return git_buf_lasterror(ceiling_dirs);
}
BEGIN_TEST(discover0, "test discover")
git_repository *repo;
git_buf ceiling_dirs_buf = GIT_BUF_INIT;
const char *ceiling_dirs;
char repository_path[GIT_PATH_MAX];
char sub_repository_path[GIT_PATH_MAX];
char found_path[GIT_PATH_MAX];
const mode_t mode = 0777;
git_futils_mkdir_r(DISCOVER_FOLDER, NULL, mode);
must_pass(append_ceiling_dir(&ceiling_dirs_buf, TEMP_REPO_FOLDER));
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
must_be_true(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO);
must_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1));
must_pass(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs));
git_repository_free(repo);
must_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0));
must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode));
must_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, NULL, mode));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, NULL, mode));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT));
must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../"));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path));
must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, NULL, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:"));
must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, NULL, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:"));
must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, NULL, mode));
must_pass(write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n"));
must_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, NULL, mode));
must_pass(write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist"));
must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs));
must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs));
must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs));
must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs));
must_pass(append_ceiling_dir(&ceiling_dirs_buf, SUB_REPOSITORY_FOLDER));
ceiling_dirs = git_buf_cstr(&ceiling_dirs_buf);
//this must pass as ceiling_directories cannot predent the current
//working directory to be checked
must_pass(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs));
must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs));
must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs));
must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs));
//.gitfile redirection should not be affected by ceiling directories
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path));
must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path));
must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1));
git_repository_free(repo);
git_buf_free(&ceiling_dirs_buf);
END_TEST
BEGIN_SUITE(repository)
ADD_TEST(discover0);
END_SUITE
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "test_helpers.h"
#include "cache.h"
typedef struct {
git_cached_obj cached;
unsigned int __dummy;
} ttest_obj;
BEGIN_TEST(cache0, "run several threads polling the cache at the same time")
END_TEST
BEGIN_SUITE(threads)
ADD_TEST(cache0);
END_SUITE
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "test_helpers.h"
#include <git2.h>
#include "buffer.h"
const char *test_string = "Have you seen that? Have you seeeen that??";
BEGIN_TEST(buf0, "check that resizing works properly")
git_buf buf = GIT_BUF_INIT;
git_buf_puts(&buf, test_string);
must_be_true(git_buf_oom(&buf) == 0);
must_be_true(strcmp(git_buf_cstr(&buf), test_string) == 0);
git_buf_puts(&buf, test_string);
must_be_true(strlen(git_buf_cstr(&buf)) == strlen(test_string) * 2);
git_buf_free(&buf);
END_TEST
BEGIN_TEST(buf1, "check that printf works properly")
git_buf buf = GIT_BUF_INIT;
git_buf_printf(&buf, "%s %s %d ", "shoop", "da", 23);
must_be_true(git_buf_oom(&buf) == 0);
must_be_true(strcmp(git_buf_cstr(&buf), "shoop da 23 ") == 0);
git_buf_printf(&buf, "%s %d", "woop", 42);
must_be_true(git_buf_oom(&buf) == 0);
must_be_true(strcmp(git_buf_cstr(&buf), "shoop da 23 woop 42") == 0);
git_buf_free(&buf);
END_TEST
BEGIN_SUITE(buffers)
ADD_TEST(buf0)
ADD_TEST(buf1)
END_SUITE
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment