summaryrefslogtreecommitdiff
path: root/tests/unit/unit1602.c
diff options
context:
space:
mode:
authordfandrich <dan@coneharvesters.com>2015-11-12 19:30:59 +0100
committerDan Fandrich <dan@coneharvesters.com>2015-11-12 22:47:37 +0100
commit278ea24a7a6461a97c3c5d9b37fc9fdd3a9802f4 (patch)
treef7badd8cb0e99d67ab598906a496295f90e37018 /tests/unit/unit1602.c
parent1f82df91468a1e0634fae5119677c4b5f91d473d (diff)
downloadcurl-278ea24a7a6461a97c3c5d9b37fc9fdd3a9802f4.tar.gz
unit1602: Fixed failure in torture test
Diffstat (limited to 'tests/unit/unit1602.c')
-rw-r--r--tests/unit/unit1602.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/tests/unit/unit1602.c b/tests/unit/unit1602.c
index 3b25556bf..982d67b4a 100644
--- a/tests/unit/unit1602.c
+++ b/tests/unit/unit1602.c
@@ -28,53 +28,52 @@
#include "memdebug.h" /* LAST include file */
- static CURLcode unit_setup( void )
+static struct curl_hash hash_static;
+
+static void mydtor(void *p)
{
- return CURLE_OK;
+ int *ptr = (int*)p;
+ free(ptr);
}
-static void unit_stop( void )
+static CURLcode unit_setup( void )
{
-
+ return Curl_hash_init(&hash_static, 7, Curl_hash_str,
+ Curl_str_key_compare, mydtor);
}
-static void mydtor(void *p)
+static void unit_stop( void )
{
- int *ptr = (int*)p;
- free(ptr);
+ Curl_hash_destroy(&hash_static);
}
UNITTEST_START
int *value;
int *value2;
+ int *nodep;
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));
-
+ abort_unless(value != NULL, "Out of memory");
*value = 199;
- *value2 = 204;
- Curl_hash_add(&hash_static, &key, klen, value);
+ nodep = Curl_hash_add(&hash_static, &key, klen, value);
+ if(!nodep)
+ free(value);
+ abort_unless(nodep, "insertion into hash failed");
Curl_hash_clean(&hash_static);
/* Attempt to add another key/value pair */
- Curl_hash_add(&hash_static, &key2, klen, value2);
+ value2 = malloc(sizeof(int));
+ abort_unless(value2 != NULL, "Out of memory");
+ *value2 = 204;
+ nodep = Curl_hash_add(&hash_static, &key2, klen, value2);
+ if(!nodep)
+ free(value2);
+ abort_unless(nodep, "insertion into hash failed");
- Curl_hash_destroy(&hash_static);
-
UNITTEST_STOP