]>
git.proxmox.com Git - libgit2.git/blob - tests/t02-objread.c
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.
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.)
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.
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.
26 #include "test_helpers.h"
33 BEGIN_TEST(existsloose0
, "check if a loose object exists on the odb")
37 must_pass(write_object_files(odb_dir
, &one
));
38 must_pass(git_odb_open(&db
, odb_dir
));
39 must_pass(git_oid_fromstr(&id
, one
.id
));
41 must_be_true(git_odb_exists(db
, &id
));
43 /* Test for a non-existant object */
44 must_pass(git_oid_fromstr(&id2
, "8b137891791fe96927ad78e64b0aad7bded08baa"));
45 must_be_true(0 == git_odb_exists(db
, &id2
));
48 must_pass(remove_object_files(odb_dir
, &one
));
51 BEGIN_TEST(readloose0
, "read a loose commit")
56 must_pass(write_object_files(odb_dir
, &commit
));
57 must_pass(git_odb_open(&db
, odb_dir
));
58 must_pass(git_oid_fromstr(&id
, commit
.id
));
60 must_pass(git_odb_read(&obj
, db
, &id
));
61 must_pass(cmp_objects((git_rawobj
*)&obj
->raw
, &commit
));
63 git_odb_object_close(obj
);
65 must_pass(remove_object_files(odb_dir
, &commit
));
68 BEGIN_TEST(readloose1
, "read a loose tree")
73 must_pass(write_object_files(odb_dir
, &tree
));
74 must_pass(git_odb_open(&db
, odb_dir
));
75 must_pass(git_oid_fromstr(&id
, tree
.id
));
77 must_pass(git_odb_read(&obj
, db
, &id
));
78 must_pass(cmp_objects((git_rawobj
*)&obj
->raw
, &tree
));
80 git_odb_object_close(obj
);
82 must_pass(remove_object_files(odb_dir
, &tree
));
85 BEGIN_TEST(readloose2
, "read a loose tag")
90 must_pass(write_object_files(odb_dir
, &tag
));
91 must_pass(git_odb_open(&db
, odb_dir
));
92 must_pass(git_oid_fromstr(&id
, tag
.id
));
94 must_pass(git_odb_read(&obj
, db
, &id
));
95 must_pass(cmp_objects((git_rawobj
*)&obj
->raw
, &tag
));
97 git_odb_object_close(obj
);
99 must_pass(remove_object_files(odb_dir
, &tag
));
102 BEGIN_TEST(readloose3
, "read a loose zero-bytes object")
107 must_pass(write_object_files(odb_dir
, &zero
));
108 must_pass(git_odb_open(&db
, odb_dir
));
109 must_pass(git_oid_fromstr(&id
, zero
.id
));
111 must_pass(git_odb_read(&obj
, db
, &id
));
112 must_pass(cmp_objects((git_rawobj
*)&obj
->raw
, &zero
));
114 git_odb_object_close(obj
);
116 must_pass(remove_object_files(odb_dir
, &zero
));
119 BEGIN_TEST(readloose4
, "read a one-byte long loose object")
124 must_pass(write_object_files(odb_dir
, &one
));
125 must_pass(git_odb_open(&db
, odb_dir
));
126 must_pass(git_oid_fromstr(&id
, one
.id
));
128 must_pass(git_odb_read(&obj
, db
, &id
));
129 must_pass(cmp_objects(&obj
->raw
, &one
));
131 git_odb_object_close(obj
);
133 must_pass(remove_object_files(odb_dir
, &one
));
136 BEGIN_TEST(readloose5
, "read a two-bytes long loose object")
141 must_pass(write_object_files(odb_dir
, &two
));
142 must_pass(git_odb_open(&db
, odb_dir
));
143 must_pass(git_oid_fromstr(&id
, two
.id
));
145 must_pass(git_odb_read(&obj
, db
, &id
));
146 must_pass(cmp_objects(&obj
->raw
, &two
));
148 git_odb_object_close(obj
);
150 must_pass(remove_object_files(odb_dir
, &two
));
153 BEGIN_TEST(readloose6
, "read a loose object which is several bytes long")
158 must_pass(write_object_files(odb_dir
, &some
));
159 must_pass(git_odb_open(&db
, odb_dir
));
160 must_pass(git_oid_fromstr(&id
, some
.id
));
162 must_pass(git_odb_read(&obj
, db
, &id
));
163 must_pass(cmp_objects(&obj
->raw
, &some
));
165 git_odb_object_close(obj
);
167 must_pass(remove_object_files(odb_dir
, &some
));
170 BEGIN_TEST(readpack0
, "read several packed objects")
174 must_pass(git_odb_open(&db
, ODB_FOLDER
));
176 for (i
= 0; i
< ARRAY_SIZE(packed_objects
); ++i
) {
180 must_pass(git_oid_fromstr(&id
, packed_objects
[i
]));
181 must_be_true(git_odb_exists(db
, &id
) == 1);
182 must_pass(git_odb_read(&obj
, db
, &id
));
184 git_odb_object_close(obj
);
190 BEGIN_TEST(readheader0
, "read only the header of several packed objects")
194 must_pass(git_odb_open(&db
, ODB_FOLDER
));
196 for (i
= 0; i
< ARRAY_SIZE(packed_objects
); ++i
) {
202 must_pass(git_oid_fromstr(&id
, packed_objects
[i
]));
204 must_pass(git_odb_read(&obj
, db
, &id
));
205 must_pass(git_odb_read_header(&len
, &type
, db
, &id
));
207 must_be_true(obj
->raw
.len
== len
);
208 must_be_true(obj
->raw
.type
== type
);
210 git_odb_object_close(obj
);
216 BEGIN_TEST(readheader1
, "read only the header of several loose objects")
220 must_pass(git_odb_open(&db
, ODB_FOLDER
));
222 for (i
= 0; i
< ARRAY_SIZE(loose_objects
); ++i
) {
228 must_pass(git_oid_fromstr(&id
, loose_objects
[i
]));
230 must_be_true(git_odb_exists(db
, &id
) == 1);
232 must_pass(git_odb_read(&obj
, db
, &id
));
233 must_pass(git_odb_read_header(&len
, &type
, db
, &id
));
235 must_be_true(obj
->raw
.len
== len
);
236 must_be_true(obj
->raw
.type
== type
);
238 git_odb_object_close(obj
);
245 ADD_TEST(existsloose0
);
247 ADD_TEST(readloose0
);
248 ADD_TEST(readloose1
);
249 ADD_TEST(readloose2
);
250 ADD_TEST(readloose3
);
251 ADD_TEST(readloose4
);
252 ADD_TEST(readloose5
);
253 ADD_TEST(readloose6
);
256 ADD_TEST(readloose_enc0);
257 ADD_TEST(readloose_enc1);
258 ADD_TEST(readloose_enc2);
259 ADD_TEST(readloose_enc3);
260 ADD_TEST(readloose_enc4);
261 ADD_TEST(readloose_enc5);
262 ADD_TEST(readloose_enc6);
267 ADD_TEST(readheader0
);
268 ADD_TEST(readheader1
);