test_resolv_fake.c revision bf54fbed126ec3d459af40ea370ffadacd31c76d
/*
Authors:
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) 2014 Red Hat
SSSD tests: Resolver tests using a fake resolver library
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 <talloc.h>
#include <tevent.h>
#include <errno.h>
#include <popt.h>
#include <stdarg.h>
#include <stdlib.h>
#include <resolv.h>
#include "tests/cmocka/common_mock.h"
#include "tests/cmocka/common_mock_resp.h"
#define TEST_BUFSIZE 1024
#define TEST_DEFAULT_TIMEOUT 5
#define TEST_SRV_QUERY "_ldap._tcp.sssd.com"
struct srv_rrdata {
const char *hostname;
};
{
HEADER *h;
return NS_HFIXEDSZ;
}
{
unsigned char *qb = *question_ptr;
int n;
assert_true(n > 0);
qb += n;
remaining -= n;
*question_ptr = qb;
return n + 2 * sizeof(uint16_t);
}
const char *key,
{
}
const char *question,
{
unsigned char hostname_compressed[MAXDNAME];
/* Prepare the data to write */
return resp_size;
}
const char *question,
struct srv_rrdata *rrs,
{
unsigned char *buf;
unsigned char *buf_head;
ssize_t i;
assert_true(len > 0);
assert_true(len > 0);
/* answer */
for (i = 0; i < n_rrs; i++) {
assert_true(len > 0);
}
return buf_head;
}
struct fake_ares_query {
int status;
int timeouts;
unsigned char *abuf;
int alen;
};
{
}
{
struct fake_ares_query query;
}
/* The unit test */
struct resolv_fake_ctx {
struct resolv_ctx *resolv;
struct sss_test_ctx *ctx;
};
void test_resolv_fake_setup(void **state)
{
struct resolv_fake_ctx *test_ctx;
int ret;
struct resolv_fake_ctx);
}
void test_resolv_fake_teardown(void **state)
{
struct resolv_fake_ctx *test_ctx =
}
{
int status;
struct resolv_fake_ctx *test_ctx =
&srv_replies, &ttl);
}
void test_resolv_fake_srv(void **state)
{
int ret;
struct tevent_req *req;
struct resolv_fake_ctx *test_ctx =
unsigned char *buf;
}
{
int rv;
int opt;
struct poptOption long_options[] = {
};
};
/* Set debug level to invalid value so we can deside if -d 0 was used. */
switch(opt) {
default:
return 1;
}
}
/* Even though normally the tests should clean up after themselves
* they might not after a failed run. Remove the old db to be sure */
return rv;
}