X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=support%2Fregression%2Ftests%2Fmalloc.c;h=6659b949df114dd2e6e9143e868abc1210821289;hb=3270f325cf2270f7656186324330c4ee3b9c9515;hp=1f19501d95a0c1c82c674a913bffefd919419c76;hpb=36d0b20243251f44573d20e6e012d450ab0df882;p=fw%2Fsdcc diff --git a/support/regression/tests/malloc.c b/support/regression/tests/malloc.c index 1f19501d..6659b949 100644 --- a/support/regression/tests/malloc.c +++ b/support/regression/tests/malloc.c @@ -16,9 +16,15 @@ void testMalloc(void) { void XDATA *p1, *p2, *p3; - + char *p; + unsigned char i; + #if !defined(__gbz80) && !defined(__z80) && !defined(__GNUC__) - init_dynamic_memory((MEMHEADER xdata *)heap, sizeof(heap)); + init_dynamic_memory((MEMHEADER XDATA *)heap, sizeof(heap)); + + p1 = malloc(200); + ASSERT(p1 == NULL); + LOG(("p1 == NULL when out of memory\n")); #endif p1 = malloc(5); @@ -37,6 +43,34 @@ testMalloc(void) LOG(("p2: %u\n", (unsigned) p2)); #endif + p = (char*)p2; + for (i=0; i<20; i++, p++) + *p = i; + + p2 = realloc(p2, 25); + ASSERT(p2 != NULL); +#ifdef PORT_HOST + LOG(("p2, after expanding realloc: %p\n", p2)); +#else + LOG(("p2, after expanding realloc: %u\n", (unsigned) p2)); +#endif + + p = (char*)p2; + for (i=0; i<20; i++, p++) + ASSERT(*p == i); + + p2 = realloc(p2, 15); + ASSERT(p2 != NULL); +#ifdef PORT_HOST + LOG(("p2, after shrinking realloc: %p\n", p2)); +#else + LOG(("p2, after shrinking realloc: %u\n", (unsigned) p2)); +#endif + + p = (char*)p2; + for (i=0; i<15; i++, p++) + ASSERT(*p == i); + free(p2); p3 = malloc(10);