1/*
2 * Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17/* $Id$ */
18
19/*! \file */
20
21#include <config.h>
22
23#include <atf-c.h>
24
25#include <unistd.h>
26
27#include <dns/db.h>
28#include <dns/nsec3.h>
29
30#include "dnstest.h"
31
32/*
33 * Helper functions
34 */
35
36static void
37iteration_test(const char* file, unsigned int expected) {
38	isc_result_t result;
39	dns_db_t *db = NULL;
40	unsigned int iterations;
41
42	result = dns_test_begin(NULL, ISC_FALSE);
43	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
44
45	result = dns_test_loaddb(&db, dns_dbtype_zone, "test", file);
46	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
47
48	result = dns_nsec3_maxiterations(db, NULL, mctx, &iterations);
49	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
50
51	ATF_REQUIRE_EQ(iterations, expected);
52
53	dns_db_detach(&db);
54
55	dns_test_end();
56}
57
58/*
59 * Individual unit tests
60 */
61
62ATF_TC(max_iterations);
63ATF_TC_HEAD(max_iterations, tc) {
64	atf_tc_set_md_var(tc, "descr", "check that appropriate max iterations "
65			  " is returned for different key size mixes");
66}
67ATF_TC_BODY(max_iterations, tc) {
68
69	UNUSED(tc);
70
71	iteration_test("testdata/nsec3/1024.db", 150);
72	iteration_test("testdata/nsec3/2048.db", 500);
73	iteration_test("testdata/nsec3/4096.db", 2500);
74	iteration_test("testdata/nsec3/min-1024.db", 150);
75	iteration_test("testdata/nsec3/min-2048.db", 500);
76}
77
78/*
79 * Main
80 */
81ATF_TP_ADD_TCS(tp) {
82	ATF_TP_ADD_TC(tp, max_iterations);
83
84	return (atf_no_error());
85}
86
87