diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/Makefile.inc | 2 | ||||
-rw-r--r-- | tests/data/test1602 | 26 | ||||
-rw-r--r-- | tests/unit/Makefile.inc | 5 | ||||
-rw-r--r-- | tests/unit/unit1305.c | 2 | ||||
-rw-r--r-- | tests/unit/unit1602.c | 80 |
5 files changed, 112 insertions, 3 deletions
diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 57a4e79dc..a15ff8afb 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -155,7 +155,7 @@ test1520 \ \ test1525 test1526 test1527 test1528 test1529 \ \ -test1600 test1601 \ +test1600 test1601 test1602 \ \ test1800 test1801 \ \ diff --git a/tests/data/test1602 b/tests/data/test1602 new file mode 100644 index 000000000..4717058ce --- /dev/null +++ b/tests/data/test1602 @@ -0,0 +1,26 @@ +<testcase> +<info> +<keywords> +unittest +hash +</keywords> +</info> + +# +# Client-side +<client> +<server> +none +</server> +<features> +unittest +</features> + <name> +Internal hash create/add/destroy testing, exercising clean functions + </name> +<tool> +unit1602 +</tool> +</client> + +</testcase> diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc index d68c03701..9073b34e6 100644 --- a/tests/unit/Makefile.inc +++ b/tests/unit/Makefile.inc @@ -7,7 +7,7 @@ UNITFILES = curlcheck.h \ # These are all unit test programs UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \ unit1308 unit1309 unit1330 unit1394 unit1395 unit1396 unit1397 unit1398 \ - unit1600 unit1601 + unit1600 unit1601 unit1602 unit1300_SOURCES = unit1300.c $(UNITFILES) unit1300_CPPFLAGS = $(AM_CPPFLAGS) @@ -63,3 +63,6 @@ unit1600_CPPFLAGS = $(AM_CPPFLAGS) unit1601_SOURCES = unit1601.c $(UNITFILES) unit1601_CPPFLAGS = $(AM_CPPFLAGS) +unit1602_SOURCES = unit1602.c $(UNITFILES) +unit1602_CPPFLAGS = $(AM_CPPFLAGS) + diff --git a/tests/unit/unit1305.c b/tests/unit/unit1305.c index b4e837762..96913f1fa 100644 --- a/tests/unit/unit1305.c +++ b/tests/unit/unit1305.c @@ -67,7 +67,7 @@ static void unit_stop( void ) free(data_node); } free(data_key); - Curl_hash_clean(&hp); + Curl_hash_destroy(&hp); curl_easy_cleanup(data); curl_global_cleanup(); diff --git a/tests/unit/unit1602.c b/tests/unit/unit1602.c new file mode 100644 index 000000000..3b25556bf --- /dev/null +++ b/tests/unit/unit1602.c @@ -0,0 +1,80 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#include "curlcheck.h" + +#define ENABLE_CURLX_PRINTF +#include "curlx.h" + +#include "hash.h" + +#include "memdebug.h" /* LAST include file */ + + static CURLcode unit_setup( void ) +{ + return CURLE_OK; +} + +static void unit_stop( void ) +{ + +} + +static void mydtor(void *p) +{ + int *ptr = (int*)p; + free(ptr); +} + +UNITTEST_START + int *value; + int *value2; + size_t klen = sizeof(int); + + struct curl_hash hash_static; + int key = 20; + int key2 = 25; + int rc = 0; + + rc = Curl_hash_init(&hash_static, 7, Curl_hash_str, + Curl_str_key_compare, mydtor); + + if(rc) + { + fail("Curl_hash_init failed to initialize static hash!"); + goto unit_test_abort; + } + + value = malloc(sizeof(int)); + value2 = malloc(sizeof(int)); + + *value = 199; + *value2 = 204; + Curl_hash_add(&hash_static, &key, klen, value); + + Curl_hash_clean(&hash_static); + + /* Attempt to add another key/value pair */ + Curl_hash_add(&hash_static, &key2, klen, value2); + + Curl_hash_destroy(&hash_static); + +UNITTEST_STOP |