summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/tests/libntp/octtoint.c
blob: 83a1c994aa46001be4cb177832191a135940ac0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "config.h"

#include "ntp_stdlib.h"

#include "unity.h"


void test_SingleDigit(void);
void test_MultipleDigits(void);
void test_Zero(void);
void test_MaximumUnsigned32bit(void);
void test_Overflow(void);
void test_IllegalCharacter(void);
void test_IllegalDigit(void);


void
test_SingleDigit(void)
{
	const char* str = "5";
	u_long actual;

	TEST_ASSERT_TRUE(octtoint(str, &actual));
	TEST_ASSERT_EQUAL(5, actual);

	return;
}

void
test_MultipleDigits(void)
{
	const char* str = "271";
	u_long actual;

	TEST_ASSERT_TRUE(octtoint(str, &actual));
	TEST_ASSERT_EQUAL(185, actual);

	return;
}

void
test_Zero(void)
{
	const char* str = "0";
	u_long actual;

	TEST_ASSERT_TRUE(octtoint(str, &actual));
	TEST_ASSERT_EQUAL(0, actual);

	return;
}

void
test_MaximumUnsigned32bit(void)
{
	const char* str = "37777777777";
	u_long actual;

	TEST_ASSERT_TRUE(octtoint(str, &actual));
	TEST_ASSERT_EQUAL(4294967295UL, actual);

	return;
}

void
test_Overflow(void)
{
	const char* str = "40000000000";
	u_long actual;

	TEST_ASSERT_FALSE(octtoint(str, &actual));

	return;
}

void
test_IllegalCharacter(void)
{
	const char* str = "5ac2";
	u_long actual;

	TEST_ASSERT_FALSE(octtoint(str, &actual));

	return;
}

void
test_IllegalDigit(void)
{
	const char* str = "5283";
	u_long actual;

	TEST_ASSERT_FALSE(octtoint(str, &actual));

	return;
}
OpenPOWER on IntegriCloud