Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "curlcheck.h"
00023
00024 #ifdef HAVE_NETINET_IN_H
00025 # include <netinet/in.h>
00026 #endif
00027 #ifdef HAVE_NETDB_H
00028 # include <netdb.h>
00029 #endif
00030 #ifdef HAVE_ARPA_INET_H
00031 # include <arpa/inet.h>
00032 #endif
00033
00034 #define ENABLE_CURLX_PRINTF
00035 #include "curlx.h"
00036
00037 #include "hash.h"
00038 #include "hostip.h"
00039
00040 #include "memdebug.h"
00041
00042 static struct Curl_easy *data;
00043 static struct curl_hash hp;
00044 static char *data_key;
00045 static struct Curl_dns_entry *data_node;
00046
00047 static CURLcode unit_setup(void)
00048 {
00049 int rc;
00050 data = curl_easy_init();
00051 if(!data)
00052 return CURLE_OUT_OF_MEMORY;
00053
00054 rc = Curl_mk_dnscache(&hp);
00055 if(rc) {
00056 curl_easy_cleanup(data);
00057 curl_global_cleanup();
00058 return CURLE_OUT_OF_MEMORY;
00059 }
00060 return CURLE_OK;
00061 }
00062
00063 static void unit_stop(void)
00064 {
00065 if(data_node) {
00066 Curl_freeaddrinfo(data_node->addr);
00067 free(data_node);
00068 }
00069 free(data_key);
00070 Curl_hash_destroy(&hp);
00071
00072 curl_easy_cleanup(data);
00073 curl_global_cleanup();
00074 }
00075
00076 static Curl_addrinfo *fake_ai(void)
00077 {
00078 static Curl_addrinfo *ai;
00079 int ss_size;
00080
00081 ss_size = sizeof(struct sockaddr_in);
00082
00083 ai = calloc(1, sizeof(Curl_addrinfo));
00084 if(!ai)
00085 return NULL;
00086
00087 ai->ai_canonname = strdup("dummy");
00088 if(!ai->ai_canonname) {
00089 free(ai);
00090 return NULL;
00091 }
00092
00093 ai->ai_addr = calloc(1, ss_size);
00094 if(!ai->ai_addr) {
00095 free(ai->ai_canonname);
00096 free(ai);
00097 return NULL;
00098 }
00099
00100 ai->ai_family = AF_INET;
00101 ai->ai_addrlen = ss_size;
00102
00103 return ai;
00104 }
00105
00106 static CURLcode create_node(void)
00107 {
00108 data_key = aprintf("%s:%d", "dummy", 0);
00109 if(!data_key)
00110 return CURLE_OUT_OF_MEMORY;
00111
00112 data_node = calloc(1, sizeof(struct Curl_dns_entry));
00113 if(!data_node)
00114 return CURLE_OUT_OF_MEMORY;
00115
00116 data_node->addr = fake_ai();
00117 if(!data_node->addr)
00118 return CURLE_OUT_OF_MEMORY;
00119
00120 return CURLE_OK;
00121 }
00122
00123
00124 UNITTEST_START
00125
00126 struct Curl_dns_entry *nodep;
00127 size_t key_len;
00128
00129
00130 if(strcmp(arg, "1305") != 0) {
00131 CURLcode rc = create_node();
00132 abort_unless(rc == CURLE_OK, "data node creation failed");
00133 key_len = strlen(data_key);
00134
00135 data_node->inuse = 1;
00136 nodep = Curl_hash_add(&hp, data_key, key_len+1, data_node);
00137 abort_unless(nodep, "insertion into hash failed");
00138
00139 data_node = NULL;
00140 }
00141
00142 UNITTEST_STOP