From ea648e70a989cca190cd7403fe892fd2dcc290b4 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 5 May 2024 20:37:14 +0200 Subject: Adding upstream version 1:9.11.5.P4+dfsg. Signed-off-by: Daniel Baumann --- lib/isccfg/tests/Atffile | 5 ++ lib/isccfg/tests/Kyuafile | 4 + lib/isccfg/tests/Makefile.in | 54 ++++++++++++ lib/isccfg/tests/parser_test.c | 192 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 255 insertions(+) create mode 100644 lib/isccfg/tests/Atffile create mode 100644 lib/isccfg/tests/Kyuafile create mode 100644 lib/isccfg/tests/Makefile.in create mode 100644 lib/isccfg/tests/parser_test.c (limited to 'lib/isccfg/tests') diff --git a/lib/isccfg/tests/Atffile b/lib/isccfg/tests/Atffile new file mode 100644 index 0000000..f399e12 --- /dev/null +++ b/lib/isccfg/tests/Atffile @@ -0,0 +1,5 @@ +Content-Type: application/X-atf-atffile; version="1" + +prop: test-suite = bind9 + +tp: parser_test diff --git a/lib/isccfg/tests/Kyuafile b/lib/isccfg/tests/Kyuafile new file mode 100644 index 0000000..342d25f --- /dev/null +++ b/lib/isccfg/tests/Kyuafile @@ -0,0 +1,4 @@ +syntax(2) +test_suite('bind9') + +atf_test_program{name='parser_test'} diff --git a/lib/isccfg/tests/Makefile.in b/lib/isccfg/tests/Makefile.in new file mode 100644 index 0000000..327226b --- /dev/null +++ b/lib/isccfg/tests/Makefile.in @@ -0,0 +1,54 @@ +# Copyright (C) Internet Systems Consortium, Inc. ("ISC") +# +# 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/. +# +# See the COPYRIGHT file distributed with this work for additional +# information regarding copyright ownership. + +srcdir = @srcdir@ +VPATH = @srcdir@ +top_srcdir = @top_srcdir@ + +# Attempt to disable parallel processing. +.NOTPARALLEL: +.NO_PARALLEL: + +VERSION=@BIND9_VERSION@ + +@BIND9_MAKE_INCLUDES@ + +CINCLUDES = -I. -Iinclude \ + ${DNS_INCLUDES} ${ISC_INCLUDES} ${ISCCFG_INCLUDES} \ + @DST_OPENSSL_INC@ +CDEFINES = @CRYPTO@ -DTESTS="\"${top_builddir}/lib/dns/tests/\"" + +ISCLIBS = ../../isc/libisc.@A@ +ISCDEPLIBS = ../../isc/libisc.@A@ +DNSLIBS = ../../dns/libdns.@A@ @DNS_CRYPTO_LIBS@ +DNSDEPLIBS = ../../dns/libdns.@A@ +ISCCFGLIBS = ../libisccfg.@A@ +ISCCFGDEPLIBS = ../libisccfg.@A@ + +LIBS = @LIBS@ @ATFLIBS@ + +OBJS = +SRCS = parser_test.c + +SUBDIRS = +TARGETS = parser_test@EXEEXT@ + +@BIND9_MAKE_RULES@ + +parser_test@EXEEXT@: parser_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS} ${ISCCFGDEPLIBS} + ${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \ + parser_test.@O@ ${ISCCFGLIBS} ${DNSLIBS} \ + ${ISCLIBS} ${LIBS} + +unit:: + sh ${top_builddir}/unit/unittest.sh + +clean distclean:: + rm -f ${TARGETS} + rm -f atf.out diff --git a/lib/isccfg/tests/parser_test.c b/lib/isccfg/tests/parser_test.c new file mode 100644 index 0000000..606bbeb --- /dev/null +++ b/lib/isccfg/tests/parser_test.c @@ -0,0 +1,192 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * 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/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define CHECK(r) \ + do { \ + result = (r); \ + if (result != ISC_R_SUCCESS) \ + goto cleanup; \ + } while (0) + +isc_mem_t *mctx = NULL; +isc_log_t *lctx = NULL; +static isc_logcategory_t categories[] = { + { "", 0 }, + { "client", 0 }, + { "network", 0 }, + { "update", 0 }, + { "queries", 0 }, + { "unmatched", 0 }, + { "update-security", 0 }, + { "query-errors", 0 }, + { NULL, 0 } +}; + +static void +cleanup() { + if (lctx != NULL) + isc_log_destroy(&lctx); + if (mctx != NULL) + isc_mem_destroy(&mctx); +} + +static isc_result_t +setup() { + isc_result_t result; + + isc_mem_debugging |= ISC_MEM_DEBUGRECORD; + CHECK(isc_mem_create(0, 0, &mctx)); + + isc_logdestination_t destination; + isc_logconfig_t *logconfig = NULL; + + CHECK(isc_log_create(mctx, &lctx, &logconfig)); + isc_log_registercategories(lctx, categories); + isc_log_setcontext(lctx); + + destination.file.stream = stderr; + destination.file.name = NULL; + destination.file.versions = ISC_LOG_ROLLNEVER; + destination.file.maximum_size = 0; + CHECK(isc_log_createchannel(logconfig, "stderr", + ISC_LOG_TOFILEDESC, + ISC_LOG_DYNAMIC, + &destination, 0)); + CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL)); + + return (ISC_R_SUCCESS); + + cleanup: + cleanup(); + return (result); +} + +ATF_TC(parse_buffer); +ATF_TC_HEAD(parse_buffer, tc) { + atf_tc_set_md_var(tc, "descr", "cfg_parse_buffer"); +} +ATF_TC_BODY(parse_buffer, tc) { + isc_result_t result; + unsigned char text[] = "options\n{\nrecursion yes;\n};\n"; + isc_buffer_t buf1, buf2; + cfg_parser_t *p1 = NULL, *p2 = NULL; + cfg_obj_t *c1 = NULL, *c2 = NULL; + + UNUSED(tc); + + setup(); + + isc_buffer_init(&buf1, &text[0], sizeof(text) - 1); + isc_buffer_add(&buf1, sizeof(text) - 1); + + /* Parse with default line numbering */ + result = cfg_parser_create(mctx, lctx, &p1); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + + result = cfg_parse_buffer3(p1, &buf1, "text1", 0, + &cfg_type_namedconf, &c1); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + ATF_REQUIRE_EQ(p1->line, 5); + + isc_buffer_init(&buf2, &text[0], sizeof(text) - 1); + isc_buffer_add(&buf2, sizeof(text) - 1); + + /* Parse with changed line number */ + result = cfg_parser_create(mctx, lctx, &p2); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + + result = cfg_parse_buffer3(p2, &buf2, "text2", 100, + &cfg_type_namedconf, &c2); + ATF_REQUIRE_EQ(result, ISC_R_SUCCESS); + ATF_REQUIRE_EQ(p2->line, 104); + + cfg_obj_destroy(p1, &c1); + cfg_obj_destroy(p2, &c2); + + cfg_parser_destroy(&p1); + cfg_parser_destroy(&p2); + + cleanup(); +} + +ATF_TC(cfg_map_firstclause); +ATF_TC_HEAD(cfg_map_firstclause, tc) { + atf_tc_set_md_var(tc, "descr", "cfg_map_firstclause"); +} +ATF_TC_BODY(cfg_map_firstclause, tc) { + const char *name = NULL; + const void *clauses = NULL; + unsigned int idx; + + UNUSED(tc); + + name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx); + ATF_CHECK(name != NULL); + ATF_CHECK(clauses != NULL); + ATF_CHECK_EQ(idx, 0); +} + +ATF_TC(cfg_map_nextclause); +ATF_TC_HEAD(cfg_map_nextclause, tc) { + atf_tc_set_md_var(tc, "descr", "cfg_map_firstclause"); +} +ATF_TC_BODY(cfg_map_nextclause, tc) { + const char *name = NULL; + const void *clauses = NULL; + unsigned int idx; + + UNUSED(tc); + + name = cfg_map_firstclause(&cfg_type_zoneopts, &clauses, &idx); + ATF_REQUIRE(name != NULL); + ATF_REQUIRE(clauses != NULL); + ATF_REQUIRE_EQ(idx, ISC_R_SUCCESS); + + do { + name = cfg_map_nextclause(&cfg_type_zoneopts, &clauses, &idx); + if (name != NULL) { + ATF_CHECK(clauses != NULL); + } else { + ATF_CHECK_EQ(clauses, NULL); + ATF_CHECK_EQ(idx, 0); + } + } while (name != NULL); +} + +/* + * Main + */ +ATF_TP_ADD_TCS(tp) { + ATF_TP_ADD_TC(tp, parse_buffer); + ATF_TP_ADD_TC(tp, cfg_map_firstclause); + ATF_TP_ADD_TC(tp, cfg_map_nextclause); + return (atf_no_error()); +} -- cgit v1.2.3