bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / srclib / apr / test / testud.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 #include <stdio.h>
18 #include <stdlib.h>
19 #include "apr_file_io.h"
20 #include "apr_errno.h"
21 #include "apr_general.h"
22 #include "apr_lib.h"
23 #include "apr_strings.h"
24 #include "test_apr.h"
25
26 static apr_pool_t *pool;
27 static char *testdata;
28 static int cleanup_called = 0;
29
30 static apr_status_t string_cleanup(void *data)
31 {
32     cleanup_called = 1;
33     return APR_SUCCESS;
34 }
35
36 static void set_userdata(CuTest *tc)
37 {
38     apr_status_t rv;
39
40     rv = apr_pool_userdata_set(testdata, "TEST", string_cleanup, pool);
41     CuAssertIntEquals(tc, rv, APR_SUCCESS);
42 }
43
44 static void get_userdata(CuTest *tc)
45 {
46     apr_status_t rv;
47     char *retdata;
48
49     rv = apr_pool_userdata_get((void **)&retdata, "TEST", pool);
50     CuAssertIntEquals(tc, rv, APR_SUCCESS);
51     CuAssertStrEquals(tc, retdata, testdata);
52 }
53
54 static void get_nonexistkey(CuTest *tc)
55 {
56     apr_status_t rv;
57     char *retdata;
58
59     rv = apr_pool_userdata_get((void **)&retdata, "DOESNTEXIST", pool);
60     CuAssertIntEquals(tc, rv, APR_SUCCESS);
61     CuAssertPtrEquals(tc, retdata, NULL);
62 }
63
64 static void post_pool_clear(CuTest *tc)
65 {
66     apr_status_t rv;
67     char *retdata;
68
69     rv = apr_pool_userdata_get((void **)&retdata, "DOESNTEXIST", pool);
70     CuAssertIntEquals(tc, rv, APR_SUCCESS);
71     CuAssertPtrEquals(tc, retdata, NULL);
72 }
73
74 CuSuite *testud(void)
75 {
76     CuSuite *suite = CuSuiteNew("User Data");
77
78     apr_pool_create(&pool, p);
79     testdata = apr_pstrdup(pool, "This is a test\n");
80
81     SUITE_ADD_TEST(suite, set_userdata);
82     SUITE_ADD_TEST(suite, get_userdata);
83     SUITE_ADD_TEST(suite, get_nonexistkey);
84
85     apr_pool_clear(pool);
86
87     SUITE_ADD_TEST(suite, post_pool_clear);
88
89     return suite;
90 }
91