1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
12 #ifdef HAVE_SYS_SOCKET_H
13 # include <sys/socket.h>
15 #ifdef HAVE_NETINET_IN_H
16 # include <netinet/in.h>
21 #ifdef HAVE_ARPA_INET_H
22 # include <arpa/inet.h>
25 #define ENABLE_CURLX_PRINTF
31 #include "curl_memory.h"
34 /* This source file is used for test # 558 and 559 */
37 * This hacky test bypasses the library external API,
38 * using internal only libcurl functions. So don't be
39 * surprised if we cannot run it when the library has
40 * been built with hidden symbols, exporting only the
41 * ones in the public API.
44 #if defined(CURL_HIDDEN_SYMBOLS)
46 #elif defined(WIN32) && !defined(CURL_STATICLIB)
53 #if !defined(SKIP_TEST)
56 static Curl_addrinfo *fake_ai(void)
61 ss_size = sizeof (struct sockaddr_in);
63 if((ai = calloc(1, sizeof(Curl_addrinfo))) == NULL)
66 if((ai->ai_canonname = strdup("dummy")) == NULL) {
71 if((ai->ai_addr = calloc(1, ss_size)) == NULL) {
72 free(ai->ai_canonname);
77 ai->ai_family = AF_INET;
78 ai->ai_addrlen = ss_size;
88 struct curl_hash *hp = NULL;
91 if(!strcmp(URL, "check")) {
92 /* test harness script verifying if this test can run */
93 return 0; /* sure, run this! */
96 easyh = curl_easy_init();
98 fprintf(stdout, "easy handle init failed\n");
99 result = TEST_ERR_MAJOR_BAD;
102 fprintf(stdout, "easy handle init OK\n");
104 fprintf(stdout, "creating hash...\n");
105 hp = Curl_mk_dnscache();
107 fprintf(stdout, "hash creation failed\n");
108 result = TEST_ERR_MAJOR_BAD;
111 fprintf(stdout, "hash creation OK\n");
117 struct Curl_dns_entry *data_node;
118 struct Curl_dns_entry *nodep;
121 data_key = aprintf("%s:%d", "dummy", 0);
123 fprintf(stdout, "data key creation failed\n");
124 result = TEST_ERR_MAJOR_BAD;
127 key_len = strlen(data_key);
129 data_node = calloc(1, sizeof(struct Curl_dns_entry));
131 fprintf(stdout, "data node creation failed\n");
132 result = TEST_ERR_MAJOR_BAD;
137 data_node->addr = fake_ai();
138 if(!data_node->addr) {
139 fprintf(stdout, "actual data creation failed\n");
140 result = TEST_ERR_MAJOR_BAD;
146 nodep = Curl_hash_add(hp, data_key, key_len+1, (void *)data_node);
148 fprintf(stdout, "insertion into hash failed\n");
149 result = TEST_ERR_MAJOR_BAD;
150 Curl_freeaddrinfo(data_node->addr);
163 fprintf(stdout, "destroying hash...\n");
164 Curl_hash_destroy(hp);
165 fprintf(stdout, "hash destruction OK\n");
167 fprintf(stdout, "destroying easy handle...\n");
168 curl_easy_cleanup(easyh);
169 fprintf(stdout, "easy handle destruction OK\n");
171 curl_global_cleanup();
177 #else /* !defined(SKIP_TEST) */
183 fprintf(stdout, "libcurl built with hidden symbols");
184 return 1; /* skip test */
188 #endif /* !defined(SKIP_TEST) */