]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/atoint.c
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / atoint.c
1 #include "config.h"
2
3 #include "ntp_stdlib.h"
4 #include "ntp_calendar.h"
5 #include "unity.h"
6
7 void test_RegularPositive(void) {
8         const char *str = "17";
9         long val;
10
11         TEST_ASSERT_TRUE(atoint(str, &val));
12         TEST_ASSERT_EQUAL(17, val);
13 }
14
15 void test_RegularNegative(void) {
16         const char *str = "-20";
17         long val;
18
19         TEST_ASSERT_TRUE(atoint(str, &val));
20         TEST_ASSERT_EQUAL(-20, val);
21 }
22
23 void test_PositiveOverflowBoundary(void) {
24         const char *str = "2147483648";
25         long val;
26
27         TEST_ASSERT_FALSE(atoint(str, &val));
28 }
29
30 void test_NegativeOverflowBoundary(void) {
31         const char *str = "-2147483649";
32         long val;
33
34         TEST_ASSERT_FALSE(atoint(str, &val));
35 }
36
37 void test_PositiveOverflowBig(void) {
38         const char *str = "2300000000";
39         long val;
40
41         TEST_ASSERT_FALSE(atoint(str, &val));
42 }
43
44 void test_IllegalCharacter(void) {
45         const char *str = "4500l";
46         long val;
47
48         TEST_ASSERT_FALSE(atoint(str, &val));
49 }
50
51