test: restore the old test 1609 as 3271
No binary (build failed)
—
(log yok)
| @@ -56,18 +56,13 @@ | |
| #include "curlx/strcopy.h" | |
| #include "curlx/strparse.h" | |
| - | #define MAX_HOSTCACHE_LEN (255 + 3) /* max FQDN + type + port */ |
| - | |
| #define MAX_DNS_CACHE_SIZE 29999 | |
| - | struct dnsc_id { |
| - | struct Curl_str name; |
| - | uint16_t port; |
| - | char type; |
| - | }; |
| - | |
| - | static void dnsc_peer2id(struct dnsc_id *pid, char type, |
| - | struct Curl_peer *peer) |
| + | /* @unittest 3217 */ |
| + | UNITTEST void dnsc_peer2id(struct dnsc_id *pid, char type, |
| + | struct Curl_peer *peer); |
| + | UNITTEST void dnsc_peer2id(struct dnsc_id *pid, char type, |
| + | struct Curl_peer *peer) |
| { | |
| curlx_str_assign(&pid->name, peer->hostname, strlen(peer->hostname)); | |
| pid->port = peer->port; | |
| @@ -82,16 +77,14 @@ static void dnsc_str2id(struct dnsc_id *pid, char type, | |
| pid->type = type; | |
| } | |
| - | struct dnsc_key { |
| - | uint8_t data[MAX_HOSTCACHE_LEN]; |
| - | size_t len; |
| - | }; |
| - | |
| /* | |
| * Create a hostcache id string for the provided host + port, to be used by | |
| * the DNS caching. Without alloc. Return length of the id string. | |
| + | * |
| + | * @unittest 3217 |
| */ | |
| - | static void dnsc_id2key(struct dnsc_key *key, struct dnsc_id *id) |
| + | UNITTEST void dnsc_id2key(struct dnsc_key *key, struct dnsc_id *id); |
| + | UNITTEST void dnsc_id2key(struct dnsc_key *key, struct dnsc_id *id) |
| { | |
| size_t namelen = curlx_strlen(&id->name); | |
| if(namelen > (sizeof(key->data) - 3)) | |
| @@ -27,6 +27,7 @@ | |
| #include "hash.h" | |
| #include "curlx/timeval.h" | |
| + | #include "curlx/strparse.h" |
| struct addrinfo; | |
| struct hostent; | |
| @@ -58,6 +59,19 @@ struct Curl_dns_entry { | |
| char hostname[1]; | |
| }; | |
| + | struct dnsc_id { |
| + | struct Curl_str name; |
| + | uint16_t port; |
| + | char type; |
| + | }; |
| + | |
| + | #define MAX_HOSTCACHE_LEN (255 + 3) /* max FQDN + type + port */ |
| + | |
| + | struct dnsc_key { |
| + | uint8_t data[MAX_HOSTCACHE_LEN]; |
| + | size_t len; |
| + | }; |
| + | |
| /* | |
| * Create a `Curl_dns_entry` with a reference count of 1. | |
| * Use `Curl_dns_entry_unlink()` to release your hold on it. | |
| @@ -2116,7 +2116,7 @@ TESTCASES = \ | |
| test3231 \ | |
| test3232 \ | |
| test3233 \ | |
| - | \ |
| + | test3271 \ |
| test3300 \ | |
| test3301 \ | |
| test3302 \ | |
| @@ -0,0 +1,21 @@ | |
| + | <?xml version="1.0" encoding="US-ASCII"?> |
| + | <testcase> |
| + | <info> |
| + | <keywords> |
| + | unittest |
| + | CURLOPT_RESOLVE |
| + | </keywords> |
| + | </info> |
| + | |
| + | # Client-side |
| + | <client> |
| + | <features> |
| + | unittest |
| + | </features> |
| + | |
| + | # this test extends 1607 - they should probably be combined one day |
| + | <name> |
| + | CURLOPT_RESOLVE override |
| + | </name> |
| + | </client> |
| + | </testcase> |
| @@ -49,7 +49,6 @@ TESTS_C = \ | |
| unit1606.c \ | |
| unit1607.c \ | |
| unit1608.c \ | |
| - | unit1609.c \ |
| unit1610.c \ | |
| unit1611.c \ | |
| unit1612.c \ | |
| @@ -102,6 +101,7 @@ TESTS_C = \ | |
| unit3219.c \ | |
| unit3227.c \ | |
| unit3230.c \ | |
| + | unit3271.c \ |
| unit3300.c \ | |
| unit3301.c \ | |
| unit3302.c \ | |
| @@ -26,7 +26,7 @@ | |
| #include "connect.h" | |
| #include "curl_addrinfo.h" | |
| - | static CURLcode t1609_setup(void) |
| + | static CURLcode t3271_setup(void) |
| { | |
| CURLcode result = CURLE_OK; | |
| global_init(CURL_GLOBAL_ALL); | |
| @@ -66,9 +66,9 @@ static CURLcode t1609_setup(void) | |
| expected result: cached address has zero timestamp and new address | |
| */ | |
| - | static CURLcode test_unit1609(const char *arg) |
| + | static CURLcode test_unit3271(const char *arg) |
| { | |
| - | UNITTEST_BEGIN(t1609_setup()) |
| + | UNITTEST_BEGIN(t3271_setup()) |
| struct testcase { | |
| /* host:port:address[,address]... */ | |
| @@ -76,14 +76,14 @@ static CURLcode test_unit1609(const char *arg) | |
| /* lowercase host and port to retrieve the addresses from hostcache */ | |
| const char *host; | |
| - | int port; |
| + | uint16_t port; |
| /* 0 to 9 addresses expected from hostcache */ | |
| const char *address[10]; | |
| }; | |
| static const struct testcase tests[] = { | |
| - | /* spaces are not allowed, for now */ |
| + | /* spaces are not allowed */ |
| { "test.com:80:127.0.0.1", | |
| "test.com", 80, { "127.0.0.1", } | |
| }, | |
| @@ -97,17 +97,20 @@ static CURLcode test_unit1609(const char *arg) | |
| struct Curl_easy *easy = NULL; | |
| struct curl_slist *list = NULL; | |
| - | /* important: we setup cache outside of the loop |
| - | and also clean cache after the loop. In contrast, for example, |
| - | test 1607 sets up and cleans cache on each iteration. */ |
| + | /* important: we setup cache outside of the loop and also clean cache after |
| + | the loop. In contrast, for example, test 1607 sets up and cleans cache on |
| + | each iteration. */ |
| for(i = 0; i < CURL_ARRAYSIZE(tests); ++i) { | |
| size_t j; | |
| size_t addressnum = CURL_ARRAYSIZE(tests[i].address); | |
| struct Curl_addrinfo *addr; | |
| struct Curl_dns_entry *dns; | |
| - | void *entry_id; |
| + | struct dnsc_id id; |
| + | struct dnsc_key key; |
| + | const char type = CURL_DNST_ADDR; |
| bool problem = FALSE; | |
| + | struct Curl_peer *peer = NULL; |
| easy = curl_easy_init(); | |
| if(!easy) { | |
| curl_global_cleanup(); | |
| @@ -129,13 +132,13 @@ static CURLcode test_unit1609(const char *arg) | |
| if(Curl_loadhostpairs(easy)) | |
| goto error; | |
| - | entry_id = (void *)curl_maprintf("%s:%d", tests[i].host, tests[i].port); |
| - | if(!entry_id) |
| + | if(Curl_peer_create(easy, &Curl_scheme_http, |
| + | tests[i].host, tests[i].port, &peer)) |
| goto error; | |
| - | dns = Curl_hash_pick(&multi->dnscache.entries, |
| - | entry_id, strlen(entry_id) + 1); |
| - | curlx_safefree(entry_id); |
| + | dnsc_peer2id(&id, type, peer); |
| + | dnsc_id2key(&key, &id); |
| + | dns = Curl_hash_pick(&multi->dnscache.entries, key.data, key.len); |
| addr = dns ? dns->addr : NULL; | |
| @@ -194,6 +197,7 @@ static CURLcode test_unit1609(const char *arg) | |
| addr = addr->ai_next; | |
| } | |
| + | Curl_peer_unlink(&peer); |
| curl_easy_cleanup(easy); | |
| easy = NULL; | |