#define dfwmalloc_test_calloc entry
#include <my_assert.h>

static void check_zero (char *p, int len, int line)
{
    int i;
    for (i = 0; i < len; i++) {
        if (*p != '\0') {
            printf ("not zero at line %d\n", line);
            exit (1);
        }
    }
}


void dfwmalloc_test_calloc (void)
{
    char *p[100];
    char *q;
    int i, n;

    printf ("testing calloc\n");

    n = 0;
    for (i = 10; i <= 1000000; i *= 10) {
        p[n] = (char *) calloc (1, i);
        check_zero (p[n], i, i);
        n++;
    }
    for (i = 0; i < n; i++)
        free (p[i]);

    dfwmalloc_truncate_heap ();

    n = 0;
    for (i = 10; i <= 1000000; i *= 10) {
        p[n] = (char *) calloc (1, i);
        check_zero (p[n], i, i);
        n++;
    }
    q = (char *) calloc (1, 1000000 * 2);
    for (i = 0; i < n; i++)
        free (p[i]);

    n = 0;
    for (i = 10; i <= 1000000; i *= 10) {
        p[n] = (char *) calloc (1, i);
        check_zero (p[n], i, i);
        n++;
    }
    for (i = 0; i < n; i++)
        free (p[i]);

    free (q);
    dfwmalloc_truncate_heap ();

    printf ("calloc test done\n");
}


