|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "curlcheck.h" |
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H |
|
|
# include <netinet/in.h> |
|
|
#endif |
|
|
#ifdef HAVE_NETDB_H |
|
|
# include <netdb.h> |
|
|
#endif |
|
|
#ifdef HAVE_ARPA_INET_H |
|
|
# include <arpa/inet.h> |
|
|
#endif |
|
|
|
|
|
#include "curlx.h" |
|
|
|
|
|
#include "hash.h" |
|
|
#include "hostip.h" |
|
|
|
|
|
#include "memdebug.h" |
|
|
|
|
|
static struct Curl_easy *testdata; |
|
|
static struct Curl_hash hp; |
|
|
static char *data_key; |
|
|
static struct Curl_dns_entry *data_node; |
|
|
|
|
|
static CURLcode unit_setup(void) |
|
|
{ |
|
|
testdata = curl_easy_init(); |
|
|
if(!testdata) { |
|
|
curl_global_cleanup(); |
|
|
return CURLE_OUT_OF_MEMORY; |
|
|
} |
|
|
|
|
|
Curl_init_dnscache(&hp, 7); |
|
|
return CURLE_OK; |
|
|
} |
|
|
|
|
|
static void unit_stop(void) |
|
|
{ |
|
|
if(data_node) { |
|
|
Curl_freeaddrinfo(data_node->addr); |
|
|
free(data_node); |
|
|
} |
|
|
free(data_key); |
|
|
Curl_hash_destroy(&hp); |
|
|
|
|
|
curl_easy_cleanup(testdata); |
|
|
curl_global_cleanup(); |
|
|
} |
|
|
|
|
|
static struct Curl_addrinfo *fake_ai(void) |
|
|
{ |
|
|
static struct Curl_addrinfo *ai; |
|
|
static const char dummy[]="dummy"; |
|
|
size_t namelen = sizeof(dummy); |
|
|
|
|
|
ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) + |
|
|
namelen); |
|
|
if(!ai) |
|
|
return NULL; |
|
|
|
|
|
ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo)); |
|
|
ai->ai_canonname = (void *)((char *)ai->ai_addr + |
|
|
sizeof(struct sockaddr_in)); |
|
|
memcpy(ai->ai_canonname, dummy, namelen); |
|
|
|
|
|
ai->ai_family = AF_INET; |
|
|
ai->ai_addrlen = sizeof(struct sockaddr_in); |
|
|
|
|
|
return ai; |
|
|
} |
|
|
|
|
|
static CURLcode create_node(void) |
|
|
{ |
|
|
data_key = aprintf("%s:%d", "dummy", 0); |
|
|
if(!data_key) |
|
|
return CURLE_OUT_OF_MEMORY; |
|
|
|
|
|
data_node = calloc(1, sizeof(struct Curl_dns_entry)); |
|
|
if(!data_node) |
|
|
return CURLE_OUT_OF_MEMORY; |
|
|
|
|
|
data_node->addr = fake_ai(); |
|
|
if(!data_node->addr) |
|
|
return CURLE_OUT_OF_MEMORY; |
|
|
|
|
|
return CURLE_OK; |
|
|
} |
|
|
|
|
|
|
|
|
UNITTEST_START |
|
|
|
|
|
struct Curl_dns_entry *nodep; |
|
|
size_t key_len; |
|
|
|
|
|
|
|
|
if(strcmp(arg, "1305") != 0) { |
|
|
CURLcode rc = create_node(); |
|
|
abort_unless(rc == CURLE_OK, "data node creation failed"); |
|
|
key_len = strlen(data_key); |
|
|
|
|
|
data_node->refcount = 1; |
|
|
nodep = Curl_hash_add(&hp, data_key, key_len + 1, data_node); |
|
|
abort_unless(nodep, "insertion into hash failed"); |
|
|
|
|
|
data_node = NULL; |
|
|
} |
|
|
|
|
|
UNITTEST_STOP |
|
|
|