]> CyberLeo.Net >> Repos - FreeBSD/releng/9.3.git/blob - contrib/ntp/tests/ntpd/t-ntp_scanner.c
o Fix invalid TCP checksums with pf(4). [EN-16:02.pf]
[FreeBSD/releng/9.3.git] / contrib / ntp / tests / ntpd / t-ntp_scanner.c
1 #include "config.h"
2
3 #include "unity.h"
4
5 //#include <stdio.h>
6 //#include <ctype.h>
7 //#include <stdlib.h>
8 //#include <errno.h>
9 //#include <string.h>
10
11 //#include "ntpd.h"
12 //#include "ntp_config.h"
13 //#include "ntpsim.h"
14 //#include "ntp_scanner.h"
15 //#include "ntp_parser.h"
16
17 #include "ntp_scanner.c"
18 /* ntp_keyword.h declares finite state machine and token text */
19 //#include "ntp_keyword.h"
20
21 void test_keywordIncorrectToken(void);
22 void test_keywordServerToken(void);
23 void test_DropUninitializedStack(void);
24 void test_IncorrectlyInitializeLexStack(void);
25 void test_InitializeLexStack(void);
26
27
28 void test_keywordIncorrectToken(void){
29         const char * temp = keyword(999);
30         //printf("%s\n",temp);
31         TEST_ASSERT_EQUAL_STRING("(keyword not found)",temp);
32 }
33
34 void test_keywordServerToken(void){
35         const char * temp = keyword(T_Server);
36         //printf("%s",temp); //143 or 401 ?
37         TEST_ASSERT_EQUAL_STRING("server",temp);
38 }
39
40 void test_DropUninitializedStack(void){
41         lex_drop_stack();
42 }
43
44 void test_IncorrectlyInitializeLexStack(void){
45
46         TEST_ASSERT_FALSE(lex_init_stack(NULL,NULL));
47         lex_drop_stack();
48 }
49
50 void test_InitializeLexStack(void){
51         
52         //Some sort of server is required for this to work.
53         sockaddr_u *    remote_addr;
54         char origin[128] ={ "" } ;
55         strcat(origin,"127.0.0.1");
56         //snprintf(origin, sizeof(origin), "remote config from %s", stoa(remote_addr));
57         TEST_ASSERT_TRUE(lex_init_stack(origin,NULL)); //path, mode -> NULL is ok!
58         lex_drop_stack();
59 }
60
61 void test_PopEmptyStack(void){
62         int temp = lex_pop_file();
63
64         TEST_ASSERT_FALSE(temp);
65 }
66
67
68
69 void test_IsInteger(void){ //boolean
70         int temp = is_integer("123");
71         TEST_ASSERT_TRUE(temp);
72         temp = is_integer("-999");
73         TEST_ASSERT_TRUE(temp);
74         temp = is_integer("0"); //what about -0?
75         TEST_ASSERT_TRUE(temp);
76         temp = is_integer("16.5");
77         TEST_ASSERT_FALSE(temp);
78         temp = is_integer("12ab");
79         TEST_ASSERT_FALSE(temp);
80         temp = is_integer("2147483647");
81         TEST_ASSERT_TRUE(temp);
82         temp = is_integer("2347483647"); //too big for signed int
83         TEST_ASSERT_FALSE(temp);
84
85 }
86
87 void test_IsUint(void){
88         int temp;
89         temp = is_u_int("-123");
90         TEST_ASSERT_FALSE(temp);
91         temp = is_u_int("0");
92         TEST_ASSERT_TRUE(temp); //-0 fails btw
93         temp = is_u_int("2347483647"); //fits into u_int
94         TEST_ASSERT_TRUE(temp);
95         temp = is_u_int("112347483647"); //too big even for uint
96         TEST_ASSERT_TRUE(temp);         
97 }
98
99 void test_IsDouble(void){
100         int temp;       
101         temp = is_double("0");
102         TEST_ASSERT_TRUE(temp);
103         temp = is_double("123");
104         TEST_ASSERT_TRUE(temp);
105         temp = is_double("123.45"); //DOESN'T WORK WITH 123,45, not sure if intented?
106         TEST_ASSERT_TRUE(temp);
107         temp = is_double("-123.45"); //DOESN'T WORK WITH 123,45, not sure if intented?
108         TEST_ASSERT_TRUE(temp);
109 }
110
111 void test_SpecialSymbols(void){
112         int temp ;
113         temp = is_special('a');
114         TEST_ASSERT_FALSE(temp);
115         temp = is_special('?');
116         TEST_ASSERT_FALSE(temp);
117
118 }
119
120 void test_EOC(void){
121         int temp;
122         if(old_config_style){
123                 temp = is_EOC('\n');
124                 TEST_ASSERT_TRUE(temp);
125         }
126         else {
127                 temp = is_EOC(';');
128                 TEST_ASSERT_TRUE(temp);
129         }
130         temp = is_EOC('A');
131         TEST_ASSERT_FALSE(temp);
132         temp = is_EOC('1');
133         TEST_ASSERT_FALSE(temp);
134
135 }
136