summaryrefslogtreecommitdiff
path: root/unittests/lib/strntol.c
blob: 14adde2c657919573712a9d7410e02983fe15da5 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "../unittest.h"

#include "../../lib/strntol.h"

static void test_strntol_1(void)
{
	char s[] = "12345";
	char *endp = NULL;
	long ret = strntol(s, strlen(s), &endp, 10);

	CU_ASSERT_EQUAL(ret, 12345);
	CU_ASSERT_NOT_EQUAL(endp, NULL);
	CU_ASSERT_EQUAL(*endp, '\0');
}

static void test_strntol_2(void)
{
	char s[] = "     12345";
	char *endp = NULL;
	long ret = strntol(s, strlen(s), &endp, 10);

	CU_ASSERT_EQUAL(ret, 12345);
	CU_ASSERT_NOT_EQUAL(endp, NULL);
	CU_ASSERT_EQUAL(*endp, '\0');
}

static void test_strntol_3(void)
{
	char s[] = "0x12345";
	char *endp = NULL;
	long ret = strntol(s, strlen(s), &endp, 16);

	CU_ASSERT_EQUAL(ret, 0x12345);
	CU_ASSERT_NOT_EQUAL(endp, NULL);
	CU_ASSERT_EQUAL(*endp, '\0');
}

static struct fio_unittest_entry tests[] = {
	{
		.name	= "strntol/1",
		.fn	= test_strntol_1,
	},
	{
		.name	= "strntol/2",
		.fn	= test_strntol_2,
	},
	{
		.name	= "strntol/3",
		.fn	= test_strntol_3,
	},
	{
		.name	= NULL,
	},
};

CU_ErrorCode fio_unittest_lib_strntol(void)
{
	return fio_unittest_add_suite("lib/strntol.c", NULL, NULL, tests);
}