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.
19 #include "apr_file_io.h"
20 #include "apr_errno.h"
21 #include "apr_general.h"
23 #include "apr_strings.h"
26 static apr_pool_t *pool;
27 static char *testdata;
28 static int cleanup_called = 0;
30 static apr_status_t string_cleanup(void *data)
36 static void set_userdata(CuTest *tc)
40 rv = apr_pool_userdata_set(testdata, "TEST", string_cleanup, pool);
41 CuAssertIntEquals(tc, rv, APR_SUCCESS);
44 static void get_userdata(CuTest *tc)
49 rv = apr_pool_userdata_get((void **)&retdata, "TEST", pool);
50 CuAssertIntEquals(tc, rv, APR_SUCCESS);
51 CuAssertStrEquals(tc, retdata, testdata);
54 static void get_nonexistkey(CuTest *tc)
59 rv = apr_pool_userdata_get((void **)&retdata, "DOESNTEXIST", pool);
60 CuAssertIntEquals(tc, rv, APR_SUCCESS);
61 CuAssertPtrEquals(tc, retdata, NULL);
64 static void post_pool_clear(CuTest *tc)
69 rv = apr_pool_userdata_get((void **)&retdata, "DOESNTEXIST", pool);
70 CuAssertIntEquals(tc, rv, APR_SUCCESS);
71 CuAssertPtrEquals(tc, retdata, NULL);
76 CuSuite *suite = CuSuiteNew("User Data");
78 apr_pool_create(&pool, p);
79 testdata = apr_pstrdup(pool, "This is a test\n");
81 SUITE_ADD_TEST(suite, set_userdata);
82 SUITE_ADD_TEST(suite, get_userdata);
83 SUITE_ADD_TEST(suite, get_nonexistkey);
87 SUITE_ADD_TEST(suite, post_pool_clear);