aboutsummaryrefslogtreecommitdiff
path: root/tests/ntpd/t-ntp_scanner.c
blob: 862a2ee2bbae35fb82949fe688ee34ec3aee27a0 (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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "config.h"

#include "unity.h"

//#include <stdio.h>
//#include <ctype.h>
//#include <stdlib.h>
//#include <errno.h>
//#include <string.h>

//#include "ntpd.h"
//#include "ntp_config.h"
//#include "ntpsim.h"
//#include "ntp_scanner.h"
//#include "ntp_parser.h"

#include "ntp_scanner.c"
/* ntp_keyword.h declares finite state machine and token text */
//#include "ntp_keyword.h"

void test_keywordIncorrectToken(void);
void test_keywordServerToken(void);
void test_DropUninitializedStack(void);
void test_IncorrectlyInitializeLexStack(void);
void test_InitializeLexStack(void);


void test_keywordIncorrectToken(void){
	const char * temp = keyword(999);
	//printf("%s\n",temp);
	TEST_ASSERT_EQUAL_STRING("(keyword not found)",temp);
}

void test_keywordServerToken(void){
	const char * temp = keyword(T_Server);
	//printf("%s",temp); //143 or 401 ?
	TEST_ASSERT_EQUAL_STRING("server",temp);
}

void test_DropUninitializedStack(void){
	lex_drop_stack();
}

void test_IncorrectlyInitializeLexStack(void){

	TEST_ASSERT_FALSE(lex_init_stack(NULL,NULL));
	lex_drop_stack();
}

void test_InitializeLexStack(void){
	
	//Some sort of server is required for this to work.
	sockaddr_u *	remote_addr;
	char origin[128] ={ "" } ;
	strcat(origin,"127.0.0.1");
	//snprintf(origin, sizeof(origin), "remote config from %s", stoa(remote_addr));
	TEST_ASSERT_TRUE(lex_init_stack(origin,NULL)); //path, mode -> NULL is ok!
	lex_drop_stack();
}

void test_PopEmptyStack(void){
	int temp = lex_pop_file();

	TEST_ASSERT_FALSE(temp);
}



void test_IsInteger(void){ //boolean
	int temp = is_integer("123");
	TEST_ASSERT_TRUE(temp);
	temp = is_integer("-999");
	TEST_ASSERT_TRUE(temp);
	temp = is_integer("0"); //what about -0?
	TEST_ASSERT_TRUE(temp);
	temp = is_integer("16.5");
	TEST_ASSERT_FALSE(temp);
	temp = is_integer("12ab");
	TEST_ASSERT_FALSE(temp);
	temp = is_integer("2147483647");
	TEST_ASSERT_TRUE(temp);
	temp = is_integer("2347483647"); //too big for signed int
	TEST_ASSERT_FALSE(temp);

}

void test_IsUint(void){
	int temp;
	temp = is_u_int("-123");
	TEST_ASSERT_FALSE(temp);
	temp = is_u_int("0");
	TEST_ASSERT_TRUE(temp); //-0 fails btw
	temp = is_u_int("2347483647"); //fits into u_int
	TEST_ASSERT_TRUE(temp);
	temp = is_u_int("112347483647"); //too big even for uint
	TEST_ASSERT_TRUE(temp);		
}

void test_IsDouble(void){
	int temp;	
	temp = is_double("0");
	TEST_ASSERT_TRUE(temp);
	temp = is_double("123");
	TEST_ASSERT_TRUE(temp);
	temp = is_double("123.45"); //DOESN'T WORK WITH 123,45, not sure if intented?
	TEST_ASSERT_TRUE(temp);
	temp = is_double("-123.45"); //DOESN'T WORK WITH 123,45, not sure if intented?
	TEST_ASSERT_TRUE(temp);
}

void test_SpecialSymbols(void){
	int temp ;
	temp = is_special('a');
	TEST_ASSERT_FALSE(temp);
	temp = is_special('?');
	TEST_ASSERT_FALSE(temp);

}

void test_EOC(void){
	int temp;
	if(old_config_style){
		temp = is_EOC('\n');
		TEST_ASSERT_TRUE(temp);
	}
	else {
		temp = is_EOC(';');
		TEST_ASSERT_TRUE(temp);
	}
	temp = is_EOC('A');
	TEST_ASSERT_FALSE(temp);
	temp = is_EOC('1');
	TEST_ASSERT_FALSE(temp);

}