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