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
10void test_SingleDigit(void);
11void test_MultipleDigits(void);
12void test_Zero(void);
13void test_MaximumUnsigned32bit(void);
14void test_Overflow(void);
15void test_IllegalCharacter(void);
16void test_IllegalDigit(void);
17
18
19void
20test_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
31void
32test_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
43void
44test_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
55void
56test_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
67void
68test_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
78void
79test_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
89void
90test_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