summaryrefslogtreecommitdiff
path: root/tests/commonlib/bsd/string-test.c
blob: d94b82e18c5cb76fddc66e0bad5e942fb48757b4 (plain)
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
/* SPDX-License-Identifier: GPL-2.0-only */

#include <commonlib/bsd/string.h>
#include <tests/test.h>

/* Used to test skip_atoi */
struct str_with_u_val_t {
	char *str;
	uint32_t value;
	uint32_t offset;
} str_with_u_val[] = {
	{"42aa", 42, 2},
	{"a", 0, 0},
	{"0", 0, 1},
	{"4a2", 4, 1},
};

static void test_skip_atoi(void **state)
{
	int i;
	char *ptr, *copy;

	for (i = 0; i < ARRAY_SIZE(str_with_u_val); i++) {
		ptr = str_with_u_val[i].str;
		copy = ptr;
		assert_true(str_with_u_val[i].value == skip_atoi(&ptr));
		assert_int_equal(str_with_u_val[i].offset, ptr - copy);
	}
}

int main(void)
{
	const struct CMUnitTest tests[] = {
		cmocka_unit_test(test_skip_atoi),
	};

	return cb_run_group_tests(tests, NULL, NULL);
}