1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. 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(CuTest *tc)
40 alloc = apr_palloc(pmain, ALLOC_BYTES);
41 CuAssertPtrNotNull(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(CuTest *tc)
58 alloc = apr_pcalloc(pmain, ALLOC_BYTES);
59 CuAssertPtrNotNull(tc, alloc);
61 for (i=0;i<ALLOC_BYTES;i++) {
62 char *ptr = alloc + i;
63 CuAssertTrue(tc, *ptr == '\0');
67 static void parent_pool(CuTest *tc)
71 rv = apr_pool_create(&pmain, NULL);
72 CuAssertIntEquals(tc, rv, APR_SUCCESS);
73 CuAssertPtrNotNull(tc, pmain);
76 static void child_pool(CuTest *tc)
80 rv = apr_pool_create(&pchild, pmain);
81 CuAssertIntEquals(tc, rv, APR_SUCCESS);
82 CuAssertPtrNotNull(tc, pchild);
85 static void test_ancestor(CuTest *tc)
87 CuAssertIntEquals(tc, 1, apr_pool_is_ancestor(pmain, pchild));
90 static void test_notancestor(CuTest *tc)
92 CuAssertIntEquals(tc, 0, apr_pool_is_ancestor(pchild, pmain));
95 CuSuite *testpool(void)
97 CuSuite *suite = CuSuiteNew("Pools");
99 SUITE_ADD_TEST(suite, parent_pool);
100 SUITE_ADD_TEST(suite, child_pool);
101 SUITE_ADD_TEST(suite, test_ancestor);
102 SUITE_ADD_TEST(suite, test_notancestor);
103 SUITE_ADD_TEST(suite, alloc_bytes);
104 SUITE_ADD_TEST(suite, calloc_bytes);