]> git.proxmox.com Git - libgit2.git/blob - tests/t09-tree.c
I broke your bindings
[libgit2.git] / tests / t09-tree.c
1 /*
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
5 *
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
14 *
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
24 */
25 #include "test_lib.h"
26 #include "test_helpers.h"
27
28 #include "tree.h"
29
30 static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
31
32 BEGIN_TEST(read0, "acces randomly the entries on a loaded tree")
33 git_oid id;
34 git_repository *repo;
35 git_tree *tree;
36
37 must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
38
39 git_oid_mkstr(&id, tree_oid);
40
41 must_pass(git_tree_lookup(&tree, repo, &id));
42
43 must_be_true(git_tree_entry_byname(tree, "README") != NULL);
44 must_be_true(git_tree_entry_byname(tree, "NOTEXISTS") == NULL);
45 must_be_true(git_tree_entry_byname(tree, "") == NULL);
46 must_be_true(git_tree_entry_byindex(tree, 0) != NULL);
47 must_be_true(git_tree_entry_byindex(tree, 2) != NULL);
48 must_be_true(git_tree_entry_byindex(tree, 3) == NULL);
49 must_be_true(git_tree_entry_byindex(tree, -1) == NULL);
50
51 git_repository_free(repo);
52 END_TEST
53
54 BEGIN_TEST(read1, "read a tree from the repository")
55 git_oid id;
56 git_repository *repo;
57 git_tree *tree;
58 git_tree_entry *entry;
59 git_object *obj;
60
61 must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
62
63 git_oid_mkstr(&id, tree_oid);
64
65 must_pass(git_tree_lookup(&tree, repo, &id));
66
67 must_be_true(git_tree_entrycount(tree) == 3);
68
69 /* GH-86: git_object_lookup() should also check the type if the object comes from the cache */
70 must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_TREE) == 0);
71 must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_BLOB) == GIT_EINVALIDTYPE);
72
73 entry = git_tree_entry_byname(tree, "README");
74 must_be_true(entry != NULL);
75
76 must_be_true(strcmp(git_tree_entry_name(entry), "README") == 0);
77
78 must_pass(git_tree_entry_2object(&obj, repo, entry));
79
80 git_repository_free(repo);
81 END_TEST
82
83 BEGIN_SUITE(tree)
84 ADD_TEST(read0);
85 ADD_TEST(read1);
86 // ADD_TEST(write0); /* TODO THREADSAFE */
87 // ADD_TEST(write1);
88 END_SUITE
89