1 /* $NetBSD: octtoint.c,v 1.2 2020/05/25 20:47:36 christos Exp $ */
2
3 #include "config.h"
4
5 #include "ntp_stdlib.h"
6
7 #include "unity.h"
8
9
10 void test_SingleDigit(void);
11 void test_MultipleDigits(void);
12 void test_Zero(void);
13 void test_MaximumUnsigned32bit(void);
14 void test_Overflow(void);
15 void test_IllegalCharacter(void);
16 void test_IllegalDigit(void);
17
18
19 void
test_SingleDigit(void)20 test_SingleDigit(void)
21 {
22 const char* str = "5";
23 u_long actual;
24
25 TEST_ASSERT_TRUE(octtoint(str, &actual));
26 TEST_ASSERT_EQUAL(5, actual);
27
28 return;
29 }
30
31 void
test_MultipleDigits(void)32 test_MultipleDigits(void)
33 {
34 const char* str = "271";
35 u_long actual;
36
37 TEST_ASSERT_TRUE(octtoint(str, &actual));
38 TEST_ASSERT_EQUAL(185, actual);
39
40 return;
41 }
42
43 void
test_Zero(void)44 test_Zero(void)
45 {
46 const char* str = "0";
47 u_long actual;
48
49 TEST_ASSERT_TRUE(octtoint(str, &actual));
50 TEST_ASSERT_EQUAL(0, actual);
51
52 return;
53 }
54
55 void
test_MaximumUnsigned32bit(void)56 test_MaximumUnsigned32bit(void)
57 {
58 const char* str = "37777777777";
59 u_long actual;
60
61 TEST_ASSERT_TRUE(octtoint(str, &actual));
62 TEST_ASSERT_EQUAL(4294967295UL, actual);
63
64 return;
65 }
66
67 void
test_Overflow(void)68 test_Overflow(void)
69 {
70 const char* str = "40000000000";
71 u_long actual;
72
73 TEST_ASSERT_FALSE(octtoint(str, &actual));
74
75 return;
76 }
77
78 void
test_IllegalCharacter(void)79 test_IllegalCharacter(void)
80 {
81 const char* str = "5ac2";
82 u_long actual;
83
84 TEST_ASSERT_FALSE(octtoint(str, &actual));
85
86 return;
87 }
88
89 void
test_IllegalDigit(void)90 test_IllegalDigit(void)
91 {
92 const char* str = "5283";
93 u_long actual;
94
95 TEST_ASSERT_FALSE(octtoint(str, &actual));
96
97 return;
98 }
99