mirror of
https://github.com/isc-projects/bind9.git
synced 2026-04-29 09:59:08 -04:00
convert notify_test
This commit is contained in:
parent
318b340f5e
commit
48dc2831d7
3 changed files with 70 additions and 34 deletions
|
|
@ -2,5 +2,5 @@ syntax(2)
|
|||
test_suite('bind9')
|
||||
|
||||
atf_test_program{name='listenlist_test'}
|
||||
atf_test_program{name='notify_test'}
|
||||
tap_test_program{name='notify_test'}
|
||||
tap_test_program{name='query_test'}
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ listenlist_test@EXEEXT@: listenlist_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIB
|
|||
${ISCLIBS} ${LIBS}
|
||||
|
||||
notify_test@EXEEXT@: notify_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
|
||||
notify_test.@O@ nstest.@O@ ${NSLIBS} ${DNSLIBS} \
|
||||
${ISCLIBS} ${LIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
|
||||
${LDFLAGS} -o $@ notify_test.@O@ nstest.@O@ \
|
||||
${NSLIBS} ${DNSLIBS} ${ISCLIBS} ${LIBS} ${CMOCKA_LIBS}
|
||||
|
||||
query_test@EXEEXT@: query_test.@O@ nstest.@O@ ${NSDEPLIBS} ${ISCDEPLIBS} ${DNSDEPLIBS}
|
||||
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${CMOCKA_CFLAGS} \
|
||||
|
|
|
|||
|
|
@ -9,18 +9,26 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#if HAVE_CMOCKA
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define UNIT_TESTING
|
||||
#include <cmocka.h>
|
||||
|
||||
#include <isc/event.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/task.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <dns/acl.h>
|
||||
#include <dns/rcode.h>
|
||||
|
|
@ -31,6 +39,27 @@
|
|||
|
||||
#include "nstest.h"
|
||||
|
||||
static int
|
||||
_setup(void **state) {
|
||||
isc_result_t result;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
result = ns_test_begin(NULL, true);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
_teardown(void **state) {
|
||||
UNUSED(state);
|
||||
|
||||
ns_test_end();
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
check_response(isc_buffer_t *buf) {
|
||||
isc_result_t result;
|
||||
|
|
@ -39,25 +68,23 @@ check_response(isc_buffer_t *buf) {
|
|||
isc_buffer_t b;
|
||||
|
||||
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_message_parse(message, buf, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
isc_buffer_init(&b, rcodebuf, sizeof(rcodebuf));
|
||||
result = dns_rcode_totext(message->rcode, &b);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
ATF_CHECK_EQ(message->rcode, dns_rcode_noerror);
|
||||
assert_int_equal(message->rcode, dns_rcode_noerror);
|
||||
|
||||
dns_message_destroy(&message);
|
||||
}
|
||||
|
||||
ATF_TC(notify_start);
|
||||
ATF_TC_HEAD(notify_start, tc) {
|
||||
atf_tc_set_md_var(tc, "descr", "notify start");
|
||||
}
|
||||
ATF_TC_BODY(notify_start, tc) {
|
||||
/* test ns_notify_start() */
|
||||
static void
|
||||
notify_start(void **state) {
|
||||
isc_result_t result;
|
||||
ns_client_t *client = NULL;
|
||||
dns_message_t *nmsg = NULL;
|
||||
|
|
@ -65,20 +92,17 @@ ATF_TC_BODY(notify_start, tc) {
|
|||
isc_buffer_t nbuf;
|
||||
size_t nsize;
|
||||
|
||||
UNUSED(tc);
|
||||
|
||||
result = ns_test_begin(NULL, true);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
UNUSED(state);
|
||||
|
||||
result = ns_test_getclient(NULL, false, &client);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = ns_test_makeview("view", false, &client->view);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = ns_test_serve_zone("example.com", "testdata/notify/zone1.db",
|
||||
client->view);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Create a NOTIFY message by parsing a file in testdata.
|
||||
|
|
@ -87,15 +111,15 @@ ATF_TC_BODY(notify_start, tc) {
|
|||
|
||||
result = ns_test_getdata("testdata/notify/notify1.msg",
|
||||
ndata, sizeof(ndata), &nsize);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
isc_buffer_init(&nbuf, ndata, nsize);
|
||||
isc_buffer_add(&nbuf, nsize);
|
||||
|
||||
result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &nmsg);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
result = dns_message_parse(nmsg, &nbuf, 0);
|
||||
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
|
||||
assert_int_equal(result, ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Set up client object with this message and test the NOTIFY
|
||||
|
|
@ -115,14 +139,26 @@ ATF_TC_BODY(notify_start, tc) {
|
|||
ns_test_cleanup_zone();
|
||||
|
||||
ns_client_detach(&client);
|
||||
|
||||
ns_test_end();
|
||||
}
|
||||
|
||||
/*
|
||||
* Main
|
||||
*/
|
||||
ATF_TP_ADD_TCS(tp) {
|
||||
ATF_TP_ADD_TC(tp, notify_start);
|
||||
return (atf_no_error());
|
||||
int
|
||||
main(void) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test_setup_teardown(notify_start,
|
||||
_setup, _teardown),
|
||||
};
|
||||
|
||||
return (cmocka_run_group_tests(tests, NULL, NULL));
|
||||
}
|
||||
|
||||
#else /* HAVE_CMOCKA */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(void) {
|
||||
printf("1..0 # Skipped: cmocka not available\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue