/[ascend]/trunk/base/generic/utilities/test/test_ascPrint.c
ViewVC logotype

Contents of /trunk/base/generic/utilities/test/test_ascPrint.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 60 - (show annotations) (download) (as text)
Mon Oct 31 03:39:15 2005 UTC (18 years, 7 months ago) by jds
File MIME type: text/x-csrc
File size: 20633 byte(s)
- jam build up and limping on Linux (finally).
- fixes to CUnit test suite to compile on Linux (still not operable, though).
1 /*
2 * Unit test functions for ASCEND: utilities/ascPrint.c
3 *
4 * Copyright (C) 2005 Jerry St.Clair
5 *
6 * This file is part of the Ascend Environment.
7 *
8 * The Ascend Environment is free software; you can redistribute it
9 * and/or modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * The Ascend Environment is distributed in hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with the program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
21 * COPYING.
22 */
23
24 #include <stdio.h>
25 #ifdef __WIN32__
26 #include <io.h>
27 #endif
28 #include <stdarg.h>
29 #include "utilities/ascConfig.h"
30 #include "utilities/ascMalloc.h"
31 #include "utilities/ascPrint.h"
32 #include "utilities/ascPrintType.h"
33 #include "CUnit/CUnit.h"
34 #include "test_ascPrint.h"
35 #include "printutil.h"
36
37 #undef STR_LEN
38 #define STR_LEN 4096
39
40 /* flag for whether test_print1() was called. */
41 static int test_print1_called = FALSE;
42 /* static string to hold result of call to test_print1() */
43 static char test_print1_str[STR_LEN];
44 /* static FILE * to hold result of call to test_print2() */
45 static FILE *test_print1_fp;
46 /* print function for test_ascPrint_vtable1 */
47 static int test_print1(FILE *fp, CONST char *format, va_list args)
48 {
49 int result;
50
51 test_print1_called = TRUE;
52 test_print1_fp = fp;
53 result = vsnprintf(test_print1_str, STR_LEN, format, args);
54 test_print1_str[STR_LEN-1] = '\0';
55 return result;
56 }
57
58 /* flag for whether test_flush1() was called. */
59 static int test_flush1_called = FALSE;
60 /* static FILE * to hold result of call to test_flush1() */
61 static FILE *test_flush1_fp;
62 /* flush function for test_ascPrint_vtable1 */
63 static int test_flush1(FILE *fp)
64 {
65 test_flush1_fp = fp;
66 test_flush1_called = TRUE;
67 return 0;
68 }
69
70 /*
71 * Vtable for testing of ascPrint.
72 * print and flush point to special functions which record the
73 * fact and details of their invocation using static variables.
74 */
75 static struct Asc_PrintVTable f_test_ascPrint_vtable1 = { "test_vtable1", test_print1, test_flush1, NULL };
76
77 /* flag for whether test_print2() was called. */
78 static int test_print2_called = FALSE;
79 /* static string to hold result of call to test_print2() */
80 static char test_print2_str[STR_LEN];
81 /* static FILE * to hold result of call to test_print2() */
82 static FILE *test_print2_fp;
83 /* print function for test_ascPrint_vtable2 */
84 static int test_print2(FILE *fp, CONST char *format, va_list args)
85 {
86 int result;
87
88 test_print2_called = TRUE;
89 test_print2_fp = fp;
90 result = vsnprintf(test_print2_str, STR_LEN, format, args);
91 test_print2_str[STR_LEN-1] = '\0';
92 return result;
93 }
94
95 /* flag for whether test_flush2() was called. */
96 static int test_flush2_called = FALSE;
97 /* static FILE * to hold result of call to test_flush2() */
98 static FILE *test_flush2_fp;
99 /* flush function for test_ascPrint_vtable1 */
100 static int test_flush2(FILE *fp)
101 {
102 test_flush2_fp = fp;
103 test_flush2_called = TRUE;
104 return 0;
105 }
106
107 /*
108 * Another vtable for testing of ascPrint.
109 * print and flush point to special functions which record the
110 * fact and details of their invocation using static variables.
111 */
112 static struct Asc_PrintVTable f_test_ascPrint_vtable2 = { "test_vtable2", test_print2, test_flush2, NULL };
113
114 static struct Asc_PrintVTable f_bad_vtable1 = { NULL, test_print1, test_flush1, NULL };
115 static struct Asc_PrintVTable f_bad_vtable2 = { "Bad_vtable", NULL, test_flush1, NULL };
116 static struct Asc_PrintVTable f_bad_vtable3 = { "Bad_vtable", test_print1, NULL, NULL };
117 static struct Asc_PrintVTable f_bad_vtable4 = { "Bad_vtable", test_print1, test_flush1, &f_bad_vtable1 };
118
119 /*
120 * We direct output to to special functions that keep track of whether
121 * they were called and with which parameters. This allows checking
122 * the marshalling of output via the registered vtables.
123 */
124 static void test_ascPrint(void)
125 {
126 char str[STR_LEN];
127 int nchars;
128 int i_disabled_printing = FALSE;
129 unsigned long prior_meminuse;
130
131 prior_meminuse = ascmeminuse(); /* save meminuse() at start of test function */
132
133 if (test_printing_enabled()) { /* turn off printing (i.e. remove global vtable) */
134 i_disabled_printing = TRUE;
135 test_disable_printing();
136 }
137
138 /* test Asc_PrintPushVTable() */
139
140 CU_TEST(1 == Asc_PrintPushVTable(NULL)); /* error - NULL vtable */
141 CU_TEST(1 == Asc_PrintPushVTable(&f_bad_vtable1)); /* error - NULL name */
142 CU_TEST(1 == Asc_PrintPushVTable(&f_bad_vtable2)); /* error - NULL print */
143 CU_TEST(1 == Asc_PrintPushVTable(&f_bad_vtable3)); /* error - NULL flush */
144 CU_TEST(1 == Asc_PrintPushVTable(&f_bad_vtable4)); /* error - non-NULL next */
145 CU_TEST(FALSE == Asc_PrintHasVTable("Bad_vtable"));
146 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable1"));
147 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable2"));
148
149 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable1)); /* push a normal vtable */
150 CU_TEST(TRUE == Asc_PrintHasVTable("test_vtable1"));
151 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable2"));
152
153 test_print1_called = FALSE;
154 test_print1_str[0] = '\0';
155 test_print1_fp = NULL;
156 test_print2_called = FALSE;
157 test_print2_str[0] = '\0';
158 test_print2_fp = NULL;
159
160 Asc_Printf("This is test string #1."); /* print - should only go to 1st vtable */
161 CU_TEST(TRUE == test_print1_called);
162 CU_TEST(0 == strcmp(test_print1_str, "This is test string #1."));
163 CU_TEST(stdout == test_print1_fp);
164 CU_TEST(FALSE == test_print2_called);
165 CU_TEST(test_print2_str[0] == '\0');
166 CU_TEST(NULL == test_print2_fp);
167
168 test_flush1_called = FALSE;
169 test_flush1_fp = NULL;
170 test_flush2_called = FALSE;
171 test_flush2_fp = NULL;
172
173 Asc_FFlush(stdout); /* flush - should only go to 1st vtable */
174 CU_TEST(TRUE == test_flush1_called);
175 CU_TEST(stdout == test_flush1_fp);
176 CU_TEST(FALSE == test_flush2_called);
177 CU_TEST(NULL == test_flush2_fp);
178
179 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable2)); /* push another vtable */
180 CU_TEST(TRUE == Asc_PrintHasVTable("test_vtable1"));
181 CU_TEST(TRUE == Asc_PrintHasVTable("test_vtable2"));
182
183 test_print1_called = FALSE;
184 test_print1_str[0] = '\0';
185 test_print1_fp = NULL;
186 test_print2_called = FALSE;
187 test_print2_str[0] = '\0';
188 test_print2_fp = NULL;
189
190 Asc_Printf("This is test string #2."); /* print - should go to both vtables */
191 CU_TEST(TRUE == test_print1_called);
192 CU_TEST(0 == strcmp(test_print1_str, "This is test string #2."));
193 CU_TEST(stdout == test_print1_fp);
194 CU_TEST(TRUE == test_print2_called);
195 CU_TEST(0 == strcmp(test_print2_str, "This is test string #2."));
196 CU_TEST(stdout == test_print2_fp);
197
198 test_flush1_called = FALSE;
199 test_flush1_fp = NULL;
200 test_flush2_called = FALSE;
201 test_flush2_fp = NULL;
202
203 Asc_FFlush(stdout); /* flush - should go to both vtables */
204 CU_TEST(TRUE == test_flush1_called);
205 CU_TEST(stdout == test_flush1_fp);
206 CU_TEST(TRUE == test_flush2_called);
207 CU_TEST(stdout == test_flush2_fp);
208
209 CU_TEST(&f_test_ascPrint_vtable1 == Asc_PrintRemoveVTable("test_vtable1")); /* remove a vtable */
210 f_test_ascPrint_vtable1.next = NULL;
211 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable1"));
212 CU_TEST(TRUE == Asc_PrintHasVTable("test_vtable2"));
213
214 test_print1_called = FALSE;
215 test_print1_str[0] = '\0';
216 test_print1_fp = NULL;
217 test_print2_called = FALSE;
218 test_print2_str[0] = '\0';
219 test_print2_fp = NULL;
220
221 Asc_Printf("This is test string last."); /* print - should only go to 2nd vtable */
222 CU_TEST(FALSE == test_print1_called);
223 CU_TEST(test_print1_str[0] == '\0');
224 CU_TEST(NULL == test_print1_fp);
225 CU_TEST(TRUE == test_print2_called);
226 CU_TEST(0 == strcmp(test_print2_str, "This is test string last."));
227 CU_TEST(stdout == test_print2_fp);
228
229 test_flush1_called = FALSE;
230 test_flush1_fp = NULL;
231 test_flush2_called = FALSE;
232 test_flush2_fp = NULL;
233
234 Asc_FFlush(stdout); /* flush - should only go to 2nd vtable */
235 CU_TEST(FALSE == test_flush1_called);
236 CU_TEST(NULL == test_flush1_fp);
237 CU_TEST(TRUE == test_flush2_called);
238 CU_TEST(stdout == test_flush2_fp);
239
240 CU_TEST(&f_test_ascPrint_vtable2 == Asc_PrintRemoveVTable("test_vtable2")); /* remove a vtable */
241 f_test_ascPrint_vtable2.next = NULL;
242 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable1"));
243 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable2"));
244
245 test_print1_called = FALSE;
246 test_print1_str[0] = '\0';
247 test_print1_fp = NULL;
248 test_print2_called = FALSE;
249 test_print2_str[0] = '\0';
250 test_print2_fp = NULL;
251
252 Asc_Printf("No one should get this one."); /* print - no printing should occur */
253 CU_TEST(FALSE == test_print1_called);
254 CU_TEST(test_print1_str[0] == '\0');
255 CU_TEST(NULL == test_print1_fp);
256 CU_TEST(FALSE == test_print2_called);
257 CU_TEST(test_print2_str[0] == '\0');
258 CU_TEST(NULL == test_print2_fp);
259
260 test_flush1_called = FALSE;
261 test_flush1_fp = NULL;
262 test_flush2_called = FALSE;
263 test_flush2_fp = NULL;
264
265 Asc_FFlush(stdout); /* flush - no flushing should occur */
266 CU_TEST(FALSE == test_flush1_called);
267 CU_TEST(NULL == test_flush1_fp);
268 CU_TEST(FALSE == test_flush2_called);
269 CU_TEST(NULL == test_flush2_fp);
270
271 /* test Asc_PrintRemoveVTable() */
272 /* basic functionality tested in other sections - focus on error conditions */
273
274 CU_TEST(NULL == Asc_PrintRemoveVTable(NULL)); /* error - NULL name */
275 CU_TEST(NULL == Asc_PrintRemoveVTable("test_vtable1"));/* name not registered */
276 CU_TEST(NULL == Asc_PrintRemoveVTable("test_vtable2"));/* name not registered */
277
278 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable2)); /* push a vtable */
279 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable1"));
280 CU_TEST(TRUE == Asc_PrintHasVTable("test_vtable2"));
281 CU_TEST(NULL == Asc_PrintRemoveVTable(NULL)); /* error - NULL name */
282 CU_TEST(NULL == Asc_PrintRemoveVTable("test_vtable1"));/* name not registered */
283 CU_TEST(NULL == Asc_PrintRemoveVTable("")); /* name empty (not registered) */
284 CU_TEST(&f_test_ascPrint_vtable2 == Asc_PrintRemoveVTable("test_vtable2")); /* normal removal */
285 f_test_ascPrint_vtable2.next = NULL;
286 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable1"));
287 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable2"));
288
289 /* test Asc_PrintHasVTable() */
290 /* basic functionality tested in other sections - focus on error conditions */
291
292 CU_TEST(FALSE == Asc_PrintHasVTable(NULL)); /* error - NULL name */
293 CU_TEST(FALSE == Asc_PrintHasVTable("")); /* empty name */
294 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable1")); /* name not registered */
295 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable2")); /* name not registered */
296
297 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable1)); /* push vtables */
298 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable2));
299
300 CU_TEST(FALSE == Asc_PrintHasVTable(NULL)); /* error - NULL name */
301 CU_TEST(FALSE == Asc_PrintHasVTable("")); /* empty name */
302 CU_TEST(TRUE == Asc_PrintHasVTable("test_vtable1")); /* name registered */
303 CU_TEST(TRUE == Asc_PrintHasVTable("test_vtable2")); /* name registered */
304
305 CU_TEST(&f_test_ascPrint_vtable2 == Asc_PrintRemoveVTable("test_vtable2")); /* normal removal */
306 CU_TEST(&f_test_ascPrint_vtable1 == Asc_PrintRemoveVTable("test_vtable1")); /* normal removal */
307 f_test_ascPrint_vtable1.next = NULL;
308 f_test_ascPrint_vtable2.next = NULL;
309
310 CU_TEST(FALSE == Asc_PrintHasVTable(NULL)); /* error - NULL name */
311 CU_TEST(FALSE == Asc_PrintHasVTable("")); /* empty name */
312 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable1")); /* name not registered */
313 CU_TEST(FALSE == Asc_PrintHasVTable("test_vtable2")); /* name not registered */
314
315 /* test Asc_Printf() */
316
317 test_print1_called = FALSE;
318 test_print1_str[0] = '\0';
319 test_print1_fp = NULL;
320 test_print2_called = FALSE;
321 test_print2_str[0] = '\0';
322 test_print2_fp = NULL;
323
324 nchars = snprintf(str, STR_LEN, "%s%d%c%s%f", "my_float[", 7, ']', " = ", 8.12);
325 CU_TEST(0 == Asc_Printf("%s%d%c%s%f", "my_float[", 7, ']', " = ", 8.12)); /* no vtables registered */
326 CU_TEST(FALSE == test_print1_called);
327 CU_TEST('\0' == test_print1_str[0]);
328 CU_TEST(NULL == test_print1_fp);
329 CU_TEST(FALSE == test_print2_called);
330 CU_TEST('\0' == test_print2_str[0]);
331 CU_TEST(NULL == test_print2_fp);
332
333 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable1)); /* push vtables */
334 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable2));
335
336 test_print1_called = FALSE;
337 test_print1_str[0] = '\0';
338 test_print1_fp = NULL;
339 test_print2_called = FALSE;
340 test_print2_str[0] = '\0';
341 test_print2_fp = NULL;
342
343 nchars = snprintf(str, STR_LEN, "%s%d%c%s%f", "my_float[", 7, ']', " = ", 8.12);
344 CU_TEST(nchars == Asc_Printf("%s%d%c%s%f", "my_float[", 7, ']', " = ", 8.12)); /* print something */
345 CU_TEST(TRUE == test_print1_called);
346 CU_TEST(0 == strcmp(test_print1_str, str));
347 CU_TEST(stdout == test_print1_fp);
348 CU_TEST(TRUE == test_print2_called);
349 CU_TEST(0 == strcmp(test_print2_str, str));
350 CU_TEST(stdout == test_print2_fp);
351
352 CU_TEST(&f_test_ascPrint_vtable2 == Asc_PrintRemoveVTable("test_vtable2")); /* cleanup */
353 CU_TEST(&f_test_ascPrint_vtable1 == Asc_PrintRemoveVTable("test_vtable1"));
354 f_test_ascPrint_vtable1.next = NULL;
355 f_test_ascPrint_vtable2.next = NULL;
356
357 /* test Asc_FPrintf() */
358
359 test_print1_called = FALSE;
360 test_print1_str[0] = '\0';
361 test_print1_fp = NULL;
362 test_print2_called = FALSE;
363 test_print2_str[0] = '\0';
364 test_print2_fp = NULL;
365
366 nchars = snprintf(str, STR_LEN, "%s%d%c%s%f", "my_float[", 7, ']', " = ", 8.12);
367 CU_TEST(0 == Asc_FPrintf((FILE *)10, "%s%d%c%s%f", "my_float[", 7, ']', " = ", 8.12)); /* no vtables registered */
368 CU_TEST(FALSE == test_print1_called);
369 CU_TEST('\0' == test_print1_str[0]);
370 CU_TEST(NULL == test_print1_fp);
371 CU_TEST(FALSE == test_print2_called);
372 CU_TEST('\0' == test_print2_str[0]);
373 CU_TEST(NULL == test_print2_fp);
374
375 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable1)); /* push vtables */
376 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable2));
377
378 test_print1_called = FALSE;
379 test_print1_str[0] = '\0';
380 test_print1_fp = NULL;
381 test_print2_called = FALSE;
382 test_print2_str[0] = '\0';
383 test_print2_fp = NULL;
384
385 memset(str, '?', STR_LEN-1);
386 str[STR_LEN-1] = '\0';
387 CU_TEST(STR_LEN-1 == Asc_FPrintf(stderr, "%s", str));/* print something */
388 CU_TEST(TRUE == test_print1_called);
389 CU_TEST(0 == strcmp(test_print1_str, str));
390 CU_TEST(stderr == test_print1_fp);
391 CU_TEST(TRUE == test_print2_called);
392 CU_TEST(0 == strcmp(test_print2_str, str));
393 CU_TEST(stderr == test_print2_fp);
394
395 test_print1_called = FALSE;
396 test_print1_str[0] = '\0';
397 test_print1_fp = NULL;
398 test_print2_called = FALSE;
399 test_print2_str[0] = '\0';
400 test_print2_fp = NULL;
401
402 nchars = snprintf(str, STR_LEN, "%s%d%c%s%f", "my_float[", 7, ']', " = ", 8.12);
403 CU_TEST(nchars == Asc_FPrintf((FILE *)10, "%s%d%c%s%f", "my_float[", 7, ']', " = ", 8.12)); /* print something */
404 CU_TEST(TRUE == test_print1_called);
405 CU_TEST(0 == strcmp(test_print1_str, str));
406 CU_TEST((FILE *)10 == test_print1_fp);
407 CU_TEST(TRUE == test_print2_called);
408 CU_TEST(0 == strcmp(test_print2_str, str));
409 CU_TEST((FILE *)10 == test_print2_fp);
410
411 CU_TEST(&f_test_ascPrint_vtable2 == Asc_PrintRemoveVTable("test_vtable2")); /* cleanup */
412 CU_TEST(&f_test_ascPrint_vtable1 == Asc_PrintRemoveVTable("test_vtable1"));
413 f_test_ascPrint_vtable1.next = NULL;
414 f_test_ascPrint_vtable2.next = NULL;
415
416 /* test Asc_FFlush() */
417
418 test_flush1_called = FALSE;
419 test_flush1_fp = NULL;
420 test_flush2_called = FALSE;
421 test_flush2_fp = NULL;
422
423 CU_TEST(0 == Asc_FFlush(stderr)); /* no vtables registered */
424 CU_TEST(FALSE == test_flush1_called);
425 CU_TEST(NULL == test_flush1_fp);
426 CU_TEST(FALSE == test_flush2_called);
427 CU_TEST(NULL == test_flush2_fp);
428
429 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable1)); /* push vtables */
430 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable2));
431
432 test_flush1_called = FALSE;
433 test_flush1_fp = NULL;
434 test_flush2_called = FALSE;
435 test_flush2_fp = NULL;
436
437 CU_TEST(0 == Asc_FFlush((FILE *)100)); /* flush a (FILE *) */
438 CU_TEST(TRUE == test_flush1_called);
439 CU_TEST((FILE *)100 == test_flush1_fp);
440 CU_TEST(TRUE == test_flush2_called);
441 CU_TEST((FILE *)100 == test_flush2_fp);
442
443 CU_TEST(&f_test_ascPrint_vtable2 == Asc_PrintRemoveVTable("test_vtable2")); /* cleanup */
444 CU_TEST(&f_test_ascPrint_vtable1 == Asc_PrintRemoveVTable("test_vtable1"));
445 f_test_ascPrint_vtable1.next = NULL;
446 f_test_ascPrint_vtable2.next = NULL;
447
448 /* test Asc_FPutc() */
449
450 test_print1_called = FALSE;
451 test_print1_str[0] = '\0';
452 test_print1_fp = NULL;
453 test_print2_called = FALSE;
454 test_print2_str[0] = '\0';
455 test_print2_fp = NULL;
456
457 CU_TEST(0 == Asc_FPutc('Y', stdout)); /* no vtables registered */
458 CU_TEST(FALSE == test_print1_called);
459 CU_TEST('\0' == test_print1_str[0]);
460 CU_TEST(NULL == test_print1_fp);
461 CU_TEST(FALSE == test_print2_called);
462 CU_TEST('\0' == test_print2_str[0]);
463 CU_TEST(NULL == test_print2_fp);
464
465 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable1)); /* push vtables */
466 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable2));
467
468 test_print1_called = FALSE;
469 test_print1_str[0] = '\0';
470 test_print1_fp = NULL;
471 test_print2_called = FALSE;
472 test_print2_str[0] = '\0';
473 test_print2_fp = NULL;
474
475 CU_TEST(0 != Asc_FPutc('Y', stderr)); /* print a char */
476 CU_TEST(TRUE == test_print1_called);
477 CU_TEST(0 == strcmp("Y", test_print1_str));
478 CU_TEST(stderr == test_print1_fp);
479 CU_TEST(TRUE == test_print2_called);
480 CU_TEST(0 == strcmp("Y", test_print2_str));
481 CU_TEST(stderr == test_print2_fp);
482
483 CU_TEST(&f_test_ascPrint_vtable2 == Asc_PrintRemoveVTable("test_vtable2")); /* cleanup */
484 CU_TEST(&f_test_ascPrint_vtable1 == Asc_PrintRemoveVTable("test_vtable1"));
485 f_test_ascPrint_vtable1.next = NULL;
486 f_test_ascPrint_vtable2.next = NULL;
487
488 /* test Asc_FPutc() */
489
490 test_print1_called = FALSE;
491 test_print1_str[0] = '\0';
492 test_print1_fp = NULL;
493 test_print2_called = FALSE;
494 test_print2_str[0] = '\0';
495 test_print2_fp = NULL;
496
497 CU_TEST(0 == Asc_Putchar('N')); /* no vtables registered */
498 CU_TEST(FALSE == test_print1_called);
499 CU_TEST('\0' == test_print1_str[0]);
500 CU_TEST(NULL == test_print1_fp);
501 CU_TEST(FALSE == test_print2_called);
502 CU_TEST('\0' == test_print2_str[0]);
503 CU_TEST(NULL == test_print2_fp);
504
505 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable1)); /* push vtables */
506 CU_TEST(0 == Asc_PrintPushVTable(&f_test_ascPrint_vtable2));
507
508 test_print1_called = FALSE;
509 test_print1_str[0] = '\0';
510 test_print1_fp = NULL;
511 test_print2_called = FALSE;
512 test_print2_str[0] = '\0';
513 test_print2_fp = NULL;
514
515 CU_TEST(1 == Asc_Putchar('N')); /* print a char */
516 CU_TEST(TRUE == test_print1_called);
517 CU_TEST(0 == strcmp("N", test_print1_str));
518 CU_TEST(stdout == test_print1_fp);
519 CU_TEST(TRUE == test_print2_called);
520 CU_TEST(0 == strcmp("N", test_print2_str));
521 CU_TEST(stdout == test_print2_fp);
522
523 CU_TEST(&f_test_ascPrint_vtable2 == Asc_PrintRemoveVTable("test_vtable2")); /* cleanup */
524 CU_TEST(&f_test_ascPrint_vtable1 == Asc_PrintRemoveVTable("test_vtable1"));
525 f_test_ascPrint_vtable1.next = NULL;
526 f_test_ascPrint_vtable2.next = NULL;
527
528 if (TRUE == i_disabled_printing) { /* restore global vtable if necessary */
529 test_enable_printing();
530 }
531
532 CU_TEST(prior_meminuse == ascmeminuse()); /* make sure we cleaned up after ourselves */
533 }
534
535 /*===========================================================================*/
536 /* Registration information */
537
538 static CU_TestInfo ascPrint_test_list[] = {
539 {"test_ascPrint", test_ascPrint},
540 CU_TEST_INFO_NULL
541 };
542
543 static CU_SuiteInfo suites[] = {
544 {"test_utilities_ascPrint", NULL, NULL, ascPrint_test_list},
545 CU_SUITE_INFO_NULL
546 };
547
548 /*-------------------------------------------------------------------*/
549 CU_ErrorCode test_register_utilities_ascPrint(void)
550 {
551 return CU_register_suites(suites);
552 }

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22