|
1 |
| -#include "test-lib.h" |
| 1 | +#include "unit-test.h" |
2 | 2 | #include "lib-oid.h"
|
3 | 3 | #include "strbuf.h"
|
4 | 4 | #include "hex.h"
|
5 | 5 |
|
6 |
| -int init_hash_algo(void) |
| 6 | +int cl_setup_hash_algo(void) |
7 | 7 | {
|
8 | 8 | static int algo = -1;
|
9 | 9 |
|
10 | 10 | if (algo < 0) {
|
11 | 11 | const char *algo_name = getenv("GIT_TEST_DEFAULT_HASH");
|
12 | 12 | algo = algo_name ? hash_algo_by_name(algo_name) : GIT_HASH_SHA1;
|
13 | 13 |
|
14 |
| - if (!check(algo != GIT_HASH_UNKNOWN)) |
15 |
| - test_msg("BUG: invalid GIT_TEST_DEFAULT_HASH value ('%s')", |
16 |
| - algo_name); |
| 14 | + cl_assert(algo != GIT_HASH_UNKNOWN); |
17 | 15 | }
|
18 | 16 | return algo;
|
19 | 17 | }
|
20 | 18 |
|
21 |
| -static int get_oid_arbitrary_hex_algop(const char *hex, struct object_id *oid, |
| 19 | +static void cl_parse_oid(const char *hex, struct object_id *oid, |
22 | 20 | const struct git_hash_algo *algop)
|
23 | 21 | {
|
24 |
| - int ret; |
25 | 22 | size_t sz = strlen(hex);
|
26 | 23 | struct strbuf buf = STRBUF_INIT;
|
27 | 24 |
|
28 |
| - if (!check(sz <= algop->hexsz)) { |
29 |
| - test_msg("BUG: hex string (%s) bigger than maximum allowed (%lu)", |
30 |
| - hex, (unsigned long)algop->hexsz); |
31 |
| - return -1; |
32 |
| - } |
| 25 | + cl_assert(sz <= algop->hexsz); |
33 | 26 |
|
34 | 27 | strbuf_add(&buf, hex, sz);
|
35 | 28 | strbuf_addchars(&buf, '0', algop->hexsz - sz);
|
36 | 29 |
|
37 |
| - ret = get_oid_hex_algop(buf.buf, oid, algop); |
38 |
| - if (!check_int(ret, ==, 0)) |
39 |
| - test_msg("BUG: invalid hex input (%s) provided", hex); |
| 30 | + cl_assert_equal_i(get_oid_hex_algop(buf.buf, oid, algop), 0); |
40 | 31 |
|
41 | 32 | strbuf_release(&buf);
|
42 |
| - return ret; |
43 | 33 | }
|
44 | 34 |
|
45 |
| -int get_oid_arbitrary_hex(const char *hex, struct object_id *oid) |
| 35 | + |
| 36 | +void cl_parse_any_oid(const char *hex, struct object_id *oid) |
46 | 37 | {
|
47 |
| - int hash_algo = init_hash_algo(); |
| 38 | + int hash_algo = cl_setup_hash_algo(); |
48 | 39 |
|
49 |
| - if (!check_int(hash_algo, !=, GIT_HASH_UNKNOWN)) |
50 |
| - return -1; |
51 |
| - return get_oid_arbitrary_hex_algop(hex, oid, &hash_algos[hash_algo]); |
| 40 | + cl_assert(hash_algo != GIT_HASH_UNKNOWN); |
| 41 | + cl_parse_oid(hex, oid, &hash_algos[hash_algo]); |
52 | 42 | }
|
0 commit comments