1
0
mirror of https://github.com/moparisthebest/curl synced 2024-08-13 17:03:50 -04:00

unit1602: Fixed failure in torture test

This commit is contained in:
dfandrich 2015-11-12 19:30:59 +01:00 committed by Dan Fandrich
parent 1f82df9146
commit 278ea24a7a

View File

@ -28,15 +28,7 @@
#include "memdebug.h" /* LAST include file */ #include "memdebug.h" /* LAST include file */
static CURLcode unit_setup( void ) static struct curl_hash hash_static;
{
return CURLE_OK;
}
static void unit_stop( void )
{
}
static void mydtor(void *p) static void mydtor(void *p)
{ {
@ -44,37 +36,44 @@ static void mydtor(void *p)
free(ptr); free(ptr);
} }
static CURLcode unit_setup( void )
{
return Curl_hash_init(&hash_static, 7, Curl_hash_str,
Curl_str_key_compare, mydtor);
}
static void unit_stop( void )
{
Curl_hash_destroy(&hash_static);
}
UNITTEST_START UNITTEST_START
int *value; int *value;
int *value2; int *value2;
int *nodep;
size_t klen = sizeof(int); size_t klen = sizeof(int);
struct curl_hash hash_static;
int key = 20; int key = 20;
int key2 = 25; 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)); value = malloc(sizeof(int));
value2 = malloc(sizeof(int)); abort_unless(value != NULL, "Out of memory");
*value = 199; *value = 199;
*value2 = 204; nodep = Curl_hash_add(&hash_static, &key, klen, value);
Curl_hash_add(&hash_static, &key, klen, value); if(!nodep)
free(value);
abort_unless(nodep, "insertion into hash failed");
Curl_hash_clean(&hash_static); Curl_hash_clean(&hash_static);
/* Attempt to add another key/value pair */ /* 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 UNITTEST_STOP