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