xref: /NextBSD/contrib/ntp/tests/libntp/atouint.c (revision 84d351007654069f9643c8e4b4802a7f5f08ee42)
1 #include "config.h"
2 
3 #include "ntp_stdlib.h"
4 #include "ntp_calendar.h"
5 #include "ntp_fp.h"
6 
7 #include "unity.h"
8 
9 void test_RegularPositive(void);
10 void test_PositiveOverflowBoundary(void);
11 void test_PositiveOverflowBig(void);
12 void test_Negative(void);
13 void test_IllegalChar(void);
14 
15 
16 
test_RegularPositive(void)17 void test_RegularPositive(void) {
18 	const char *str = "305";
19 	u_long actual;
20 
21 	TEST_ASSERT_TRUE(atouint(str, &actual));
22 	TEST_ASSERT_EQUAL(305, actual);
23 }
24 
test_PositiveOverflowBoundary(void)25 void test_PositiveOverflowBoundary(void) {
26 	const char *str = "4294967296";
27 	u_long actual;
28 
29 	TEST_ASSERT_FALSE(atouint(str, &actual));
30 }
31 
test_PositiveOverflowBig(void)32 void test_PositiveOverflowBig(void) {
33 	const char *str = "8000000000";
34 	u_long actual;
35 
36 	TEST_ASSERT_FALSE(atouint(str, &actual));
37 }
38 
test_Negative(void)39 void test_Negative(void) {
40 	const char *str = "-1";
41 	u_long actual;
42 
43 	TEST_ASSERT_FALSE(atouint(str, &actual));
44 }
45 
test_IllegalChar(void)46 void test_IllegalChar(void) {
47 	const char *str = "50c3";
48 	u_long actual;
49 
50 	TEST_ASSERT_FALSE(atouint(str, &actual));
51 }
52