summaryrefslogtreecommitdiff
path: root/tests/libgit2/odb/loose.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libgit2/odb/loose.c')
-rw-r--r--tests/libgit2/odb/loose.c144
1 files changed, 119 insertions, 25 deletions
diff --git a/tests/libgit2/odb/loose.c b/tests/libgit2/odb/loose.c
index fe013a78c..e79525478 100644
--- a/tests/libgit2/odb/loose.c
+++ b/tests/libgit2/odb/loose.c
@@ -34,24 +34,27 @@ static void cmp_objects(git_rawobj *o, object_data *d)
static void test_read_object(object_data *data)
{
- git_oid id;
- git_odb_object *obj;
+ git_oid id;
+ git_odb_object *obj;
git_odb *odb;
git_rawobj tmp;
+ git_odb_options opts = GIT_ODB_OPTIONS_INIT;
+
+ opts.oid_type = data->id_type;
- write_object_files(data);
+ write_object_files(data);
- cl_git_pass(git_odb_open(&odb, "test-objects"));
- cl_git_pass(git_oid_fromstr(&id, data->id));
- cl_git_pass(git_odb_read(&obj, odb, &id));
+ cl_git_pass(git_odb__open(&odb, "test-objects", &opts));
+ cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type));
+ cl_git_pass(git_odb_read(&obj, odb, &id));
tmp.data = obj->buffer;
tmp.len = obj->cached.size;
tmp.type = obj->cached.type;
- cmp_objects(&tmp, data);
+ cmp_objects(&tmp, data);
- git_odb_object_free(obj);
+ git_odb_object_free(obj);
git_odb_free(odb);
}
@@ -61,11 +64,14 @@ static void test_read_header(object_data *data)
git_odb *odb;
size_t len;
git_object_t type;
+ git_odb_options opts = GIT_ODB_OPTIONS_INIT;
+
+ opts.oid_type = data->id_type;
write_object_files(data);
- cl_git_pass(git_odb_open(&odb, "test-objects"));
- cl_git_pass(git_oid_fromstr(&id, data->id));
+ cl_git_pass(git_odb__open(&odb, "test-objects", &opts));
+ cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type));
cl_git_pass(git_odb_read_header(&len, &type, odb, &id));
cl_assert_equal_sz(data->dlen, len);
@@ -83,11 +89,14 @@ static void test_readstream_object(object_data *data, size_t blocksize)
char buf[2048], *ptr = buf;
size_t remain;
int ret;
+ git_odb_options opts = GIT_ODB_OPTIONS_INIT;
+
+ opts.oid_type = data->id_type;
write_object_files(data);
- cl_git_pass(git_odb_open(&odb, "test-objects"));
- cl_git_pass(git_oid_fromstr(&id, data->id));
+ cl_git_pass(git_odb__open(&odb, "test-objects", &opts));
+ cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type));
cl_git_pass(git_odb_open_rstream(&stream, &tmp.len, &tmp.type, odb, &id));
remain = tmp.len;
@@ -124,32 +133,62 @@ void test_odb_loose__cleanup(void)
cl_fixture_cleanup("test-objects");
}
-void test_odb_loose__exists(void)
+void test_odb_loose__exists_sha1(void)
{
git_oid id, id2;
git_odb *odb;
write_object_files(&one);
- cl_git_pass(git_odb_open(&odb, "test-objects"));
+ cl_git_pass(git_odb__open(&odb, "test-objects", NULL));
- cl_git_pass(git_oid_fromstr(&id, one.id));
+ cl_git_pass(git_oid__fromstr(&id, one.id, GIT_OID_SHA1));
cl_assert(git_odb_exists(odb, &id));
- cl_git_pass(git_oid_fromstrp(&id, "8b137891"));
+ cl_git_pass(git_oid__fromstrp(&id, "8b137891", GIT_OID_SHA1));
cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8));
cl_assert_equal_i(0, git_oid_streq(&id2, one.id));
/* Test for a missing object */
- cl_git_pass(git_oid_fromstr(&id, "8b137891791fe96927ad78e64b0aad7bded08baa"));
+ cl_git_pass(git_oid__fromstr(&id, "8b137891791fe96927ad78e64b0aad7bded08baa", GIT_OID_SHA1));
cl_assert(!git_odb_exists(odb, &id));
- cl_git_pass(git_oid_fromstrp(&id, "8b13789a"));
+ cl_git_pass(git_oid__fromstrp(&id, "8b13789a", GIT_OID_SHA1));
cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8));
git_odb_free(odb);
}
-void test_odb_loose__simple_reads(void)
+void test_odb_loose__exists_sha256(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ git_oid id, id2;
+ git_odb *odb;
+ git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT;
+
+ odb_opts.oid_type = GIT_OID_SHA256;
+
+ write_object_files(&one_sha256);
+ cl_git_pass(git_odb__open(&odb, "test-objects", &odb_opts));
+
+ cl_git_pass(git_oid__fromstr(&id, one_sha256.id, GIT_OID_SHA256));
+ cl_assert(git_odb_exists(odb, &id));
+
+ cl_git_pass(git_oid__fromstrp(&id, "4c0d52d1", GIT_OID_SHA256));
+ cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8));
+ cl_assert_equal_i(0, git_oid_streq(&id2, one_sha256.id));
+
+ /* Test for a missing object */
+ cl_git_pass(git_oid__fromstr(&id, "4c0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493faa", GIT_OID_SHA256));
+ cl_assert(!git_odb_exists(odb, &id));
+
+ cl_git_pass(git_oid__fromstrp(&id, "4c0d52da", GIT_OID_SHA256));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8));
+
+ git_odb_free(odb);
+#endif
+}
+
+void test_odb_loose__simple_reads_sha1(void)
{
test_read_object(&commit);
test_read_object(&tree);
@@ -160,7 +199,20 @@ void test_odb_loose__simple_reads(void)
test_read_object(&some);
}
-void test_odb_loose__streaming_reads(void)
+void test_odb_loose__simple_reads_sha256(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ test_read_object(&commit_sha256);
+ test_read_object(&tree_sha256);
+ test_read_object(&tag_sha256);
+ test_read_object(&zero_sha256);
+ test_read_object(&one_sha256);
+ test_read_object(&two_sha256);
+ test_read_object(&some_sha256);
+#endif
+}
+
+void test_odb_loose__streaming_reads_sha1(void)
{
size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 };
size_t i;
@@ -176,7 +228,25 @@ void test_odb_loose__streaming_reads(void)
}
}
-void test_odb_loose__read_header(void)
+void test_odb_loose__streaming_reads_sha256(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 };
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(blocksizes); i++) {
+ test_readstream_object(&commit_sha256, blocksizes[i]);
+ test_readstream_object(&tree_sha256, blocksizes[i]);
+ test_readstream_object(&tag_sha256, blocksizes[i]);
+ test_readstream_object(&zero_sha256, blocksizes[i]);
+ test_readstream_object(&one_sha256, blocksizes[i]);
+ test_readstream_object(&two_sha256, blocksizes[i]);
+ test_readstream_object(&some_sha256, blocksizes[i]);
+ }
+#endif
+}
+
+void test_odb_loose__read_header_sha1(void)
{
test_read_header(&commit);
test_read_header(&tree);
@@ -187,6 +257,19 @@ void test_odb_loose__read_header(void)
test_read_header(&some);
}
+void test_odb_loose__read_header_sha256(void)
+{
+#ifdef GIT_EXPERIMENTAL_SHA256
+ test_read_header(&commit_sha256);
+ test_read_header(&tree_sha256);
+ test_read_header(&tag_sha256);
+ test_read_header(&zero_sha256);
+ test_read_header(&one_sha256);
+ test_read_header(&two_sha256);
+ test_read_header(&some_sha256);
+#endif
+}
+
static void test_write_object_permission(
mode_t dir_mode, mode_t file_mode,
mode_t expected_dir_mode, mode_t expected_file_mode)
@@ -196,6 +279,7 @@ static void test_write_object_permission(
git_oid oid;
struct stat statbuf;
mode_t mask, os_mask;
+ git_odb_backend_loose_options opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT;
/* Windows does not return group/user bits from stat,
* files are never executable.
@@ -209,8 +293,11 @@ static void test_write_object_permission(
mask = p_umask(0);
p_umask(mask);
- cl_git_pass(git_odb_new(&odb));
- cl_git_pass(git_odb_backend_loose(&backend, "test-objects", -1, 0, dir_mode, file_mode));
+ opts.dir_mode = dir_mode;
+ opts.file_mode = file_mode;
+
+ cl_git_pass(git_odb__new(&odb, NULL));
+ cl_git_pass(git_odb__backend_loose(&backend, "test-objects", &opts));
cl_git_pass(git_odb_add_backend(odb, backend, 1));
cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB));
@@ -243,9 +330,16 @@ static void write_object_to_loose_odb(int fsync)
git_odb *odb;
git_odb_backend *backend;
git_oid oid;
+ git_odb_backend_loose_options opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT;
+
+ if (fsync)
+ opts.flags |= GIT_ODB_BACKEND_LOOSE_FSYNC;
+
+ opts.dir_mode = 0777;
+ opts.file_mode = 0666;
- cl_git_pass(git_odb_new(&odb));
- cl_git_pass(git_odb_backend_loose(&backend, "test-objects", -1, fsync, 0777, 0666));
+ cl_git_pass(git_odb__new(&odb, NULL));
+ cl_git_pass(git_odb__backend_loose(&backend, "test-objects", &opts));
cl_git_pass(git_odb_add_backend(odb, backend, 1));
cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB));
git_odb_free(odb);