summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/tests/libntp/atouint.c
blob: 460bf1caf5540d0f81d5fb9675f242dbbf645a38 (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
#include "config.h"

#include "ntp_stdlib.h"
#include "ntp_calendar.h"
#include "ntp_fp.h"

#include "unity.h"

void test_RegularPositive(void);
void test_PositiveOverflowBoundary(void);
void test_PositiveOverflowBig(void);
void test_Negative(void);
void test_IllegalChar(void);



void test_RegularPositive(void) {
	const char *str = "305";
	u_long actual;

	TEST_ASSERT_TRUE(atouint(str, &actual));
	TEST_ASSERT_EQUAL(305, actual);
}

void test_PositiveOverflowBoundary(void) {
	const char *str = "4294967296";
	u_long actual;

	TEST_ASSERT_FALSE(atouint(str, &actual));
}

void test_PositiveOverflowBig(void) {
	const char *str = "8000000000";
	u_long actual;

	TEST_ASSERT_FALSE(atouint(str, &actual));
}

void test_Negative(void) {
	const char *str = "-1";
	u_long actual;

	TEST_ASSERT_FALSE(atouint(str, &actual));
}

void test_IllegalChar(void) {
	const char *str = "50c3";
	u_long actual;

	TEST_ASSERT_FALSE(atouint(str, &actual));
}
OpenPOWER on IntegriCloud