"Fossies" - the Fresh Open Source Software Archive

Member "ftwin-master/check/check_apr_hash.c" (15 Feb 2015, 2224 Bytes) of package /linux/privat/ftwin-master.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * Copyright (C) 2007 Fran├žois Pesce : francois.pesce (at) gmail (dot) com
    3  *
    4  * Licensed under the Apache License, Version 2.0 (the "License");
    5  * you may not use this file except in compliance with the License.
    6  * 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 <unistd.h>
   18 #include <stdlib.h>
   19 #include <check.h>
   20 
   21 #include <apr_hash.h>
   22 #include <apr_strings.h>
   23 
   24 #include "debug.h"
   25 
   26 extern apr_pool_t *main_pool;
   27 apr_pool_t *pool;
   28 
   29 static void setup(void)
   30 {
   31     apr_status_t rs;
   32 
   33     rs = apr_pool_create(&pool, main_pool);
   34     if (rs != APR_SUCCESS) {
   35     DEBUG_ERR("Error creating pool");
   36     exit(1);
   37     }
   38 }
   39 
   40 static void teardown(void)
   41 {
   42     apr_pool_destroy(pool);
   43 }
   44 
   45 /* http://www.burtleburtle.net/bob/hash/integer.html */
   46 static unsigned int hash_int(const char *key, apr_ssize_t * klen)
   47 {
   48     apr_off_t i = *(apr_off_t *) key;
   49 
   50     printf("b:%" APR_OFF_T_FMT "\n", i);
   51     /* We take a bad hash_func to collide numbers */
   52     i = (i & 0x0000000f);
   53     printf("a:%" APR_OFF_T_FMT "\n", i);
   54 
   55     return i;
   56 }
   57 
   58 START_TEST(test_apr_hash_int)
   59 {
   60     apr_off_t array[] = { 0x00000001, 0x00000002, 0x00000004, 0x10000001, 0x00000004 };
   61     const char *array_str[] = { "1", "2", "3", "4", "5" };
   62     apr_hash_t *hash;
   63     int i;
   64 
   65     hash = apr_hash_make_custom(pool, hash_int);
   66     for (i = 0; i < 5; i++) {
   67     apr_hash_set(hash, &(array[i]), sizeof(apr_off_t), array_str[i]);
   68     }
   69     for (i = 0; i < 5; i++) {
   70     printf("%s\n", (char *) apr_hash_get(hash, &(array[i]), sizeof(apr_off_t)));
   71     }
   72 }
   73 /* *INDENT-OFF* */
   74 END_TEST
   75 /* *INDENT-ON* */
   76 
   77 Suite *make_apr_hash_suite(void)
   78 {
   79     Suite *s;
   80     TCase *tc_core;
   81     s = suite_create("Apr_Hash");
   82     tc_core = tcase_create("Core Tests");
   83 
   84     tcase_add_checked_fixture(tc_core, setup, teardown);
   85     tcase_add_test(tc_core, test_apr_hash_int);
   86     suite_add_tcase(s, tc_core);
   87 
   88     return s;
   89 }