]> git.proxmox.com Git - libgit2.git/blob - tests/odb/emptyobjects.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / odb / emptyobjects.c
1 #include "clar_libgit2.h"
2 #include "odb.h"
3 #include "filebuf.h"
4
5 #define TEST_REPO_PATH "redundant.git"
6
7 git_repository *g_repo;
8 git_odb *g_odb;
9
10 void test_odb_emptyobjects__initialize(void)
11 {
12 g_repo = cl_git_sandbox_init(TEST_REPO_PATH);
13 cl_git_pass(git_repository_odb(&g_odb, g_repo));
14 }
15
16 void test_odb_emptyobjects__cleanup(void)
17 {
18 git_odb_free(g_odb);
19 cl_git_sandbox_cleanup();
20 }
21
22 void test_odb_emptyobjects__blob_notfound(void)
23 {
24 git_oid id, written_id;
25 git_blob *blob;
26
27 cl_git_pass(git_oid_fromstr(&id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
28 cl_git_fail_with(GIT_ENOTFOUND, git_blob_lookup(&blob, g_repo, &id));
29
30 cl_git_pass(git_odb_write(&written_id, g_odb, "", 0, GIT_OBJECT_BLOB));
31 cl_assert(git_fs_path_exists(TEST_REPO_PATH "/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391"));
32 }
33
34 void test_odb_emptyobjects__read_tree(void)
35 {
36 git_oid id;
37 git_tree *tree;
38
39 cl_git_pass(git_oid_fromstr(&id, "4b825dc642cb6eb9a060e54bf8d69288fbee4904"));
40 cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
41 cl_assert_equal_i(GIT_OBJECT_TREE, git_object_type((git_object *) tree));
42 cl_assert_equal_i(0, git_tree_entrycount(tree));
43 cl_assert_equal_p(NULL, git_tree_entry_byname(tree, "foo"));
44 git_tree_free(tree);
45 }
46
47 void test_odb_emptyobjects__read_tree_odb(void)
48 {
49 git_oid id;
50 git_odb_object *tree_odb;
51
52 cl_git_pass(git_oid_fromstr(&id, "4b825dc642cb6eb9a060e54bf8d69288fbee4904"));
53 cl_git_pass(git_odb_read(&tree_odb, g_odb, &id));
54 cl_assert(git_odb_object_data(tree_odb));
55 cl_assert_equal_s("", git_odb_object_data(tree_odb));
56 cl_assert_equal_i(0, git_odb_object_size(tree_odb));
57 git_odb_object_free(tree_odb);
58 }