1 /* SPDX-License-Identifier: GPL-2.0-only */
7 #include <tests/test.h>
14 {.str
= "A", .res
= 0},
15 {.str
= "AB", .val
= (int[]){171}, .res
= 1},
16 {.str
= "277a", .val
= (int[]){39, 122}, .res
= 2},
17 {.str
= "277ab", .val
= (int[]){39, 122}, .res
= 2},
18 {.str
= "\n\rx1234567ijkl", .val
= (int[]){18, 52, 86}, .res
= 3},
19 {.str
= "\nB*e/ef-", .val
= (int[]){190, 239}, .res
= 2},
22 static void test_hexstrtobin(void **state
)
27 for (int i
= 0; i
< ARRAY_SIZE(hexstr
); i
++) {
28 len
= strlen(hexstr
[i
].str
) / 2 + 1;
30 res
= hexstrtobin(hexstr
[i
].str
, buf
, len
);
32 assert_int_equal(hexstr
[i
].res
, res
);
34 for (int j
= 0; j
< res
; j
++)
35 assert_int_equal(hexstr
[i
].val
[j
], buf
[j
]);
43 const struct CMUnitTest tests
[] = {
44 cmocka_unit_test(test_hexstrtobin
),
47 return cb_run_group_tests(tests
, NULL
, NULL
);