1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
22 #include "curlcheck.h"
24 #ifdef HAVE_NETINET_IN_H
25 # include <netinet/in.h>
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
34 #define ENABLE_CURLX_PRINTF
40 #include "memdebug.h" /* LAST include file */
42 static struct Curl_easy *data;
43 static struct curl_hash hp;
44 static char *data_key;
45 static struct Curl_dns_entry *data_node;
47 static CURLcode unit_setup(void)
50 data = curl_easy_init();
52 return CURLE_OUT_OF_MEMORY;
54 rc = Curl_mk_dnscache(&hp);
56 curl_easy_cleanup(data);
57 curl_global_cleanup();
58 return CURLE_OUT_OF_MEMORY;
63 static void unit_stop(void)
66 Curl_freeaddrinfo(data_node->addr);
70 Curl_hash_destroy(&hp);
72 curl_easy_cleanup(data);
73 curl_global_cleanup();
76 static Curl_addrinfo *fake_ai(void)
78 static Curl_addrinfo *ai;
81 ss_size = sizeof (struct sockaddr_in);
83 if((ai = calloc(1, sizeof(Curl_addrinfo))) == NULL)
86 if((ai->ai_canonname = strdup("dummy")) == NULL) {
91 if((ai->ai_addr = calloc(1, ss_size)) == NULL) {
92 free(ai->ai_canonname);
97 ai->ai_family = AF_INET;
98 ai->ai_addrlen = ss_size;
103 static CURLcode create_node(void)
105 data_key = aprintf("%s:%d", "dummy", 0);
107 return CURLE_OUT_OF_MEMORY;
109 data_node = calloc(1, sizeof(struct Curl_dns_entry));
111 return CURLE_OUT_OF_MEMORY;
113 data_node->addr = fake_ai();
115 return CURLE_OUT_OF_MEMORY;
123 struct Curl_dns_entry *nodep;
126 /* Test 1305 exits without adding anything to the hash */
127 if(strcmp(arg, "1305") != 0) {
128 CURLcode rc = create_node();
129 abort_unless(rc == CURLE_OK, "data node creation failed");
130 key_len = strlen(data_key);
132 data_node->inuse = 1; /* hash will hold the reference */
133 nodep = Curl_hash_add(&hp, data_key, key_len+1, data_node);
134 abort_unless(nodep, "insertion into hash failed");
135 /* Freeing will now be done by Curl_hash_destroy */