Home | History | Annotate | Download | only in unit
      1 /***************************************************************************
      2  *                                  _   _ ____  _
      3  *  Project                     ___| | | |  _ \| |
      4  *                             / __| | | | |_) | |
      5  *                            | (__| |_| |  _ <| |___
      6  *                             \___|\___/|_| \_\_____|
      7  *
      8  * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel (at) haxx.se>, et al.
      9  *
     10  * This software is licensed as described in the file COPYING, which
     11  * you should have received as part of this distribution. The terms
     12  * are also available at http://curl.haxx.se/docs/copyright.html.
     13  *
     14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
     15  * copies of the Software, and permit persons to whom the Software is
     16  * furnished to do so, under the terms of the COPYING file.
     17  *
     18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
     19  * KIND, either express or implied.
     20  *
     21  ***************************************************************************/
     22 #include "curlcheck.h"
     23 
     24 #define ENABLE_CURLX_PRINTF
     25 #include "curlx.h"
     26 
     27 #include "hash.h"
     28 
     29 #include "memdebug.h" /* LAST include file */
     30 
     31  static CURLcode unit_setup( void )
     32 {
     33   return CURLE_OK;
     34 }
     35 
     36 static void unit_stop( void )
     37 {
     38 
     39 }
     40 
     41 static void mydtor(void *p)
     42 {
     43   int *ptr = (int*)p;
     44   free(ptr);
     45 }
     46 
     47 UNITTEST_START
     48   int *value;
     49   int *value2;
     50   size_t klen = sizeof(int);
     51 
     52   struct curl_hash hash_static;
     53   int key = 20;
     54   int key2 = 25;
     55   int rc = 0;
     56 
     57   rc = Curl_hash_init(&hash_static, 7, Curl_hash_str,
     58                         Curl_str_key_compare, mydtor);
     59 
     60   if(rc)
     61   {
     62     fail("Curl_hash_init failed to initialize static hash!");
     63     goto unit_test_abort;
     64   }
     65 
     66   value = malloc(sizeof(int));
     67   value2 = malloc(sizeof(int));
     68 
     69   *value = 199;
     70   *value2 = 204;
     71   Curl_hash_add(&hash_static, &key, klen, value);
     72 
     73   Curl_hash_clean(&hash_static);
     74 
     75   /* Attempt to add another key/value pair */
     76   Curl_hash_add(&hash_static, &key2, klen, value2);
     77 
     78   Curl_hash_destroy(&hash_static);
     79 
     80 UNITTEST_STOP
     81