xref: /aosp_15_r20/external/coreboot/tests/commonlib/bsd/string-test.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <commonlib/bsd/string.h>
4 #include <tests/test.h>
5 
6 /* Used to test skip_atoi */
7 struct str_with_u_val_t {
8 	char *str;
9 	uint32_t value;
10 	uint32_t offset;
11 } str_with_u_val[] = {
12 	{"42aa", 42, 2},
13 	{"a", 0, 0},
14 	{"0", 0, 1},
15 	{"4a2", 4, 1},
16 };
17 
test_skip_atoi(void ** state)18 static void test_skip_atoi(void **state)
19 {
20 	int i;
21 	char *ptr, *copy;
22 
23 	for (i = 0; i < ARRAY_SIZE(str_with_u_val); i++) {
24 		ptr = str_with_u_val[i].str;
25 		copy = ptr;
26 		assert_true(str_with_u_val[i].value == skip_atoi(&ptr));
27 		assert_int_equal(str_with_u_val[i].offset, ptr - copy);
28 	}
29 }
30 
main(void)31 int main(void)
32 {
33 	const struct CMUnitTest tests[] = {
34 		cmocka_unit_test(test_skip_atoi),
35 	};
36 
37 	return cb_run_group_tests(tests, NULL, NULL);
38 }
39