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
);
265 int test_parse_expression()
268 char source
[] = "-(-(2 + (-12 / 12)*83));\n";
270 test_msg_start("Testing Expression Parsing - Numerical");
273 pC
= advance(pC
, pT
);
278 /* pointer to code should be in correct position */
279 if(pC
- source
!= 24) { result
++; }
281 /* token should be correct */
282 if(strcmp(pT
, ";") != 0) { result
++; }
286 test_msg_end(PASSED
);
288 test_msg_end(FAILED
);
294 int test_parse_expression_keyword()
296 int result
= 0, i
= 0;
305 test_msg_start("Testing Expression Parsing - Keywords");
310 pC
= advance(pC
, pT
);
315 /* pointer to code should be in correct position */
318 if(pC
- source
[i
] != 5) { result
++; }
320 if(pC
- source
[i
] != 6) { result
++; }
323 /* token should be correct */
324 if(strcmp(pT
, ";") != 0) { result
++; }
330 test_msg_end(PASSED
);
332 test_msg_end(FAILED
);
338 int test_parse_expression_nested_array()
341 char source
[] = "data1[data2[12]];\n";
343 test_msg_start("Testing Expression Parsing - Nested Arrays");
346 pC
= advance(pC
, pT
);
351 /* pointer to code should be in correct position */
352 if(pC
- source
!= 17) { result
++; }
354 /* token should be correct */
355 if(strcmp(pT
, ";") != 0) { result
++; }
359 test_msg_end(PASSED
);
361 test_msg_end(FAILED
);
367 int test_parse_expression_nested_sub()
370 char source
[] = "data1(data2(12));\n";
372 test_msg_start("Testing Expression Parsing - Nested Subroutine");
375 pC
= advance(pC
, pT
);
380 /* pointer to code should be in correct position */
381 if(pC
- source
!= 17) { result
++; }
383 /* token should be correct */
384 if(strcmp(pT
, ";") != 0) { result
++; }
388 test_msg_end(PASSED
);
390 test_msg_end(FAILED
);
396 int test_parse_expression_class_sub()
399 char source
[] = "class_name.sub_name();\n";
401 test_msg_start("Testing Expression Parsing - Class Subroutine");
404 pC
= advance(pC
, pT
);
409 /* pointer to code should be in correct position */
410 if(pC
- source
!= 22) { result
++; }
412 /* token should be correct */
413 if(strcmp(pT
, ";") != 0) { result
++; }
417 test_msg_end(PASSED
);
419 test_msg_end(FAILED
);
425 int test_parse_expression_list()
428 char source
[] = "class_name.sub_name(87, var_name);\n";
430 test_msg_start("Testing Expression Parsing - Expression List");
433 pC
= advance(pC
, pT
);
438 /* pointer to code should be in correct position */
439 if(pC
- source
!= 34) { result
++; }
441 /* token should be correct */
442 if(strcmp(pT
, ";") != 0) { result
++; }
446 test_msg_end(PASSED
);
448 test_msg_end(FAILED
);
458 /* modify settings regardless of command line options */
461 result
+= test_c_comments();
462 result
+= test_nested_c_comments();
463 result
+= test_cpp_comments();
464 result
+= test_nested_cpp_comments();
465 result
+= test_literal_strings();
466 result
+= test_symbol_recog();
467 result
+= test_keyword_recog();
468 result
+= test_token_type();
469 result
+= test_end_of_code();
470 result
+= test_no_code();
471 result
+= test_parse_expression();
472 result
+= test_parse_expression_keyword();
473 result
+= test_parse_expression_nested_array();
474 result
+= test_parse_expression_nested_sub();
475 result
+= test_parse_expression_class_sub();
476 result
+= test_parse_expression_list();