161e803a5608956271d8120be37a1b383d14b647Mark Andrews/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2013, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
161e803a5608956271d8120be37a1b383d14b647Mark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
161e803a5608956271d8120be37a1b383d14b647Mark Andrews */
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews/* $Id$ */
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews/*! \file */
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include <config.h>
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include <atf-c.h>
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include <unistd.h>
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include <stdlib.h>
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include <dns/db.h>
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include <dns/dbiterator.h>
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include <dns/name.h>
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include <dns/journal.h>
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#include "dnstest.h"
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews/*
161e803a5608956271d8120be37a1b383d14b647Mark Andrews * Helper functions
161e803a5608956271d8120be37a1b383d14b647Mark Andrews */
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#define BUFLEN 255
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#define BIGBUFLEN (64 * 1024)
161e803a5608956271d8120be37a1b383d14b647Mark Andrews#define TEST_ORIGIN "test"
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews/*
161e803a5608956271d8120be37a1b383d14b647Mark Andrews * Individual unit tests
161e803a5608956271d8120be37a1b383d14b647Mark Andrews */
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark AndrewsATF_TC(getoriginnode);
161e803a5608956271d8120be37a1b383d14b647Mark AndrewsATF_TC_HEAD(getoriginnode, tc) {
161e803a5608956271d8120be37a1b383d14b647Mark Andrews atf_tc_set_md_var(tc, "descr",
161e803a5608956271d8120be37a1b383d14b647Mark Andrews "test multiple calls to dns_db_getoriginnode");
161e803a5608956271d8120be37a1b383d14b647Mark Andrews}
161e803a5608956271d8120be37a1b383d14b647Mark AndrewsATF_TC_BODY(getoriginnode, tc) {
161e803a5608956271d8120be37a1b383d14b647Mark Andrews dns_db_t *db = NULL;
161e803a5608956271d8120be37a1b383d14b647Mark Andrews dns_dbnode_t *node = NULL;
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt isc_mem_t *mymctx = NULL;
161e803a5608956271d8120be37a1b383d14b647Mark Andrews isc_result_t result;
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt result = isc_mem_create(0, 0, &mymctx);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt result = isc_hash_create(mymctx, NULL, 256);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt result = dns_db_create(mymctx, "rbt", dns_rootname, dns_dbtype_zone,
161e803a5608956271d8120be37a1b383d14b647Mark Andrews dns_rdataclass_in, 0, NULL, &db);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews result = dns_db_getoriginnode(db, &node);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews dns_db_detachnode(db, &node);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews result = dns_db_getoriginnode(db, &node);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews dns_db_detachnode(db, &node);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews dns_db_detach(&db);
11463c0ac24692e229ec87f307f5e7df3c0a7e10Evan Hunt isc_mem_detach(&mymctx);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews}
161e803a5608956271d8120be37a1b383d14b647Mark Andrews
161e803a5608956271d8120be37a1b383d14b647Mark Andrews/*
161e803a5608956271d8120be37a1b383d14b647Mark Andrews * Main
161e803a5608956271d8120be37a1b383d14b647Mark Andrews */
161e803a5608956271d8120be37a1b383d14b647Mark AndrewsATF_TP_ADD_TCS(tp) {
161e803a5608956271d8120be37a1b383d14b647Mark Andrews ATF_TP_ADD_TC(tp, getoriginnode);
161e803a5608956271d8120be37a1b383d14b647Mark Andrews return (atf_no_error());
161e803a5608956271d8120be37a1b383d14b647Mark Andrews}