tests/regress_dns: cover that randomize-case works case-insensitive

Regression-for: #288
This commit is contained in:
Azat Khuzhin 2015-10-09 01:11:09 +03:00
parent 0c615f4ef3
commit 1e8bfbc6bc
3 changed files with 34 additions and 6 deletions

View File

@ -72,6 +72,8 @@
#include "regress.h"
#include "regress_testutils.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
static int dns_ok = 0;
static int dns_got_cancel = 0;
static int dns_err = 0;
@ -526,10 +528,10 @@ static struct regress_dns_server_table search_table[] = {
{ "*", "err", "3", 0 },
{ NULL, NULL, NULL, 0 }
};
static void
dns_search_test(void *arg)
dns_search_test_impl(void *arg, int lower)
{
struct regress_dns_server_table table[ARRAY_SIZE(search_table)];
struct basic_test_data *data = arg;
struct event_base *base = data->base;
struct evdns_base *dns = NULL;
@ -538,7 +540,12 @@ dns_search_test(void *arg)
struct generic_dns_callback_result r[8];
tt_assert(regress_dnsserver(base, &portnum, search_table));
for (size_t i = 0; i < ARRAY_SIZE(table); ++i) {
table[i] = search_table[i];
table[i].lower = lower;
}
tt_assert(regress_dnsserver(base, &portnum, table));
evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum);
dns = evdns_base_new(base, 0);
@ -548,7 +555,7 @@ dns_search_test(void *arg)
evdns_base_search_add(dns, "b.example.com");
evdns_base_search_add(dns, "c.example.com");
n_replies_left = sizeof(r)/sizeof(r[0]);
n_replies_left = ARRAY_SIZE(r);
exit_base = base;
evdns_base_resolve_ipv4(dns, "host", 0, generic_dns_callback, &r[0]);
@ -584,6 +591,16 @@ end:
regress_clean_dnsserver();
}
static void
dns_search_test(void *arg)
{
return dns_search_test_impl(arg, 0);
}
static void
dns_search_lower_test(void *arg)
{
return dns_search_test_impl(arg, 1);
}
static int request_count = 0;
static struct evdns_request *current_req = NULL;
@ -1672,7 +1689,6 @@ test_getaddrinfo_async(void *arg)
end:
if (local_outcome.ai)
evutil_freeaddrinfo(local_outcome.ai);
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
for (i=0;i<(int)ARRAY_SIZE(a_out);++i) {
if (a_out[i].ai)
evutil_freeaddrinfo(a_out[i].ai);
@ -2010,6 +2026,7 @@ struct testcase_t dns_testcases[] = {
DNS_LEGACY(gethostbyaddr, TT_FORK|TT_NEED_BASE|TT_NEED_DNS|TT_OFF_BY_DEFAULT),
{ "resolve_reverse", dns_resolve_reverse, TT_FORK|TT_OFF_BY_DEFAULT, NULL, NULL },
{ "search", dns_search_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
{ "search_lower", dns_search_lower_test, TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
{ "search_cancel", dns_search_cancel_test,
TT_FORK|TT_NEED_BASE, &basic_setup, NULL },
{ "retry", dns_retry_test, TT_FORK|TT_NEED_BASE|TT_NO_LOGS, &basic_setup, NULL },

View File

@ -135,11 +135,18 @@ regress_clean_dnsserver(void)
evutil_closesocket(dns_sock);
}
static void strtolower(char *s)
{
while (*s) {
*s = EVUTIL_TOLOWER_(*s);
++s;
}
}
void
regress_dns_server_cb(struct evdns_server_request *req, void *data)
{
struct regress_dns_server_table *tab = data;
const char *question;
char *question;
if (req->nquestions != 1)
TT_DIE(("Only handling one question at a time; got %d",
@ -155,6 +162,9 @@ regress_dns_server_cb(struct evdns_server_request *req, void *data)
++tab->seen;
if (tab->lower)
strtolower(question);
if (!strcmp(tab->anstype, "err")) {
int err = atoi(tab->ans);
tt_assert(! evdns_server_request_respond(req, err));

View File

@ -34,6 +34,7 @@ struct regress_dns_server_table {
const char *anstype;
const char *ans;
int seen;
int lower;
};
struct evdns_server_port *