]> git.proxmox.com Git - libgit2.git/blame - tests-clar/object/tree/read.c
Update test suite
[libgit2.git] / tests-clar / object / tree / read.c
CommitLineData
9a39a364
BS
1#include "clar_libgit2.h"
2
3#include "tree.h"
4
5static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
6
7static git_repository *g_repo;
8
9// Fixture setup and teardown
10void test_object_tree_read__initialize(void)
11{
12 g_repo = cl_git_sandbox_init("testrepo");
13}
14
15void test_object_tree_read__cleanup(void)
16{
17 cl_git_sandbox_cleanup();
18}
19
20
21
22void test_object_tree_read__loaded(void)
23{
24 // acces randomly the entries on a loaded tree
25 git_oid id;
26 git_tree *tree;
27
28 git_oid_fromstr(&id, tree_oid);
29
30 cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
31
32 cl_assert(git_tree_entry_byname(tree, "README") != NULL);
33 cl_assert(git_tree_entry_byname(tree, "NOTEXISTS") == NULL);
34 cl_assert(git_tree_entry_byname(tree, "") == NULL);
35 cl_assert(git_tree_entry_byindex(tree, 0) != NULL);
36 cl_assert(git_tree_entry_byindex(tree, 2) != NULL);
37 cl_assert(git_tree_entry_byindex(tree, 3) == NULL);
38 cl_assert(git_tree_entry_byindex(tree, (unsigned int)-1) == NULL);
39
40 git_tree_free(tree);
41}
42
43void test_object_tree_read__two(void)
44{
45 // read a tree from the repository
46 git_oid id;
47 git_tree *tree;
48 const git_tree_entry *entry;
49 git_object *obj;
50
51 git_oid_fromstr(&id, tree_oid);
52
53 cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
54
55 cl_assert(git_tree_entrycount(tree) == 3);
56
57 /* GH-86: git_object_lookup() should also check the type if the object comes from the cache */
58 cl_assert(git_object_lookup(&obj, g_repo, &id, GIT_OBJ_TREE) == 0);
59 cl_assert(obj != NULL);
60 git_object_free(obj);
61 obj = NULL;
62 cl_assert(git_object_lookup(&obj, g_repo, &id, GIT_OBJ_BLOB) == GIT_EINVALIDTYPE);
63 cl_assert(obj == NULL);
64
65 entry = git_tree_entry_byname(tree, "README");
66 cl_assert(entry != NULL);
67
946a6dc4 68 cl_assert_equal_s(git_tree_entry_name(entry), "README");
9a39a364
BS
69
70 cl_git_pass(git_tree_entry_2object(&obj, g_repo, entry));
71 cl_assert(obj != NULL);
72
73 git_object_free(obj);
74 git_tree_free(tree);
75}