Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 #include <sys/stat.h>
18 #include <sys/queue.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <sha1.h>
23 #include <zlib.h>
25 #include "got_error.h"
26 #include "got_object.h"
27 #include "pack.h"
29 #define RUN_TEST(expr, name) \
30 if (!(expr)) { printf("test %s failed\n", (name)); failure = 1; }
32 #define GOT_REPO_PATH "../../../"
34 static int
35 packfile_read_idx(const char *repo_path)
36 {
37 const struct got_error *err;
38 struct got_packidx_v2_hdr *packidx;
39 const char *pack_checksum = "5414c35e56c54294d2515863832bf46ad0e321d7";
40 const char *pack_prefix = ".git/objects/pack/pack";
41 char *fullpath;
42 int ret = 1;
44 if (asprintf(&fullpath, "%s/%s-%s.idx", repo_path, pack_prefix,
45 pack_checksum) == -1)
46 return 0;
48 err = got_packidx_open(&packidx, fullpath);
49 if (err) {
50 printf("got_packidx_open: %s\n", err->msg);
51 ret = 0;
52 }
54 got_packidx_close(packidx);
55 free(fullpath);
56 return ret;
57 }
59 int
60 main(int argc, const char *argv[])
61 {
62 int failure = 0;
63 const char *repo_path;
65 if (argc == 1)
66 repo_path = GOT_REPO_PATH;
67 else if (argc == 2)
68 repo_path = argv[1];
69 else {
70 fprintf(stderr, "usage: repository_test [REPO_PATH]\n");
71 return 1;
72 }
74 RUN_TEST(packfile_read_idx(repo_path), "packfile_read_idx");
76 return failure ? 1 : 0;
77 }