]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/ntp/tests/libntp/octtoint.c
Upgrade NTP to 4.2.8p4.
[FreeBSD/releng/10.2.git] / contrib / ntp / tests / libntp / octtoint.c
1 #include "config.h"
2
3 #include "ntp_stdlib.h"
4
5 #include "unity.h"
6
7
8 void test_SingleDigit(void);
9 void test_MultipleDigits(void);
10 void test_Zero(void);
11 void test_MaximumUnsigned32bit(void);
12 void test_Overflow(void);
13 void test_IllegalCharacter(void);
14 void test_IllegalDigit(void);
15
16
17 void test_SingleDigit(void) {
18         const char* str = "5";
19         u_long actual;
20
21         TEST_ASSERT_TRUE(octtoint(str, &actual) );
22         TEST_ASSERT_EQUAL(5, actual);
23 }
24
25 void test_MultipleDigits(void){
26         const char* str = "271";
27         u_long actual;
28
29         TEST_ASSERT_TRUE(octtoint(str, &actual) );
30         TEST_ASSERT_EQUAL(185, actual);
31
32 }
33
34 void test_Zero(void){
35         const char* str = "0";
36         u_long actual;
37
38         TEST_ASSERT_TRUE(octtoint(str, &actual) );
39         TEST_ASSERT_EQUAL(0, actual);
40
41 }
42
43 void test_MaximumUnsigned32bit(void){
44         const char* str = "37777777777";
45         u_long actual;
46
47         TEST_ASSERT_TRUE(octtoint(str, &actual) );
48         TEST_ASSERT_EQUAL(4294967295UL, actual);
49
50 }
51
52 void test_Overflow(void){
53         const char* str = "40000000000";
54         u_long actual;
55
56         TEST_ASSERT_FALSE(octtoint(str, &actual) );
57
58 }
59
60 void test_IllegalCharacter(void){
61         const char* str = "5ac2";
62         u_long actual;
63
64         TEST_ASSERT_FALSE(octtoint(str, &actual) );
65
66 }
67
68 void test_IllegalDigit(void){
69         const char* str = "5283";
70         u_long actual;
71
72         TEST_ASSERT_FALSE(octtoint(str, &actual) );
73
74 }