mirror of
https://github.com/curl/curl.git
synced 2026-08-26 17:43:31 +03:00
Converted tests 558 & 559 to use the unit test framework as 1305
Test 558 was just a subset of 559 which is something that can be easily added later.
This commit is contained in:
parent
a8aab6e7d4
commit
fb199cd29d
10 changed files with 166 additions and 294 deletions
|
|
@ -3,10 +3,11 @@
|
|||
UNITFILES = curlcheck.h
|
||||
|
||||
# These are all unit test programs
|
||||
noinst_PROGRAMS = unit1300 unit1301 unit1302 unit1303 unit1304
|
||||
noinst_PROGRAMS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305
|
||||
|
||||
unit1300_SOURCES = unit1300.c $(UNITFILES)
|
||||
unit1301_SOURCES = unit1301.c $(UNITFILES)
|
||||
unit1302_SOURCES = unit1302.c $(UNITFILES)
|
||||
unit1303_SOURCES = unit1303.c $(UNITFILES)
|
||||
unit1304_SOURCES = unit1304.c $(UNITFILES)
|
||||
unit1305_SOURCES = unit1305.c $(UNITFILES)
|
||||
|
|
|
|||
131
tests/unit/unit1305.c
Normal file
131
tests/unit/unit1305.c
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
/*****************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
*/
|
||||
|
||||
#include "test.h"
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
#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
|
||||
|
||||
#define ENABLE_CURLX_PRINTF
|
||||
#include "curlx.h"
|
||||
|
||||
#include "hash.h"
|
||||
#include "hostip.h"
|
||||
#include "curlcheck.h"
|
||||
|
||||
#include "curl_memory.h"
|
||||
#include "memdebug.h" /* LAST include file */
|
||||
|
||||
static struct SessionHandle *data;
|
||||
static struct curl_hash *hp;
|
||||
static char *data_key;
|
||||
static struct Curl_dns_entry *data_node;
|
||||
|
||||
static CURLcode unit_setup( void )
|
||||
{
|
||||
data = curl_easy_init();
|
||||
if (!data)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
hp = Curl_mk_dnscache();
|
||||
if(!hp) {
|
||||
curl_easy_cleanup(data);
|
||||
curl_global_cleanup();
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static void unit_stop( void )
|
||||
{
|
||||
if (data_node) {
|
||||
Curl_freeaddrinfo(data_node->addr);
|
||||
free(data_node);
|
||||
}
|
||||
if (data_key)
|
||||
free(data_key);
|
||||
|
||||
Curl_hash_destroy(hp);
|
||||
|
||||
curl_easy_cleanup(data);
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
static Curl_addrinfo *fake_ai(void)
|
||||
{
|
||||
static Curl_addrinfo *ai;
|
||||
int ss_size;
|
||||
|
||||
ss_size = sizeof (struct sockaddr_in);
|
||||
|
||||
if((ai = calloc(1, sizeof(Curl_addrinfo))) == NULL)
|
||||
return NULL;
|
||||
|
||||
if((ai->ai_canonname = strdup("dummy")) == NULL) {
|
||||
free(ai);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if((ai->ai_addr = calloc(1, ss_size)) == NULL) {
|
||||
free(ai->ai_canonname);
|
||||
free(ai);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ai->ai_family = AF_INET;
|
||||
ai->ai_addrlen = ss_size;
|
||||
|
||||
return ai;
|
||||
}
|
||||
|
||||
static CURLcode create_node(void)
|
||||
{
|
||||
data_key = aprintf("%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;
|
||||
|
||||
CURLcode rc = create_node();
|
||||
abort_unless(rc == CURLE_OK, "data node creation failed");
|
||||
key_len = strlen(data_key);
|
||||
|
||||
nodep = Curl_hash_add(hp, 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;
|
||||
|
||||
/* To do: test retrieval, deletion, edge conditions */
|
||||
|
||||
UNITTEST_STOP
|
||||
Loading…
Add table
Add a link
Reference in a new issue