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

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