123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- /* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include "fspr_general.h"
- #include "fspr_pools.h"
- #include "fspr_errno.h"
- #include "fspr_file_io.h"
- #include <string.h>
- #include <stdlib.h>
- #include <stdio.h>
- #if APR_HAVE_UNISTD_H
- #include <unistd.h>
- #endif
- #include "testutil.h"
- #define ALLOC_BYTES 1024
- static fspr_pool_t *pmain = NULL;
- static fspr_pool_t *pchild = NULL;
- static void alloc_bytes(abts_case *tc, void *data)
- {
- int i;
- char *alloc;
-
- alloc = fspr_palloc(pmain, ALLOC_BYTES);
- ABTS_PTR_NOTNULL(tc, alloc);
- for (i=0;i<ALLOC_BYTES;i++) {
- char *ptr = alloc + i;
- *ptr = 0xa;
- }
- /* This is just added to get the positive. If this test fails, the
- * suite will seg fault.
- */
- ABTS_TRUE(tc, 1);
- }
- static void calloc_bytes(abts_case *tc, void *data)
- {
- int i;
- char *alloc;
-
- alloc = fspr_pcalloc(pmain, ALLOC_BYTES);
- ABTS_PTR_NOTNULL(tc, alloc);
- for (i=0;i<ALLOC_BYTES;i++) {
- char *ptr = alloc + i;
- ABTS_TRUE(tc, *ptr == '\0');
- }
- }
- static void parent_pool(abts_case *tc, void *data)
- {
- fspr_status_t rv;
- rv = fspr_pool_create(&pmain, NULL);
- ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
- ABTS_PTR_NOTNULL(tc, pmain);
- }
- static void child_pool(abts_case *tc, void *data)
- {
- fspr_status_t rv;
- rv = fspr_pool_create(&pchild, pmain);
- ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
- ABTS_PTR_NOTNULL(tc, pchild);
- }
- static void test_ancestor(abts_case *tc, void *data)
- {
- ABTS_INT_EQUAL(tc, 1, fspr_pool_is_ancestor(pmain, pchild));
- }
- static void test_notancestor(abts_case *tc, void *data)
- {
- ABTS_INT_EQUAL(tc, 0, fspr_pool_is_ancestor(pchild, pmain));
- }
- static fspr_status_t success_cleanup(void *data)
- {
- return APR_SUCCESS;
- }
- static char *checker_data = "Hello, world.";
- static fspr_status_t checker_cleanup(void *data)
- {
- return data == checker_data ? APR_SUCCESS : APR_EGENERAL;
- }
- static void test_cleanups(abts_case *tc, void *data)
- {
- fspr_status_t rv;
- int n;
- /* do this several times to test the cleanup freelist handling. */
- for (n = 0; n < 5; n++) {
- fspr_pool_cleanup_register(pchild, NULL, success_cleanup,
- success_cleanup);
- fspr_pool_cleanup_register(pchild, checker_data, checker_cleanup,
- success_cleanup);
- fspr_pool_cleanup_register(pchild, NULL, checker_cleanup,
- success_cleanup);
- rv = fspr_pool_cleanup_run(p, NULL, success_cleanup);
- ABTS_ASSERT(tc, "nullop cleanup run OK", rv == APR_SUCCESS);
- rv = fspr_pool_cleanup_run(p, checker_data, checker_cleanup);
- ABTS_ASSERT(tc, "cleanup passed correct data", rv == APR_SUCCESS);
- rv = fspr_pool_cleanup_run(p, NULL, checker_cleanup);
- ABTS_ASSERT(tc, "cleanup passed correct data", rv == APR_EGENERAL);
- if (n == 2) {
- /* clear the pool to check that works */
- fspr_pool_clear(pchild);
- }
- if (n % 2 == 0) {
- /* throw another random cleanup into the mix */
- fspr_pool_cleanup_register(pchild, NULL,
- fspr_pool_cleanup_null,
- fspr_pool_cleanup_null);
- }
- }
- }
- abts_suite *testpool(abts_suite *suite)
- {
- suite = ADD_SUITE(suite)
- abts_run_test(suite, parent_pool, NULL);
- abts_run_test(suite, child_pool, NULL);
- abts_run_test(suite, test_ancestor, NULL);
- abts_run_test(suite, test_notancestor, NULL);
- abts_run_test(suite, alloc_bytes, NULL);
- abts_run_test(suite, calloc_bytes, NULL);
- abts_run_test(suite, test_cleanups, NULL);
- return suite;
- }
|