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 GOT_REPO_PATH "../../../"
31 static int
32 packfile_read_idx(const char *repo_path)
33 {
34 const struct got_error *err;
35 struct got_packidx_v2_hdr *packidx;
36 const char *pack_checksum = "5414c35e56c54294d2515863832bf46ad0e321d7";
37 const char *pack_prefix = ".git/objects/pack/pack";
38 char *fullpath;
39 int ret = 1;
41 if (asprintf(&fullpath, "%s/%s-%s.idx", repo_path, pack_prefix,
42 pack_checksum) == -1)
43 return 0;
45 err = got_packidx_open(&packidx, fullpath);
46 if (err) {
47 printf("got_packidx_open: %s\n", err->msg);
48 ret = 0;
49 }
51 got_packidx_close(packidx);
52 free(fullpath);
53 return ret;
54 }
56 #define RUN_TEST(expr, name) \
57 { test_ok = (expr); \
58 printf("test %s %s\n", (name), test_ok ? "ok" : "failed"); \
59 failure = (failure || !test_ok); }
61 int
62 main(int argc, const char *argv[])
63 {
64 int test_ok = 0, failure = 0;
65 const char *repo_path;
67 if (argc == 1)
68 repo_path = GOT_REPO_PATH;
69 else if (argc == 2)
70 repo_path = argv[1];
71 else {
72 fprintf(stderr, "usage: repository_test [REPO_PATH]\n");
73 return 1;
74 }
76 RUN_TEST(packfile_read_idx(repo_path), "packfile_read_idx");
78 return failure ? 1 : 0;
79 }