Blame


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