1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
13 #ifdef HAVE_SYS_SOCKET_H
14 # include <sys/socket.h>
16 #ifdef HAVE_NETINET_IN_H
17 # include <netinet/in.h>
22 #ifdef HAVE_ARPA_INET_H
23 # include <arpa/inet.h>
26 #define ENABLE_CURLX_PRINTF
32 #include "curl_memory.h"
35 /* This source file is used for test # 558 and 559 */
38 * This hacky test bypasses the library external API,
39 * using internal only libcurl functions. So don't be
40 * surprised if we cannot run it when the library has
41 * been built with hidden symbols, exporting only the
42 * ones in the public API.
45 #if defined(CURL_HIDDEN_SYMBOLS)
47 #elif defined(WIN32) && !defined(CURL_STATICLIB)
54 #if !defined(SKIP_TEST)
57 static Curl_addrinfo *fake_ai(void)
62 ss_size = sizeof (struct sockaddr_in);
64 if((ai = calloc(1, sizeof(Curl_addrinfo))) == NULL)
67 if((ai->ai_canonname = strdup("dummy")) == NULL) {
72 if((ai->ai_addr = calloc(1, ss_size)) == NULL) {
73 free(ai->ai_canonname);
78 ai->ai_family = AF_INET;
79 ai->ai_addrlen = ss_size;
89 struct curl_hash *hp = NULL;
92 if(!strcmp(URL, "check")) {
93 /* test harness script verifying if this test can run */
94 return 0; /* sure, run this! */
97 easyh = curl_easy_init();
99 fprintf(stdout, "easy handle init failed\n");
100 result = TEST_ERR_MAJOR_BAD;
103 fprintf(stdout, "easy handle init OK\n");
105 fprintf(stdout, "creating hash...\n");
106 hp = Curl_mk_dnscache();
108 fprintf(stdout, "hash creation failed\n");
109 result = TEST_ERR_MAJOR_BAD;
112 fprintf(stdout, "hash creation OK\n");
118 struct Curl_dns_entry *data_node;
119 struct Curl_dns_entry *nodep;
122 data_key = aprintf("%s:%d", "dummy", 0);
124 fprintf(stdout, "data key creation failed\n");
125 result = TEST_ERR_MAJOR_BAD;
128 key_len = strlen(data_key);
130 data_node = calloc(1, sizeof(struct Curl_dns_entry));
132 fprintf(stdout, "data node creation failed\n");
133 result = TEST_ERR_MAJOR_BAD;
138 data_node->addr = fake_ai();
139 if(!data_node->addr) {
140 fprintf(stdout, "actual data creation failed\n");
141 result = TEST_ERR_MAJOR_BAD;
147 nodep = Curl_hash_add(hp, data_key, key_len+1, (void *)data_node);
149 fprintf(stdout, "insertion into hash failed\n");
150 result = TEST_ERR_MAJOR_BAD;
151 Curl_freeaddrinfo(data_node->addr);
164 fprintf(stdout, "destroying hash...\n");
165 Curl_hash_destroy(hp);
166 fprintf(stdout, "hash destruction OK\n");
168 fprintf(stdout, "destroying easy handle...\n");
169 curl_easy_cleanup(easyh);
170 fprintf(stdout, "easy handle destruction OK\n");
172 curl_global_cleanup();
178 #else /* !defined(SKIP_TEST) */
184 fprintf(stdout, "libcurl built with hidden symbols");
185 return 1; /* skip test */
189 #endif /* !defined(SKIP_TEST) */