Commit 2a1732b4 by Vicent Marti

Rewrite the unit testing suite

NIH Enterprises presents: a new testing system based on CuTesT, which is
faster than our previous one and fortunately uses no preprocessing on
the source files, which means we can run that from CMake.

The test suites have been gathered together into bigger files (one file
per suite, testing each of the different submodules of the library).

Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent b70e4f8a
#include "test_lib.h"
#include "common.h"
BEGIN_TEST(init_inc2_dec2_free)
git_refcnt p;
gitrc_init(&p);
gitrc_inc(&p);
gitrc_inc(&p);
must_be_true(!gitrc_dec(&p));
must_be_true(gitrc_dec(&p));
gitrc_free(&p);
END_TEST
#include "test_lib.h"
#include "common.h"
BEGIN_TEST(prefixcmp_empty_empty)
must_be_true(git__prefixcmp("", "") == 0);
END_TEST
BEGIN_TEST(prefixcmp_a_empty)
must_be_true(git__prefixcmp("a", "") == 0);
END_TEST
BEGIN_TEST(prefixcmp_empty_a)
must_be_true(git__prefixcmp("", "a") < 0);
END_TEST
BEGIN_TEST(prefixcmp_a_b)
must_be_true(git__prefixcmp("a", "b") < 0);
END_TEST
BEGIN_TEST(prefixcmp_b_a)
must_be_true(git__prefixcmp("b", "a") > 0);
END_TEST
BEGIN_TEST(prefixcmp_ab_a)
must_be_true(git__prefixcmp("ab", "a") == 0);
END_TEST
BEGIN_TEST(prefixcmp_ab_ac)
must_be_true(git__prefixcmp("ab", "ac") < 0);
END_TEST
BEGIN_TEST(prefixcmp_ab_aa)
must_be_true(git__prefixcmp("ab", "aa") > 0);
END_TEST
BEGIN_TEST(suffixcmp_empty_empty)
must_be_true(git__suffixcmp("", "") == 0);
END_TEST
BEGIN_TEST(suffixcmp_a_empty)
must_be_true(git__suffixcmp("a", "") == 0);
END_TEST
BEGIN_TEST(suffixcmp_empty_a)
must_be_true(git__suffixcmp("", "a") < 0);
END_TEST
BEGIN_TEST(suffixcmp_a_b)
must_be_true(git__suffixcmp("a", "b") < 0);
END_TEST
BEGIN_TEST(suffixcmp_b_a)
must_be_true(git__suffixcmp("b", "a") > 0);
END_TEST
BEGIN_TEST(suffixcmp_ba_a)
must_be_true(git__suffixcmp("ba", "a") == 0);
END_TEST
BEGIN_TEST(suffixcmp_zaa_ac)
must_be_true(git__suffixcmp("zaa", "ac") < 0);
END_TEST
BEGIN_TEST(suffixcmp_zaz_ac)
must_be_true(git__suffixcmp("zaz", "ac") > 0);
END_TEST
BEGIN_TEST(dirname)
char dir[64];
must_be_true(!(git__dirname(dir, sizeof(dir), NULL) < 0));
must_be_true(!strcmp(dir, "."));
must_be_true(!(git__dirname(dir, sizeof(dir), "") < 0));
must_be_true(!strcmp(dir, "."));
must_be_true(!(git__dirname(dir, sizeof(dir), "a") < 0));
must_be_true(!strcmp(dir, "."));
must_be_true(!(git__dirname(dir, sizeof(dir), "/") < 0));
must_be_true(!strcmp(dir, "/"));
must_be_true(!(git__dirname(dir, sizeof(dir), "/usr") < 0));
must_be_true(!strcmp(dir, "/"));
/* TODO: should this be "/" instead (ie strip trailing / first) */
must_be_true(!(git__dirname(dir, sizeof(dir), "/usr/") < 0));
must_be_true(!strcmp(dir, "/usr"));
must_be_true(!(git__dirname(dir, sizeof(dir), "/usr/lib") < 0));
must_be_true(!strcmp(dir, "/usr"));
must_be_true(!(git__dirname(dir, sizeof(dir), "usr/lib") < 0));
must_be_true(!strcmp(dir, "usr"));
END_TEST
BEGIN_TEST(basename)
char base[64];
must_be_true(!(git__basename(base, sizeof(base), NULL) < 0));
must_be_true(!strcmp(base, "."));
must_be_true(!(git__basename(base, sizeof(base), "") < 0));
must_be_true(!strcmp(base, "."));
must_be_true(!(git__basename(base, sizeof(base), "a") < 0));
must_be_true(!strcmp(base, "a"));
must_be_true(!(git__basename(base, sizeof(base), "/") < 0));
must_be_true(!strcmp(base, "/"));
must_be_true(!(git__basename(base, sizeof(base), "/usr") < 0));
must_be_true(!strcmp(base, "usr"));
/* TODO: should this be "usr" instead (ie strip trailing / first) */
must_be_true(!(git__basename(base, sizeof(base), "/usr/") < 0));
must_be_true(!strcmp(base, ""));
must_be_true(!(git__basename(base, sizeof(base), "/usr/lib") < 0));
must_be_true(!strcmp(base, "lib"));
must_be_true(!(git__basename(base, sizeof(base), "usr/lib") < 0));
must_be_true(!strcmp(base, "lib"));
END_TEST
#include "test_lib.h"
#include "common.h"
#include "vector.h"
/* Initial size of 1 will cause writing past array bounds prior to fix */
BEGIN_TEST(initial_size_one)
git_vector x;
int i;
git_vector_init(&x, 1, NULL, NULL);
for (i = 0; i < 10; ++i) {
git_vector_insert(&x, (void*) 0xabc);
}
git_vector_free(&x);
END_TEST
/* vector used to read past array bounds on remove() */
BEGIN_TEST(remove)
git_vector x;
// make initial capacity exact for our insertions.
git_vector_init(&x, 3, NULL, NULL);
git_vector_insert(&x, (void*) 0xabc);
git_vector_insert(&x, (void*) 0xdef);
git_vector_insert(&x, (void*) 0x123);
git_vector_remove(&x, 0); // used to read past array bounds.
git_vector_free(&x);
END_TEST
#include "test_lib.h"
#include "fileops.h"
typedef int (normalize_path)(char *, const char *);
static int ensure_normalized(const char *input_path, const char *expected_path, normalize_path normalizer)
{
int error = GIT_SUCCESS;
char buffer_out[GIT_PATH_MAX];
error = normalizer(buffer_out, input_path);
if (error < GIT_SUCCESS)
return error;
if (expected_path == NULL)
return error;
if (strcmp(buffer_out, expected_path))
error = GIT_ERROR;
return error;
}
static int ensure_dir_path_normalized(const char *input_path, const char *expected_path)
{
return ensure_normalized(input_path, expected_path, gitfo_prettify_dir_path);
}
static int ensure_file_path_normalized(const char *input_path, const char *expected_path)
{
return ensure_normalized(input_path, expected_path, gitfo_prettify_file_path);
}
BEGIN_TEST(file_path_prettifying)
must_pass(ensure_file_path_normalized("a", "a"));
must_pass(ensure_file_path_normalized("./testrepo.git", "testrepo.git"));
must_pass(ensure_file_path_normalized("./.git", ".git"));
must_pass(ensure_file_path_normalized("./git.", "git."));
must_fail(ensure_file_path_normalized("git./", NULL));
must_fail(ensure_file_path_normalized("", NULL));
must_fail(ensure_file_path_normalized(".", NULL));
must_fail(ensure_file_path_normalized("./", NULL));
must_fail(ensure_file_path_normalized("./.", NULL));
must_fail(ensure_file_path_normalized("./..", NULL));
must_fail(ensure_file_path_normalized("../.", NULL));
must_fail(ensure_file_path_normalized("./.././/", NULL));
must_fail(ensure_file_path_normalized("dir/..", NULL));
must_fail(ensure_file_path_normalized("dir/sub/../..", NULL));
must_fail(ensure_file_path_normalized("dir/sub/..///..", NULL));
must_fail(ensure_file_path_normalized("dir/sub///../..", NULL));
must_fail(ensure_file_path_normalized("dir/sub///..///..", NULL));
must_fail(ensure_file_path_normalized("dir/sub/../../..", NULL));
must_pass(ensure_file_path_normalized("dir", "dir"));
must_fail(ensure_file_path_normalized("dir//", NULL));
must_pass(ensure_file_path_normalized("./dir", "dir"));
must_fail(ensure_file_path_normalized("dir/.", NULL));
must_fail(ensure_file_path_normalized("dir///./", NULL));
must_fail(ensure_file_path_normalized("dir/sub/..", NULL));
must_fail(ensure_file_path_normalized("dir//sub/..",NULL));
must_fail(ensure_file_path_normalized("dir//sub/../", NULL));
must_fail(ensure_file_path_normalized("dir/sub/../", NULL));
must_fail(ensure_file_path_normalized("dir/sub/../.", NULL));
must_fail(ensure_file_path_normalized("dir/s1/../s2/", NULL));
must_fail(ensure_file_path_normalized("d1/s1///s2/..//../s3/", NULL));
must_pass(ensure_file_path_normalized("d1/s1//../s2/../../d2", "d2"));
must_fail(ensure_file_path_normalized("dir/sub/../", NULL));
must_fail(ensure_file_path_normalized("....", NULL));
must_fail(ensure_file_path_normalized("...", NULL));
must_fail(ensure_file_path_normalized("./...", NULL));
must_fail(ensure_file_path_normalized("d1/...", NULL));
must_fail(ensure_file_path_normalized("d1/.../", NULL));
must_fail(ensure_file_path_normalized("d1/.../d2", NULL));
must_pass(ensure_file_path_normalized("/a", "/a"));
must_pass(ensure_file_path_normalized("/./testrepo.git", "/testrepo.git"));
must_pass(ensure_file_path_normalized("/./.git", "/.git"));
must_pass(ensure_file_path_normalized("/./git.", "/git."));
must_fail(ensure_file_path_normalized("/git./", NULL));
must_fail(ensure_file_path_normalized("/", NULL));
must_fail(ensure_file_path_normalized("/.", NULL));
must_fail(ensure_file_path_normalized("/./", NULL));
must_fail(ensure_file_path_normalized("/./.", NULL));
must_fail(ensure_file_path_normalized("/./..", NULL));
must_fail(ensure_file_path_normalized("/../.", NULL));
must_fail(ensure_file_path_normalized("/./.././/", NULL));
must_fail(ensure_file_path_normalized("/dir/..", NULL));
must_fail(ensure_file_path_normalized("/dir/sub/../..", NULL));
must_fail(ensure_file_path_normalized("/dir/sub/..///..", NULL));
must_fail(ensure_file_path_normalized("/dir/sub///../..", NULL));
must_fail(ensure_file_path_normalized("/dir/sub///..///..", NULL));
must_fail(ensure_file_path_normalized("/dir/sub/../../..", NULL));
must_pass(ensure_file_path_normalized("/dir", "/dir"));
must_fail(ensure_file_path_normalized("/dir//", NULL));
must_pass(ensure_file_path_normalized("/./dir", "/dir"));
must_fail(ensure_file_path_normalized("/dir/.", NULL));
must_fail(ensure_file_path_normalized("/dir///./", NULL));
must_fail(ensure_file_path_normalized("/dir/sub/..", NULL));
must_fail(ensure_file_path_normalized("/dir//sub/..",NULL));
must_fail(ensure_file_path_normalized("/dir//sub/../", NULL));
must_fail(ensure_file_path_normalized("/dir/sub/../", NULL));
must_fail(ensure_file_path_normalized("/dir/sub/../.", NULL));
must_fail(ensure_file_path_normalized("/dir/s1/../s2/", NULL));
must_fail(ensure_file_path_normalized("/d1/s1///s2/..//../s3/", NULL));
must_pass(ensure_file_path_normalized("/d1/s1//../s2/../../d2", "/d2"));
must_fail(ensure_file_path_normalized("/dir/sub/../", NULL));
must_fail(ensure_file_path_normalized("/....", NULL));
must_fail(ensure_file_path_normalized("/...", NULL));
must_fail(ensure_file_path_normalized("/./...", NULL));
must_fail(ensure_file_path_normalized("/d1/...", NULL));
must_fail(ensure_file_path_normalized("/d1/.../", NULL));
must_fail(ensure_file_path_normalized("/d1/.../d2", NULL));
END_TEST
BEGIN_TEST(dir_path_prettifying)
must_pass(ensure_dir_path_normalized("./testrepo.git", "testrepo.git/"));
must_pass(ensure_dir_path_normalized("./.git", ".git/"));
must_pass(ensure_dir_path_normalized("./git.", "git./"));
must_pass(ensure_dir_path_normalized("git./", "git./"));
must_pass(ensure_dir_path_normalized("", ""));
must_pass(ensure_dir_path_normalized(".", ""));
must_pass(ensure_dir_path_normalized("./", ""));
must_pass(ensure_dir_path_normalized("./.", ""));
must_fail(ensure_dir_path_normalized("./..", NULL));
must_fail(ensure_dir_path_normalized("../.", NULL));
must_fail(ensure_dir_path_normalized("./.././/", NULL));
must_pass(ensure_dir_path_normalized("dir/..", ""));
must_pass(ensure_dir_path_normalized("dir/sub/../..", ""));
must_pass(ensure_dir_path_normalized("dir/sub/..///..", ""));
must_pass(ensure_dir_path_normalized("dir/sub///../..", ""));
must_pass(ensure_dir_path_normalized("dir/sub///..///..", ""));
must_fail(ensure_dir_path_normalized("dir/sub/../../..", NULL));
must_pass(ensure_dir_path_normalized("dir", "dir/"));
must_pass(ensure_dir_path_normalized("dir//", "dir/"));
must_pass(ensure_dir_path_normalized("./dir", "dir/"));
must_pass(ensure_dir_path_normalized("dir/.", "dir/"));
must_pass(ensure_dir_path_normalized("dir///./", "dir/"));
must_pass(ensure_dir_path_normalized("dir/sub/..", "dir/"));
must_pass(ensure_dir_path_normalized("dir//sub/..", "dir/"));
must_pass(ensure_dir_path_normalized("dir//sub/../", "dir/"));
must_pass(ensure_dir_path_normalized("dir/sub/../", "dir/"));
must_pass(ensure_dir_path_normalized("dir/sub/../.", "dir/"));
must_pass(ensure_dir_path_normalized("dir/s1/../s2/", "dir/s2/"));
must_pass(ensure_dir_path_normalized("d1/s1///s2/..//../s3/", "d1/s3/"));
must_pass(ensure_dir_path_normalized("d1/s1//../s2/../../d2", "d2/"));
must_pass(ensure_dir_path_normalized("dir/sub/../", "dir/"));
must_fail(ensure_dir_path_normalized("....", NULL));
must_fail(ensure_dir_path_normalized("...", NULL));
must_fail(ensure_dir_path_normalized("./...", NULL));
must_fail(ensure_dir_path_normalized("d1/...", NULL));
must_fail(ensure_dir_path_normalized("d1/.../", NULL));
must_fail(ensure_dir_path_normalized("d1/.../d2", NULL));
must_pass(ensure_dir_path_normalized("/./testrepo.git", "/testrepo.git/"));
must_pass(ensure_dir_path_normalized("/./.git", "/.git/"));
must_pass(ensure_dir_path_normalized("/./git.", "/git./"));
must_pass(ensure_dir_path_normalized("/git./", "/git./"));
must_pass(ensure_dir_path_normalized("/", "/"));
must_pass(ensure_dir_path_normalized("//", "/"));
must_pass(ensure_dir_path_normalized("///", "/"));
must_pass(ensure_dir_path_normalized("/.", "/"));
must_pass(ensure_dir_path_normalized("/./", "/"));
must_fail(ensure_dir_path_normalized("/./..", NULL));
must_fail(ensure_dir_path_normalized("/../.", NULL));
must_fail(ensure_dir_path_normalized("/./.././/", NULL));
must_pass(ensure_dir_path_normalized("/dir/..", "/"));
must_pass(ensure_dir_path_normalized("/dir/sub/../..", "/"));
must_fail(ensure_dir_path_normalized("/dir/sub/../../..", NULL));
must_pass(ensure_dir_path_normalized("/dir", "/dir/"));
must_pass(ensure_dir_path_normalized("/dir//", "/dir/"));
must_pass(ensure_dir_path_normalized("/./dir", "/dir/"));
must_pass(ensure_dir_path_normalized("/dir/.", "/dir/"));
must_pass(ensure_dir_path_normalized("/dir///./", "/dir/"));
must_pass(ensure_dir_path_normalized("/dir//sub/..", "/dir/"));
must_pass(ensure_dir_path_normalized("/dir/sub/../", "/dir/"));
must_pass(ensure_dir_path_normalized("//dir/sub/../.", "/dir/"));
must_pass(ensure_dir_path_normalized("/dir/s1/../s2/", "/dir/s2/"));
must_pass(ensure_dir_path_normalized("/d1/s1///s2/..//../s3/", "/d1/s3/"));
must_pass(ensure_dir_path_normalized("/d1/s1//../s2/../../d2", "/d2/"));
must_fail(ensure_dir_path_normalized("/....", NULL));
must_fail(ensure_dir_path_normalized("/...", NULL));
must_fail(ensure_dir_path_normalized("/./...", NULL));
must_fail(ensure_dir_path_normalized("/d1/...", NULL));
must_fail(ensure_dir_path_normalized("/d1/.../", NULL));
must_fail(ensure_dir_path_normalized("/d1/.../d2", NULL));
END_TEST
#include "test_lib.h"
#include "fileops.h"
typedef struct name_data {
int count; /* return count */
char *name; /* filename */
} name_data;
typedef struct walk_data {
char *sub; /* sub-directory name */
name_data *names; /* name state data */
} walk_data;
static char path_buffer[GIT_PATH_MAX];
static char *top_dir = "dir-walk";
static walk_data *state_loc;
static int error(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
return -1;
}
static int setup(walk_data *d)
{
name_data *n;
if (gitfo_mkdir(top_dir, 0755) < 0)
return error("can't mkdir(\"%s\")", top_dir);
if (gitfo_chdir(top_dir) < 0)
return error("can't chdir(\"%s\")", top_dir);
if (strcmp(d->sub, ".") != 0)
if (gitfo_mkdir(d->sub, 0755) < 0)
return error("can't mkdir(\"%s\")", d->sub);
strcpy(path_buffer, d->sub);
state_loc = d;
for (n = d->names; n->name; n++) {
git_file fd = gitfo_creat(n->name, 0600);
must_be_true(fd >= 0);
gitfo_close(fd);
n->count = 0;
}
return 0;
}
static int knockdown(walk_data *d)
{
name_data *n;
for (n = d->names; n->name; n++) {
if (gitfo_unlink(n->name) < 0)
return error("can't unlink(\"%s\")", n->name);
}
if (strcmp(d->sub, ".") != 0)
if (gitfo_rmdir(d->sub) < 0)
return error("can't rmdir(\"%s\")", d->sub);
if (gitfo_chdir("..") < 0)
return error("can't chdir(\"..\")");
if (gitfo_rmdir(top_dir) < 0)
return error("can't rmdir(\"%s\")", top_dir);
return 0;
}
static int check_counts(walk_data *d)
{
int ret = 0;
name_data *n;
for (n = d->names; n->name; n++) {
if (n->count != 1)
ret = error("count (%d, %s)", n->count, n->name);
}
return ret;
}
static int one_entry(void *state, char *path)
{
walk_data *d = (walk_data *) state;
name_data *n;
must_be_true(state == state_loc);
must_be_true(path == path_buffer);
for (n = d->names; n->name; n++) {
if (!strcmp(n->name, path)) {
n->count++;
return 0;
}
}
test_die("unexpected path \"%s\"", path);
}
static name_data dot_names[] = {
{ 0, "./a" },
{ 0, "./asdf" },
{ 0, "./pack-foo.pack" },
{ 0, NULL }
};
static walk_data dot = {
".",
dot_names
};
BEGIN_TEST(dot)
must_pass(setup(&dot));
must_pass(gitfo_dirent(path_buffer,
sizeof(path_buffer),
one_entry,
&dot));
must_pass(check_counts(&dot));
must_pass(knockdown(&dot));
END_TEST
static name_data sub_names[] = {
{ 0, "sub/a" },
{ 0, "sub/asdf" },
{ 0, "sub/pack-foo.pack" },
{ 0, NULL }
};
static walk_data sub = {
"sub",
sub_names
};
BEGIN_TEST(sub)
must_pass(setup(&sub));
must_pass(gitfo_dirent(path_buffer,
sizeof(path_buffer),
one_entry,
&sub));
must_pass(check_counts(&sub));
must_pass(knockdown(&sub));
END_TEST
static walk_data sub_slash = {
"sub/",
sub_names
};
BEGIN_TEST(sub_slash)
must_pass(setup(&sub_slash));
must_pass(gitfo_dirent(path_buffer,
sizeof(path_buffer),
one_entry,
&sub_slash));
must_pass(check_counts(&sub_slash));
must_pass(knockdown(&sub_slash));
END_TEST
static name_data empty_names[] = {
{ 0, NULL }
};
static walk_data empty = {
"empty",
empty_names
};
static int dont_call_me(void *GIT_UNUSED(state), char *GIT_UNUSED(path))
{
GIT_UNUSED_ARG(state)
GIT_UNUSED_ARG(path)
test_die("dont_call_me: unexpected callback!");
}
BEGIN_TEST(empty)
must_pass(setup(&empty));
must_pass(gitfo_dirent(path_buffer,
sizeof(path_buffer),
one_entry,
&empty));
must_pass(check_counts(&empty));
/* make sure callback not called */
must_pass(gitfo_dirent(path_buffer,
sizeof(path_buffer),
dont_call_me,
&empty));
must_pass(knockdown(&empty));
END_TEST
static name_data odd_names[] = {
{ 0, "odd/.a" },
{ 0, "odd/..c" },
/* the following don't work on cygwin/win32 */
/* { 0, "odd/.b." }, */
/* { 0, "odd/..d.." }, */
{ 0, NULL }
};
static walk_data odd = {
"odd",
odd_names
};
BEGIN_TEST(odd)
must_pass(setup(&odd));
must_pass(gitfo_dirent(path_buffer,
sizeof(path_buffer),
one_entry,
&odd));
must_pass(check_counts(&odd));
must_pass(knockdown(&odd));
END_TEST
#include "test_lib.h" /*
#include <git2/odb.h> * Raw data
*/
static char *commit_id = "3d7f8a6af076c8c3f20071a8935cdbe8228594d1";
static unsigned char commit_data[] = { static unsigned char commit_data[] = {
0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66, 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66,
0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35, 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35,
...@@ -52,13 +50,6 @@ static unsigned char commit_data[] = { ...@@ -52,13 +50,6 @@ static unsigned char commit_data[] = {
0x3e, 0x0a, 0x3e, 0x0a,
}; };
static git_rawobj commit_obj = {
commit_data,
sizeof(commit_data),
GIT_OBJ_COMMIT
};
static char *tree_id = "dff2da90b254e1beb889d1f1f1288be1803782df";
static unsigned char tree_data[] = { static unsigned char tree_data[] = {
0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f, 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f,
...@@ -79,14 +70,6 @@ static unsigned char tree_data[] = { ...@@ -79,14 +70,6 @@ static unsigned char tree_data[] = {
0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91,
}; };
static git_rawobj tree_obj = {
tree_data,
sizeof(tree_data),
GIT_OBJ_TREE
};
static char *tag_id = "09d373e1dfdc16b129ceec6dd649739911541e05";
static unsigned char tag_data[] = { static unsigned char tag_data[] = {
0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33,
0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66, 0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66,
...@@ -112,50 +95,18 @@ static unsigned char tag_data[] = { ...@@ -112,50 +95,18 @@ static unsigned char tag_data[] = {
0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x2e, 0x30, 0x2e, 0x31, 0x0a,
}; };
static git_rawobj tag_obj = {
tag_data,
sizeof(tag_data),
GIT_OBJ_TAG
};
static char *zero_id = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
static unsigned char zero_data[] = { static unsigned char zero_data[] = {
0x00 /* dummy data */ 0x00 /* dummy data */
}; };
static git_rawobj zero_obj = {
zero_data,
0,
GIT_OBJ_BLOB
};
static char *one_id = "8b137891791fe96927ad78e64b0aad7bded08bdc";
static unsigned char one_data[] = { static unsigned char one_data[] = {
0x0a, 0x0a,
}; };
static git_rawobj one_obj = {
one_data,
sizeof(one_data),
GIT_OBJ_BLOB
};
static char *two_id = "78981922613b2afb6025042ff6bd878ac1994e85";
static unsigned char two_data[] = { static unsigned char two_data[] = {
0x61, 0x0a, 0x61, 0x0a,
}; };
static git_rawobj two_obj = {
two_data,
sizeof(two_data),
GIT_OBJ_BLOB
};
static char *some_id = "fd8430bc864cfcd5f10e5590f8a447e01b942bfe";
static unsigned char some_data[] = { static unsigned char some_data[] = {
0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68, 0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68,
0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20,
...@@ -306,6 +257,56 @@ static unsigned char some_data[] = { ...@@ -306,6 +257,56 @@ static unsigned char some_data[] = {
0x0a, 0x0a,
}; };
/*
* Sha1 IDS
*/
static char *commit_id = "3d7f8a6af076c8c3f20071a8935cdbe8228594d1";
static char *tree_id = "dff2da90b254e1beb889d1f1f1288be1803782df";
static char *tag_id = "09d373e1dfdc16b129ceec6dd649739911541e05";
static char *zero_id = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
static char *one_id = "8b137891791fe96927ad78e64b0aad7bded08bdc";
static char *two_id = "78981922613b2afb6025042ff6bd878ac1994e85";
static char *some_id = "fd8430bc864cfcd5f10e5590f8a447e01b942bfe";
/*
* In memory objects
*/
static git_rawobj tree_obj = {
tree_data,
sizeof(tree_data),
GIT_OBJ_TREE
};
static git_rawobj tag_obj = {
tag_data,
sizeof(tag_data),
GIT_OBJ_TAG
};
static git_rawobj zero_obj = {
zero_data,
0,
GIT_OBJ_BLOB
};
static git_rawobj one_obj = {
one_data,
sizeof(one_data),
GIT_OBJ_BLOB
};
static git_rawobj two_obj = {
two_data,
sizeof(two_data),
GIT_OBJ_BLOB
};
static git_rawobj commit_obj = {
commit_data,
sizeof(commit_data),
GIT_OBJ_COMMIT
};
static git_rawobj some_obj = { static git_rawobj some_obj = {
some_data, some_data,
sizeof(some_data), sizeof(some_data),
...@@ -319,105 +320,3 @@ static git_rawobj junk_obj = { ...@@ -319,105 +320,3 @@ static git_rawobj junk_obj = {
}; };
BEGIN_TEST(hash_junk)
git_oid id, id_zero;
must_pass(git_oid_mkstr(&id_zero, zero_id));
/* invalid types: */
junk_obj.data = some_data;
must_fail(git_rawobj_hash(&id, &junk_obj));
junk_obj.type = GIT_OBJ__EXT1;
must_fail(git_rawobj_hash(&id, &junk_obj));
junk_obj.type = GIT_OBJ__EXT2;
must_fail(git_rawobj_hash(&id, &junk_obj));
junk_obj.type = GIT_OBJ_OFS_DELTA;
must_fail(git_rawobj_hash(&id, &junk_obj));
junk_obj.type = GIT_OBJ_REF_DELTA;
must_fail(git_rawobj_hash(&id, &junk_obj));
/* data can be NULL only if len is zero: */
junk_obj.type = GIT_OBJ_BLOB;
junk_obj.data = NULL;
must_pass(git_rawobj_hash(&id, &junk_obj));
must_be_true(git_oid_cmp(&id, &id_zero) == 0);
junk_obj.len = 1;
must_fail(git_rawobj_hash(&id, &junk_obj));
END_TEST
BEGIN_TEST(hash_commit)
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, commit_id));
must_pass(git_rawobj_hash(&id2, &commit_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
BEGIN_TEST(hash_tree)
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, tree_id));
must_pass(git_rawobj_hash(&id2, &tree_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
BEGIN_TEST(hash_tag)
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, tag_id));
must_pass(git_rawobj_hash(&id2, &tag_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
BEGIN_TEST(hash_zero)
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, zero_id));
must_pass(git_rawobj_hash(&id2, &zero_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
BEGIN_TEST(hash_one)
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, one_id));
must_pass(git_rawobj_hash(&id2, &one_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
BEGIN_TEST(hash_two)
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, two_id));
must_pass(git_rawobj_hash(&id2, &two_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
BEGIN_TEST(hash_some)
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, some_id));
must_pass(git_rawobj_hash(&id2, &some_obj));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
#include "test_lib.h"
#include "hash.h"
#include <git2/oid.h>
static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511";
static char *hello_text = "hello world\n";
static char *bye_id = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09";
static char *bye_text = "bye world\n";
BEGIN_TEST(hash_iuf)
git_hash_ctx *ctx;
git_oid id1, id2;
must_be_true((ctx = git_hash_new_ctx()) != NULL);
/* should already be init'd */
git_hash_update(ctx, hello_text, strlen(hello_text));
git_hash_final(&id2, ctx);
must_pass(git_oid_mkstr(&id1, hello_id));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
/* reinit should permit reuse */
git_hash_init(ctx);
git_hash_update(ctx, bye_text, strlen(bye_text));
git_hash_final(&id2, ctx);
must_pass(git_oid_mkstr(&id1, bye_id));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
git_hash_free_ctx(ctx);
END_TEST
BEGIN_TEST(hash_buf)
git_oid id1, id2;
must_pass(git_oid_mkstr(&id1, hello_id));
git_hash_buf(&id2, hello_text, strlen(hello_text));
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
BEGIN_TEST(hash_vec)
git_oid id1, id2;
git_buf_vec vec[2];
must_pass(git_oid_mkstr(&id1, hello_id));
vec[0].data = hello_text;
vec[0].len = 4;
vec[1].data = hello_text+4;
vec[1].len = strlen(hello_text)-4;
git_hash_vec(&id2, vec, 2);
must_be_true(git_oid_cmp(&id1, &id2) == 0);
END_TEST
#include "test_lib.h"
#include <git2/odb.h>
#include <git2/object.h>
BEGIN_TEST(type_to_string)
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_BAD), ""));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ__EXT1), ""));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_COMMIT), "commit"));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_TREE), "tree"));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_BLOB), "blob"));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_TAG), "tag"));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ__EXT2), ""));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_OFS_DELTA), "OFS_DELTA"));
must_be_true(!strcmp(git_object_type2string(GIT_OBJ_REF_DELTA), "REF_DELTA"));
must_be_true(!strcmp(git_object_type2string(-2), ""));
must_be_true(!strcmp(git_object_type2string(8), ""));
must_be_true(!strcmp(git_object_type2string(1234), ""));
END_TEST
BEGIN_TEST(string_to_type)
must_be_true(git_object_string2type(NULL) == GIT_OBJ_BAD);
must_be_true(git_object_string2type("") == GIT_OBJ_BAD);
must_be_true(git_object_string2type("commit") == GIT_OBJ_COMMIT);
must_be_true(git_object_string2type("tree") == GIT_OBJ_TREE);
must_be_true(git_object_string2type("blob") == GIT_OBJ_BLOB);
must_be_true(git_object_string2type("tag") == GIT_OBJ_TAG);
must_be_true(git_object_string2type("OFS_DELTA") == GIT_OBJ_OFS_DELTA);
must_be_true(git_object_string2type("REF_DELTA") == GIT_OBJ_REF_DELTA);
must_be_true(git_object_string2type("CoMmIt") == GIT_OBJ_BAD);
must_be_true(git_object_string2type("hohoho") == GIT_OBJ_BAD);
END_TEST
BEGIN_TEST(loose_object)
must_be_true(git_object_typeisloose(GIT_OBJ_BAD) == 0);
must_be_true(git_object_typeisloose(GIT_OBJ__EXT1) == 0);
must_be_true(git_object_typeisloose(GIT_OBJ_COMMIT) == 1);
must_be_true(git_object_typeisloose(GIT_OBJ_TREE) == 1);
must_be_true(git_object_typeisloose(GIT_OBJ_BLOB) == 1);
must_be_true(git_object_typeisloose(GIT_OBJ_TAG) == 1);
must_be_true(git_object_typeisloose(GIT_OBJ__EXT2) == 0);
must_be_true(git_object_typeisloose(GIT_OBJ_OFS_DELTA) == 0);
must_be_true(git_object_typeisloose(GIT_OBJ_REF_DELTA) == 0);
must_be_true(git_object_typeisloose(-2) == 0);
must_be_true(git_object_typeisloose(8) == 0);
must_be_true(git_object_typeisloose(1234) == 0);
END_TEST
#include "test_lib.h" static char *odb_dir = "test-objects";
#include "test_helpers.h"
#include <git2/odb.h>
/* /* one == 8b137891791fe96927ad78e64b0aad7bded08bdc */
* read loose objects from the object directory. The objects are static unsigned char one_bytes[] = {
* written using the current object encoding, using an zlib 0x31, 0x78, 0x9c, 0xe3, 0x02, 0x00, 0x00, 0x0b,
* compression level of Z_BEST_SPEED (1). See also 0x00, 0x0b,
* t0203-readloose.c. };
*/
static unsigned char one_data[] = {
0x0a,
};
static object_data one = {
one_bytes,
sizeof(one_bytes),
"8b137891791fe96927ad78e64b0aad7bded08bdc",
"blob",
"test-objects/8b",
"test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc",
one_data,
sizeof(one_data),
};
BEGIN_TEST("existsloose", exists_loose_one)
git_odb *db;
git_oid id, id2;
must_pass(write_object_files(odb_dir, &one));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, one.id));
must_be_true(git_odb_exists(db, &id));
/* Test for a non-existant object */
must_pass(git_oid_mkstr(&id2, "8b137891791fe96927ad78e64b0aad7bded08baa"));
must_be_true(0 == git_odb_exists(db, &id2));
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &one));
END_TEST
static char *odb_dir = "test-objects";
/* commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 */ /* commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 */
static unsigned char commit_bytes[] = { static unsigned char commit_bytes[] = {
...@@ -235,27 +265,6 @@ static object_data zero = { ...@@ -235,27 +265,6 @@ static object_data zero = {
0, 0,
}; };
/* one == 8b137891791fe96927ad78e64b0aad7bded08bdc */
static unsigned char one_bytes[] = {
0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30,
0x64, 0xe0, 0x02, 0x00, 0x0b, 0xad, 0x01, 0xfb,
};
static unsigned char one_data[] = {
0x0a,
};
static object_data one = {
one_bytes,
sizeof(one_bytes),
"8b137891791fe96927ad78e64b0aad7bded08bdc",
"blob",
"test-objects/8b",
"test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc",
one_data,
sizeof(one_data),
};
/* two == 78981922613b2afb6025042ff6bd878ac1994e85 */ /* two == 78981922613b2afb6025042ff6bd878ac1994e85 */
static unsigned char two_bytes[] = { static unsigned char two_bytes[] = {
0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30, 0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30,
...@@ -523,122 +532,3 @@ static object_data some = { ...@@ -523,122 +532,3 @@ static object_data some = {
sizeof(some_data), sizeof(some_data),
}; };
BEGIN_TEST(read_loose_commit)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &commit));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, commit.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &commit));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &commit));
END_TEST
BEGIN_TEST(read_loose_tree)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &tree));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, tree.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &tree));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &tree));
END_TEST
BEGIN_TEST(read_loose_tag)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &tag));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, tag.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &tag));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &tag));
END_TEST
BEGIN_TEST(read_loose_zero)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &zero));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, zero.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &zero));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &zero));
END_TEST
BEGIN_TEST(read_loose_one)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &one));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, one.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &one));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &one));
END_TEST
BEGIN_TEST(read_loose_two)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &two));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, two.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &two));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &two));
END_TEST
BEGIN_TEST(read_loose_some)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &some));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, some.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &some));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &some));
END_TEST
/*
* 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 "t02-data.h"
#include "t02-oids.h"
BEGIN_TEST("readloose", read_loose_commit)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &commit));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, commit.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &commit));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &commit));
END_TEST
BEGIN_TEST("readloose", read_loose_tree)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &tree));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, tree.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &tree));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &tree));
END_TEST
BEGIN_TEST("readloose", read_loose_tag)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &tag));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, tag.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &tag));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &tag));
END_TEST
BEGIN_TEST("readloose", read_loose_zero)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &zero));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, zero.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &zero));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &zero));
END_TEST
BEGIN_TEST("readloose", read_loose_one)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &one));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, one.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &one));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &one));
END_TEST
BEGIN_TEST("readloose", read_loose_two)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &two));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, two.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &two));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &two));
END_TEST
BEGIN_TEST("readloose", read_loose_some)
git_odb *db;
git_oid id;
git_rawobj obj;
must_pass(write_object_files(odb_dir, &some));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, some.id));
must_pass(git_odb_read(&obj, db, &id));
must_pass(cmp_objects(&obj, &some));
git_rawobj_close(&obj);
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &some));
END_TEST
BEGIN_TEST("readpack", readpacked_test)
unsigned int i;
git_odb *db;
must_pass(git_odb_open(&db, ODB_FOLDER));
for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) {
git_oid id;
git_rawobj obj;
must_pass(git_oid_mkstr(&id, packed_objects[i]));
must_be_true(git_odb_exists(db, &id) == 1);
must_pass(git_odb_read(&obj, db, &id));
git_rawobj_close(&obj);
}
git_odb_close(db);
END_TEST
BEGIN_TEST("readheader", readheader_packed_test)
unsigned int i;
git_odb *db;
must_pass(git_odb_open(&db, ODB_FOLDER));
for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) {
git_oid id;
git_rawobj obj, header;
must_pass(git_oid_mkstr(&id, packed_objects[i]));
must_pass(git_odb_read(&obj, db, &id));
must_pass(git_odb_read_header(&header, db, &id));
must_be_true(obj.len == header.len);
must_be_true(obj.type == header.type);
git_rawobj_close(&obj);
}
git_odb_close(db);
END_TEST
BEGIN_TEST("readheader", readheader_loose_test)
unsigned int i;
git_odb *db;
must_pass(git_odb_open(&db, ODB_FOLDER));
for (i = 0; i < ARRAY_SIZE(loose_objects); ++i) {
git_oid id;
git_rawobj obj, header;
must_pass(git_oid_mkstr(&id, loose_objects[i]));
must_be_true(git_odb_exists(db, &id) == 1);
must_pass(git_odb_read(&obj, db, &id));
must_pass(git_odb_read_header(&header, db, &id));
must_be_true(obj.len == header.len);
must_be_true(obj.type == header.type);
git_rawobj_close(&obj);
}
git_odb_close(db);
END_TEST
git_testsuite *libgit2_suite_objread(void)
{
git_testsuite *suite = git_testsuite_new("Object Read");
ADD_TEST(suite, "existsloose", exists_loose_one);
ADD_TEST(suite, "readloose", read_loose_commit);
ADD_TEST(suite, "readloose", read_loose_tree);
ADD_TEST(suite, "readloose", read_loose_tag);
ADD_TEST(suite, "readloose", read_loose_zero);
ADD_TEST(suite, "readloose", read_loose_one);
ADD_TEST(suite, "readloose", read_loose_two);
ADD_TEST(suite, "readloose", read_loose_some);
/* TODO: import these (naming conflicts) */
/*
ADD_TEST(suite, "readloose", read_loose_commit_enc);
ADD_TEST(suite, "readloose", read_loose_tree_enc);
ADD_TEST(suite, "readloose", read_loose_tag_enc);
ADD_TEST(suite, "readloose", read_loose_zero_enc);
ADD_TEST(suite, "readloose", read_loose_one_enc);
ADD_TEST(suite, "readloose", read_loose_two_enc);
ADD_TEST(suite, "readloose", read_loose_some_enc);
*/
ADD_TEST(suite, "readpack", readpacked_test);
ADD_TEST(suite, "readheader", readheader_packed_test);
ADD_TEST(suite, "readheader", readheader_loose_test);
return suite;
}
#include "test_lib.h"
#include "test_helpers.h"
#include <git2/odb.h>
static const char *packed_objects[] = { static const char *packed_objects[] = {
"0266163a49e280c4f5ed1e08facd36a2bd716bcf", "0266163a49e280c4f5ed1e08facd36a2bd716bcf",
...@@ -131,22 +128,25 @@ static const char *packed_objects[] = { ...@@ -131,22 +128,25 @@ static const char *packed_objects[] = {
"b1bb1d888f0c5e19278536d49fa77db035fac7ae" "b1bb1d888f0c5e19278536d49fa77db035fac7ae"
}; };
BEGIN_TEST(readpacked_test) static const char *loose_objects[] = {
unsigned int i; "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
git_odb *db; "a8233120f6ad708f843d861ce2b7228ec4e3dec6",
"fd093bff70906175335656e6ce6ae05783708765",
must_pass(git_odb_open(&db, ODB_FOLDER)); "c47800c7266a2be04c571c04d5a6614691ea99bd",
"a71586c1dfe8a71c6cbf6c129f404c5642ff31bd",
for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) { "8496071c1b46c854b31185ea97743be6a8774479",
git_oid id; "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
git_rawobj obj; "814889a078c031f61ed08ab5fa863aea9314344d",
"5b5b025afb0b4c913b4c338a42934a3863bf3644",
must_pass(git_oid_mkstr(&id, packed_objects[i])); "1385f264afb75a56a5bec74243be9b367ba4ca08",
must_be_true(git_odb_exists(db, &id) == 1); "f60079018b664e4e79329a7ef9559c8d9e0378d1",
must_pass(git_odb_read(&obj, db, &id)); "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
"75057dd4114e74cca1d750d0aee1647c903cb60a",
git_rawobj_close(&obj); "fa49b077972391ad58037050f2a75f74e3671e92",
} "9fd738e8f7967c078dceed8190330fc8648ee56a",
"1810dff58d8a660512d4832e740f692884338ccd",
"181037049a54a1eb5fab404658a3a250b44335d7",
"a4a7dce85cf63874e984719f4fdd239f5145052f",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
};
git_odb_close(db);
END_TEST
#include "test_lib.h"
#include "test_helpers.h"
#include <git2/odb.h>
static char *odb_dir = "test-objects";
/* one == 8b137891791fe96927ad78e64b0aad7bded08bdc */
static unsigned char one_bytes[] = {
0x31, 0x78, 0x9c, 0xe3, 0x02, 0x00, 0x00, 0x0b,
0x00, 0x0b,
};
static unsigned char one_data[] = {
0x0a,
};
static object_data one = {
one_bytes,
sizeof(one_bytes),
"8b137891791fe96927ad78e64b0aad7bded08bdc",
"blob",
"test-objects/8b",
"test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc",
one_data,
sizeof(one_data),
};
BEGIN_TEST(exists_loose_one)
git_odb *db;
git_oid id, id2;
must_pass(write_object_files(odb_dir, &one));
must_pass(git_odb_open(&db, odb_dir));
must_pass(git_oid_mkstr(&id, one.id));
must_be_true(git_odb_exists(db, &id));
/* Test for a non-existant object */
must_pass(git_oid_mkstr(&id2, "8b137891791fe96927ad78e64b0aad7bded08baa"));
must_be_true(0 == git_odb_exists(db, &id2));
git_odb_close(db);
must_pass(remove_object_files(odb_dir, &one));
END_TEST
#include "test_lib.h"
#include "test_helpers.h"
#include <git2/odb.h>
static const char *packed_objects[] = {
"0266163a49e280c4f5ed1e08facd36a2bd716bcf",
"53fc32d17276939fc79ed05badaef2db09990016",
"6336846bd5c88d32f93ae57d846683e61ab5c530",
"6dcf9bf7541ee10456529833502442f385010c3d",
"bed08a0b30b72a9d4aed7f1af8c8ca124e8d64b9",
"e90810b8df3e80c413d903f631643c716887138d",
"fc3c3a2083e9f6f89e6bd53e9420e70d1e357c9b",
"fc58168adf502d0c0ef614c3111a7038fc8c09c8",
"fd0ec0333948dfe23265ac46be0205a436a8c3a5",
"fd8430bc864cfcd5f10e5590f8a447e01b942bfe",
"fd899f45951c15c1c5f7c34b1c864e91bd6556c6",
"fda23b974899e7e1f938619099280bfda13bdca9",
"fdbec189efb657c8325962b494875987881a356b",
"fe1ca6bd22b5d8353ce6c2f3aba80805c438a7a5",
"fe3a6a42c87ff1239370c741a265f3997add87c1",
"deb106bfd2d36ecf9f0079224c12022201a39ad1",
"dec93efc79e60f2680de3e666755d335967eec30",
"def425bf8568b9c1e20879bf5be6f9c52b7361c4",
"df48000ac4f48570054e3a71a81916357997b680",
"dfae6ed8f6dd8acc3b40a31811ea316239223559",
"dff79e27d3d2cdc09790ded80fe2ea8ff5d61034",
"e00e46abe4c542e17c8bc83d72cf5be8018d7b0e",
"e01b107b4f77f8f98645adac0206a504f2d29d7c",
"e032d863f512c47b479bd984f8b6c8061f66b7d4",
"e044baa468a1c74f9f9da36805445f6888358b49",
"e04529998989ba8ae3419538dd57969af819b241",
"e0637ddfbea67c8d7f557c709e095af8906e9176",
"e0743ad4031231e71700abdc6fdbe94f189d20e5",
"cf33ac7a3d8b2b8f6bb266518aadbf59de397608",
"cf5f7235b9c9689b133f6ea12015720b411329bd",
"cf6cccf1297284833a9a03138a1f5738fa1c6c94",
"cf7992bde17ce7a79cab5f0c1fcbe8a0108721ed",
"cfe3a027ab12506d4144ee8a35669ae8fc4b7ab1",
"cfe96f31dfad7bab49977aa1df7302f7fafcb025",
"cff54d138945ef4de384e9d2759291d0c13ea90a",
"d01f7573ac34c2f502bd1cf18cde73480c741151",
"d03f567593f346a1ca96a57f8191def098d126e3",
"d047b47aadf88501238f36f5c17dd0a50dc62087",
"d0a0d63086fae3b0682af7261df21f7d0f7f066d",
"d0a44bd6ed0be21b725a96c0891bbc79bc1a540c",
"d0d7e736e536a41bcb885005f8bf258c61cad682",
"d0e7959d4b95ffec6198df6f5a7ae259b23a5f50",
"bf2fe2acca17d13356ce802ba9dc8343f710dfb7",
"bf55f407d6d9418e51f42ea7a3a6aadf17388349",
"bf92206f8b633b88a66dca4a911777630b06fbac",
"bfaf8c42eb8842abe206179fee864cfba87e3ca9",
"bfe05675d4e8f6b59d50932add8790f1a06b10ee",
"bff8618112330763327cfa6ce6e914db84f51ddf",
"bff873e9853ed99fed52c25f7ad29f78b27dcec2",
"c01c3fae7251098d7af1b459bcd0786e81d4616d",
"c0220fca67f48b8a5d4163d53b1486224be3a198",
"c02d0b160b82ee72469c269f13de4c26a7ea09cb",
"c059510ad1b45ab58390e042d7dee1ac46703854",
"c07204a1897aeeaa3c248d29dbfa9b033baf9755",
"c073337a4dd7276931b4b3fdbc3f0040e9441793",
"0fd7e4bfba5b3a82be88d1057757ca8b2c5e6d26",
"100746511cc45c9f1ad6721c4ef5be49222fee4d",
"1088490171d9b984d68b8b9be9ca003f4eafff59",
"1093c8ff4cb78fcf5f79dbbeedcb6e824bd4e253",
"10aa3fa72afab7ee31e116ae06442fe0f7b79df2",
"10b759e734e8299aa0dca08be935d95d886127b6",
"111d5ccf0bb010c4e8d7af3eedfa12ef4c5e265b",
"11261fbff21758444d426356ff6327ee01e90752",
"112998d425717bb922ce74e8f6f0f831d8dc4510",
"2ef4e5d838b6507bd61d457cf6466662b791c5c0",
"2ef4faa0f82efa00eeac6cae9e8b2abccc8566ee",
"2f06098183b0d7be350acbe39cdbaccff2df0c4a",
"2f1c5d509ac5bffb3c62f710a1c2c542e126dfd1",
"2f205b20fc16423c42b3ba51b2ea78d7b9ff3578",
"2f9b6b6e3d9250ba09360734aa47973a993b59d1",
"30c62a2d5a8d644f1311d4f7fe3f6a788e4c8188",
"31438e245492d85fd6da4d1406eba0fbde8332a4",
"3184a3abdfea231992254929ff4e275898e5bbf6",
"3188ffdbb3a3d52e0f78f30c484533899224436e",
"32581d0093429770d044a60eb0e9cc0462bedb13",
"32679a9544d83e5403202c4d5efb61ad02492847",
"4e7e9f60b7e2049b7f5697daf133161a18ef688f",
"4e8cda27ddc8be7db875ceb0f360c37734724c6d",
"4ea481c61c59ab55169b7cbaae536ad50b49d6f0",
"4f0adcd0e61eabe06fe32be66b16559537124b7a",
"4f1355c91100d12f9e7202f91b245df0c110867c",
"4f6eadeb08b9d0d1e8b1b3eac8a34940adf29a2d",
"4f9339df943c53117a5fc8e86e2f38716ff3a668",
"4fc3874b118752e40de556b1c3e7b4a9f1737d00",
"4ff1dd0992dd6baafdb5e166be6f9f23b59bdf87",
"5018a35e0b7e2eec7ce5050baf9c7343f3f74164",
"50298f44a45eda3a29dae82dbe911b5aa176ac07",
"502acd164fb115768d723144da2e7bb5a24891bb",
"50330c02bd4fd95c9db1fcf2f97f4218e42b7226",
"5052bf355d9f8c52446561a39733a8767bf31e37",
"6f2cd729ae42988c1dd43588d3a6661ba48ad7a0",
"6f4e2c42d9138bfbf3e0f908f1308828cc6f2178",
"6f6a17db05a83620cef4572761831c20a70ba9b9",
"6faad60901e36538634f0d8b8ff3f21f83503c71",
"6fc72e46de3df0c3842dab302bbacf697a63abab",
"6fdccd49f442a7204399ca9b418f017322dbded8",
"6fe7568fc3861c334cb008fd85d57d9647249ef5",
"700f55d91d7b55665594676a4bada1f1457a0598",
"702bd70595a7b19afc48a1f784a6505be68469d4",
"7033f9ee0e52b08cb5679cd49b7b7999eaf9eaf8",
"70957110ce446c4e250f865760fb3da513cdcc92",
"8ec696a4734f16479d091bc70574d23dd9fe7443",
"8ed341c55ed4d6f4cdc8bf4f0ca18a08c93f6962",
"8edc2805f1f11b63e44bf81f4557f8b473612b69",
"8ef9060a954118a698fc10e20acdc430566a100f",
"8f0c4b543f4bb6eb1518ecfc3d4699e43108d393",
"8fac94df3035405c2e60b3799153ce7c428af6b9",
"904c0ac12b23548de524adae712241b423d765a3",
"90bbaa9a809c3a768d873a9cc7d52b4f3bf3d1b9",
"90d4d2f0fc362beabbbf76b4ffda0828229c198d",
"90f9ff6755330b685feff6c3d81782ee3592ab04",
"91822c50ebe4f9bf5bbb8308ecf9f6557062775c",
"91d973263a55708fa8255867b3202d81ef9c2868",
"af292c99c6148d772af3315a1c74e83330e7ead7",
"af3b99d5be330dbbce0b9250c3a5fb05911908cc",
"af55d0cdeb280af2db8697e5afa506e081012719",
"af795e498d411142ddb073e8ca2c5447c3295a4c",
"afadc73a392f8cc8e2cc77dd62a7433dd3bafa8c",
"affd84ed8ec7ce67612fe3c12a80f8164b101f6a",
"b0941f9c70ffe67f0387a827b338e64ecf3190f0",
"b0a3077f9ef6e093f8d9869bdb0c07095bd722cb",
"b0a8568a7614806378a54db5706ee3b06ae58693",
"b0fb7372f242233d1d35ce7d8e74d3990cbc5841",
"b10489944b9ead17427551759d180d10203e06ba",
"b196a807b323f2748ffc6b1d42cd0812d04c9a40",
"b1bb1d888f0c5e19278536d49fa77db035fac7ae"
};
static const char *loose_objects[] = {
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"a8233120f6ad708f843d861ce2b7228ec4e3dec6",
"fd093bff70906175335656e6ce6ae05783708765",
"c47800c7266a2be04c571c04d5a6614691ea99bd",
"a71586c1dfe8a71c6cbf6c129f404c5642ff31bd",
"8496071c1b46c854b31185ea97743be6a8774479",
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
"814889a078c031f61ed08ab5fa863aea9314344d",
"5b5b025afb0b4c913b4c338a42934a3863bf3644",
"1385f264afb75a56a5bec74243be9b367ba4ca08",
"f60079018b664e4e79329a7ef9559c8d9e0378d1",
"be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
"75057dd4114e74cca1d750d0aee1647c903cb60a",
"fa49b077972391ad58037050f2a75f74e3671e92",
"9fd738e8f7967c078dceed8190330fc8648ee56a",
"1810dff58d8a660512d4832e740f692884338ccd",
"181037049a54a1eb5fab404658a3a250b44335d7",
"a4a7dce85cf63874e984719f4fdd239f5145052f",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045"
};
BEGIN_TEST(readheader_packed_test)
unsigned int i;
git_odb *db;
must_pass(git_odb_open(&db, ODB_FOLDER));
for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) {
git_oid id;
git_rawobj obj, header;
must_pass(git_oid_mkstr(&id, packed_objects[i]));
must_pass(git_odb_read(&obj, db, &id));
must_pass(git_odb_read_header(&header, db, &id));
must_be_true(obj.len == header.len);
must_be_true(obj.type == header.type);
git_rawobj_close(&obj);
}
git_odb_close(db);
END_TEST
BEGIN_TEST(readheader_loose_test)
unsigned int i;
git_odb *db;
must_pass(git_odb_open(&db, ODB_FOLDER));
for (i = 0; i < ARRAY_SIZE(loose_objects); ++i) {
git_oid id;
git_rawobj obj, header;
must_pass(git_oid_mkstr(&id, loose_objects[i]));
must_be_true(git_odb_exists(db, &id) == 1);
must_pass(git_odb_read(&obj, db, &id));
must_pass(git_odb_read_header(&header, db, &id));
must_be_true(obj.len == header.len);
must_be_true(obj.type == header.type);
git_rawobj_close(&obj);
}
git_odb_close(db);
END_TEST
/*
* 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_lib.h"
#include <git2/odb.h>
#include "fileops.h" #include "fileops.h"
static char *odb_dir = "test-objects"; static char *odb_dir = "test-objects";
...@@ -362,25 +385,6 @@ static int make_odb_dir(void) ...@@ -362,25 +385,6 @@ static int make_odb_dir(void)
return 0; return 0;
} }
static int remove_object_files(object_data *d)
{
if (gitfo_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1;
}
if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove directory \"%s\"\n", d->dir);
return -1;
}
if (gitfo_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir);
return -1;
}
return 0;
}
static int check_object_files(object_data *d) static int check_object_files(object_data *d)
{ {
if (gitfo_exists(d->dir) < 0) if (gitfo_exists(d->dir) < 0)
...@@ -401,7 +405,26 @@ static int cmp_objects(git_rawobj *o1, git_rawobj *o2) ...@@ -401,7 +405,26 @@ static int cmp_objects(git_rawobj *o1, git_rawobj *o2)
return 0; return 0;
} }
BEGIN_TEST(write_commit) static int remove_object_files(object_data *d)
{
if (gitfo_unlink(d->file) < 0) {
fprintf(stderr, "can't delete object file \"%s\"\n", d->file);
return -1;
}
if ((gitfo_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) {
fprintf(stderr, "can't remove directory \"%s\"\n", d->dir);
return -1;
}
if (gitfo_rmdir(odb_dir) < 0) {
fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir);
return -1;
}
return 0;
}
BEGIN_TEST("write", write_commit)
git_odb *db; git_odb *db;
git_oid id1, id2; git_oid id1, id2;
git_rawobj obj; git_rawobj obj;
...@@ -422,7 +445,7 @@ BEGIN_TEST(write_commit) ...@@ -422,7 +445,7 @@ BEGIN_TEST(write_commit)
must_pass(remove_object_files(&commit)); must_pass(remove_object_files(&commit));
END_TEST END_TEST
BEGIN_TEST(write_tree) BEGIN_TEST("write", write_tree)
git_odb *db; git_odb *db;
git_oid id1, id2; git_oid id1, id2;
git_rawobj obj; git_rawobj obj;
...@@ -443,7 +466,7 @@ BEGIN_TEST(write_tree) ...@@ -443,7 +466,7 @@ BEGIN_TEST(write_tree)
must_pass(remove_object_files(&tree)); must_pass(remove_object_files(&tree));
END_TEST END_TEST
BEGIN_TEST(write_tag) BEGIN_TEST("write", write_tag)
git_odb *db; git_odb *db;
git_oid id1, id2; git_oid id1, id2;
git_rawobj obj; git_rawobj obj;
...@@ -464,7 +487,7 @@ BEGIN_TEST(write_tag) ...@@ -464,7 +487,7 @@ BEGIN_TEST(write_tag)
must_pass(remove_object_files(&tag)); must_pass(remove_object_files(&tag));
END_TEST END_TEST
BEGIN_TEST(write_zero) BEGIN_TEST("write", write_zero)
git_odb *db; git_odb *db;
git_oid id1, id2; git_oid id1, id2;
git_rawobj obj; git_rawobj obj;
...@@ -485,7 +508,7 @@ BEGIN_TEST(write_zero) ...@@ -485,7 +508,7 @@ BEGIN_TEST(write_zero)
must_pass(remove_object_files(&zero)); must_pass(remove_object_files(&zero));
END_TEST END_TEST
BEGIN_TEST(write_one) BEGIN_TEST("write", write_one)
git_odb *db; git_odb *db;
git_oid id1, id2; git_oid id1, id2;
git_rawobj obj; git_rawobj obj;
...@@ -506,7 +529,7 @@ BEGIN_TEST(write_one) ...@@ -506,7 +529,7 @@ BEGIN_TEST(write_one)
must_pass(remove_object_files(&one)); must_pass(remove_object_files(&one));
END_TEST END_TEST
BEGIN_TEST(write_two) BEGIN_TEST("write", write_two)
git_odb *db; git_odb *db;
git_oid id1, id2; git_oid id1, id2;
git_rawobj obj; git_rawobj obj;
...@@ -527,7 +550,7 @@ BEGIN_TEST(write_two) ...@@ -527,7 +550,7 @@ BEGIN_TEST(write_two)
must_pass(remove_object_files(&two)); must_pass(remove_object_files(&two));
END_TEST END_TEST
BEGIN_TEST(write_some) BEGIN_TEST("write", write_some)
git_odb *db; git_odb *db;
git_oid id1, id2; git_oid id1, id2;
git_rawobj obj; git_rawobj obj;
...@@ -548,3 +571,18 @@ BEGIN_TEST(write_some) ...@@ -548,3 +571,18 @@ BEGIN_TEST(write_some)
must_pass(remove_object_files(&some)); must_pass(remove_object_files(&some));
END_TEST END_TEST
git_testsuite *libgit2_suite_objwrite(void)
{
git_testsuite *suite = git_testsuite_new("Object Write");
ADD_TEST(suite, "write", write_commit);
ADD_TEST(suite, "write", write_tree);
ADD_TEST(suite, "write", write_tag);
ADD_TEST(suite, "write", write_zero);
ADD_TEST(suite, "write", write_one);
ADD_TEST(suite, "write", write_two);
ADD_TEST(suite, "write", write_some);
return 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_lib.h"
#include "test_helpers.h" #include "test_helpers.h"
#include "commit.h" #include "commit.h"
#include "signature.h" #include "signature.h"
#include <git2/odb.h>
#include <git2/commit.h>
#include <git2/revwalk.h>
static char *test_commits_broken[] = { static char *test_commits_broken[] = {
...@@ -87,7 +109,7 @@ committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\ ...@@ -87,7 +109,7 @@ committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\
a simple commit which works\n", a simple commit which works\n",
}; };
BEGIN_TEST(parse_oid_test) BEGIN_TEST("parse", parse_oid_test)
git_oid oid; git_oid oid;
...@@ -129,7 +151,7 @@ BEGIN_TEST(parse_oid_test) ...@@ -129,7 +151,7 @@ BEGIN_TEST(parse_oid_test)
END_TEST END_TEST
BEGIN_TEST(parse_sig_test) BEGIN_TEST("parse", parse_sig_test)
#define TEST_SIGNATURE_PASS(_string, _header, _name, _email, _time, _offset) { \ #define TEST_SIGNATURE_PASS(_string, _header, _name, _email, _time, _offset) { \
char *ptr = _string; \ char *ptr = _string; \
...@@ -263,7 +285,7 @@ END_TEST ...@@ -263,7 +285,7 @@ END_TEST
/* External declaration for testing the buffer parsing method */ /* External declaration for testing the buffer parsing method */
int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int parse_flags); int commit_parse_buffer(git_commit *commit, void *data, size_t len, unsigned int parse_flags);
BEGIN_TEST(parse_buffer_test) BEGIN_TEST("parse", parse_buffer_test)
const int broken_commit_count = sizeof(test_commits_broken) / sizeof(*test_commits_broken); const int broken_commit_count = sizeof(test_commits_broken) / sizeof(*test_commits_broken);
const int working_commit_count = sizeof(test_commits_working) / sizeof(*test_commits_working); const int working_commit_count = sizeof(test_commits_working) / sizeof(*test_commits_working);
...@@ -320,3 +342,178 @@ BEGIN_TEST(parse_buffer_test) ...@@ -320,3 +342,178 @@ BEGIN_TEST(parse_buffer_test)
git_repository_free(repo); git_repository_free(repo);
END_TEST END_TEST
static const char *commit_ids[] = {
"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
"9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
};
BEGIN_TEST("details", query_details_test)
const size_t commit_count = sizeof(commit_ids) / sizeof(const char *);
unsigned int i;
git_repository *repo;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
for (i = 0; i < commit_count; ++i) {
git_oid id;
git_commit *commit;
const git_signature *author, *committer;
const char *message, *message_short;
time_t commit_time;
unsigned int parents, p;
git_commit *parent;
git_oid_mkstr(&id, commit_ids[i]);
must_pass(git_commit_lookup(&commit, repo, &id));
message = git_commit_message(commit);
message_short = git_commit_message_short(commit);
author = git_commit_author(commit);
committer = git_commit_committer(commit);
commit_time = git_commit_time(commit);
parents = git_commit_parentcount(commit);
must_be_true(strcmp(author->name, "Scott Chacon") == 0);
must_be_true(strcmp(author->email, "schacon@gmail.com") == 0);
must_be_true(strcmp(committer->name, "Scott Chacon") == 0);
must_be_true(strcmp(committer->email, "schacon@gmail.com") == 0);
must_be_true(strchr(message, '\n') != NULL);
must_be_true(strchr(message_short, '\n') == NULL);
must_be_true(commit_time > 0);
must_be_true(parents <= 2);
for (p = 0;p < parents;p++) {
parent = git_commit_parent(commit, p);
must_be_true(parent != NULL);
must_be_true(git_commit_author(parent) != NULL); // is it really a commit?
}
must_be_true(git_commit_parent(commit, parents) == NULL);
}
git_repository_free(repo);
END_TEST
#define COMMITTER_NAME "Vicent Marti"
#define COMMITTER_EMAIL "vicent@github.com"
#define COMMIT_MESSAGE "This commit has been created in memory\n\
This is a commit created in memory and it will be written back to disk\n"
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
BEGIN_TEST("write", writenew_test)
git_repository *repo;
git_commit *commit, *parent;
git_tree *tree;
git_oid id;
const git_signature *author, *committer;
/* char hex_oid[41]; */
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
/* Create commit in memory */
must_pass(git_commit_new(&commit, repo));
/* Add new parent */
git_oid_mkstr(&id, commit_ids[4]);
must_pass(git_commit_lookup(&parent, repo, &id));
git_commit_add_parent(commit, parent);
/* Set other attributes */
committer = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60);
must_be_true(committer != NULL);
author = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90);
must_be_true(author != NULL);
git_commit_set_committer(commit, committer);
git_commit_set_author(commit, author);
git_commit_set_message(commit, COMMIT_MESSAGE);
git_signature_free((git_signature *)committer);
git_signature_free((git_signature *)author);
/* Check attributes were set correctly */
author = git_commit_author(commit);
must_be_true(author != NULL);
must_be_true(strcmp(author->name, COMMITTER_NAME) == 0);
must_be_true(strcmp(author->email, COMMITTER_EMAIL) == 0);
must_be_true(author->when.time == 987654321);
must_be_true(author->when.offset == 90);
committer = git_commit_committer(commit);
must_be_true(committer != NULL);
must_be_true(strcmp(committer->name, COMMITTER_NAME) == 0);
must_be_true(strcmp(committer->email, COMMITTER_EMAIL) == 0);
must_be_true(committer->when.time == 123456789);
must_be_true(committer->when.offset == 60);
must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0);
/* add new tree */
git_oid_mkstr(&id, tree_oid);
must_pass(git_tree_lookup(&tree, repo, &id));
git_commit_set_tree(commit, tree);
/* Test it has no OID */
must_be_true(git_commit_id(commit) == NULL);
/* Write to disk */
must_pass(git_object_write((git_object *)commit));
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
git_repository_free(repo);
END_TEST
BEGIN_TEST("write", writeback_test)
git_repository *repo;
git_oid id;
git_commit *commit, *parent;
const char *message;
/* char hex_oid[41]; */
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id, commit_ids[0]);
must_pass(git_commit_lookup(&commit, repo, &id));
message = git_commit_message(commit);
git_commit_set_message(commit, "This is a new test message. Cool!\n");
git_oid_mkstr(&id, commit_ids[4]);
must_pass(git_commit_lookup(&parent, repo, &id));
git_commit_add_parent(commit, parent);
must_pass(git_object_write((git_object *)commit));
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
git_repository_free(repo);
END_TEST
git_testsuite *libgit2_suite_commit(void)
{
git_testsuite *suite = git_testsuite_new("Commit");
ADD_TEST(suite, "parse", parse_oid_test);
ADD_TEST(suite, "parse", parse_sig_test);
ADD_TEST(suite, "parse", parse_buffer_test);
ADD_TEST(suite, "details", query_details_test);
ADD_TEST(suite, "write", writenew_test);
ADD_TEST(suite, "write", writeback_test);
return suite;
}
#include "test_lib.h"
#include "test_helpers.h"
#include "commit.h"
#include "signature.h"
#include <git2/odb.h>
#include <git2/commit.h>
#include <git2/revwalk.h>
static const char *commit_ids[] = {
"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
"9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
};
BEGIN_TEST(query_details_test)
const size_t commit_count = sizeof(commit_ids) / sizeof(const char *);
unsigned int i;
git_repository *repo;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
for (i = 0; i < commit_count; ++i) {
git_oid id;
git_commit *commit;
const git_signature *author, *committer;
const char *message, *message_short;
time_t commit_time;
unsigned int parents, p;
git_commit *parent;
git_oid_mkstr(&id, commit_ids[i]);
must_pass(git_commit_lookup(&commit, repo, &id));
message = git_commit_message(commit);
message_short = git_commit_message_short(commit);
author = git_commit_author(commit);
committer = git_commit_committer(commit);
commit_time = git_commit_time(commit);
parents = git_commit_parentcount(commit);
must_be_true(strcmp(author->name, "Scott Chacon") == 0);
must_be_true(strcmp(author->email, "schacon@gmail.com") == 0);
must_be_true(strcmp(committer->name, "Scott Chacon") == 0);
must_be_true(strcmp(committer->email, "schacon@gmail.com") == 0);
must_be_true(strchr(message, '\n') != NULL);
must_be_true(strchr(message_short, '\n') == NULL);
must_be_true(commit_time > 0);
must_be_true(parents <= 2);
for (p = 0;p < parents;p++) {
parent = git_commit_parent(commit, p);
must_be_true(parent != NULL);
must_be_true(git_commit_author(parent) != NULL); // is it really a commit?
}
must_be_true(git_commit_parent(commit, parents) == NULL);
}
git_repository_free(repo);
END_TEST
#include "test_lib.h"
#include "test_helpers.h"
#include "commit.h"
#include "signature.h"
#include <git2/odb.h>
#include <git2/commit.h>
#include <git2/revwalk.h>
#include <git2/signature.h>
static const char *commit_ids[] = {
"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
"9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
};
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
#define COMMITTER_NAME "Vicent Marti"
#define COMMITTER_EMAIL "vicent@github.com"
#define COMMIT_MESSAGE "This commit has been created in memory\n\
This is a commit created in memory and it will be written back to disk\n"
BEGIN_TEST(writenew_test)
git_repository *repo;
git_commit *commit, *parent;
git_tree *tree;
git_oid id;
const git_signature *author, *committer;
/* char hex_oid[41]; */
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
/* Create commit in memory */
must_pass(git_commit_new(&commit, repo));
/* Add new parent */
git_oid_mkstr(&id, commit_ids[4]);
must_pass(git_commit_lookup(&parent, repo, &id));
git_commit_add_parent(commit, parent);
/* Set other attributes */
committer = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60);
must_be_true(committer != NULL);
author = git_signature_new(COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90);
must_be_true(author != NULL);
git_commit_set_committer(commit, committer);
git_commit_set_author(commit, author);
git_commit_set_message(commit, COMMIT_MESSAGE);
git_signature_free((git_signature *)committer);
git_signature_free((git_signature *)author);
/* Check attributes were set correctly */
author = git_commit_author(commit);
must_be_true(author != NULL);
must_be_true(strcmp(author->name, COMMITTER_NAME) == 0);
must_be_true(strcmp(author->email, COMMITTER_EMAIL) == 0);
must_be_true(author->when.time == 987654321);
must_be_true(author->when.offset == 90);
committer = git_commit_committer(commit);
must_be_true(committer != NULL);
must_be_true(strcmp(committer->name, COMMITTER_NAME) == 0);
must_be_true(strcmp(committer->email, COMMITTER_EMAIL) == 0);
must_be_true(committer->when.time == 123456789);
must_be_true(committer->when.offset == 60);
must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0);
/* add new tree */
git_oid_mkstr(&id, tree_oid);
must_pass(git_tree_lookup(&tree, repo, &id));
git_commit_set_tree(commit, tree);
/* Test it has no OID */
must_be_true(git_commit_id(commit) == NULL);
/* Write to disk */
must_pass(git_object_write((git_object *)commit));
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
git_repository_free(repo);
END_TEST
BEGIN_TEST(writeback_test)
git_repository *repo;
git_oid id;
git_commit *commit, *parent;
const char *message;
/* char hex_oid[41]; */
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id, commit_ids[0]);
must_pass(git_commit_lookup(&commit, repo, &id));
message = git_commit_message(commit);
git_commit_set_message(commit, "This is a new test message. Cool!\n");
git_oid_mkstr(&id, commit_ids[4]);
must_pass(git_commit_lookup(&parent, repo, &id));
git_commit_add_parent(commit, parent);
must_pass(git_object_write((git_object *)commit));
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit));
git_repository_free(repo);
END_TEST
/*
* 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_lib.h"
#include "test_helpers.h" #include "test_helpers.h"
#include "commit.h"
#include <git2/odb.h> #include "revwalk.h"
#include <git2/commit.h>
#include <git2/revwalk.h>
/* /*
$ git log --oneline --graph --decorate $ git log --oneline --graph --decorate
...@@ -89,7 +110,7 @@ static int test_walk(git_revwalk *walk, git_commit *start_from, ...@@ -89,7 +110,7 @@ static int test_walk(git_revwalk *walk, git_commit *start_from,
return GIT_ERROR; return GIT_ERROR;
} }
BEGIN_TEST(simple_walk_test) BEGIN_TEST("walk", simple_walk_test)
git_oid id; git_oid id;
git_repository *repo; git_repository *repo;
git_revwalk *walk; git_revwalk *walk;
...@@ -123,3 +144,78 @@ BEGIN_TEST(simple_walk_test) ...@@ -123,3 +144,78 @@ BEGIN_TEST(simple_walk_test)
git_revwalk_free(walk); git_revwalk_free(walk);
git_repository_free(repo); git_repository_free(repo);
END_TEST END_TEST
BEGIN_TEST("list", list_timesort_test)
git_revwalk_list list;
git_revwalk_listnode *n;
int i, t;
time_t previous_time;
#define TEST_SORTED() \
previous_time = INT_MAX;\
for (n = list.head; n != NULL; n = n->next) {\
must_be_true(n->walk_commit->commit_object->committer->when.time <= previous_time);\
previous_time = n->walk_commit->commit_object->committer->when.time;\
}
#define CLEAR_LIST() \
for (n = list.head; n != NULL; n = n->next) {\
git_signature_free(n->walk_commit->commit_object->committer);\
free(n->walk_commit->commit_object);\
free(n->walk_commit);\
}\
git_revwalk_list_clear(&list);
memset(&list, 0x0, sizeof(git_revwalk_list));
srand((unsigned int)time(NULL));
for (t = 0; t < 20; ++t) {
const int test_size = rand() % 500 + 500;
/* Purely random sorting test */
for (i = 0; i < test_size; ++i) {
git_commit *c = git__malloc(sizeof(git_commit));
git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit));
c->committer = git_signature_new("", "", (time_t)rand(), 0);
rc->commit_object = c;
git_revwalk_list_push_back(&list, rc);
}
git_revwalk_list_timesort(&list);
TEST_SORTED();
CLEAR_LIST();
}
/* Try to sort list with all dates equal. */
for (i = 0; i < 200; ++i) {
git_commit *c = git__malloc(sizeof(git_commit));
git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit));
c->committer = git_signature_new("", "", 0, 0);
rc->commit_object = c;
git_revwalk_list_push_back(&list, rc);
}
git_revwalk_list_timesort(&list);
TEST_SORTED();
CLEAR_LIST();
/* Try to sort empty list */
git_revwalk_list_timesort(&list);
TEST_SORTED();
END_TEST
git_testsuite *libgit2_suite_revwalk(void)
{
git_testsuite *suite = git_testsuite_new("Revwalk");
ADD_TEST(suite, "walk", simple_walk_test);
ADD_TEST(suite, "list", list_timesort_test);
return suite;
}
#include "test_lib.h"
#include "test_helpers.h"
#include "commit.h"
#include "revwalk.h"
#include <git2/odb.h>
#include <git2/commit.h>
#include <git2/signature.h>
BEGIN_TEST(list_timesort_test)
git_revwalk_list list;
git_revwalk_listnode *n;
int i, t;
time_t previous_time;
#define TEST_SORTED() \
previous_time = INT_MAX;\
for (n = list.head; n != NULL; n = n->next) {\
must_be_true(n->walk_commit->commit_object->committer->when.time <= previous_time);\
previous_time = n->walk_commit->commit_object->committer->when.time;\
}
#define CLEAR_LIST() \
for (n = list.head; n != NULL; n = n->next) {\
git_signature_free(n->walk_commit->commit_object->committer);\
free(n->walk_commit->commit_object);\
free(n->walk_commit);\
}\
git_revwalk_list_clear(&list);
memset(&list, 0x0, sizeof(git_revwalk_list));
srand((unsigned int)time(NULL));
for (t = 0; t < 20; ++t) {
const int test_size = rand() % 500 + 500;
/* Purely random sorting test */
for (i = 0; i < test_size; ++i) {
git_commit *c = git__malloc(sizeof(git_commit));
git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit));
c->committer = git_signature_new("", "", (time_t)rand(), 0);
rc->commit_object = c;
git_revwalk_list_push_back(&list, rc);
}
git_revwalk_list_timesort(&list);
TEST_SORTED();
CLEAR_LIST();
}
/* Try to sort list with all dates equal. */
for (i = 0; i < 200; ++i) {
git_commit *c = git__malloc(sizeof(git_commit));
git_revwalk_commit *rc = git__malloc(sizeof(git_revwalk_commit));
c->committer = git_signature_new("", "", 0, 0);
rc->commit_object = c;
git_revwalk_list_push_back(&list, rc);
}
git_revwalk_list_timesort(&list);
TEST_SORTED();
CLEAR_LIST();
/* Try to sort empty list */
git_revwalk_list_timesort(&list);
TEST_SORTED();
END_TEST
/*
* 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_lib.h"
#include "test_helpers.h" #include "test_helpers.h"
#include "index.h"
#include <git2/odb.h> #include "index.h"
#include <git2/index.h>
#define TEST_INDEX_ENTRY_COUNT 109 #define TEST_INDEX_ENTRY_COUNT 109
#define TEST_INDEX2_ENTRY_COUNT 1437 #define TEST_INDEX2_ENTRY_COUNT 1437
...@@ -23,7 +45,7 @@ struct test_entry TEST_ENTRIES[] = { ...@@ -23,7 +45,7 @@ struct test_entry TEST_ENTRIES[] = {
{48, "src/revobject.h", 1448, 0x4C3F7FE2} {48, "src/revobject.h", 1448, 0x4C3F7FE2}
}; };
BEGIN_TEST(index_loadempty_test) BEGIN_TEST("read", index_loadempty_test)
git_index *index; git_index *index;
must_pass(git_index_open_bare(&index, "in-memory-index")); must_pass(git_index_open_bare(&index, "in-memory-index"));
...@@ -38,7 +60,7 @@ BEGIN_TEST(index_loadempty_test) ...@@ -38,7 +60,7 @@ BEGIN_TEST(index_loadempty_test)
git_index_free(index); git_index_free(index);
END_TEST END_TEST
BEGIN_TEST(index_load_test) BEGIN_TEST("read", index_load_test)
git_index *index; git_index *index;
unsigned int i; unsigned int i;
git_index_entry **entries; git_index_entry **entries;
...@@ -65,7 +87,7 @@ BEGIN_TEST(index_load_test) ...@@ -65,7 +87,7 @@ BEGIN_TEST(index_load_test)
git_index_free(index); git_index_free(index);
END_TEST END_TEST
BEGIN_TEST(index2_load_test) BEGIN_TEST("read", index2_load_test)
git_index *index; git_index *index;
must_pass(git_index_open_bare(&index, TEST_INDEX2_PATH)); must_pass(git_index_open_bare(&index, TEST_INDEX2_PATH));
...@@ -81,7 +103,7 @@ BEGIN_TEST(index2_load_test) ...@@ -81,7 +103,7 @@ BEGIN_TEST(index2_load_test)
git_index_free(index); git_index_free(index);
END_TEST END_TEST
BEGIN_TEST(index_find_test) BEGIN_TEST("read", index_find_test)
git_index *index; git_index *index;
unsigned int i; unsigned int i;
...@@ -96,7 +118,7 @@ BEGIN_TEST(index_find_test) ...@@ -96,7 +118,7 @@ BEGIN_TEST(index_find_test)
git_index_free(index); git_index_free(index);
END_TEST END_TEST
BEGIN_TEST(index_findempty_test) BEGIN_TEST("read", index_findempty_test)
git_index *index; git_index *index;
unsigned int i; unsigned int i;
...@@ -109,3 +131,90 @@ BEGIN_TEST(index_findempty_test) ...@@ -109,3 +131,90 @@ BEGIN_TEST(index_findempty_test)
git_index_free(index); git_index_free(index);
END_TEST END_TEST
BEGIN_TEST("write", index_write_test)
git_index *index;
git_filelock out_file;
must_pass(git_index_open_bare(&index, TEST_INDEX_PATH));
must_pass(git_index_read(index));
must_be_true(index->on_disk);
must_pass(git_filelock_init(&out_file, "index_rewrite"));
must_pass(git_filelock_lock(&out_file, 0));
must_pass(git_index__write(index, &out_file));
must_pass(git_filelock_commit(&out_file));
git_index_free(index);
END_TEST
static 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("sort", 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("sort", 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
git_testsuite *libgit2_suite_index(void)
{
git_testsuite *suite = git_testsuite_new("Index");
ADD_TEST(suite, "read", index_loadempty_test);
ADD_TEST(suite, "read", index_load_test);
ADD_TEST(suite, "read", index2_load_test);
ADD_TEST(suite, "read", index_find_test);
ADD_TEST(suite, "read", index_findempty_test);
ADD_TEST(suite, "write", index_write_test);
ADD_TEST(suite, "sort", index_sort_test);
ADD_TEST(suite, "sort", index_sort_empty_test);
return suite;
}
#include "test_lib.h"
#include "test_helpers.h"
#include "index.h"
#include <git2/odb.h>
#include <git2/index.h>
int filecmp(const char *filename1, const char *filename2)
{
git_file file1, file2;
struct stat stat1, stat2;
/* char buffer1[1024], buffer2[1024]; */
file1 = gitfo_open(filename1, O_RDONLY);
file2 = gitfo_open(filename2, O_RDONLY);
if (file1 < 0 || file2 < 0)
return GIT_ERROR;
gitfo_fstat(file1, &stat1);
gitfo_fstat(file2, &stat2);
if (stat1.st_size != stat2.st_size)
return GIT_ERROR;
/* TODO: byte-per-byte comparison */
return 0;
}
BEGIN_TEST(index_load_test)
git_index *index;
git_filelock out_file;
must_pass(git_index_open_bare(&index, TEST_INDEX_PATH));
must_pass(git_index_read(index));
must_be_true(index->on_disk);
must_pass(git_filelock_init(&out_file, "index_rewrite"));
must_pass(git_filelock_lock(&out_file, 0));
must_pass(git_index__write(index, &out_file));
must_pass(git_filelock_commit(&out_file));
git_index_free(index);
END_TEST
#include "test_lib.h"
#include "test_helpers.h"
#include "index.h"
#include <git2/odb.h>
#include <git2/index.h>
/*
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
/*
* 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_lib.h"
#include "test_helpers.h" #include "test_helpers.h"
#include "commit.h"
#include "hash.h"
#include "hashtable.h" #include "hashtable.h"
#include "hash.h"
typedef struct table_item typedef struct _aux_object {
{
int __bulk; int __bulk;
git_oid id; git_oid id;
int visited;
} table_item; } table_item;
uint32_t hash_func(const void *key) uint32_t hash_func(const void *key)
{ {
uint32_t r; uint32_t r;
...@@ -32,7 +55,7 @@ int hash_haskey(void *item, const void *key) ...@@ -32,7 +55,7 @@ int hash_haskey(void *item, const void *key)
return (git_oid_cmp(oid, &obj->id) == 0); return (git_oid_cmp(oid, &obj->id) == 0);
} }
BEGIN_TEST(table_create) BEGIN_TEST("table", table_create)
git_hashtable *table = NULL; git_hashtable *table = NULL;
...@@ -44,7 +67,7 @@ BEGIN_TEST(table_create) ...@@ -44,7 +67,7 @@ BEGIN_TEST(table_create)
END_TEST END_TEST
BEGIN_TEST(table_populate) BEGIN_TEST("table", table_populate)
const int objects_n = 32; const int objects_n = 32;
int i; int i;
...@@ -92,7 +115,7 @@ BEGIN_TEST(table_populate) ...@@ -92,7 +115,7 @@ BEGIN_TEST(table_populate)
END_TEST END_TEST
BEGIN_TEST(table_resize) BEGIN_TEST("table", table_resize)
const int objects_n = 64; const int objects_n = 64;
int i; int i;
...@@ -132,3 +155,52 @@ BEGIN_TEST(table_resize) ...@@ -132,3 +155,52 @@ BEGIN_TEST(table_resize)
free(objects); free(objects);
END_TEST END_TEST
BEGIN_TEST("tableit", table_iterator)
const int objects_n = 32;
int i;
table_item *objects, *ob;
git_hashtable *table = NULL;
git_hashtable_iterator iterator;
table = git_hashtable_alloc(objects_n * 2, hash_func, hash_haskey);
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_iterator_init(table, &iterator);
/* iterate through all nodes, mark as visited */
while ((ob = (table_item *)git_hashtable_iterator_next(&iterator)) != NULL)
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);
free(objects);
END_TEST
git_testsuite *libgit2_suite_hashtable(void)
{
git_testsuite *suite = git_testsuite_new("Hashtable");
ADD_TEST(suite, "table", table_create);
ADD_TEST(suite, "table", table_populate);
ADD_TEST(suite, "table", table_resize);
ADD_TEST(suite, "tableit", table_iterator);
return suite;
}
#include "test_lib.h"
#include "test_helpers.h"
#include "commit.h"
#include "hashtable.h"
#include "hash.h"
typedef struct _aux_object {
int __bulk;
git_oid id;
int visited;
} table_item;
uint32_t hash_func(const void *key)
{
uint32_t r;
git_oid *id;
id = (git_oid *)key;
memcpy(&r, id->id, sizeof(r));
return r;
}
int hash_haskey(void *item, const void *key)
{
table_item *obj;
git_oid *oid;
obj = (table_item *)item;
oid = (git_oid *)key;
return (git_oid_cmp(oid, &obj->id) == 0);
}
BEGIN_TEST(table_iterator)
const int objects_n = 32;
int i;
table_item *objects, *ob;
git_hashtable *table = NULL;
git_hashtable_iterator iterator;
table = git_hashtable_alloc(objects_n * 2, hash_func, hash_haskey);
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_iterator_init(table, &iterator);
/* iterate through all nodes, mark as visited */
while ((ob = (table_item *)git_hashtable_iterator_next(&iterator)) != NULL)
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);
free(objects);
END_TEST
/*
* 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 "tag.h"
static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
BEGIN_TEST("readtag", readtag)
git_repository *repo;
git_tag *tag1, *tag2;
git_commit *commit;
git_oid id1, id2, id_commit;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id1, tag1_id);
git_oid_mkstr(&id2, tag2_id);
git_oid_mkstr(&id_commit, tagged_commit);
must_pass(git_tag_lookup(&tag1, repo, &id1));
must_be_true(strcmp(git_tag_name(tag1), "test") == 0);
must_be_true(git_tag_type(tag1) == GIT_OBJ_TAG);
tag2 = (git_tag *)git_tag_target(tag1);
must_be_true(tag2 != NULL);
must_be_true(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
commit = (git_commit *)git_tag_target(tag2);
must_be_true(commit != NULL);
must_be_true(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
git_repository_free(repo);
END_TEST
BEGIN_TEST("write", tag_writeback_test)
git_oid id;
git_repository *repo;
git_tag *tag;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id, tag1_id);
must_pass(git_tag_lookup(&tag, repo, &id));
git_tag_set_name(tag, "This is a different tag LOL");
must_pass(git_object_write((git_object *)tag));
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag));
git_repository_free(repo);
END_TEST
git_testsuite *libgit2_suite_tag(void)
{
git_testsuite *suite = git_testsuite_new("Tag");
ADD_TEST(suite, "readtag", readtag);
ADD_TEST(suite, "write", tag_writeback_test);
return suite;
}
#include "test_lib.h"
#include "test_helpers.h"
#include "commit.h"
#include <git2/odb.h>
#include <git2/commit.h>
#include <git2/tag.h>
static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
BEGIN_TEST(readtag)
git_repository *repo;
git_tag *tag1, *tag2;
git_commit *commit;
git_oid id1, id2, id_commit;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id1, tag1_id);
git_oid_mkstr(&id2, tag2_id);
git_oid_mkstr(&id_commit, tagged_commit);
must_pass(git_tag_lookup(&tag1, repo, &id1));
must_be_true(strcmp(git_tag_name(tag1), "test") == 0);
must_be_true(git_tag_type(tag1) == GIT_OBJ_TAG);
tag2 = (git_tag *)git_tag_target(tag1);
must_be_true(tag2 != NULL);
must_be_true(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
commit = (git_commit *)git_tag_target(tag2);
must_be_true(commit != NULL);
must_be_true(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
git_repository_free(repo);
END_TEST
#include "test_lib.h"
#include "test_helpers.h"
#include "commit.h"
#include <git2/odb.h>
#include <git2/tag.h>
#include <git2/revwalk.h>
static const char *tag_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
BEGIN_TEST(tag_writeback_test)
git_oid id;
git_repository *repo;
git_tag *tag;
/* char hex_oid[41]; */
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id, tag_id);
must_pass(git_tag_lookup(&tag, repo, &id));
git_tag_set_name(tag, "This is a different tag LOL");
must_pass(git_object_write((git_object *)tag));
/*
git_oid_fmt(hex_oid, git_tag_id(tag));
hex_oid[40] = 0;
printf("TAG New SHA1: %s\n", hex_oid);
*/
must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag));
git_repository_free(repo);
END_TEST
/*
* 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_lib.h"
#include "test_helpers.h" #include "test_helpers.h"
#include "commit.h"
#include <git2/odb.h> #include "tree.h"
#include <git2/commit.h>
#include <git2/revwalk.h>
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
BEGIN_TEST(tree_in_memory_add_test) BEGIN_TEST("readtree", tree_entry_access_test)
git_oid id;
git_repository *repo;
git_tree *tree;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&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, -1) == NULL);
git_repository_free(repo);
END_TEST
BEGIN_TEST("readtree", tree_read_test)
git_oid id;
git_repository *repo;
git_tree *tree;
git_tree_entry *entry;
git_object *obj;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id, tree_oid);
must_pass(git_tree_lookup(&tree, repo, &id));
must_be_true(git_tree_entrycount(tree) == 3);
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, entry));
git_repository_free(repo);
END_TEST
BEGIN_TEST("modify", tree_in_memory_add_test)
const unsigned int entry_count = 128; const unsigned int entry_count = 128;
git_repository *repo; git_repository *repo;
...@@ -38,7 +106,7 @@ BEGIN_TEST(tree_in_memory_add_test) ...@@ -38,7 +106,7 @@ BEGIN_TEST(tree_in_memory_add_test)
git_repository_free(repo); git_repository_free(repo);
END_TEST END_TEST
BEGIN_TEST(tree_add_entry_test) BEGIN_TEST("modify", tree_add_entry_test)
git_oid id; git_oid id;
git_repository *repo; git_repository *repo;
git_tree *tree; git_tree *tree;
...@@ -87,3 +155,16 @@ BEGIN_TEST(tree_add_entry_test) ...@@ -87,3 +155,16 @@ BEGIN_TEST(tree_add_entry_test)
git_object_free((git_object *)tree); git_object_free((git_object *)tree);
git_repository_free(repo); git_repository_free(repo);
END_TEST END_TEST
git_testsuite *libgit2_suite_tree(void)
{
git_testsuite *suite = git_testsuite_new("Tree");
ADD_TEST(suite, "readtree", tree_entry_access_test);
ADD_TEST(suite, "readtree", tree_read_test);
ADD_TEST(suite, "modify", tree_in_memory_add_test);
ADD_TEST(suite, "modify", tree_add_entry_test);
return suite;
}
#include "test_lib.h"
#include "test_helpers.h"
#include "commit.h"
#include <git2/odb.h>
#include <git2/commit.h>
#include <git2/revwalk.h>
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
BEGIN_TEST(tree_entry_access_test)
git_oid id;
git_repository *repo;
git_tree *tree;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&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, -1) == NULL);
git_repository_free(repo);
END_TEST
BEGIN_TEST(tree_read_test)
git_oid id;
git_repository *repo;
git_tree *tree;
git_tree_entry *entry;
git_object *obj;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id, tree_oid);
must_pass(git_tree_lookup(&tree, repo, &id));
must_be_true(git_tree_entrycount(tree) == 3);
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, entry));
git_repository_free(repo);
END_TEST
/*
* 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 "refs.h"
static const char *loose_tag_ref_name = "refs/tags/test";
static const char *non_existing_tag_ref_name = "refs/tags/i-do-not-exist";
BEGIN_TEST("readtag", loose_tag_reference_looking_up)
git_repository *repo;
git_reference *reference;
git_object *object;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, loose_tag_ref_name));
must_be_true(reference->type == GIT_REF_OID);
must_be_true(reference->packed == 0);
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
must_pass(git_repository_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_TAG);
git_repository_free(repo);
END_TEST
BEGIN_TEST("readtag", non_existing_tag_reference_looking_up)
git_repository *repo;
git_reference *reference;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_fail(git_repository_lookup_ref(&reference, repo, non_existing_tag_ref_name));
git_repository_free(repo);
END_TEST
static const char *head_ref_name = "HEAD";
static const char *current_head_target = "refs/heads/master";
static const char *current_master_tip = "be3563ae3f795b2b4353bcce3a527ad0a4f7f644";
BEGIN_TEST("readsymref", symbolic_reference_looking_up)
git_repository *repo;
git_reference *reference, *resolved_ref;
git_object *object;
git_oid id;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, head_ref_name));
must_be_true(reference->type == GIT_REF_SYMBOLIC);
must_be_true(reference->packed == 0);
must_be_true(strcmp(reference->name, head_ref_name) == 0);
must_pass(git_reference_resolve(&resolved_ref, reference));
must_be_true(resolved_ref->type == GIT_REF_OID);
must_pass(git_repository_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_COMMIT);
git_oid_mkstr(&id, current_master_tip);
must_be_true(git_oid_cmp(&id, git_object_id(object)) == 0);
git_repository_free(repo);
END_TEST
BEGIN_TEST("readsymref", looking_up_head_then_master)
git_repository *repo;
git_reference *reference;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, head_ref_name));
must_pass(git_repository_lookup_ref(&reference, repo, current_head_target));
git_repository_free(repo);
END_TEST
BEGIN_TEST("readsymref", looking_up_master_then_head)
git_repository *repo;
git_reference *reference, *master_ref;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&master_ref, repo, current_head_target));
must_pass(git_repository_lookup_ref(&reference, repo, head_ref_name));
git_repository_free(repo);
END_TEST
static const char *packed_head_name = "refs/heads/packed";
static const char *packed_test_head_name = "refs/heads/packed-test";
BEGIN_TEST("readpackedref", packed_reference_looking_up)
git_repository *repo;
git_reference *reference;
git_object *object;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, packed_head_name));
must_be_true(reference->type == GIT_REF_OID);
must_be_true(reference->packed == 1);
must_be_true(strcmp(reference->name, packed_head_name) == 0);
must_pass(git_repository_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_COMMIT);
git_repository_free(repo);
END_TEST
BEGIN_TEST("readpackedref", packed_exists_but_more_recent_loose_reference_is_retrieved)
git_repository *repo;
git_reference *reference;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, packed_head_name));
must_pass(git_repository_lookup_ref(&reference, repo, packed_test_head_name));
must_be_true(reference->type == GIT_REF_OID);
must_be_true(reference->packed == 0);
must_be_true(strcmp(reference->name, packed_test_head_name) == 0);
git_repository_free(repo);
END_TEST
git_testsuite *libgit2_suite_refs(void)
{
git_testsuite *suite = git_testsuite_new("References");
ADD_TEST(suite, "readtag", loose_tag_reference_looking_up);
ADD_TEST(suite, "readtag", non_existing_tag_reference_looking_up);
ADD_TEST(suite, "readsymref", symbolic_reference_looking_up);
ADD_TEST(suite, "readsymref", looking_up_head_then_master);
ADD_TEST(suite, "readsymref", looking_up_master_then_head);
ADD_TEST(suite, "readpackedref", packed_reference_looking_up);
ADD_TEST(suite, "readpackedref", packed_exists_but_more_recent_loose_reference_is_retrieved);
return suite;
}
#include "test_lib.h"
#include "test_helpers.h"
#include "refs.h"
static const char *loose_tag_ref_name = "refs/tags/test";
static const char *non_existing_tag_ref_name = "refs/tags/i-do-not-exist";
BEGIN_TEST(loose_tag_reference_looking_up)
git_repository *repo;
git_reference *reference;
git_object *object;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, loose_tag_ref_name));
must_be_true(reference->type == GIT_REF_OID);
must_be_true(reference->packed == 0);
must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0);
must_pass(git_repository_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_TAG);
git_repository_free(repo);
END_TEST
BEGIN_TEST(non_existing_tag_reference_looking_up)
git_repository *repo;
git_reference *reference;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_fail(git_repository_lookup_ref(&reference, repo, non_existing_tag_ref_name));
git_repository_free(repo);
END_TEST
#include "test_lib.h"
#include "test_helpers.h"
#include "refs.h"
static const char *head_ref_name = "HEAD";
static const char *current_head_target = "refs/heads/master";
static const char *current_master_tip = "be3563ae3f795b2b4353bcce3a527ad0a4f7f644";
BEGIN_TEST(symbolic_reference_looking_up)
git_repository *repo;
git_reference *reference, *resolved_ref;
git_object *object;
git_oid id;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, head_ref_name));
must_be_true(reference->type == GIT_REF_SYMBOLIC);
must_be_true(reference->packed == 0);
must_be_true(strcmp(reference->name, head_ref_name) == 0);
must_pass(git_reference_resolve(&resolved_ref, reference));
must_be_true(resolved_ref->type == GIT_REF_OID);
must_pass(git_repository_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_COMMIT);
git_oid_mkstr(&id, current_master_tip);
must_be_true(git_oid_cmp(&id, git_object_id(object)) == 0);
git_repository_free(repo);
END_TEST
BEGIN_TEST(looking_up_head_then_master)
git_repository *repo;
git_reference *reference;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, head_ref_name));
must_pass(git_repository_lookup_ref(&reference, repo, current_head_target));
git_repository_free(repo);
END_TEST
BEGIN_TEST(looking_up_master_then_head)
git_repository *repo;
git_reference *reference, *master_ref;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&master_ref, repo, current_head_target));
must_pass(git_repository_lookup_ref(&reference, repo, head_ref_name));
git_repository_free(repo);
END_TEST
#include "test_lib.h"
#include "test_helpers.h"
#include "refs.h"
static const char *packed_head_name = "refs/heads/packed";
static const char *packed_test_head_name = "refs/heads/packed-test";
BEGIN_TEST(packed_reference_looking_up)
git_repository *repo;
git_reference *reference;
git_object *object;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, packed_head_name));
must_be_true(reference->type == GIT_REF_OID);
must_be_true(reference->packed == 1);
must_be_true(strcmp(reference->name, packed_head_name) == 0);
must_pass(git_repository_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY));
must_be_true(object != NULL);
must_be_true(git_object_type(object) == GIT_OBJ_COMMIT);
git_repository_free(repo);
END_TEST
BEGIN_TEST(packed_exists_but_more_recent_loose_reference_is_retrieved)
git_repository *repo;
git_reference *reference;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_lookup_ref(&reference, repo, packed_head_name));
must_pass(git_repository_lookup_ref(&reference, repo, packed_test_head_name));
must_be_true(reference->type == GIT_REF_OID);
must_be_true(reference->packed == 0);
must_be_true(strcmp(reference->name, packed_test_head_name) == 0);
git_repository_free(repo);
END_TEST
/* #include <assert.h>
* This file is free software; you can redistribute it and/or modify #include <setjmp.h>
* it under the terms of the GNU General Public License, version 2, #include <stdlib.h>
* as published by the Free Software Foundation. #include <stdio.h>
* #include <string.h>
* In addition to the permissions in the GNU General Public License, #include <math.h>
* 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.
*/
#define GIT__NO_HIDE_MALLOC
#include "test_lib.h" #include "test_lib.h"
struct test_info { #define DO_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE)))
struct test_info *next; #define GIT_MAX_TEST_CASES 64
const char *test_name;
const char *file_name; struct git_test {
int line_no; char *name;
git_testfunc function;
int failed;
int ran;
const char *message;
jmp_buf *jump;
};
struct git_testsuite {
char *name;
int count, fail_count;
git_test *list[GIT_MAX_TEST_CASES];
}; };
static int first_test = 1; static void test_init(git_test *t, const char *name, git_testfunc function)
static struct test_info *current_test; {
t->name = strdup(name);
t->failed = 0;
t->ran = 0;
t->message = NULL;
t->function = function;
t->jump = NULL;
}
static void test_free(git_test *t)
{
if (t) {
free(t->name);
free(t);
}
}
void test_run(git_test *tc)
{
jmp_buf buf;
tc->jump = &buf;
if (setjmp(buf) == 0) {
tc->ran = 1;
(tc->function)(tc);
}
tc->jump = 0;
}
git_test *git_test_new(const char *name, git_testfunc function)
{
git_test *tc = DO_ALLOC(git_test);
test_init(tc, name, function);
return tc;
}
/*-------------------------------------------------------------------------*
* Public assert methods
*-------------------------------------------------------------------------*/
static void fail_test(git_test *tc, const char *file, int line, const char *message)
{
char buf[1024];
snprintf(buf, 1024, "%s @ %s:%d", message, file, line);
tc->failed = 1;
tc->message = strdup(buf);
static void show_test_result(const char *status) if (tc->jump != 0)
longjmp(*(tc->jump), 0);
}
void git_test__fail(git_test *tc, const char *file, int line, const char *message)
{ {
fprintf(stderr, "* %-6s %5d: %s\n", fail_test(tc, file, line, message);
status,
current_test->line_no,
current_test->test_name);
} }
void test_die(const char *fmt, ...) void git_test__assert(git_test *tc, const char *file, int line, const char *message, int condition)
{ {
va_list p; if (condition == 0)
fail_test(tc, file, line, message);
}
if (current_test) /*-------------------------------------------------------------------------*
show_test_result("FAILED"); * Test Suite
*-------------------------------------------------------------------------*/
va_start(p, fmt); static void testsuite_init(git_testsuite *ts)
vfprintf(stderr, fmt, p); {
va_end(p); ts->count = 0;
fputc('\n', stderr); ts->fail_count = 0;
fflush(stderr); memset(ts->list, 0, sizeof(ts->list));
exit(128); }
git_testsuite *git_testsuite_new(const char *name)
{
git_testsuite *ts = DO_ALLOC(git_testsuite);
testsuite_init(ts);
ts->name = strdup(name);
return ts;
} }
void test_begin( void git_testsuite_free(git_testsuite *ts)
const char *test_name,
const char *file_name,
int line_no)
{ {
struct test_info *i = malloc(sizeof(*i)); unsigned int n;
if (!i)
test_die("cannot malloc memory"); for (n = 0; n < GIT_MAX_TEST_CASES; n++)
if (ts->list[n])
i->test_name = test_name; test_free(ts->list[n]);
i->file_name = file_name;
i->line_no = line_no; free(ts);
current_test = i; }
if (first_test) { void git_testsuite_add(git_testsuite *ts, git_test *tc)
const char *name = strrchr(i->file_name, '/'); {
if (name) assert(ts->count < GIT_MAX_TEST_CASES);
name = name + 1; ts->list[ts->count++] = tc;
else }
name = i->file_name;
fprintf(stderr, "*** %s ***\n", name); void git_testsuite_addsuite(git_testsuite *ts, git_testsuite *ts2)
first_test = 0; {
int i;
for (i = 0 ; i < ts2->count ; ++i)
git_testsuite_add(ts, ts2->list[i]);
}
static void print_details(git_testsuite *ts)
{
int i;
int failCount = 0;
if (ts->fail_count == 0) {
const char *testWord = ts->count == 1 ? "test" : "tests";
printf("OK (%d %s)\n", ts->count, testWord);
} else {
printf("Failed (%d failures):\n", ts->fail_count);
for (i = 0 ; i < ts->count ; ++i) {
git_test *tc = ts->list[i];
if (tc->failed) {
failCount++;
printf(" %d) %s: %s\n", failCount, tc->name, tc->message);
}
}
} }
} }
void test_end(void) void git_testsuite_run(git_testsuite *ts)
{ {
if (!current_test) int i;
test_die("BEGIN_TEST() not used before END_TEST");
printf("Suite \"%s\": ", ts->name);
show_test_result("ok"); for (i = 0 ; i < ts->count ; ++i) {
free(current_test); git_test *tc = ts->list[i];
current_test = NULL;
test_run(tc);
if (tc->failed) {
ts->fail_count++;
putchar('F');
} else
putchar('.');
}
printf("\n ");
print_details(ts);
} }
/* #ifndef __LIBGIT2_TEST_H__
* This file is free software; you can redistribute it and/or modify #define __LIBGIT2_TEST_H__
* 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 "common.h"
#include <git2/common.h>
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
/** Declare a function never returns to the caller. */ #include "common.h"
#ifdef __GNUC__ #include <git2.h>
# define NORETURN __attribute__((__noreturn__))
#elif defined(_MSC_VER)
# define NORETURN __declspec(noreturn)
#else
# define NORETURN /* noreturn */
#endif
/** #define ADD_TEST(SUITE, MODULE, TEST) \
* Declares a new test block starting, with the specified name. git_testsuite_add(SUITE, git_test_new(#TEST " (" MODULE ")", &_gittest__##TEST))
* @param name C symbol to assign to this test's function.
*/ #define BEGIN_TEST(MODULE, TEST) \
#define BEGIN_TEST(name) \ void _gittest__##TEST(git_test *_gittest) \
void testfunc__##name(void) \
{ \ { \
test_begin(#name, __FILE__, __LINE__); \ assert(_gittest);\
{ {\
#define END_TEST }}
typedef struct git_test git_test;
typedef struct git_testsuite git_testsuite;
typedef void (*git_testfunc)(git_test *);
/** Denote the end of a test. */ void git_test__fail(git_test *tc, const char *file, int line, const char *message);
#define END_TEST \ void git_test__assert(git_test *tc, const char *file, int line, const char *message, int condition);
} \
test_end(); \
}
/* These are internal functions for BEGIN_TEST, END_TEST. */ #define must_pass(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Method failed, " #expr, (expr) == 0)
extern void test_begin(const char *, const char *, int); #define must_fail(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expected method to fail, " #expr, (expr) < 0)
extern void test_end(void); #define must_be_true(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expected " #expr, !!(expr))
/** git_testsuite *git_testsuite_new(const char *name);
* Abort the current test suite. git_test *git_test_new(const char *name, git_testfunc function);
*
* This function terminates the current test suite
* and does not return to the caller.
*
* @param fmt printf style format string.
*/
extern void NORETURN test_die(const char *fmt, ...)
GIT_FORMAT_PRINTF(1, 2);
/** void git_testsuite_free(git_testsuite *ts);
* Evaluate a library function which must return success.
*
* The definition of "success" is the classical 0 return value.
* This macro makes the test suite fail if the expression evaluates
* to a non-zero result. It is suitable for testing most API
* functions in the library.
*
* @param expr the expression to evaluate, and test the result of.
*/
#define must_pass(expr) \
if (expr) test_die("line %d: %s", __LINE__, #expr)
/** void git_testsuite_add(git_testsuite *ts, git_test *tc);
* Evaluate a library function which must return an error. void git_testsuite_addsuite(git_testsuite* ts, git_testsuite *ts2);
* void git_testsuite_run(git_testsuite *ts);
* The definition of "failure" is the classical non-0 return value.
* This macro makes the test suite fail if the expression evaluates #endif
* to 0 (aka success). It is suitable for testing most API
* functions in the library.
*
* @param expr the expression to evaluate, and test the result of.
*/
#define must_fail(expr) \
if (!(expr)) test_die("line %d: %s", __LINE__, #expr)
/**
* Evaluate an expression which must produce a true result.
*
* @param expr the expression to evaluate, and test the result of.
*/
#define must_be_true(expr) \
if (!(expr)) test_die("line %d: %s", __LINE__, #expr)
...@@ -23,73 +23,82 @@ ...@@ -23,73 +23,82 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include "test_lib.h"
#include <string.h> #include <string.h>
#include <git2.h>
#include "test_lib.h"
#include "test_helpers.h"
extern git_testsuite *libgit2_suite_core(void);
extern git_testsuite *libgit2_suite_rawobjects(void);
extern git_testsuite *libgit2_suite_objread(void);
extern git_testsuite *libgit2_suite_objwrite(void);
extern git_testsuite *libgit2_suite_commit(void);
extern git_testsuite *libgit2_suite_revwalk(void);
extern git_testsuite *libgit2_suite_index(void);
extern git_testsuite *libgit2_suite_hashtable(void);
extern git_testsuite *libgit2_suite_tag(void);
extern git_testsuite *libgit2_suite_tree(void);
extern git_testsuite *libgit2_suite_refs(void);
typedef git_testsuite *(*libgit2_suite)(void);
static libgit2_suite suite_methods[]= {
libgit2_suite_core,
libgit2_suite_rawobjects,
libgit2_suite_objread,
libgit2_suite_objwrite,
libgit2_suite_commit,
libgit2_suite_revwalk,
libgit2_suite_index,
libgit2_suite_hashtable,
libgit2_suite_tag,
libgit2_suite_tree,
libgit2_suite_refs
};
#define GIT_SUITE_COUNT (ARRAY_SIZE(suite_methods))
/*
* print backtrace when a test fails;
* GCC only
*/
#ifdef BACKTRACE
#include <stdio.h>
#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>
void crash_handler(int sig) git_testsuite **libgit2_get_suites()
{ {
void *array[10]; git_testsuite **suites;
size_t size; unsigned int i;
size = backtrace(array, 10); suites = git__malloc(GIT_SUITE_COUNT * sizeof(void *));
if (suites == NULL)
return NULL;
fprintf(stderr, "Error (signal %d)\n", sig); for (i = 0; i < GIT_SUITE_COUNT; ++i)
backtrace_symbols_fd(array, size, 2); suites[i] = suite_methods[i]();
exit(1);
}
#endif
return suites;
}
void libgit2_free_suites(git_testsuite **suites)
{
unsigned int i;
#undef BEGIN_TEST for (i = 0; i < GIT_SUITE_COUNT; ++i)
#define BEGIN_TEST(name) extern void testfunc__##name(void); git_testsuite_free(suites[i]);
#include TEST_TOC
struct test_def { free(suites);
const char *name; }
void (*fun)(void);
};
struct test_def all_tests[] = {
# undef BEGIN_TEST
# define BEGIN_TEST(name) {#name, testfunc__##name},
# include TEST_TOC
{NULL, NULL}
};
int main(int argc, char **argv) int main(int GIT_UNUSED(argc), char *GIT_UNUSED(argv[]))
{ {
struct test_def *t; unsigned int i;
git_testsuite **suites;
#ifdef BACKTRACE
signal(SIGSEGV, crash_handler); GIT_UNUSED_ARG(argc);
#endif GIT_UNUSED_ARG(argv);
if (argc == 1) { suites = libgit2_get_suites();
for (t = all_tests; t->name; t++)
t->fun(); for (i = 0; i < GIT_SUITE_COUNT; ++i)
return 0; git_testsuite_run(suites[i]);
} else if (argc == 2) {
for (t = all_tests; t->name; t++) { libgit2_free_suites(suites);
if (!strcmp(t->name, argv[1])) { return 0;
t->fun();
return 0;
}
}
fprintf(stderr, "error: No test '%s' in %s\n", argv[1], argv[0]);
return 1;
} else {
fprintf(stderr, "usage: %s [test_name]\n", argv[0]);
return 1;
}
} }
...@@ -90,9 +90,9 @@ def build(bld): ...@@ -90,9 +90,9 @@ def build(bld):
build_library(bld, 'shared') build_library(bld, 'shared')
# command '[build|clean]-tests' # command '[build|clean]-tests'
elif bld.variant == 'tests': elif bld.variant == 'test':
build_library(bld, 'objects') build_library(bld, 'objects')
build_tests(bld) build_test(bld)
# command 'build|clean|install|uninstall': by default, run # command 'build|clean|install|uninstall': by default, run
# the same command for both the static and the shared lib # the same command for both the static and the shared lib
...@@ -156,43 +156,20 @@ def call_ldconfig(bld): ...@@ -156,43 +156,20 @@ def call_ldconfig(bld):
if ldconf: if ldconf:
bld.exec_command(ldconf) bld.exec_command(ldconf)
def grep_test_header(text, test_file): def build_test(bld):
return '\n'.join(l for l in test_file.read().splitlines() if text in l)
def build_tests(bld):
import os
if bld.is_install:
return
directory = bld.path directory = bld.path
resources_path = directory.find_node('tests/resources/').abspath().replace('\\', '/') resources_path = directory.find_node('tests/resources/').abspath().replace('\\', '/')
# Common object with the Test library methods sources = ['tests/test_lib.c', 'tests/test_helpers.c', 'tests/test_main.c']
bld.objects(source=['tests/test_helpers.c', 'tests/test_lib.c'], includes=['src', 'tests'], target='test_helper') sources = sources + directory.ant_glob('tests/t??-*.c')
# Build all tests in the tests/ folder
for test_file in directory.ant_glob('tests/t????-*.c'):
test_name, _ = os.path.splitext(os.path.basename(test_file.abspath()))
# Preprocess table of contents for each test
test_toc_file = directory.make_node('tests/%s.toc' % test_name)
if bld.cmd == 'clean-tests': # cleanup; delete the generated TOC file
test_toc_file.delete()
elif bld.cmd == 'build-tests': # build; create TOC
test_toc_file.write(grep_test_header('BEGIN_TEST', test_file))
# Build individual test (don't run)
bld.program(
source=[test_file, 'tests/test_main.c'],
target=test_name,
includes=['src', 'tests'],
defines=['TEST_TOC="%s.toc"' % test_name, 'TEST_RESOURCES="%s"' % resources_path],
install_path=None,
use=['test_helper', 'git2'] + ALL_LIBS # link with all the libs we know
# libraries which are not enabled won't link
)
bld.program(
source=sources,
target='libgit2_test',
includes=['src', 'tests'],
defines=['TEST_RESOURCES="%s"' % resources_path],
use=['git2'] + ALL_LIBS
)
class _test(BuildContext): class _test(BuildContext):
cmd = 'test' cmd = 'test'
...@@ -200,7 +177,7 @@ class _test(BuildContext): ...@@ -200,7 +177,7 @@ class _test(BuildContext):
def test(bld): def test(bld):
from waflib import Options from waflib import Options
Options.commands = ['build-tests', 'run-tests'] + Options.commands Options.commands = ['build-test', 'run-test'] + Options.commands
class _build_doc(Context): class _build_doc(Context):
cmd = 'doxygen' cmd = 'doxygen'
...@@ -216,24 +193,24 @@ def build_docs(ctx): ...@@ -216,24 +193,24 @@ def build_docs(ctx):
ctx.exec_command("git push origin gh-pages") ctx.exec_command("git push origin gh-pages")
ctx.exec_command("git checkout master") ctx.exec_command("git checkout master")
class _run_tests(Context): class _run_test(Context):
cmd = 'run-tests' cmd = 'run-test'
fun = 'run_tests' fun = 'run_test'
def run_tests(ctx): def run_test(ctx):
import shutil, tempfile, sys import shutil, tempfile, sys
failed = False failed = False
test_folder = tempfile.mkdtemp()
test_glob = 'build/tests/t????-*'
test_path = 'build/test/libgit2_test'
if sys.platform == 'win32': if sys.platform == 'win32':
test_glob += '.exe' test_path += '.exe'
test_folder = tempfile.mkdtemp()
test = ctx.path.find_node(test_path)
for test in ctx.path.ant_glob(test_glob): if not test or ctx.exec_command(test.abspath(), cwd=test_folder) != 0:
if ctx.exec_command(test.abspath(), cwd=test_folder) != 0: failed = True
failed = True
break
shutil.rmtree(test_folder) shutil.rmtree(test_folder)
...@@ -256,11 +233,11 @@ def build_command(command): ...@@ -256,11 +233,11 @@ def build_command(command):
build_command('build-static') build_command('build-static')
build_command('build-shared') build_command('build-shared')
build_command('build-tests') build_command('build-test')
build_command('clean-static') build_command('clean-static')
build_command('clean-shared') build_command('clean-shared')
build_command('clean-tests') build_command('clean-test')
build_command('install-static') build_command('install-static')
build_command('install-shared') build_command('install-shared')
......
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