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

Contents of /trunk/ascend/utilities/test/test_ascPrint.c

Parent Directory Parent Directory | Revision Log Revision Log


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

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