[master] add cfg_parse_buffer3() function with linenum parameter
4482. [cleanup] Change #4455 was incomplete. [RT #43252]
This commit is contained in:
5
lib/isccfg/tests/Atffile
Normal file
5
lib/isccfg/tests/Atffile
Normal file
@@ -0,0 +1,5 @@
|
||||
Content-Type: application/X-atf-atffile; version="1"
|
||||
|
||||
prop: test-suite = bind9
|
||||
|
||||
tp-glob: *_test
|
||||
51
lib/isccfg/tests/Makefile.in
Normal file
51
lib/isccfg/tests/Makefile.in
Normal file
@@ -0,0 +1,51 @@
|
||||
# Copyright (C) 2016 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/.
|
||||
|
||||
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_srcdir}/unit/unittest.sh
|
||||
|
||||
clean distclean::
|
||||
rm -f ${TARGETS}
|
||||
rm -f atf.out
|
||||
143
lib/isccfg/tests/parser_test.c
Normal file
143
lib/isccfg/tests/parser_test.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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/.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <isc/buffer.h>
|
||||
#include <isc/lex.h>
|
||||
#include <isc/log.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <isccfg/cfg.h>
|
||||
#include <isccfg/grammar.h>
|
||||
#include <isccfg/namedconf.h>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, parse_buffer);
|
||||
return (atf_no_error());
|
||||
}
|
||||
Reference in New Issue
Block a user