2016-10-27 13:17:58 +11:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2016-10-27 13:17:58 +11:00
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2016-10-27 13:17:58 +11:00
|
|
|
*/
|
|
|
|
|
2018-10-24 09:22:15 -07:00
|
|
|
#if HAVE_CMOCKA
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <sched.h> /* IWYU pragma: keep */
|
|
|
|
#include <setjmp.h>
|
2018-10-24 09:22:15 -07:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2016-10-27 13:17:58 +11:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2018-10-24 09:22:15 -07:00
|
|
|
#define UNIT_TESTING
|
|
|
|
#include <cmocka.h>
|
|
|
|
|
2016-10-27 13:17:58 +11:00
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
#include <irs/resconf.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <irs/types.h>
|
2016-10-27 13:17:58 +11:00
|
|
|
|
|
|
|
static isc_mem_t *mctx = NULL;
|
|
|
|
|
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
setup_test()
|
|
|
|
{
|
2019-09-05 18:40:57 +02:00
|
|
|
isc_mem_create(&mctx);
|
2016-10-27 13:17:58 +11:00
|
|
|
|
|
|
|
/*
|
2018-10-24 09:22:15 -07:00
|
|
|
* the caller might run from another directory, but tests
|
2016-10-27 13:17:58 +11:00
|
|
|
* that access test data files must first chdir to the proper
|
|
|
|
* location.
|
|
|
|
*/
|
2018-10-24 09:22:15 -07:00
|
|
|
assert_return_code(chdir(TESTS), 0);
|
2016-10-27 13:17:58 +11:00
|
|
|
}
|
|
|
|
|
2018-10-24 09:22:15 -07:00
|
|
|
/* test irs_resconf_load() */
|
|
|
|
static void
|
2020-02-12 13:59:18 +01:00
|
|
|
irs_resconf_load_test(void **state)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
2016-10-27 13:17:58 +11:00
|
|
|
irs_resconf_t *resconf = NULL;
|
2020-02-12 13:59:18 +01:00
|
|
|
unsigned int i;
|
2016-10-27 13:17:58 +11:00
|
|
|
struct {
|
2020-02-12 13:59:18 +01:00
|
|
|
const char * file;
|
2016-10-27 13:17:58 +11:00
|
|
|
isc_result_t loadres;
|
|
|
|
isc_result_t (*check)(irs_resconf_t *resconf);
|
|
|
|
isc_result_t checkres;
|
|
|
|
} tests[] = {
|
2020-02-12 13:59:18 +01:00
|
|
|
{ "testdata/domain.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
|
|
|
|
{ "testdata/nameserver-v4.conf", ISC_R_SUCCESS, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/nameserver-v6.conf", ISC_R_SUCCESS, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/nameserver-v6-scoped.conf", ISC_R_SUCCESS, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/options-debug.conf", ISC_R_SUCCESS, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/options-ndots.conf", ISC_R_SUCCESS, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/options-timeout.conf", ISC_R_SUCCESS, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/options-unknown.conf", ISC_R_SUCCESS, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/options.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
|
|
|
|
{ "testdata/options-bad-ndots.conf", ISC_R_RANGE, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/options-empty.conf", ISC_R_UNEXPECTEDEND, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/port.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
|
|
|
|
{ "testdata/resolv.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
|
|
|
|
{ "testdata/search.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
|
|
|
|
{ "testdata/sortlist-v4.conf", ISC_R_SUCCESS, NULL,
|
|
|
|
ISC_R_SUCCESS },
|
|
|
|
{ "testdata/timeout.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS },
|
|
|
|
{ "testdata/unknown.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }
|
2016-10-27 13:17:58 +11:00
|
|
|
};
|
|
|
|
|
2018-10-24 09:22:15 -07:00
|
|
|
UNUSED(state);
|
2016-10-27 13:17:58 +11:00
|
|
|
|
|
|
|
setup_test();
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
for (i = 0; i < sizeof(tests) / sizeof(tests[1]); i++) {
|
2016-10-27 13:17:58 +11:00
|
|
|
result = irs_resconf_load(mctx, tests[i].file, &resconf);
|
2018-10-24 09:22:15 -07:00
|
|
|
if (result != tests[i].loadres) {
|
|
|
|
fail_msg("# unexpected result %s loading %s",
|
|
|
|
isc_result_totext(result), tests[i].file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == ISC_R_SUCCESS && resconf == NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
fail_msg("# NULL on success loading %s", tests[i].file);
|
2018-10-24 09:22:15 -07:00
|
|
|
} else if (result != ISC_R_SUCCESS && resconf != NULL) {
|
|
|
|
fail_msg("# non-NULL on failure loading %s",
|
|
|
|
tests[i].file);
|
|
|
|
}
|
|
|
|
|
2016-10-27 13:17:58 +11:00
|
|
|
if (resconf != NULL && tests[i].check != NULL) {
|
|
|
|
result = (tests[i].check)(resconf);
|
2018-10-24 09:22:15 -07:00
|
|
|
if (result != tests[i].checkres) {
|
|
|
|
fail_msg("# unexpected result %s loading %s",
|
|
|
|
isc_result_totext(result),
|
2016-10-27 13:17:58 +11:00
|
|
|
tests[i].file);
|
2018-10-24 09:22:15 -07:00
|
|
|
}
|
2016-10-27 13:17:58 +11:00
|
|
|
}
|
2018-10-24 09:22:15 -07:00
|
|
|
if (resconf != NULL) {
|
2016-10-27 13:17:58 +11:00
|
|
|
irs_resconf_destroy(&resconf);
|
2018-10-24 09:22:15 -07:00
|
|
|
}
|
2016-10-27 13:17:58 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_mem_detach(&mctx);
|
|
|
|
}
|
|
|
|
|
2018-10-24 09:22:15 -07:00
|
|
|
int
|
2020-02-12 13:59:18 +01:00
|
|
|
main(void)
|
|
|
|
{
|
2018-10-24 09:22:15 -07:00
|
|
|
const struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test(irs_resconf_load_test),
|
|
|
|
};
|
|
|
|
|
|
|
|
return (cmocka_run_group_tests(tests, NULL, NULL));
|
2016-10-27 13:17:58 +11:00
|
|
|
}
|
2018-10-24 09:22:15 -07:00
|
|
|
|
|
|
|
#else /* HAVE_CMOCKA */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int
|
2020-02-12 13:59:18 +01:00
|
|
|
main(void)
|
|
|
|
{
|
2018-10-24 09:22:15 -07:00
|
|
|
printf("1..0 # Skipped: cmocka not available\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* if HAVE_CMOCKA */
|