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 test_SingleDigit(void)
19 {
20 const char* str = "5";
21 u_long actual;
22
23 TEST_ASSERT_TRUE(octtoint(str, &actual));
24 TEST_ASSERT_EQUAL(5, actual);
25
26 return;
27 }
28
29 void
test_MultipleDigits(void)30 test_MultipleDigits(void)
31 {
32 const char* str = "271";
33 u_long actual;
34
35 TEST_ASSERT_TRUE(octtoint(str, &actual));
36 TEST_ASSERT_EQUAL(185, actual);
37
38 return;
39 }
40
41 void
test_Zero(void)42 test_Zero(void)
43 {
44 const char* str = "0";
45 u_long actual;
46
47 TEST_ASSERT_TRUE(octtoint(str, &actual));
48 TEST_ASSERT_EQUAL(0, actual);
49
50 return;
51 }
52
53 void
test_MaximumUnsigned32bit(void)54 test_MaximumUnsigned32bit(void)
55 {
56 const char* str = "37777777777";
57 u_long actual;
58
59 TEST_ASSERT_TRUE(octtoint(str, &actual));
60 TEST_ASSERT_EQUAL(4294967295UL, actual);
61
62 return;
63 }
64
65 void
test_Overflow(void)66 test_Overflow(void)
67 {
68 const char* str = "40000000000";
69 u_long actual;
70
71 TEST_ASSERT_FALSE(octtoint(str, &actual));
72
73 return;
74 }
75
76 void
test_IllegalCharacter(void)77 test_IllegalCharacter(void)
78 {
79 const char* str = "5ac2";
80 u_long actual;
81
82 TEST_ASSERT_FALSE(octtoint(str, &actual));
83
84 return;
85 }
86
87 void
test_IllegalDigit(void)88 test_IllegalDigit(void)
89 {
90 const char* str = "5283";
91 u_long actual;
92
93 TEST_ASSERT_FALSE(octtoint(str, &actual));
94
95 return;
96 }
97