23 |
|
|
24 |
#include <stdio.h> |
#include <stdio.h> |
25 |
#include <utilities/ascConfig.h> |
#include <utilities/ascConfig.h> |
26 |
|
#include <utilities/error.h> |
27 |
#ifdef __WIN32__ |
#ifdef __WIN32__ |
28 |
#include <io.h> |
#include <io.h> |
29 |
#endif |
#endif |
30 |
#include <utilities/ascPanic.h> |
#include <utilities/ascPanic.h> |
31 |
#include <utilities/ascMalloc.h> |
#include <utilities/ascMalloc.h> |
32 |
#include "CUnit/CUnit.h" |
#include <CUnit/CUnit.h> |
33 |
#include "test_ascMalloc.h" |
#include "test_ascMalloc.h" |
34 |
#include "assertimpl.h" |
#include "assertimpl.h" |
35 |
|
|
65 |
unsigned long prior_meminuse; |
unsigned long prior_meminuse; |
66 |
|
|
67 |
prior_meminuse = ascmeminuse(); /* save meminuse() at start of test function */ |
prior_meminuse = ascmeminuse(); /* save meminuse() at start of test function */ |
68 |
|
CONSOLE_DEBUG("IN USE = %lu",prior_meminuse); |
69 |
|
|
70 |
#ifdef NDEBUG |
#ifdef NDEBUG |
71 |
CU_FAIL("test_ascMalloc() compiled with NDEBUG - some features not tested."); |
CU_FAIL("test_ascMalloc() compiled with NDEBUG - some features not tested."); |
75 |
#endif |
#endif |
76 |
|
|
77 |
/* test ascstrdup() */ |
/* test ascstrdup() */ |
78 |
CU_TEST(NULL == ascstrdup(NULL)); /* NULL str */ |
CU_ASSERT(NULL == ascstrdup(NULL)); /* NULL str */ |
79 |
|
|
80 |
p_str1 = ascstrdup("Just a simple little string."); /* normal operation with literal*/ |
p_str1 = ascstrdup("Just a simple little string."); /* normal operation with literal*/ |
81 |
CU_TEST(NULL != p_str1); |
CU_ASSERT(NULL != p_str1); |
82 |
CU_TEST(0 == strcmp(p_str1, "Just a simple little string.")); |
CU_ASSERT(0 == strcmp(p_str1, "Just a simple little string.")); |
83 |
CU_TEST(0 != ascmeminuse()); |
CU_ASSERT(0 != ascmeminuse()); |
84 |
ascfree(p_str1); |
ascfree(p_str1); |
85 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
86 |
|
|
87 |
snprintf(str1, STR_LEN-1, "I'm a simple string."); |
snprintf(str1, STR_LEN-1, "I'm a simple string."); |
88 |
p_str1 = ascstrdup(str1); /* normal operation with literal*/ |
p_str1 = ascstrdup(str1); /* normal operation with literal*/ |
89 |
CU_TEST(NULL != p_str1); |
CU_ASSERT(NULL != p_str1); |
90 |
CU_TEST(0 == strcmp(p_str1, str1)); |
CU_ASSERT(0 == strcmp(p_str1, str1)); |
91 |
CU_TEST(0 != ascmeminuse()); |
CU_ASSERT(0 != ascmeminuse()); |
92 |
ascfree(p_str1); |
ascfree(p_str1); |
93 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
94 |
|
|
95 |
/* test asc_memcpy() */ |
/* test asc_memcpy() */ |
96 |
|
|
100 |
asc_assert_reset(); |
asc_assert_reset(); |
101 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
102 |
asc_memcpy(NULL, str2, STR_LEN); /* error - NULL dest */ |
asc_memcpy(NULL, str2, STR_LEN); /* error - NULL dest */ |
103 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
104 |
|
|
105 |
asc_assert_reset(); |
asc_assert_reset(); |
106 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
107 |
asc_memcpy(str1, NULL, STR_LEN); /* error - NULL src */ |
asc_memcpy(str1, NULL, STR_LEN); /* error - NULL src */ |
108 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
109 |
|
|
110 |
asc_assert_catch(FALSE); /* done testing assertions */ |
asc_assert_catch(FALSE); /* done testing assertions */ |
111 |
#endif /* !ASC_NO_ASSERTIONS */ |
#endif /* !ASC_NO_ASSERTIONS */ |
129 |
} |
} |
130 |
if (!str1_bad && !str2_bad) CU_PASS("str1 and str2 check out."); |
if (!str1_bad && !str2_bad) CU_PASS("str1 and str2 check out."); |
131 |
|
|
132 |
CU_TEST(str1 == asc_memcpy(str1, str2, STR_LEN/2)); /* copy part of a memory block */ |
CU_ASSERT(str1 == asc_memcpy(str1, str2, STR_LEN/2)); /* copy part of a memory block */ |
133 |
|
|
134 |
str1_bad = FALSE; |
str1_bad = FALSE; |
135 |
str2_bad = FALSE; |
str2_bad = FALSE; |
159 |
memset(str1, '\0', STR_LEN); |
memset(str1, '\0', STR_LEN); |
160 |
memset(str2, '*', STR_LEN); |
memset(str2, '*', STR_LEN); |
161 |
|
|
162 |
CU_TEST(str1 == asc_memcpy(str1, str2, STR_LEN)); /* copy all of a memory block */ |
CU_ASSERT(str1 == asc_memcpy(str1, str2, STR_LEN)); /* copy all of a memory block */ |
163 |
|
|
164 |
str1_bad = FALSE; |
str1_bad = FALSE; |
165 |
str2_bad = FALSE; |
str2_bad = FALSE; |
181 |
memset(str1+10, '=', 10); |
memset(str1+10, '=', 10); |
182 |
memset(str1+20, '|', 10); |
memset(str1+20, '|', 10); |
183 |
|
|
184 |
CU_TEST((str1+10) == asc_memcpy(str1+10, str1, 20)); /* copy overlapping memory block */ |
CU_ASSERT((str1+10) == asc_memcpy(str1+10, str1, 20)); /* copy overlapping memory block */ |
185 |
|
|
186 |
str1_bad = FALSE; |
str1_bad = FALSE; |
187 |
for (i=0 ; i<20 ; ++i) { |
for (i=0 ; i<20 ; ++i) { |
204 |
memset(str1+10, '=', 10); |
memset(str1+10, '=', 10); |
205 |
memset(str1+20, '|', 10); |
memset(str1+20, '|', 10); |
206 |
|
|
207 |
CU_TEST(str1 == asc_memcpy(str1, str1+10, 20)); /* copy overlapping memory block */ |
CU_ASSERT(str1 == asc_memcpy(str1, str1+10, 20)); /* copy overlapping memory block */ |
208 |
|
|
209 |
str1_bad = FALSE; |
str1_bad = FALSE; |
210 |
for (i=0 ; i<10 ; ++i) { |
for (i=0 ; i<10 ; ++i) { |
224 |
if (!str1_bad) CU_PASS("str1 and str2 check out."); |
if (!str1_bad) CU_PASS("str1 and str2 check out."); |
225 |
|
|
226 |
snprintf(str1, STR_LEN-1, "This is yet another dumb string"); |
snprintf(str1, STR_LEN-1, "This is yet another dumb string"); |
227 |
CU_TEST(str1 == asc_memcpy(str1, str1, strlen(str1))); /* to == from */ |
CU_ASSERT(str1 == asc_memcpy(str1, str1, strlen(str1))); /* to == from */ |
228 |
CU_TEST(0 == strcmp(str1, "This is yet another dumb string")); |
CU_ASSERT(0 == strcmp(str1, "This is yet another dumb string")); |
229 |
|
|
230 |
CU_TEST(str1 == asc_memcpy(str1, str2, 0)); /* n = 0 */ |
CU_ASSERT(str1 == asc_memcpy(str1, str2, 0)); /* n = 0 */ |
231 |
CU_TEST(0 == strcmp(str1, "This is yet another dumb string")); |
CU_ASSERT(0 == strcmp(str1, "This is yet another dumb string")); |
232 |
|
|
233 |
/* test ascreallocPURE() */ |
/* test ascreallocPURE() */ |
234 |
|
|
235 |
p_str1 = ASC_NEW_ARRAY(char,50); /* allocate a block & check status */ |
p_str1 = ASC_NEW_ARRAY(char,50); /* allocate a block & check status */ |
236 |
CU_TEST_FATAL(NULL != p_str1); |
CU_TEST_FATAL(NULL != p_str1); |
237 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
238 |
CU_TEST(50 == ascmeminuse()); |
CU_ASSERT(50 == ascmeminuse()); |
239 |
CU_TEST(2 == AllocatedMemory(p_str1, 50)); |
CU_ASSERT(2 == AllocatedMemory(p_str1, 50)); |
240 |
#else |
#else |
241 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
242 |
CU_TEST(1 == AllocatedMemory(p_str1, 50)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 50)); |
243 |
#endif |
#endif |
244 |
|
|
245 |
snprintf(p_str1, 49, "I should survive a reallocation!"); |
snprintf(p_str1, 49, "I should survive a reallocation!"); |
246 |
p_str1 = ascreallocPURE(p_str1, 50, 100); |
p_str1 = ascreallocPURE(p_str1, 50, 100); |
247 |
CU_TEST_FATAL(NULL != p_str1); |
CU_TEST_FATAL(NULL != p_str1); |
248 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
249 |
CU_TEST(100 == ascmeminuse()); |
CU_ASSERT(100 == ascmeminuse()); |
250 |
CU_TEST(2 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(2 == AllocatedMemory(p_str1, 100)); |
251 |
#else |
#else |
252 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
253 |
CU_TEST(1 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 100)); |
254 |
#endif |
#endif |
255 |
CU_TEST(0 == strcmp(p_str1, "I should survive a reallocation!")); |
CU_ASSERT(0 == strcmp(p_str1, "I should survive a reallocation!")); |
256 |
|
|
257 |
ascfree(p_str1); |
ascfree(p_str1); |
258 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
259 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
260 |
CU_TEST(0 == AllocatedMemory(p_str1, 0)); |
CU_ASSERT(0 == AllocatedMemory(p_str1, 0)); |
261 |
#else |
#else |
262 |
CU_TEST(1 == AllocatedMemory(p_str1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 0)); |
263 |
#endif |
#endif |
264 |
|
|
265 |
/* ascstatus(), ascstatus_detail() - reporting functions, not tested */ |
/* ascstatus(), ascstatus_detail() - reporting functions, not tested */ |
271 |
p_int1 = (int *)asccalloc(0, sizeof(int)); /* 0 elements requested */ |
p_int1 = (int *)asccalloc(0, sizeof(int)); /* 0 elements requested */ |
272 |
CU_TEST_FATAL(NULL != p_int1); |
CU_TEST_FATAL(NULL != p_int1); |
273 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
274 |
CU_TEST(AT_LEAST_1(0) == ascmeminuse()); |
CU_ASSERT(AT_LEAST_1(0) == ascmeminuse()); |
275 |
CU_TEST(2 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(2 == AllocatedMemory(p_int1, 0)); |
276 |
#else |
#else |
277 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
278 |
CU_TEST(1 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 0)); |
279 |
#endif |
#endif |
280 |
|
|
281 |
ascfree(p_int1); |
ascfree(p_int1); |
282 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
283 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
284 |
CU_TEST(0 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(0 == AllocatedMemory(p_int1, 0)); |
285 |
#else |
#else |
286 |
CU_TEST(1 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 0)); |
287 |
#endif |
#endif |
288 |
|
|
289 |
p_int1 = (int *)asccalloc(100, 0); /* 0 size requested */ |
p_int1 = (int *)asccalloc(100, 0); /* 0 size requested */ |
290 |
CU_TEST_FATAL(NULL != p_int1); |
CU_TEST_FATAL(NULL != p_int1); |
291 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
292 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
293 |
CU_TEST(2 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(2 == AllocatedMemory(p_int1, 0)); |
294 |
#else |
#else |
295 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
296 |
CU_TEST(1 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 0)); |
297 |
#endif |
#endif |
298 |
|
|
299 |
ascfree(p_int1); |
ascfree(p_int1); |
300 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
301 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
302 |
CU_TEST(0 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(0 == AllocatedMemory(p_int1, 0)); |
303 |
#else |
#else |
304 |
CU_TEST(1 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 0)); |
305 |
#endif |
#endif |
306 |
|
|
307 |
p_int1 = (int *)asccalloc(100, sizeof(int)); /* 100 elements requested */ |
p_int1 = (int *)asccalloc(100, sizeof(int)); /* 100 elements requested */ |
308 |
CU_TEST_FATAL(NULL != p_int1); |
CU_TEST_FATAL(NULL != p_int1); |
309 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
310 |
CU_TEST(100*sizeof(int) == ascmeminuse()); |
CU_ASSERT(100*sizeof(int) == ascmeminuse()); |
311 |
CU_TEST(2 == AllocatedMemory(p_int1, 100*sizeof(int))); |
CU_ASSERT(2 == AllocatedMemory(p_int1, 100*sizeof(int))); |
312 |
#else |
#else |
313 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
314 |
CU_TEST(1 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 0)); |
315 |
#endif |
#endif |
316 |
|
|
317 |
p_int2 = (int *)asccalloc(200, sizeof(int)); /* 200 more elements requested */ |
p_int2 = (int *)asccalloc(200, sizeof(int)); /* 200 more elements requested */ |
318 |
CU_TEST_FATAL(NULL != p_int2); |
CU_TEST_FATAL(NULL != p_int2); |
319 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
320 |
CU_TEST(300*sizeof(int) == ascmeminuse()); |
CU_ASSERT(300*sizeof(int) == ascmeminuse()); |
321 |
CU_TEST(2 == AllocatedMemory(p_int2, 200*sizeof(int))); |
CU_ASSERT(2 == AllocatedMemory(p_int2, 200*sizeof(int))); |
322 |
#else |
#else |
323 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
324 |
CU_TEST(1 == AllocatedMemory(p_int2, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int2, 0)); |
325 |
#endif |
#endif |
326 |
|
|
327 |
p_int3 = (int *)asccalloc(10, sizeof(int)); /* 10 more elements requested */ |
p_int3 = (int *)asccalloc(10, sizeof(int)); /* 10 more elements requested */ |
328 |
CU_TEST_FATAL(NULL != p_int3); |
CU_TEST_FATAL(NULL != p_int3); |
329 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
330 |
CU_TEST(310*sizeof(int) == ascmeminuse()); |
CU_ASSERT(310*sizeof(int) == ascmeminuse()); |
331 |
CU_TEST(2 == AllocatedMemory(p_int3, 10*sizeof(int))); |
CU_ASSERT(2 == AllocatedMemory(p_int3, 10*sizeof(int))); |
332 |
#else |
#else |
333 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
334 |
CU_TEST(1 == AllocatedMemory(p_int3, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int3, 0)); |
335 |
#endif |
#endif |
336 |
|
|
337 |
ascfree(p_int2); |
ascfree(p_int2); |
338 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
339 |
CU_TEST(110*sizeof(int) == ascmeminuse()); |
CU_ASSERT(110*sizeof(int) == ascmeminuse()); |
340 |
CU_TEST(2 == AllocatedMemory(p_int1, 100*sizeof(int))); |
CU_ASSERT(2 == AllocatedMemory(p_int1, 100*sizeof(int))); |
341 |
CU_TEST(0 == AllocatedMemory(p_int2, 200*sizeof(int))); |
CU_ASSERT(0 == AllocatedMemory(p_int2, 200*sizeof(int))); |
342 |
CU_TEST(2 == AllocatedMemory(p_int3, 10*sizeof(int))); |
CU_ASSERT(2 == AllocatedMemory(p_int3, 10*sizeof(int))); |
343 |
#else |
#else |
344 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
345 |
CU_TEST(1 == AllocatedMemory(p_int1, 100*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 100*sizeof(int))); |
346 |
CU_TEST(1 == AllocatedMemory(p_int2, 200*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int2, 200*sizeof(int))); |
347 |
CU_TEST(1 == AllocatedMemory(p_int3, 10*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int3, 10*sizeof(int))); |
348 |
#endif |
#endif |
349 |
|
|
350 |
ascfree(p_int1); |
ascfree(p_int1); |
351 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
352 |
CU_TEST(10*sizeof(int) == ascmeminuse()); |
CU_ASSERT(10*sizeof(int) == ascmeminuse()); |
353 |
CU_TEST(0 == AllocatedMemory(p_int1, 100*sizeof(int))); |
CU_ASSERT(0 == AllocatedMemory(p_int1, 100*sizeof(int))); |
354 |
CU_TEST(0 == AllocatedMemory(p_int2, 200*sizeof(int))); |
CU_ASSERT(0 == AllocatedMemory(p_int2, 200*sizeof(int))); |
355 |
CU_TEST(2 == AllocatedMemory(p_int3, 10*sizeof(int))); |
CU_ASSERT(2 == AllocatedMemory(p_int3, 10*sizeof(int))); |
356 |
#else |
#else |
357 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
358 |
CU_TEST(1 == AllocatedMemory(p_int1, 100*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 100*sizeof(int))); |
359 |
CU_TEST(1 == AllocatedMemory(p_int2, 200*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int2, 200*sizeof(int))); |
360 |
CU_TEST(1 == AllocatedMemory(p_int3, 10*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int3, 10*sizeof(int))); |
361 |
#endif |
#endif |
362 |
|
|
363 |
ascfree(p_int3); |
ascfree(p_int3); |
364 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
365 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
366 |
CU_TEST(0 == AllocatedMemory(p_int1, 100*sizeof(int))); |
CU_ASSERT(0 == AllocatedMemory(p_int1, 100*sizeof(int))); |
367 |
CU_TEST(0 == AllocatedMemory(p_int2, 200*sizeof(int))); |
CU_ASSERT(0 == AllocatedMemory(p_int2, 200*sizeof(int))); |
368 |
CU_TEST(0 == AllocatedMemory(p_int3, 10*sizeof(int))); |
CU_ASSERT(0 == AllocatedMemory(p_int3, 10*sizeof(int))); |
369 |
#else |
#else |
370 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
371 |
CU_TEST(1 == AllocatedMemory(p_int1, 100*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 100*sizeof(int))); |
372 |
CU_TEST(1 == AllocatedMemory(p_int2, 200*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int2, 200*sizeof(int))); |
373 |
CU_TEST(1 == AllocatedMemory(p_int3, 10*sizeof(int))); |
CU_ASSERT(1 == AllocatedMemory(p_int3, 10*sizeof(int))); |
374 |
#endif |
#endif |
375 |
|
|
376 |
/* test ascmalloc() */ |
/* test ascmalloc() */ |
378 |
p_int1 = (int *)ascmalloc(0); /* 0 bytes requested */ |
p_int1 = (int *)ascmalloc(0); /* 0 bytes requested */ |
379 |
CU_TEST_FATAL(NULL != p_int1); |
CU_TEST_FATAL(NULL != p_int1); |
380 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
381 |
CU_TEST(AT_LEAST_1(0) == ascmeminuse()); |
CU_ASSERT(AT_LEAST_1(0) == ascmeminuse()); |
382 |
CU_TEST(2 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(2 == AllocatedMemory(p_int1, 0)); |
383 |
#else |
#else |
384 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
385 |
CU_TEST(1 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 0)); |
386 |
#endif |
#endif |
387 |
|
|
388 |
ascfree(p_int1); |
ascfree(p_int1); |
389 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
390 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
391 |
CU_TEST(0 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(0 == AllocatedMemory(p_int1, 0)); |
392 |
#else |
#else |
393 |
CU_TEST(1 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 0)); |
394 |
#endif |
#endif |
395 |
|
|
396 |
p_int1 = (int *)ascmalloc(100); /* 100 bytes requested */ |
p_int1 = (int *)ascmalloc(100); /* 100 bytes requested */ |
397 |
CU_TEST_FATAL(NULL != p_int1); |
CU_TEST_FATAL(NULL != p_int1); |
398 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
399 |
CU_TEST(100 == ascmeminuse()); |
CU_ASSERT(100 == ascmeminuse()); |
400 |
CU_TEST(2 == AllocatedMemory(p_int1, 100)); |
CU_ASSERT(2 == AllocatedMemory(p_int1, 100)); |
401 |
#else |
#else |
402 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
403 |
CU_TEST(1 == AllocatedMemory(p_int1, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 0)); |
404 |
#endif |
#endif |
405 |
|
|
406 |
p_int2 = (int *)ascmalloc(200); /* 200 more bytes requested */ |
p_int2 = (int *)ascmalloc(200); /* 200 more bytes requested */ |
407 |
CU_TEST_FATAL(NULL != p_int2); |
CU_TEST_FATAL(NULL != p_int2); |
408 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
409 |
CU_TEST(300 == ascmeminuse()); |
CU_ASSERT(300 == ascmeminuse()); |
410 |
CU_TEST(2 == AllocatedMemory(p_int2, 200)); |
CU_ASSERT(2 == AllocatedMemory(p_int2, 200)); |
411 |
#else |
#else |
412 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
413 |
CU_TEST(1 == AllocatedMemory(p_int2, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int2, 0)); |
414 |
#endif |
#endif |
415 |
|
|
416 |
p_int3 = (int *)ascmalloc(10); /* 10 more bytes requested */ |
p_int3 = (int *)ascmalloc(10); /* 10 more bytes requested */ |
417 |
CU_TEST_FATAL(NULL != p_int3); |
CU_TEST_FATAL(NULL != p_int3); |
418 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
419 |
CU_TEST(310 == ascmeminuse()); |
CU_ASSERT(310 == ascmeminuse()); |
420 |
CU_TEST(2 == AllocatedMemory(p_int3, 10)); |
CU_ASSERT(2 == AllocatedMemory(p_int3, 10)); |
421 |
#else |
#else |
422 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
423 |
CU_TEST(1 == AllocatedMemory(p_int3, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_int3, 0)); |
424 |
#endif |
#endif |
425 |
|
|
426 |
ascfree(p_int2); |
ascfree(p_int2); |
427 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
428 |
CU_TEST(110 == ascmeminuse()); |
CU_ASSERT(110 == ascmeminuse()); |
429 |
CU_TEST(2 == AllocatedMemory(p_int1, 100)); |
CU_ASSERT(2 == AllocatedMemory(p_int1, 100)); |
430 |
CU_TEST(0 == AllocatedMemory(p_int2, 200)); |
CU_ASSERT(0 == AllocatedMemory(p_int2, 200)); |
431 |
CU_TEST(2 == AllocatedMemory(p_int3, 10)); |
CU_ASSERT(2 == AllocatedMemory(p_int3, 10)); |
432 |
#else |
#else |
433 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
434 |
CU_TEST(1 == AllocatedMemory(p_int1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 100)); |
435 |
CU_TEST(1 == AllocatedMemory(p_int2, 200)); |
CU_ASSERT(1 == AllocatedMemory(p_int2, 200)); |
436 |
CU_TEST(1 == AllocatedMemory(p_int3, 10)); |
CU_ASSERT(1 == AllocatedMemory(p_int3, 10)); |
437 |
#endif |
#endif |
438 |
|
|
439 |
ascfree(p_int1); |
ascfree(p_int1); |
440 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
441 |
CU_TEST(10 == ascmeminuse()); |
CU_ASSERT(10 == ascmeminuse()); |
442 |
CU_TEST(0 == AllocatedMemory(p_int1, 100)); |
CU_ASSERT(0 == AllocatedMemory(p_int1, 100)); |
443 |
CU_TEST(0 == AllocatedMemory(p_int2, 200)); |
CU_ASSERT(0 == AllocatedMemory(p_int2, 200)); |
444 |
CU_TEST(2 == AllocatedMemory(p_int3, 10)); |
CU_ASSERT(2 == AllocatedMemory(p_int3, 10)); |
445 |
#else |
#else |
446 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
447 |
CU_TEST(1 == AllocatedMemory(p_int1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 100)); |
448 |
CU_TEST(1 == AllocatedMemory(p_int2, 200)); |
CU_ASSERT(1 == AllocatedMemory(p_int2, 200)); |
449 |
CU_TEST(1 == AllocatedMemory(p_int3, 10)); |
CU_ASSERT(1 == AllocatedMemory(p_int3, 10)); |
450 |
#endif |
#endif |
451 |
|
|
452 |
ascfree(p_int3); |
ascfree(p_int3); |
453 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
454 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
455 |
CU_TEST(0 == AllocatedMemory(p_int1, 100)); |
CU_ASSERT(0 == AllocatedMemory(p_int1, 100)); |
456 |
CU_TEST(0 == AllocatedMemory(p_int2, 200)); |
CU_ASSERT(0 == AllocatedMemory(p_int2, 200)); |
457 |
CU_TEST(0 == AllocatedMemory(p_int3, 10)); |
CU_ASSERT(0 == AllocatedMemory(p_int3, 10)); |
458 |
#else |
#else |
459 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
460 |
CU_TEST(1 == AllocatedMemory(p_int1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_int1, 100)); |
461 |
CU_TEST(1 == AllocatedMemory(p_int2, 200)); |
CU_ASSERT(1 == AllocatedMemory(p_int2, 200)); |
462 |
CU_TEST(1 == AllocatedMemory(p_int3, 10)); |
CU_ASSERT(1 == AllocatedMemory(p_int3, 10)); |
463 |
#endif |
#endif |
464 |
|
|
465 |
/* test ascrealloc() */ |
/* test ascrealloc() */ |
471 |
CU_TEST_FATAL(NULL != p_str2); |
CU_TEST_FATAL(NULL != p_str2); |
472 |
CU_TEST_FATAL(NULL != p_str3); |
CU_TEST_FATAL(NULL != p_str3); |
473 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
474 |
CU_TEST(95 == ascmeminuse()); |
CU_ASSERT(95 == ascmeminuse()); |
475 |
CU_TEST(2 == AllocatedMemory(p_str1, 50)); |
CU_ASSERT(2 == AllocatedMemory(p_str1, 50)); |
476 |
CU_TEST(2 == AllocatedMemory(p_str2, 20)); |
CU_ASSERT(2 == AllocatedMemory(p_str2, 20)); |
477 |
CU_TEST(2 == AllocatedMemory(p_str3, 25)); |
CU_ASSERT(2 == AllocatedMemory(p_str3, 25)); |
478 |
#else |
#else |
479 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
480 |
CU_TEST(1 == AllocatedMemory(p_str1, 50)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 50)); |
481 |
CU_TEST(1 == AllocatedMemory(p_str2, 20)); |
CU_ASSERT(1 == AllocatedMemory(p_str2, 20)); |
482 |
CU_TEST(1 == AllocatedMemory(p_str3, 25)); |
CU_ASSERT(1 == AllocatedMemory(p_str3, 25)); |
483 |
#endif |
#endif |
484 |
|
|
485 |
snprintf(p_str1, 49, "I should survive a reallocation!"); |
snprintf(p_str1, 49, "I should survive a reallocation!"); |
489 |
p_str1 = ascrealloc(p_str1, 100); /* realloc to larger size */ |
p_str1 = ascrealloc(p_str1, 100); /* realloc to larger size */ |
490 |
CU_TEST_FATAL(NULL != p_str1); |
CU_TEST_FATAL(NULL != p_str1); |
491 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
492 |
CU_TEST(145 == ascmeminuse()); |
CU_ASSERT(145 == ascmeminuse()); |
493 |
CU_TEST(2 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(2 == AllocatedMemory(p_str1, 100)); |
494 |
CU_TEST(2 == AllocatedMemory(p_str2, 20)); |
CU_ASSERT(2 == AllocatedMemory(p_str2, 20)); |
495 |
CU_TEST(2 == AllocatedMemory(p_str3, 25)); |
CU_ASSERT(2 == AllocatedMemory(p_str3, 25)); |
496 |
#else |
#else |
497 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
498 |
CU_TEST(1 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 100)); |
499 |
CU_TEST(1 == AllocatedMemory(p_str2, 20)); |
CU_ASSERT(1 == AllocatedMemory(p_str2, 20)); |
500 |
CU_TEST(1 == AllocatedMemory(p_str3, 25)); |
CU_ASSERT(1 == AllocatedMemory(p_str3, 25)); |
501 |
#endif |
#endif |
502 |
CU_TEST(0 == strcmp(p_str1, "I should survive a reallocation!")); |
CU_ASSERT(0 == strcmp(p_str1, "I should survive a reallocation!")); |
503 |
CU_TEST(0 == strcmp(p_str2, "Me too?")); |
CU_ASSERT(0 == strcmp(p_str2, "Me too?")); |
504 |
CU_TEST(0 == strcmp(p_str3, "Realloc me away.")); |
CU_ASSERT(0 == strcmp(p_str3, "Realloc me away.")); |
505 |
|
|
506 |
p_str2 = ascrealloc(p_str2, 10); /* realloc to smaller size */ |
p_str2 = ascrealloc(p_str2, 10); /* realloc to smaller size */ |
507 |
CU_TEST_FATAL(NULL != p_str2); |
CU_TEST_FATAL(NULL != p_str2); |
508 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
509 |
CU_TEST(135 == ascmeminuse()); |
CU_ASSERT(135 == ascmeminuse()); |
510 |
CU_TEST(2 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(2 == AllocatedMemory(p_str1, 100)); |
511 |
CU_TEST(2 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(2 == AllocatedMemory(p_str2, 10)); |
512 |
CU_TEST(2 == AllocatedMemory(p_str3, 25)); |
CU_ASSERT(2 == AllocatedMemory(p_str3, 25)); |
513 |
#else |
#else |
514 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
515 |
CU_TEST(1 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 100)); |
516 |
CU_TEST(1 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(1 == AllocatedMemory(p_str2, 10)); |
517 |
CU_TEST(1 == AllocatedMemory(p_str3, 25)); |
CU_ASSERT(1 == AllocatedMemory(p_str3, 25)); |
518 |
#endif |
#endif |
519 |
CU_TEST(0 == strcmp(p_str1, "I should survive a reallocation!")); |
CU_ASSERT(0 == strcmp(p_str1, "I should survive a reallocation!")); |
520 |
CU_TEST(0 == strcmp(p_str2, "Me too?")); |
CU_ASSERT(0 == strcmp(p_str2, "Me too?")); |
521 |
CU_TEST(0 == strcmp(p_str3, "Realloc me away.")); |
CU_ASSERT(0 == strcmp(p_str3, "Realloc me away.")); |
522 |
|
|
523 |
p_str3 = ascrealloc(p_str3, 0); /* realloc to zero */ |
p_str3 = ascrealloc(p_str3, 0); /* realloc to zero */ |
524 |
CU_TEST(NULL == p_str3); |
CU_ASSERT(NULL == p_str3); |
525 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
526 |
CU_TEST(110+AT_LEAST_1(0) == ascmeminuse()); |
CU_ASSERT(110+AT_LEAST_1(0) == ascmeminuse()); |
527 |
CU_TEST(2 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(2 == AllocatedMemory(p_str1, 100)); |
528 |
CU_TEST(2 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(2 == AllocatedMemory(p_str2, 10)); |
529 |
CU_TEST(0 == AllocatedMemory(p_str3, 0)); |
CU_ASSERT(0 == AllocatedMemory(p_str3, 0)); |
530 |
#else |
#else |
531 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
532 |
CU_TEST(1 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 100)); |
533 |
CU_TEST(1 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(1 == AllocatedMemory(p_str2, 10)); |
534 |
CU_TEST(1 == AllocatedMemory(p_str3, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_str3, 0)); |
535 |
#endif |
#endif |
536 |
CU_TEST(0 == strcmp(p_str1, "I should survive a reallocation!")); |
CU_ASSERT(0 == strcmp(p_str1, "I should survive a reallocation!")); |
537 |
CU_TEST(0 == strcmp(p_str2, "Me too?")); |
CU_ASSERT(0 == strcmp(p_str2, "Me too?")); |
538 |
|
|
539 |
ascfree(p_str3); |
ascfree(p_str3); |
540 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
541 |
CU_TEST(110 == ascmeminuse()); |
CU_ASSERT(110 == ascmeminuse()); |
542 |
CU_TEST(2 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(2 == AllocatedMemory(p_str1, 100)); |
543 |
CU_TEST(2 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(2 == AllocatedMemory(p_str2, 10)); |
544 |
CU_TEST(0 == AllocatedMemory(p_str3, 0)); |
CU_ASSERT(0 == AllocatedMemory(p_str3, 0)); |
545 |
#else |
#else |
546 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
547 |
CU_TEST(1 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 100)); |
548 |
CU_TEST(1 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(1 == AllocatedMemory(p_str2, 10)); |
549 |
CU_TEST(1 == AllocatedMemory(p_str3, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_str3, 0)); |
550 |
#endif |
#endif |
551 |
|
|
552 |
ascfree(p_str1); |
ascfree(p_str1); |
553 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
554 |
CU_TEST(10 == ascmeminuse()); |
CU_ASSERT(10 == ascmeminuse()); |
555 |
CU_TEST(0 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(0 == AllocatedMemory(p_str1, 100)); |
556 |
CU_TEST(2 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(2 == AllocatedMemory(p_str2, 10)); |
557 |
CU_TEST(0 == AllocatedMemory(p_str3, 0)); |
CU_ASSERT(0 == AllocatedMemory(p_str3, 0)); |
558 |
#else |
#else |
559 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
560 |
CU_TEST(1 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 100)); |
561 |
CU_TEST(1 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(1 == AllocatedMemory(p_str2, 10)); |
562 |
CU_TEST(1 == AllocatedMemory(p_str3, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_str3, 0)); |
563 |
#endif |
#endif |
564 |
|
|
565 |
ascfree(p_str2); |
ascfree(p_str2); |
566 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
567 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
568 |
CU_TEST(0 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(0 == AllocatedMemory(p_str1, 100)); |
569 |
CU_TEST(0 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(0 == AllocatedMemory(p_str2, 10)); |
570 |
CU_TEST(0 == AllocatedMemory(p_str3, 0)); |
CU_ASSERT(0 == AllocatedMemory(p_str3, 0)); |
571 |
#else |
#else |
572 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
573 |
CU_TEST(1 == AllocatedMemory(p_str1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_str1, 100)); |
574 |
CU_TEST(1 == AllocatedMemory(p_str2, 10)); |
CU_ASSERT(1 == AllocatedMemory(p_str2, 10)); |
575 |
CU_TEST(1 == AllocatedMemory(p_str3, 0)); |
CU_ASSERT(1 == AllocatedMemory(p_str3, 0)); |
576 |
#endif |
#endif |
577 |
|
|
578 |
/* ascfree() tested adequately by other tests */ |
/* ascfree() tested adequately by other tests */ |
582 |
memset(str1, '\0', STR_LEN); |
memset(str1, '\0', STR_LEN); |
583 |
memset(str2, '*', STR_LEN); |
memset(str2, '*', STR_LEN); |
584 |
|
|
585 |
CU_TEST(str2 == ascbcopy(str1, str2, STR_LEN/2)); /* copy part of a memory block */ |
CU_ASSERT(str2 == ascbcopy(str1, str2, STR_LEN/2)); /* copy part of a memory block */ |
586 |
|
|
587 |
str1_bad = FALSE; |
str1_bad = FALSE; |
588 |
str2_bad = FALSE; |
str2_bad = FALSE; |
612 |
memset(str1, '+', STR_LEN); |
memset(str1, '+', STR_LEN); |
613 |
memset(str2, '-', STR_LEN); |
memset(str2, '-', STR_LEN); |
614 |
|
|
615 |
CU_TEST(str2 == ascbcopy(str1, str2, 0)); /* 0 bytes copied */ |
CU_ASSERT(str2 == ascbcopy(str1, str2, 0)); /* 0 bytes copied */ |
616 |
|
|
617 |
str1_bad = FALSE; |
str1_bad = FALSE; |
618 |
str2_bad = FALSE; |
str2_bad = FALSE; |
634 |
|
|
635 |
memset(str1, '=', STR_LEN); |
memset(str1, '=', STR_LEN); |
636 |
|
|
637 |
CU_TEST(str1 == ascbzero(str1, STR_LEN/2)); /* zero part of a memory block */ |
CU_ASSERT(str1 == ascbzero(str1, STR_LEN/2)); /* zero part of a memory block */ |
638 |
|
|
639 |
str1_bad = FALSE; |
str1_bad = FALSE; |
640 |
for (i=0 ; i<STR_LEN/2 ; ++i) { |
for (i=0 ; i<STR_LEN/2 ; ++i) { |
655 |
|
|
656 |
memset(str1, '+', STR_LEN); |
memset(str1, '+', STR_LEN); |
657 |
|
|
658 |
CU_TEST(str1 == ascbzero(str1, 0)); /* 0 bytes processed */ |
CU_ASSERT(str1 == ascbzero(str1, 0)); /* 0 bytes processed */ |
659 |
|
|
660 |
str1_bad = FALSE; |
str1_bad = FALSE; |
661 |
for (i=0 ; i<STR_LEN ; ++i) { |
for (i=0 ; i<STR_LEN ; ++i) { |
671 |
|
|
672 |
memset(str1, '@', STR_LEN); |
memset(str1, '@', STR_LEN); |
673 |
|
|
674 |
CU_TEST(str1 == ascbfill(str1, STR_LEN/2)); /* fill part of a memory block */ |
CU_ASSERT(str1 == ascbfill(str1, STR_LEN/2)); /* fill part of a memory block */ |
675 |
|
|
676 |
str1_bad = FALSE; |
str1_bad = FALSE; |
677 |
for (i=0 ; i<STR_LEN/2 ; ++i) { |
for (i=0 ; i<STR_LEN/2 ; ++i) { |
692 |
|
|
693 |
memset(str1, '#', STR_LEN); |
memset(str1, '#', STR_LEN); |
694 |
|
|
695 |
CU_TEST(str1 == ascbfill(str1, 0)); /* 0 bytes processed */ |
CU_ASSERT(str1 == ascbfill(str1, 0)); /* 0 bytes processed */ |
696 |
|
|
697 |
str1_bad = FALSE; |
str1_bad = FALSE; |
698 |
for (i=0 ; i<STR_LEN ; ++i) { |
for (i=0 ; i<STR_LEN ; ++i) { |
707 |
/* test AllocatedMemory() */ |
/* test AllocatedMemory() */ |
708 |
|
|
709 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
710 |
CU_TEST(0 == AllocatedMemory(NULL, 0)); /* NULL pointer, nothing allocated */ |
CU_ASSERT(0 == AllocatedMemory(NULL, 0)); /* NULL pointer, nothing allocated */ |
711 |
CU_TEST(0 == AllocatedMemory(&str1_bad, 0)); /* non-NULL pointer, nothing allocated */ |
CU_ASSERT(0 == AllocatedMemory(&str1_bad, 0)); /* non-NULL pointer, nothing allocated */ |
712 |
#else |
#else |
713 |
CU_TEST(1 == AllocatedMemory(NULL, 0)); /* NULL pointer, nothing allocated */ |
CU_ASSERT(1 == AllocatedMemory(NULL, 0)); /* NULL pointer, nothing allocated */ |
714 |
CU_TEST(1 == AllocatedMemory(&str1_bad, 0)); /* non-NULL pointer, nothing allocated */ |
CU_ASSERT(1 == AllocatedMemory(&str1_bad, 0)); /* non-NULL pointer, nothing allocated */ |
715 |
#endif |
#endif |
716 |
|
|
717 |
p_str1 = ASC_NEW_ARRAY(char,100); /* allocate 1 block */ |
p_str1 = ASC_NEW_ARRAY(char,100); /* allocate 1 block */ |
721 |
CU_TEST_FATAL(NULL != p_str2); |
CU_TEST_FATAL(NULL != p_str2); |
722 |
|
|
723 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
724 |
CU_TEST(0 == AllocatedMemory(NULL, 0)); /* NULL pointer */ |
CU_ASSERT(0 == AllocatedMemory(NULL, 0)); /* NULL pointer */ |
725 |
|
|
726 |
CU_TEST(0 == AllocatedMemory(p_str2, 0)); /* pointer allocated outside ascMalloc */ |
CU_ASSERT(0 == AllocatedMemory(p_str2, 0)); /* pointer allocated outside ascMalloc */ |
727 |
|
|
728 |
CU_TEST(2 == AllocatedMemory(p_str1, 100)); /* complete blocks */ |
CU_ASSERT(2 == AllocatedMemory(p_str1, 100)); /* complete blocks */ |
729 |
|
|
730 |
CU_TEST(1 == AllocatedMemory(p_str1, 99)); /* contained blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_str1, 99)); /* contained blocks */ |
731 |
CU_TEST(1 == AllocatedMemory(p_str1+1, 99)); |
CU_ASSERT(1 == AllocatedMemory(p_str1+1, 99)); |
732 |
|
|
733 |
CU_TEST(-1 == AllocatedMemory(p_str1, 101)); /* overlapping blocks */ |
CU_ASSERT(-1 == AllocatedMemory(p_str1, 101)); /* overlapping blocks */ |
734 |
CU_TEST(-1 == AllocatedMemory(p_str1+1, 100)); |
CU_ASSERT(-1 == AllocatedMemory(p_str1+1, 100)); |
735 |
CU_TEST(-1 == AllocatedMemory(p_str1-1, 2)); |
CU_ASSERT(-1 == AllocatedMemory(p_str1-1, 2)); |
736 |
CU_TEST(-1 == AllocatedMemory(p_str1-1, 150)); |
CU_ASSERT(-1 == AllocatedMemory(p_str1-1, 150)); |
737 |
|
|
738 |
CU_TEST(0 == AllocatedMemory(p_str1-10, 10)); /* non-overlapping blocks */ |
CU_ASSERT(0 == AllocatedMemory(p_str1-10, 10)); /* non-overlapping blocks */ |
739 |
CU_TEST(0 == AllocatedMemory(p_str1-1, 1)); |
CU_ASSERT(0 == AllocatedMemory(p_str1-1, 1)); |
740 |
|
|
741 |
#else |
#else |
742 |
CU_TEST(1 == AllocatedMemory(NULL, 0)); /* NULL pointer */ |
CU_ASSERT(1 == AllocatedMemory(NULL, 0)); /* NULL pointer */ |
743 |
|
|
744 |
CU_TEST(1 == AllocatedMemory(p_str2, 0)); /* pointer allocated outside ascMalloc */ |
CU_ASSERT(1 == AllocatedMemory(p_str2, 0)); /* pointer allocated outside ascMalloc */ |
745 |
|
|
746 |
CU_TEST(1 == AllocatedMemory(p_str1, 100)); /* complete blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_str1, 100)); /* complete blocks */ |
747 |
|
|
748 |
CU_TEST(1 == AllocatedMemory(p_str1, 99)); /* contained blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_str1, 99)); /* contained blocks */ |
749 |
CU_TEST(1 == AllocatedMemory(p_str1+1, 99)); |
CU_ASSERT(1 == AllocatedMemory(p_str1+1, 99)); |
750 |
|
|
751 |
CU_TEST(1 == AllocatedMemory(p_str1, 101)); /* overlapping blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_str1, 101)); /* overlapping blocks */ |
752 |
CU_TEST(1 == AllocatedMemory(p_str1+1, 100)); |
CU_ASSERT(1 == AllocatedMemory(p_str1+1, 100)); |
753 |
CU_TEST(1 == AllocatedMemory(p_str1-1, 2)); |
CU_ASSERT(1 == AllocatedMemory(p_str1-1, 2)); |
754 |
CU_TEST(1 == AllocatedMemory(p_str1-1, 150)); |
CU_ASSERT(1 == AllocatedMemory(p_str1-1, 150)); |
755 |
|
|
756 |
CU_TEST(1 == AllocatedMemory(p_str1-10, 10)); /* non-overlapping blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_str1-10, 10)); /* non-overlapping blocks */ |
757 |
CU_TEST(1 == AllocatedMemory(p_str1-1, 1)); |
CU_ASSERT(1 == AllocatedMemory(p_str1-1, 1)); |
758 |
|
|
759 |
#endif |
#endif |
760 |
|
|
761 |
ascfree(p_str1); |
ascfree(p_str1); |
762 |
free(p_str2); |
free(p_str2); |
763 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
764 |
|
|
765 |
p_doub1 = (double *)ascmalloc(sizeof(double)); /* allocate 1 block */ |
p_doub1 = (double *)ascmalloc(sizeof(double)); /* allocate 1 block */ |
766 |
CU_TEST_FATAL(NULL != p_doub1); |
CU_TEST_FATAL(NULL != p_doub1); |
769 |
CU_TEST_FATAL(NULL != p_doub2); |
CU_TEST_FATAL(NULL != p_doub2); |
770 |
|
|
771 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
772 |
CU_TEST(0 == AllocatedMemory(NULL, 0)); /* NULL pointer */ |
CU_ASSERT(0 == AllocatedMemory(NULL, 0)); /* NULL pointer */ |
773 |
|
|
774 |
CU_TEST(0 == AllocatedMemory(p_doub2, 0)); /* pointer allocated outside ascMalloc */ |
CU_ASSERT(0 == AllocatedMemory(p_doub2, 0)); /* pointer allocated outside ascMalloc */ |
775 |
|
|
776 |
CU_TEST(2 == AllocatedMemory(p_doub1, sizeof(double)));/* complete blocks */ |
CU_ASSERT(2 == AllocatedMemory(p_doub1, sizeof(double)));/* complete blocks */ |
777 |
|
|
778 |
CU_TEST(1 == AllocatedMemory(p_doub1, 0)); /* contained blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_doub1, 0)); /* contained blocks */ |
779 |
CU_TEST(1 == AllocatedMemory((char *)p_doub1+1, sizeof(double)-1)); |
CU_ASSERT(1 == AllocatedMemory((char *)p_doub1+1, sizeof(double)-1)); |
780 |
|
|
781 |
CU_TEST(-1 == AllocatedMemory(p_doub1, sizeof(double)+1)); /* overlapping blocks */ |
CU_ASSERT(-1 == AllocatedMemory(p_doub1, sizeof(double)+1)); /* overlapping blocks */ |
782 |
CU_TEST(-1 == AllocatedMemory((char *)p_doub1+1, sizeof(double))); |
CU_ASSERT(-1 == AllocatedMemory((char *)p_doub1+1, sizeof(double))); |
783 |
CU_TEST(-1 == AllocatedMemory((char *)p_doub1-1, 2)); |
CU_ASSERT(-1 == AllocatedMemory((char *)p_doub1-1, 2)); |
784 |
|
|
785 |
CU_TEST(0 == AllocatedMemory((char *)p_doub1-1, 1)); /* non-overlapping blocks */ |
CU_ASSERT(0 == AllocatedMemory((char *)p_doub1-1, 1)); /* non-overlapping blocks */ |
786 |
CU_TEST(0 == AllocatedMemory((char *)p_doub1-100, 100)); |
CU_ASSERT(0 == AllocatedMemory((char *)p_doub1-100, 100)); |
787 |
|
|
788 |
#else |
#else |
789 |
CU_TEST(1 == AllocatedMemory(NULL, 0)); /* NULL pointer */ |
CU_ASSERT(1 == AllocatedMemory(NULL, 0)); /* NULL pointer */ |
790 |
|
|
791 |
CU_TEST(1 == AllocatedMemory(p_doub2, 0)); /* pointer allocated outside ascMalloc */ |
CU_ASSERT(1 == AllocatedMemory(p_doub2, 0)); /* pointer allocated outside ascMalloc */ |
792 |
|
|
793 |
CU_TEST(1 == AllocatedMemory(p_doub1, sizeof(double)));/* complete blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_doub1, sizeof(double)));/* complete blocks */ |
794 |
|
|
795 |
CU_TEST(1 == AllocatedMemory(p_doub1, 0)); /* contained blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_doub1, 0)); /* contained blocks */ |
796 |
CU_TEST(1 == AllocatedMemory((char *)p_doub1+1, sizeof(double)-1)); |
CU_ASSERT(1 == AllocatedMemory((char *)p_doub1+1, sizeof(double)-1)); |
797 |
|
|
798 |
CU_TEST(1 == AllocatedMemory(p_doub1, sizeof(double)+1)); /* overlapping blocks */ |
CU_ASSERT(1 == AllocatedMemory(p_doub1, sizeof(double)+1)); /* overlapping blocks */ |
799 |
CU_TEST(1 == AllocatedMemory((char *)p_doub1+1, sizeof(double))); |
CU_ASSERT(1 == AllocatedMemory((char *)p_doub1+1, sizeof(double))); |
800 |
CU_TEST(1 == AllocatedMemory((char *)p_doub1-1, 2)); |
CU_ASSERT(1 == AllocatedMemory((char *)p_doub1-1, 2)); |
801 |
|
|
802 |
CU_TEST(1 == AllocatedMemory((char *)p_doub1-1, 1)); /* non-overlapping blocks */ |
CU_ASSERT(1 == AllocatedMemory((char *)p_doub1-1, 1)); /* non-overlapping blocks */ |
803 |
CU_TEST(1 == AllocatedMemory((char *)p_doub1-100, 100)); |
CU_ASSERT(1 == AllocatedMemory((char *)p_doub1-100, 100)); |
804 |
|
|
805 |
#endif |
#endif |
806 |
|
|
807 |
ascfree(p_doub1); |
ascfree(p_doub1); |
808 |
free(p_doub2); |
free(p_doub2); |
809 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
810 |
|
|
811 |
/* test InMemoryBlock() */ |
/* test InMemoryBlock() */ |
812 |
|
|
813 |
p_str1 = ASC_NEW_ARRAY(char,100); /* allocate 1 block */ |
p_str1 = ASC_NEW_ARRAY(char,100); /* allocate 1 block */ |
814 |
CU_TEST_FATAL(NULL != p_str1); |
CU_TEST_FATAL(NULL != p_str1); |
815 |
CU_TEST(0 != InMemoryBlock(p_str1, p_str1)); |
CU_ASSERT(0 != InMemoryBlock(p_str1, p_str1)); |
816 |
CU_TEST(0 != InMemoryBlock(p_str1, p_str1+1)); |
CU_ASSERT(0 != InMemoryBlock(p_str1, p_str1+1)); |
817 |
CU_TEST(0 != InMemoryBlock(p_str1, p_str1+50)); |
CU_ASSERT(0 != InMemoryBlock(p_str1, p_str1+50)); |
818 |
CU_TEST(0 != InMemoryBlock(p_str1, p_str1+99)); |
CU_ASSERT(0 != InMemoryBlock(p_str1, p_str1+99)); |
819 |
#ifdef MALLOC_DEBUG |
#ifdef MALLOC_DEBUG |
820 |
CU_TEST(0 == InMemoryBlock(p_str1, p_str1-1)); |
CU_ASSERT(0 == InMemoryBlock(p_str1, p_str1-1)); |
821 |
CU_TEST(0 == InMemoryBlock(p_str1, p_str1+100)); |
CU_ASSERT(0 == InMemoryBlock(p_str1, p_str1+100)); |
822 |
CU_TEST(0 == InMemoryBlock(p_str1, p_str1+101)); |
CU_ASSERT(0 == InMemoryBlock(p_str1, p_str1+101)); |
823 |
CU_TEST(0 == InMemoryBlock(p_str1, (VOIDPTR)0)); |
CU_ASSERT(0 == InMemoryBlock(p_str1, (VOIDPTR)0)); |
824 |
#else |
#else |
825 |
CU_TEST(1 == InMemoryBlock(p_str1, p_str1-1)); |
CU_ASSERT(1 == InMemoryBlock(p_str1, p_str1-1)); |
826 |
CU_TEST(1 == InMemoryBlock(p_str1, p_str1+100)); |
CU_ASSERT(1 == InMemoryBlock(p_str1, p_str1+100)); |
827 |
CU_TEST(1 == InMemoryBlock(p_str1, p_str1+101)); |
CU_ASSERT(1 == InMemoryBlock(p_str1, p_str1+101)); |
828 |
CU_TEST(1 == InMemoryBlock(p_str1, (VOIDPTR)0)); |
CU_ASSERT(1 == InMemoryBlock(p_str1, (VOIDPTR)0)); |
829 |
#endif |
#endif |
830 |
|
|
831 |
ascfree(p_str1); |
ascfree(p_str1); |
832 |
CU_TEST(0 == ascmeminuse()); |
CU_ASSERT(0 == ascmeminuse()); |
833 |
|
|
834 |
/* test AssertAllocatedMemory() */ |
/* test AssertAllocatedMemory() */ |
835 |
|
|
840 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
841 |
AssertAllocatedMemory(p_str1, 100); /* error - no memory allocated */ |
AssertAllocatedMemory(p_str1, 100); /* error - no memory allocated */ |
842 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
843 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
844 |
#else |
#else |
845 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
846 |
#endif |
#endif |
847 |
|
|
848 |
p_str1 = ASC_NEW_ARRAY(char,100); |
p_str1 = ASC_NEW_ARRAY(char,100); |
855 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
856 |
AssertAllocatedMemory(NULL, 100); /* error - NULL ptr */ |
AssertAllocatedMemory(NULL, 100); /* error - NULL ptr */ |
857 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
858 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
859 |
#else |
#else |
860 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
861 |
#endif |
#endif |
862 |
|
|
863 |
asc_assert_reset(); |
asc_assert_reset(); |
864 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
865 |
AssertAllocatedMemory(p_str1, 100); /* ok - allocated block, correct size*/ |
AssertAllocatedMemory(p_str1, 100); /* ok - allocated block, correct size*/ |
866 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
867 |
|
|
868 |
asc_assert_reset(); |
asc_assert_reset(); |
869 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
870 |
AssertAllocatedMemory(p_str1, 99); /* error - incorrect size */ |
AssertAllocatedMemory(p_str1, 99); /* error - incorrect size */ |
871 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
872 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
873 |
#else |
#else |
874 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
875 |
#endif |
#endif |
876 |
|
|
877 |
asc_assert_reset(); |
asc_assert_reset(); |
878 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
879 |
AssertAllocatedMemory(p_str1, 101); /* error - incorrect size */ |
AssertAllocatedMemory(p_str1, 101); /* error - incorrect size */ |
880 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
881 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
882 |
#else |
#else |
883 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
884 |
#endif |
#endif |
885 |
|
|
886 |
asc_assert_reset(); |
asc_assert_reset(); |
887 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
888 |
AssertAllocatedMemory(p_str2, 100); /* error - invalid ptr */ |
AssertAllocatedMemory(p_str2, 100); /* error - invalid ptr */ |
889 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
890 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
891 |
#else |
#else |
892 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
893 |
#endif |
#endif |
894 |
|
|
895 |
asc_assert_reset(); |
asc_assert_reset(); |
896 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
897 |
AssertAllocatedMemory(p_int1, 10*sizeof(int)); /* ok - allocated block, correct size*/ |
AssertAllocatedMemory(p_int1, 10*sizeof(int)); /* ok - allocated block, correct size*/ |
898 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
899 |
|
|
900 |
asc_assert_reset(); |
asc_assert_reset(); |
901 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
902 |
AssertAllocatedMemory(p_int1, 10*sizeof(int)-1); /* error - incorrect size */ |
AssertAllocatedMemory(p_int1, 10*sizeof(int)-1); /* error - incorrect size */ |
903 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
904 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
905 |
#else |
#else |
906 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
907 |
#endif |
#endif |
908 |
|
|
909 |
asc_assert_reset(); |
asc_assert_reset(); |
910 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
911 |
AssertAllocatedMemory(p_int1, 10*sizeof(int)+1); /* error - incorrect size */ |
AssertAllocatedMemory(p_int1, 10*sizeof(int)+1); /* error - incorrect size */ |
912 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
913 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
914 |
#else |
#else |
915 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
916 |
#endif |
#endif |
917 |
|
|
918 |
asc_assert_reset(); |
asc_assert_reset(); |
919 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
920 |
AssertAllocatedMemory(p_int2, 10*sizeof(int)); /* error - invalid ptr */ |
AssertAllocatedMemory(p_int2, 10*sizeof(int)); /* error - invalid ptr */ |
921 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
922 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
923 |
#else |
#else |
924 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
925 |
#endif |
#endif |
926 |
|
|
927 |
asc_assert_catch(FALSE); /* done testing assertions */ |
asc_assert_catch(FALSE); /* done testing assertions */ |
941 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
942 |
AssertMemory(p_str1); /* error - no memory allocated */ |
AssertMemory(p_str1); /* error - no memory allocated */ |
943 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
944 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
945 |
#else |
#else |
946 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
947 |
#endif |
#endif |
948 |
|
|
949 |
p_str1 = ASC_NEW_ARRAY(char,100); |
p_str1 = ASC_NEW_ARRAY(char,100); |
956 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
957 |
AssertMemory(NULL); /* error - NULL ptr */ |
AssertMemory(NULL); /* error - NULL ptr */ |
958 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
959 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
960 |
#else |
#else |
961 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
962 |
#endif |
#endif |
963 |
|
|
964 |
asc_assert_reset(); |
asc_assert_reset(); |
965 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
966 |
AssertMemory(p_str1); /* ok - start of allocated block*/ |
AssertMemory(p_str1); /* ok - start of allocated block*/ |
967 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
968 |
|
|
969 |
asc_assert_reset(); |
asc_assert_reset(); |
970 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
971 |
AssertMemory(p_str1+10); /* ok - in allocated block*/ |
AssertMemory(p_str1+10); /* ok - in allocated block*/ |
972 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
973 |
|
|
974 |
asc_assert_reset(); |
asc_assert_reset(); |
975 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
976 |
AssertMemory(p_int1); /* ok - start of allocated block */ |
AssertMemory(p_int1); /* ok - start of allocated block */ |
977 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
978 |
|
|
979 |
asc_assert_reset(); |
asc_assert_reset(); |
980 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
981 |
AssertMemory(p_str2); /* error - not allocated using asc*alloc */ |
AssertMemory(p_str2); /* error - not allocated using asc*alloc */ |
982 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
983 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
984 |
#else |
#else |
985 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
986 |
#endif |
#endif |
987 |
|
|
988 |
asc_assert_reset(); |
asc_assert_reset(); |
989 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
990 |
AssertMemory(p_int2); /* error - not allocated using asc*alloc */ |
AssertMemory(p_int2); /* error - not allocated using asc*alloc */ |
991 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
992 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
993 |
#else |
#else |
994 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
995 |
#endif |
#endif |
996 |
|
|
997 |
asc_assert_catch(FALSE); /* done testing assertions */ |
asc_assert_catch(FALSE); /* done testing assertions */ |
1011 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1012 |
AssertContainedMemory(p_str1, 100); /* error - no memory allocated */ |
AssertContainedMemory(p_str1, 100); /* error - no memory allocated */ |
1013 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1014 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1015 |
#else |
#else |
1016 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1017 |
#endif |
#endif |
1018 |
|
|
1019 |
p_str1 = ASC_NEW_ARRAY(char,100); |
p_str1 = ASC_NEW_ARRAY(char,100); |
1026 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1027 |
AssertContainedMemory(NULL, 100); /* error - NULL ptr */ |
AssertContainedMemory(NULL, 100); /* error - NULL ptr */ |
1028 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1029 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1030 |
#else |
#else |
1031 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1032 |
#endif |
#endif |
1033 |
|
|
1034 |
asc_assert_reset(); |
asc_assert_reset(); |
1035 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1036 |
AssertContainedMemory(p_str1, 100); /* ok - allocated block, correct size*/ |
AssertContainedMemory(p_str1, 100); /* ok - allocated block, correct size*/ |
1037 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1038 |
|
|
1039 |
asc_assert_reset(); |
asc_assert_reset(); |
1040 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1041 |
AssertContainedMemory(p_str1, 0); /* ok - contained in a block*/ |
AssertContainedMemory(p_str1, 0); /* ok - contained in a block*/ |
1042 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1043 |
|
|
1044 |
asc_assert_reset(); |
asc_assert_reset(); |
1045 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1046 |
AssertContainedMemory(p_str1+10, 50); /* ok - contained in a block */ |
AssertContainedMemory(p_str1+10, 50); /* ok - contained in a block */ |
1047 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1048 |
|
|
1049 |
asc_assert_reset(); |
asc_assert_reset(); |
1050 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1051 |
AssertContainedMemory(p_str1, 101); /* error - incorrect size */ |
AssertContainedMemory(p_str1, 101); /* error - incorrect size */ |
1052 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1053 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1054 |
#else |
#else |
1055 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1056 |
#endif |
#endif |
1057 |
|
|
1058 |
asc_assert_reset(); |
asc_assert_reset(); |
1059 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1060 |
AssertContainedMemory(p_str2, 0); /* error - invalid ptr */ |
AssertContainedMemory(p_str2, 0); /* error - invalid ptr */ |
1061 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1062 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1063 |
#else |
#else |
1064 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1065 |
#endif |
#endif |
1066 |
|
|
1067 |
asc_assert_reset(); |
asc_assert_reset(); |
1068 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1069 |
AssertContainedMemory(p_int1, 10*sizeof(int)); /* ok - allocated block, correct size*/ |
AssertContainedMemory(p_int1, 10*sizeof(int)); /* ok - allocated block, correct size*/ |
1070 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1071 |
|
|
1072 |
asc_assert_reset(); |
asc_assert_reset(); |
1073 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1074 |
AssertContainedMemory(p_int1, sizeof(int)-1); /* ok - incorrect size */ |
AssertContainedMemory(p_int1, sizeof(int)-1); /* ok - incorrect size */ |
1075 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1076 |
|
|
1077 |
asc_assert_reset(); |
asc_assert_reset(); |
1078 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1079 |
AssertContainedMemory(p_int1, 10*sizeof(int)+1); /* error - incorrect size */ |
AssertContainedMemory(p_int1, 10*sizeof(int)+1); /* error - incorrect size */ |
1080 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1081 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1082 |
#else |
#else |
1083 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1084 |
#endif |
#endif |
1085 |
|
|
1086 |
asc_assert_reset(); |
asc_assert_reset(); |
1087 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1088 |
AssertContainedMemory(p_int2, 10*sizeof(int)); /* error - invalid ptr */ |
AssertContainedMemory(p_int2, 10*sizeof(int)); /* error - invalid ptr */ |
1089 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1090 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1091 |
#else |
#else |
1092 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1093 |
#endif |
#endif |
1094 |
|
|
1095 |
asc_assert_catch(FALSE); /* done testing assertions */ |
asc_assert_catch(FALSE); /* done testing assertions */ |
1109 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1110 |
AssertContainedIn(p_str1, p_str1); /* error - no memory allocated */ |
AssertContainedIn(p_str1, p_str1); /* error - no memory allocated */ |
1111 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1112 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1113 |
#else |
#else |
1114 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1115 |
#endif |
#endif |
1116 |
|
|
1117 |
p_str1 = ASC_NEW_ARRAY(char,100); /* allocate 1 block */ |
p_str1 = ASC_NEW_ARRAY(char,100); /* allocate 1 block */ |
1120 |
asc_assert_reset(); |
asc_assert_reset(); |
1121 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1122 |
AssertContainedIn(p_str1, p_str1); /* ok - same pointer */ |
AssertContainedIn(p_str1, p_str1); /* ok - same pointer */ |
1123 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1124 |
|
|
1125 |
asc_assert_reset(); |
asc_assert_reset(); |
1126 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1127 |
AssertContainedIn(p_str1, p_str1+1); /* ok - in block */ |
AssertContainedIn(p_str1, p_str1+1); /* ok - in block */ |
1128 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1129 |
|
|
1130 |
asc_assert_reset(); |
asc_assert_reset(); |
1131 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1132 |
AssertContainedIn(p_str1, p_str1+50); /* ok - in block */ |
AssertContainedIn(p_str1, p_str1+50); /* ok - in block */ |
1133 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1134 |
|
|
1135 |
asc_assert_reset(); |
asc_assert_reset(); |
1136 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1137 |
AssertContainedIn(p_str1, p_str1+99); /* ok - in block */ |
AssertContainedIn(p_str1, p_str1+99); /* ok - in block */ |
1138 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1139 |
|
|
1140 |
asc_assert_reset(); |
asc_assert_reset(); |
1141 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1142 |
AssertContainedIn(p_str1, p_str1-1); /* error - outside block */ |
AssertContainedIn(p_str1, p_str1-1); /* error - outside block */ |
1143 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1144 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1145 |
#else |
#else |
1146 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1147 |
#endif |
#endif |
1148 |
|
|
1149 |
asc_assert_reset(); |
asc_assert_reset(); |
1150 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1151 |
AssertContainedIn(p_str1, p_str1+100); /* error - outside block */ |
AssertContainedIn(p_str1, p_str1+100); /* error - outside block */ |
1152 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1153 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1154 |
#else |
#else |
1155 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1156 |
#endif |
#endif |
1157 |
|
|
1158 |
asc_assert_reset(); |
asc_assert_reset(); |
1159 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1160 |
AssertContainedIn(p_str1, p_str1+101); /* error - outside block */ |
AssertContainedIn(p_str1, p_str1+101); /* error - outside block */ |
1161 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1162 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1163 |
#else |
#else |
1164 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1165 |
#endif |
#endif |
1166 |
|
|
1167 |
asc_assert_reset(); |
asc_assert_reset(); |
1168 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1169 |
AssertContainedIn(p_str1, NULL); /* error - NULL ptr */ |
AssertContainedIn(p_str1, NULL); /* error - NULL ptr */ |
1170 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1171 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1172 |
#else |
#else |
1173 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1174 |
#endif |
#endif |
1175 |
|
|
1176 |
asc_assert_reset(); |
asc_assert_reset(); |
1177 |
if (0 == setjmp(g_asc_test_env)) |
if (0 == setjmp(g_asc_test_env)) |
1178 |
AssertContainedIn(NULL, p_str1); /* error - NULL ptr */ |
AssertContainedIn(NULL, p_str1); /* error - NULL ptr */ |
1179 |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
#if defined(MALLOC_DEBUG) && defined(ALLOCATED_TESTS) |
1180 |
CU_TEST(TRUE == asc_assert_failed()); |
CU_ASSERT(TRUE == asc_assert_failed()); |
1181 |
#else |
#else |
1182 |
CU_TEST(FALSE == asc_assert_failed()); |
CU_ASSERT(FALSE == asc_assert_failed()); |
1183 |
#endif |
#endif |
1184 |
|
|
1185 |
asc_assert_catch(FALSE); /* done testing assertions */ |
asc_assert_catch(FALSE); /* done testing assertions */ |
1187 |
|
|
1188 |
ascfree(p_str1); |
ascfree(p_str1); |
1189 |
|
|
1190 |
CU_TEST(prior_meminuse == ascmeminuse()); /* make sure we cleaned up after ourselves */ |
CU_ASSERT(prior_meminuse == ascmeminuse()); /* make sure we cleaned up after ourselves */ |
1191 |
} |
} |
1192 |
|
|
1193 |
/*===========================================================================*/ |
/*===========================================================================*/ |