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