unit1602.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "curlcheck.h"
00023 
00024 #define ENABLE_CURLX_PRINTF
00025 #include "curlx.h"
00026 
00027 #include "hash.h"
00028 
00029 #include "memdebug.h" /* LAST include file */
00030 
00031 static struct curl_hash hash_static;
00032 
00033 static void mydtor(void *p)
00034 {
00035   int *ptr = (int *)p;
00036   free(ptr);
00037 }
00038 
00039 static CURLcode unit_setup(void)
00040 {
00041   return Curl_hash_init(&hash_static, 7, Curl_hash_str,
00042                         Curl_str_key_compare, mydtor);
00043 }
00044 
00045 static void unit_stop(void)
00046 {
00047   Curl_hash_destroy(&hash_static);
00048 }
00049 
00050 UNITTEST_START
00051   int *value;
00052   int *value2;
00053   int *nodep;
00054   size_t klen = sizeof(int);
00055 
00056   int key = 20;
00057   int key2 = 25;
00058 
00059 
00060   value = malloc(sizeof(int));
00061   abort_unless(value != NULL, "Out of memory");
00062   *value = 199;
00063   nodep = Curl_hash_add(&hash_static, &key, klen, value);
00064   if(!nodep)
00065     free(value);
00066   abort_unless(nodep, "insertion into hash failed");
00067   Curl_hash_clean(&hash_static);
00068 
00069   /* Attempt to add another key/value pair */
00070   value2 = malloc(sizeof(int));
00071   abort_unless(value2 != NULL, "Out of memory");
00072   *value2 = 204;
00073   nodep = Curl_hash_add(&hash_static, &key2, klen, value2);
00074   if(!nodep)
00075     free(value2);
00076   abort_unless(nodep, "insertion into hash failed");
00077 
00078 UNITTEST_STOP


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07