octtoint.c revision 293896
1#include "config.h"
2
3#include "ntp_stdlib.h"
4
5#include "unity.h"
6
7
8void test_SingleDigit(void);
9void test_MultipleDigits(void);
10void test_Zero(void);
11void test_MaximumUnsigned32bit(void);
12void test_Overflow(void);
13void test_IllegalCharacter(void);
14void test_IllegalDigit(void);
15
16
17void
18test_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
29void
30test_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
41void
42test_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
53void
54test_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
65void
66test_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
76void
77test_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
87void
88test_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