14 void test_msg_start(char *msg
)
16 int msg_length
= strlen(msg
);
19 /* 74 is 80 - length of "PASSED" */
20 while(msg_length
< 74)
27 void test_msg_end(int pass
)
34 exit_error(0, "UNIT TESTING FAILED");
42 char source
[] = "/* this is a test */ \tclass \0";
44 test_msg_start("Testing C Comments");
49 /* token should be correct */
50 if(strcmp(pT
, "class") != 0) { result
++; }
52 /* pointer to code should be in correct position */
53 if(pC
- pStart
!= 27) { result
++; }
65 int test_nested_c_comments()
69 char source
[] = "/* this /*is a test */ \tclass \0";
71 test_msg_start("Testing Nested C Comments");
75 /* token should be correct */
76 if(strcmp(pT
, "class") != 0) { result
++; }
78 /* pointer to code should be in correct position */
79 if(pC
- pStart
!= 29) { result
++; }
91 int test_cpp_comments()
95 char source
[] = "// this is a test\nclass \0";
97 test_msg_start("Testing C++ Comments");
101 /* token should be correct */
102 if(strcmp(pT
, "class") != 0) { result
++; }
104 /* pointer to code should be in correct position */
105 if(pC
- pStart
!= 23) { result
++; }
109 test_msg_end(PASSED
);
111 test_msg_end(FAILED
);
117 int test_nested_cpp_comments()
121 char source
[] = "// this is a //test\nclass \0";
123 test_msg_start("Testing Nested C++ Comments");
124 pC
= pStart
= source
;
125 pC
= advance(pC
, pT
);
127 /* token should be correct */
128 if(strcmp(pT
, "class") != 0) { result
++; }
130 /* pointer to code should be in correct position */
131 if(pC
- pStart
!= 25) { result
++; }
135 test_msg_end(PASSED
);
137 test_msg_end(FAILED
);
143 int test_literal_strings()
147 char source
[] = "\"S\" \0";
149 test_msg_start("Testing String Literals");
150 pC
= pStart
= source
;
151 pC
= advance(pC
, pT
);
153 /* token should be correct */
154 if(strcmp(pT
, "S") != 0) { result
++; }
156 /* pointer to code should be in correct position */
157 if(pC
- pStart
!= 3) { result
++; }
161 test_msg_end(PASSED
);
163 test_msg_end(FAILED
);
169 int test_symbol_recog()
173 char source
[] = "(){\0";
175 test_msg_start("Testing Symbol Recognition");
176 pC
= pStart
= source
;
177 pC
= advance(pC
, pT
);
179 /* token should be correct */
180 if(strcmp(pT
, "(") != 0) { result
++; }
182 /* pointer to code should be in correct position */
183 if(pC
- pStart
!= 1) { result
++; }
187 test_msg_end(PASSED
);
189 test_msg_end(FAILED
);
195 int test_keyword_recog()
201 int test_token_type()
206 test_msg_start("Testing Token Type Recognition");
208 while(keywords
[i
] != NULL
)
210 strcpy(pT
, keywords
[i
]);
211 tk
= -1; /* be certain this value is changed */
213 if(tk
!= KEYWORD
) { result
++; }
219 test_msg_end(PASSED
);
221 test_msg_end(FAILED
);
227 int test_end_of_code()
230 char source
[] = "\n\0";
232 test_msg_start("Testing For EOF Source");
235 result
= has_more_tokens(pC
);
239 test_msg_end(PASSED
);
241 test_msg_end(FAILED
);
250 test_msg_start("Testing For NULL Source");
253 result
= has_more_tokens(pC
);
257 test_msg_end(PASSED
);
259 test_msg_end(FAILED
);
269 result
+= test_c_comments();
270 result
+= test_nested_c_comments();
271 result
+= test_cpp_comments();
272 result
+= test_nested_cpp_comments();
273 result
+= test_literal_strings();
274 result
+= test_symbol_recog();
275 result
+= test_keyword_recog();
276 result
+= test_token_type();
277 result
+= test_end_of_code();
278 result
+= test_no_code();