/*
SSSD
Async resolver tests
Authors:
Martin Nagy <mnagy@redhat.com>
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) Red Hat, Inc 2009
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <check.h>
#include <string.h>
#include <talloc.h>
#include <tevent.h>
#include <popt.h>
#include "tests/common_check.h"
/* Interface under test */
#include "resolv/async_resolv.h"
static int use_net_test;
static char *txt_host;
static char *srv_host;
struct resolv_test_ctx {
enum {
int error;
bool done;
};
{
int ret;
fail("Could not allocate memory for test context");
return ENOMEM;
}
fail("Could not init tevent context");
return EFAULT;
}
fail("Could not init resolv context");
return ret;
}
return EOK;
}
{
}
struct resolv_hostent *
{
int ret;
int family;
if (!rhostent) {
return NULL;
}
goto fail;
}
struct resolv_addr);
goto fail;
}
sizeof(struct in6_addr));
goto fail;
}
if (ret != 1) {
if (ret != 1) {
goto fail;
}
}
return rhostent;
fail:
return NULL;
}
{
void *ctx;
};
}
{
void *ctx;
char *str_addr;
char *ptr_addr;
"a.6.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.c.0.c.0.0.4.0.b.8.f.7.0.6.2.ip6.arpa.") == 0, "Unexpected PTR address\n");
}
{
int recv_status;
int status;
int i;
struct resolv_test_ctx);
if (recv_status != EOK) {
"resolv_gethostbyname_recv failed: %d\n", recv_status);
return;
}
}
}
}
{
fail("Could not set up test");
return;
}
}
}
}
{
int recv_status;
int status;
int i;
struct resolv_test_ctx);
if (recv_status != EOK) {
"resolv_gethostbyname_recv failed: %d\n", recv_status);
return;
}
/* test that localhost resolves to 127.0.0.1 or ::1 */
}
}
}
{
fail("Could not set up test");
return;
}
}
}
}
{
int recv_status;
int status;
if (recv_status == EOK) {
"resolv_gethostbyname_recv succeeded in a negative test\n");
return;
}
}
{
fail("Could not set up test");
return;
}
}
}
}
{
int recv_status;
int status;
void *tmp_ctx;
int i;
switch (test_ctx->tested_function) {
case TESTING_HOSTNAME:
}
}
break;
case TESTING_TXT:
&txt_replies);
}
break;
case TESTING_SRV:
&srv_replies, NULL);
}
break;
default:
break;
}
} else if (txt_replies != NULL) {
} else if (srv_replies != NULL) {
}
}
{
fail("Could not set up test");
return;
}
}
}
}
{
int ret;
}
{
int ret;
}
struct tevent_timer *te,
{
}
struct tevent_timer *te,
{
}
{
fail("Could not set up test");
return;
}
fail("Error calling resolv_gethostbyname_send");
goto done;
}
terminate_tv.tv_usec = 0;
free_timer = tevent_add_timer(test_ctx->ev, test_ctx, free_tv, resolv_free_context, test_ctx->resolv);
if (free_timer == NULL) {
fail("Error calling tevent_add_timer");
goto done;
}
terminate_timer = tevent_add_timer(test_ctx->ev, test_ctx, terminate_tv, resolv_free_done, test_ctx);
if (terminate_timer == NULL) {
fail("Error calling tevent_add_timer");
goto done;
}
done:
}
struct tevent_timer *te,
{
}
{
int ret;
int i;
fail("Could not set up test");
return;
}
/* prepare linked list with reversed values */
for (i = 0; i<num_replies; i++) {
r->priority = num_replies-i;
r->weight = i;
if (!replies) {
replies = r;
prev = r;
} else {
}
}
/* do the sort */
/* check if the list is sorted */
prev = r;
fail_unless(r->priority == i);
}
/* check if the list is complete */
/* test if the weighting algorithm runs..not much do
* deterministically test here since it is based on
* random weight-selection */
for (i = 0; i<num_replies; i++) {
r->weight = i;
if (!replies) {
replies = r;
prev = r;
} else {
}
}
/* do the sort */
/* clean up */
prev = r;
}
/* check for leaks */
}
{
int ret;
int i;
fail("Could not set up test");
return;
}
/* prepare linked list */
for (i = 0; i < num_replies; i++) {
r->priority = 20;
r->weight = 0;
replies = r;
prev = r;
} else {
}
}
/* do the sort */
/* check if the list contains all values and is sorted */
}
}
fail_unless(i == num_replies);
/* clean up */
prev = r;
}
/* check for leaks */
}
{
fail("Could not set up test");
return;
}
fail("Error calling resolv_gethostbyname_send");
goto done;
}
/* Give enought time for c-ares request to terminate */
terminate_tv.tv_usec = 0;
if (free_timer == NULL) {
fail("Error calling tevent_add_timer");
goto done;
}
terminate_timer = tevent_add_timer(test_ctx->ev, test_ctx, terminate_tv, resolv_free_done, test_ctx);
if (terminate_timer == NULL) {
fail("Error calling tevent_add_timer");
goto done;
}
done:
}
{
int recv_status;
int status;
}
{
fail("Could not set up test");
return;
}
}
}
}
{
/* Do some testing */
if (use_net_test) {
}
}
}
/* Add all test cases to the test suite */
suite_add_tcase(s, tc_resolv);
return s;
}
{
int opt;
int failure_count;
int debug = 0;
{ "use-net-test", 'n', POPT_ARG_NONE, 0, 'n', "Run tests that need an active internet connection", NULL },
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
case 'n':
use_net_test = 1;
break;
case 't':
break;
case 's':
break;
default:
return 1;
}
}
if (!use_net_test) {
printf("Network tests disabled. Rerun with the \"-n\" "
"option to run the full suite of tests\n");
}
/* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
}