diff options
author | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2002-10-22 23:22:06 +0000 |
---|---|---|
committer | rbb <rbb@13f79535-47bb-0310-9956-ffa450edef68> | 2002-10-22 23:22:06 +0000 |
commit | c0677ae368f1a0d9d7541c1bd25e4be5fe245972 (patch) | |
tree | 1e15f97a369fd76a2ee8b7ba6748dcd835882870 /test/testpools.c | |
parent | 6eae37709ae3a5db93571c2a9710f0a9786e8bae (diff) | |
download | libapr-c0677ae368f1a0d9d7541c1bd25e4be5fe245972.tar.gz |
Port testpools to the new test suite.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@63971 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/testpools.c')
-rw-r--r-- | test/testpools.c | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/test/testpools.c b/test/testpools.c index 631c06aa0..4a8aa4588 100644 --- a/test/testpools.c +++ b/test/testpools.c @@ -65,90 +65,90 @@ #endif #include "test_apr.h" -static void alloc_bytes(apr_pool_t *p, int bytes) +#define ALLOC_BYTES 1024 + +apr_pool_t *pmain = NULL; +apr_pool_t *pchild = NULL; + +static void alloc_bytes(CuTest *tc) { int i; char *alloc; - printf("apr_palloc for %d bytes\n", bytes); - printf("%-60s", " apr_palloc"); - alloc = apr_palloc(p, bytes); - if (!alloc) { - printf("Failed\n"); - exit(-1); - } - printf("OK\n"); - - printf("%-60s", " Checking entire allocation is writable"); - for (i=0;i<bytes;i++) { + alloc = apr_palloc(pmain, ALLOC_BYTES); + CuAssertPtrNotNull(tc, alloc); + + for (i=0;i<ALLOC_BYTES;i++) { char *ptr = alloc + i; *ptr = 0xa; } - printf("OK\n"); + /* This is just added to get the positive. If this test fails, the + * suite will seg fault. + */ + CuAssertTrue(tc, 1); } -static void calloc_bytes(apr_pool_t *p, int bytes) +static void calloc_bytes(CuTest *tc) { int i; char *alloc; - printf("apr_pcalloc for %d bytes\n", bytes); - printf("%-60s", " apr_pcalloc"); - alloc = apr_pcalloc(p, bytes); - if (!alloc) { - printf("Failed\n"); - exit(-1); - } - printf("OK\n"); - - printf("%-60s", " Checking entire allocation is set to 0"); - for (i=0;i<bytes;i++) { + alloc = apr_pcalloc(pmain, ALLOC_BYTES); + CuAssertPtrNotNull(tc, alloc); + + for (i=0;i<ALLOC_BYTES;i++) { char *ptr = alloc + i; - if (*ptr != 0x0) { - printf("Error at byte %d (%d vs 0)\n", i, (*ptr)); - exit (-1); - } + CuAssertPtrEquals(tc, NULL, *ptr); } - printf("OK\n"); } +static void parent_pool(CuTest *tc) +{ + apr_status_t rv; + + rv = apr_pool_create(&pmain, NULL); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssertPtrNotNull(tc, pmain); +} -int main (int argc, char ** argv) +static void child_pool(CuTest *tc) { - apr_pool_t *pmain, *pchild; - - apr_initialize(); - atexit(apr_terminate); + apr_status_t rv; - fprintf(stdout, "APR Pools Test\n==============\n\n"); - STD_TEST_NEQ("Creating a top level pool (no parent)", apr_pool_create(&pmain, NULL)) + rv = apr_pool_create(&pchild, pmain); + CuAssertIntEquals(tc, rv, APR_SUCCESS); + CuAssertPtrNotNull(tc, pchild); +} - STD_TEST_NEQ("Create a child pool from the top level one", - apr_pool_create(&pchild, pmain)) +static void test_ancestor(CuTest *tc) +{ + CuAssertIntEquals(tc, 1, apr_pool_is_ancestor(pmain, pchild)); +} - printf("\nMain Pool\n"); - alloc_bytes(pmain, 1024); +static void test_notancestor(CuTest *tc) +{ + CuAssertIntEquals(tc, 0, apr_pool_is_ancestor(pchild, pmain)); +} - printf("\nChild Pool\n"); +CuSuite *testpool(void) +{ + CuSuite *suite = CuSuiteNew("Test Pools"); - alloc_bytes(pchild, 1024); - calloc_bytes(pchild, 1024); - alloc_bytes(pchild, 4096); - - printf("\nClearing the child pool\n\n"); - apr_pool_clear(pchild); + SUITE_ADD_TEST(suite, parent_pool); + SUITE_ADD_TEST(suite, child_pool); + SUITE_ADD_TEST(suite, test_ancestor); + SUITE_ADD_TEST(suite, test_notancestor); + SUITE_ADD_TEST(suite, alloc_bytes); + SUITE_ADD_TEST(suite, calloc_bytes); - alloc_bytes(pchild, 2048); - calloc_bytes(pchild, 1024); - alloc_bytes(pchild, 4096); - - printf("\nDestroying the child pool\n"); - apr_pool_destroy(pchild); - printf("Destroying the main pool\n"); - apr_pool_destroy(pmain); - - printf("\nAll Tests completed - OK!\n"); + return suite; +} - return (0); +#ifdef SINGLE_PROG +CuSuite *getsuite(void) +{ + return testpool(); } +#endif + |