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