aboutsummaryrefslogtreecommitdiff
path: root/tests/libntp/octtoint.c
blob: 4b0f94ceaa36a5b7637ada04684dabd37278682f (plain) (blame)
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
#include "config.h"

#include "ntp_stdlib.h"

#include "unity.h"

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

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

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

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

}

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

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

}

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

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

}

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

	TEST_ASSERT_FALSE(octtoint(str, &actual) );

}

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

	TEST_ASSERT_FALSE(octtoint(str, &actual) );

}

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

	TEST_ASSERT_FALSE(octtoint(str, &actual) );

}