-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathpattern_test.h
44 lines (37 loc) · 1.3 KB
/
pattern_test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "pattern.c" // get_prefix_ranges is a static function in pattern.c, can't introduce it by linking pattern.o
char ticker[10]; // Fix link issue: Undefined symbols for architecture x86_64: "_ticker"
START_TEST(test_get_prefix_ranges)
{
struct {
int addrtype;
const char* pattern;
const char* result_0;
const char* result_1;
} tests[] = {
{ 0,
"12",
"0AF820335D9B3D9CF58B911D87035677FB7F528100000000",
"15F04066BB367B39EB17223B0E06ACEFF6FEA501FFFFFFFF"
},
{ ADDR_TYPE_ETH,
"0xAA",
"AA00000000000000000000000000000000000000",
"AAFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
},
};
size_t n = sizeof(tests) / sizeof(tests[0]);
for (int i = 0; i < n; i++) {
char *got;
BIGNUM *ranges[4];
BN_CTX *bnctx = BN_CTX_new();
int rv = get_prefix_ranges(tests[i].addrtype, tests[i].pattern, ranges, bnctx);
ck_assert_int_eq(0, rv);
got = BN_bn2hex(ranges[0]);
ck_assert_mem_eq(got, tests[i].result_0, strlen(tests[i].result_0));
OPENSSL_free(got);
got = BN_bn2hex(ranges[1]);
ck_assert_mem_eq(got, tests[i].result_1, strlen(tests[i].result_1));
OPENSSL_free(got);
}
}
END_TEST