mirror of
https://github.com/curl/curl.git
synced 2026-06-19 14:15:39 +03:00
Using a mixture of techniques to avoid symbols collisions: - reduce scope. - add `t*_` / `T*_` prefix. - move shared functions to `testutil.c`. (`suburl()`, `rlim2str()`) - clone re-used lib*.c sources. (lib587, lib645) - include shared symbols just once in re-used `lib*.c` sources. (using `LIB*_C` guards.) - drop re-used `lib*.c` sources where they were identical or unused. - make macros global. - #undef macros before use. What remain is the entry functions `test`, and `unit_setup`, `unit_stop` in unit tests. Also: - fix formatting and other minor things along the way. - add `const` where possible. - sync some symbol names between tests. - drop `mk-bundle-hints.sh` that's no longer necessary. Closes #17468
131 lines
3.4 KiB
C
131 lines
3.4 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
#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" /* LAST include file */
|
|
|
|
static struct Curl_easy *t1305_easy;
|
|
static struct Curl_dnscache hp;
|
|
static char *data_key;
|
|
static struct Curl_dns_entry *data_node;
|
|
|
|
static CURLcode unit_setup(void)
|
|
{
|
|
t1305_easy = curl_easy_init();
|
|
if(!t1305_easy) {
|
|
curl_global_cleanup();
|
|
return CURLE_OUT_OF_MEMORY;
|
|
}
|
|
|
|
Curl_dnscache_init(&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_dnscache_destroy(&hp);
|
|
|
|
curl_easy_cleanup(t1305_easy);
|
|
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); /* including the null-terminator */
|
|
|
|
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 = curl_maprintf("%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;
|
|
|
|
/* Test 1305 exits without adding anything to the hash */
|
|
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; /* hash will hold the reference */
|
|
nodep = Curl_hash_add(&hp.entries, data_key, key_len + 1, data_node);
|
|
abort_unless(nodep, "insertion into hash failed");
|
|
/* Freeing will now be done by Curl_hash_destroy */
|
|
data_node = NULL;
|
|
}
|
|
|
|
UNITTEST_STOP
|