1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
#include "apr_general.h"
19
#include "apr_pools.h"
20
#include "apr_errno.h"
21
#include "apr_file_io.h"
30
#define ALLOC_BYTES 1024
32
static apr_pool_t *pmain = NULL;
33
static apr_pool_t *pchild = NULL;
35
static void alloc_bytes(abts_case *tc, void *data)
40
alloc = apr_palloc(pmain, ALLOC_BYTES);
41
ABTS_PTR_NOTNULL(tc, alloc);
43
for (i=0;i<ALLOC_BYTES;i++) {
44
char *ptr = alloc + i;
47
/* This is just added to get the positive. If this test fails, the
48
* suite will seg fault.
53
static void calloc_bytes(abts_case *tc, void *data)
58
alloc = apr_pcalloc(pmain, ALLOC_BYTES);
59
ABTS_PTR_NOTNULL(tc, alloc);
61
for (i=0;i<ALLOC_BYTES;i++) {
62
char *ptr = alloc + i;
63
ABTS_TRUE(tc, *ptr == '\0');
67
static void parent_pool(abts_case *tc, void *data)
71
rv = apr_pool_create(&pmain, NULL);
72
ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
73
ABTS_PTR_NOTNULL(tc, pmain);
76
static void child_pool(abts_case *tc, void *data)
80
rv = apr_pool_create(&pchild, pmain);
81
ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
82
ABTS_PTR_NOTNULL(tc, pchild);
85
static void test_ancestor(abts_case *tc, void *data)
87
ABTS_INT_EQUAL(tc, 1, apr_pool_is_ancestor(pmain, pchild));
90
static void test_notancestor(abts_case *tc, void *data)
92
ABTS_INT_EQUAL(tc, 0, apr_pool_is_ancestor(pchild, pmain));
95
static apr_status_t success_cleanup(void *data)
100
static char *checker_data = "Hello, world.";
102
static apr_status_t checker_cleanup(void *data)
104
return data == checker_data ? APR_SUCCESS : APR_EGENERAL;
107
static void test_cleanups(abts_case *tc, void *data)
112
/* do this several times to test the cleanup freelist handling. */
113
for (n = 0; n < 5; n++) {
114
apr_pool_cleanup_register(pchild, NULL, success_cleanup,
116
apr_pool_cleanup_register(pchild, checker_data, checker_cleanup,
118
apr_pool_cleanup_register(pchild, NULL, checker_cleanup,
121
rv = apr_pool_cleanup_run(p, NULL, success_cleanup);
122
ABTS_ASSERT(tc, "nullop cleanup run OK", rv == APR_SUCCESS);
123
rv = apr_pool_cleanup_run(p, checker_data, checker_cleanup);
124
ABTS_ASSERT(tc, "cleanup passed correct data", rv == APR_SUCCESS);
125
rv = apr_pool_cleanup_run(p, NULL, checker_cleanup);
126
ABTS_ASSERT(tc, "cleanup passed correct data", rv == APR_EGENERAL);
129
/* clear the pool to check that works */
130
apr_pool_clear(pchild);
134
/* throw another random cleanup into the mix */
135
apr_pool_cleanup_register(pchild, NULL,
136
apr_pool_cleanup_null,
137
apr_pool_cleanup_null);
142
abts_suite *testpool(abts_suite *suite)
144
suite = ADD_SUITE(suite)
146
abts_run_test(suite, parent_pool, NULL);
147
abts_run_test(suite, child_pool, NULL);
148
abts_run_test(suite, test_ancestor, NULL);
149
abts_run_test(suite, test_notancestor, NULL);
150
abts_run_test(suite, alloc_bytes, NULL);
151
abts_run_test(suite, calloc_bytes, NULL);
152
abts_run_test(suite, test_cleanups, NULL);