upload http
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / test / testpools.c
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include "apr_general.h"
19 #include "apr_pools.h"
20 #include "apr_errno.h"
21 #include "apr_file_io.h"
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #if APR_HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28 #include "test_apr.h"
29
30 #define ALLOC_BYTES 1024
31
32 static apr_pool_t *pmain = NULL;
33 static apr_pool_t *pchild = NULL;
34
35 static void alloc_bytes(CuTest *tc)
36 {
37     int i;
38     char *alloc;
39     
40     alloc = apr_palloc(pmain, ALLOC_BYTES);
41     CuAssertPtrNotNull(tc, alloc);
42
43     for (i=0;i<ALLOC_BYTES;i++) {
44         char *ptr = alloc + i;
45         *ptr = 0xa;
46     }
47     /* This is just added to get the positive.  If this test fails, the
48      * suite will seg fault.
49      */
50     CuAssertTrue(tc, 1);
51 }
52
53 static void calloc_bytes(CuTest *tc)
54 {
55     int i;
56     char *alloc;
57     
58     alloc = apr_pcalloc(pmain, ALLOC_BYTES);
59     CuAssertPtrNotNull(tc, alloc);
60
61     for (i=0;i<ALLOC_BYTES;i++) {
62         char *ptr = alloc + i;
63         CuAssertTrue(tc, *ptr == '\0');
64     }
65 }
66
67 static void parent_pool(CuTest *tc)
68 {
69     apr_status_t rv;
70
71     rv = apr_pool_create(&pmain, NULL);
72     CuAssertIntEquals(tc, rv, APR_SUCCESS);
73     CuAssertPtrNotNull(tc, pmain);
74 }
75
76 static void child_pool(CuTest *tc)
77 {
78     apr_status_t rv;
79
80     rv = apr_pool_create(&pchild, pmain);
81     CuAssertIntEquals(tc, rv, APR_SUCCESS);
82     CuAssertPtrNotNull(tc, pchild);
83 }
84
85 static void test_ancestor(CuTest *tc)
86 {
87     CuAssertIntEquals(tc, 1, apr_pool_is_ancestor(pmain, pchild));
88 }
89
90 static void test_notancestor(CuTest *tc)
91 {
92     CuAssertIntEquals(tc, 0, apr_pool_is_ancestor(pchild, pmain));
93 }
94
95 CuSuite *testpool(void)
96 {
97     CuSuite *suite = CuSuiteNew("Pools");
98
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);
105
106     return suite;
107 }
108