t_rbt.c revision 5f0e2c8913fed44e1629f1367ce54e74ce2a2eb3
/*
* Copyright (C) 1998, 1999 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <dns/fixedname.h>
#define BUFLEN 1024
#define DNSNAMELEN 255
char *progname;
char *firstname, char *firstorigin,
char *nextname, char *nextorigin,
char *prevname, char *prevorigin,
char *lastname, char *lastorigin);
/* parts adapted from the original rbt_test.c */
static int
char *name;
return(0);
return(1);
}
else {
}
}
static char *
}
static char *
}
#ifdef NEED_PRINT_DATA
static dns_result_t
print_data(void *data) {
char *buffer[DNSNAMELEN];
if (dns_result != DNS_R_SUCCESS) {
t_info("dns_name_totext failed %s\n",
}
return(dns_result);
}
#endif /* NEED_PRINT_DATA */
static int
int nfails;
int length;
nfails = 0;
if (s && *s) {
/*
* The buffer for the actual name will immediately follow the
* name structure.
*/
t_info("isc_mem_get failed\n");
++nfails;
}
if (result != DNS_R_SUCCESS) {
++nfails;
t_info("dns_name_fromtext(%s) failed %s\n",
s, dns_result_totext(result));
}
}
else {
++nfails;
t_info("create_name: empty name\n");
}
return(nfails);
}
static void
}
/* adapted from the original rbt_test.c */
static int
int nprobs;
nprobs = 0;
if (name && dns_result) {
if (*dns_result == DNS_R_SUCCESS) {
}
else {
++nprobs;
}
}
else {
++nprobs;
}
return(nprobs);
}
static int
int nprobs;
nprobs = 0;
if (name && dns_result) {
if (*dns_result == DNS_R_SUCCESS) {
}
else {
++nprobs;
}
}
else {
++nprobs;
}
return(nprobs);
}
static int
int nprobs;
void *data;
nprobs = 0;
if (name && dns_result) {
if (*dns_result == DNS_R_SUCCESS) {
dns_foundname, &data);
}
else {
++nprobs;
}
}
else {
++nprobs;
}
return(nprobs);
}
/* initialize a database from filename */
static int
int rval;
char *p;
return(1);
}
if (dns_result != DNS_R_SUCCESS) {
t_info("dns_rbt_create failed %s\n",
return(1);
}
/* skip any comment lines */
if ((*p == '#') || (*p == '\0') || (*p == ' ')) {
free(p);
continue;
}
if (T_debug)
t_info("adding name %s to the rbt\n", p);
t_info("add of %s failed\n", p);
return(1);
}
(void) free(p);
}
return(0);
}
static int
int rval;
int result;
if (isc_result != ISC_R_SUCCESS) {
t_info("isc_mem_create: %s: exiting\n",
return(T_UNRESOLVED);
}
return(result);
}
/* now try the database command */
}
if (rval == 0) {
if (dns_result == exp_result) {
if (rval == 0) {
if (dns_result == DNS_R_SUCCESS) {
}
else {
t_info("dns_rbt_addname didn't "
"add the name");
}
}
}
else {
t_info("add returned %s, expected %s\n",
}
}
}
if (rval == 0) {
if (dns_result == exp_result) {
if (rval == 0) {
if (dns_result == DNS_R_SUCCESS) {
t_info("dns_rbt_deletename didn't "
"delete the name");
}
else {
}
}
}
else {
t_info("delete returned %s, expected %s\n",
}
}
}
if (rval == 0) {
if (dns_result == exp_result) {
}
else {
t_info("find returned %s, expected %s\n",
}
}
}
return(result);
}
static int
test_dns_rbt_x(char *filename) {
char *p;
int line;
int cnt;
int result;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
line = 0;
++line;
/* skip comment lines */
if ((isspace((int)*p)) || (*p == '#'))
continue;
/* name of db file, command, testname, expected result */
if (cnt == 4) {
Tokens[0],
Tokens[1],
Tokens[2],
++nfails;
}
else {
t_info("bad format in %s at line %d\n",
++nprobs;
}
(void) free(p);
}
}
else {
++nprobs;
}
else if (nfails)
return(result);
}
static char *a1 = "dns_rbt_create creates a rbt and returns DNS_R_SUCCESS "
"on success";
static void
t1() {
int result;
}
static char *a2 = "dns_rbt_addname adds a name to a database and returns "
"DNS_R_SUCCESS on success";
static void
t2() {
int result;
}
static char *a3 = "when name already exists, dns_rbt_addname() returns "
"DNS_R_EXISTS";
static void
t3() {
int result;
}
static char *a4 = "when name exists, dns_rbt_deletename() returns "
"DNS_R_SUCCESS";
static void
t4() {
int result;
}
static char *a5 = "when name does not exist, dns_rbt_deletename() returns "
"DNS_R_NOTFOUND";
static void
t5() {
int result;
}
static char *a6 = "when name exists and exactly matches the search name, "
"dns_rbt_findname() returns DNS_R_SUCCESS";
static void
t6() {
int result;
}
static char *a7 = "when a name does not exist, "
"dns_rbt_findname returns DNS_R_NOTFOUND";
static void
t7() {
int result;
}
static char *a8 = "when a superdomain is found with data matching name, "
"dns_rbt_findname returns DNS_R_PARTIALMATCH";
static void
t8() {
int result;
}
static char *a9 = "a call to dns_rbtnodechain_init(chain, mctx) "
"initializes chain";
static int
int cnt;
int order;
unsigned int nlabels;
unsigned int nbits;
int nprobs;
cnt = 0;
nprobs = 0;
while (1) {
if (cnt == 0) {
if (dns_result != DNS_R_NEWORIGIN) {
t_info("dns_rbtnodechain_first returned %s, "
"expecting DNS_R_NEWORIGIN\n",
++nprobs;
break;
}
}
else {
NULL);
if (dns_result != DNS_R_SUCCESS) {
t_info("dns_name_concatenate failed %s\n",
++nprobs;
break;
}
/* expecting origin not to get touched if next doesn't return NEWORIGIN */
if (dns_result != DNS_R_NOMORE) {
t_info("dns_rbtnodechain_next failed %s\n",
++nprobs;
}
break;
}
NULL);
if (dns_result != DNS_R_SUCCESS) {
++nprobs;
break;
}
if (order >= 0) {
t_info("unexpected order %s %s %s\n",
++nprobs;
}
}
++cnt;
}
return(nprobs);
}
/* test by exercising the first|last|next|prev funcs in useful ways */
static int
int nfails;
nfails = 0;
t_info("\texpected name of %s, got %s\n",
++nfails;
}
if (exp_origin != NULL) {
t_info("checking for DNS_R_NEWORIGIN\n");
if (dns_result == DNS_R_NEWORIGIN) {
t_info("\tnew origin %s, expected %s\n",
++nfails;
}
}
else {
++nfails;
}
}
return(nfails);
}
static int
char *nextname, char *nextorigin,
char *prevname, char *prevorigin,
char *firstname, char *firstorigin,
char *lastname, char *lastorigin) {
int result;
int len;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
if (isc_result != ISC_R_SUCCESS) {
return(result);
}
return(result);
}
if (dns_result != DNS_R_SUCCESS) {
return(result);
}
/* set the starting node */
if (dns_result != DNS_R_SUCCESS) {
return(result);
}
/* check next */
t_info("checking for next name of %s and new origin of %s\n",
t_info("dns_rbtnodechain_next unexpectedly returned %s\n",
}
/* set the starting node again */
if (dns_result != DNS_R_SUCCESS) {
return(result);
}
/* check previous */
t_info("checking for previous name of %s and new origin of %s\n",
t_info("dns_rbtnodechain_prev unexpectedly returned %s\n",
}
/* check first */
t_info("checking for first name of %s and new origin of %s\n",
if (dns_result != DNS_R_NEWORIGIN) {
t_info("dns_rbtnodechain_first unexpectedly returned %s\n",
}
/* check last */
if (dns_result != DNS_R_NEWORIGIN) {
t_info("dns_rbtnodechain_last unexpectedly returned %s\n",
}
/* check node ordering */
t_info("checking node ordering\n");
if (nfails)
else
return(result);
}
static int
test_dns_rbtnodechain_init(char *filename) {
char *p;
int line;
int cnt;
int result;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
line = 0;
++line;
/* skip comment lines */
if ((isspace((int)*p)) || (*p == '#'))
continue;
if (cnt == 10) {
Tokens[0], /* dbfile */
++nfails;
else
++nprobs;
}
}
else {
t_info("bad format in %s at line %d\n",
++nprobs;
}
(void) free(p);
}
}
else {
++nprobs;
}
else if (nfails)
return(result);
}
static void
t9() {
int result;
}
static int
char *expected_firstorigin,
char *expected_nextname,
char *expected_nextorigin) {
int result;
int nfails;
nfails = 0;
if (isc_result != ISC_R_SUCCESS) {
return(result);
}
return(result);
}
t_info("testing for first name of %s, origin of %s\n",
if (dns_result != DNS_R_NEWORIGIN) {
t_info("dns_rbtnodechain_first unexpectedly returned %s\n",
}
t_info("testing for next name of %s, origin of %s\n",
t_info("dns_rbtnodechain_next unexpectedly returned %s\n",
}
if (nfails)
else
return(result);
}
static int
test_dns_rbtnodechain_first(char *filename) {
char *p;
int line;
int cnt;
int result;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
line = 0;
++line;
/* skip comment lines */
if ((isspace((int)*p)) || (*p == '#'))
continue;
if (cnt == 5) {
Tokens[0], /* dbfile */
++nfails;
else
++nprobs;
}
}
else {
t_info("bad format in %s at line %d\n",
++nprobs;
}
(void) free(p);
}
}
else {
++nprobs;
}
else if (nfails)
return(result);
}
static char *a10 = "a call to dns_rbtnodechain_first(chain, rbt, name, origin) "
"sets name to point to the root of the tree, "
"origin to point to the origin, "
" and returns DNS_R_NEWORIGIN";
static void
t10() {
int result;
}
static int
char *expected_lastorigin,
char *expected_prevname,
char *expected_prevorigin) {
int result;
int nfails;
nfails = 0;
if (isc_result != ISC_R_SUCCESS) {
return(result);
}
return(result);
}
if (dns_result != DNS_R_NEWORIGIN) {
t_info("dns_rbtnodechain_last unexpectedly returned %s\n",
}
t_info("dns_rbtnodechain_prev unexpectedly returned %s\n",
}
if (nfails)
else
return(result);
}
static int
test_dns_rbtnodechain_last(char *filename) {
char *p;
int line;
int cnt;
int result;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
line = 0;
++line;
/* skip comment lines */
if ((isspace((int)*p)) || (*p == '#'))
continue;
if (cnt == 5) {
Tokens[0], /* dbfile */
++nfails;
else
++nprobs;
}
}
else {
t_info("bad format in %s at line %d\n",
++nprobs;
}
(void) free(p);
}
}
else {
++nprobs;
}
else if (nfails)
return(result);
}
static char *a11 = "a call to dns_rbtnodechain_last(chain, rbt, name, origin) "
"sets name to point to the last node of the megatree, "
"origin to the name of the level above it, "
"and returns DNS_R_NEWORIGIN";
static void
t11() {
int result;
}
static int
char *nextname, char *nextorigin) {
int result;
int len;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
if (isc_result != ISC_R_SUCCESS) {
return(result);
}
return(result);
}
if (dns_result != DNS_R_SUCCESS) {
return(result);
}
/* set the starting node */
if (dns_result != DNS_R_SUCCESS) {
return(result);
}
/* check next */
t_info("checking for next name of %s and new origin of %s\n",
t_info("dns_rbtnodechain_next unexpectedly returned %s\n",
}
if (nfails)
else
return(result);
}
static int
test_dns_rbtnodechain_next(char *filename) {
char *p;
int line;
int cnt;
int result;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
line = 0;
++line;
/* skip comment lines */
if ((isspace((int)*p)) || (*p == '#'))
continue;
if (cnt == 4) {
Tokens[0], /* dbfile */
++nfails;
else
++nprobs;
}
}
else {
t_info("bad format in %s at line %d\n",
++nprobs;
}
(void) free(p);
}
}
else {
++nprobs;
}
else if (nfails)
return(result);
}
static char *a12 = "a call to dns_rbtnodechain_next(chain, name, origin) "
"sets name to point to the next node of the tree "
"and returns DNS_R_SUCCESS or DNS_R_NEWORIGIN on success";
static void
t12() {
int result;
}
static int
char *prevname, char *prevorigin) {
int result;
int len;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
if (isc_result != ISC_R_SUCCESS) {
return(result);
}
return(result);
}
if (dns_result != DNS_R_SUCCESS) {
return(result);
}
/* set the starting node */
if (dns_result != DNS_R_SUCCESS) {
return(result);
}
/* check next */
t_info("checking for next name of %s and new origin of %s\n",
t_info("dns_rbtnodechain_prev unexpectedly returned %s\n",
}
if (nfails)
else
return(result);
}
static int
test_dns_rbtnodechain_prev(char *filename) {
char *p;
int line;
int cnt;
int result;
int nfails;
int nprobs;
nfails = 0;
nprobs = 0;
line = 0;
++line;
/* skip comment lines */
if ((isspace((int)*p)) || (*p == '#'))
continue;
if (cnt == 4) {
Tokens[0], /* dbfile */
++nfails;
else
++nprobs;
}
}
else {
t_info("bad format in %s at line %d\n",
++nprobs;
}
(void) free(p);
}
}
else {
++nprobs;
}
else if (nfails)
return(result);
}
static char *a13 = "a call to dns_rbtnodechain_prev(chain, name, origin) "
"sets name to point to the previous node of the tree "
"and returns DNS_R_SUCCESS or DNS_R_NEWORIGIN on success";
static void
t13() {
int result;
}
testspec_t T_testlist[] = {
{ t1, "dns_rbt_create" },
{ t2, "dns_rbt_addname 1" },
{ t3, "dns_rbt_addname 2" },
{ t4, "dns_rbt_deletename 1" },
{ t5, "dns_rbt_deletename 2" },
{ t6, "dns_rbt_findname 1" },
{ t7, "dns_rbt_findname 2" },
{ t8, "dns_rbt_findname 3" },
{ t9, "dns_rbtnodechain_init" },
{ t10, "dns_rbtnodechain_first" },
{ t11, "dns_rbtnodechain_last" },
{ t12, "dns_rbtnodechain_next" },
{ t13, "dns_rbtnodechain_prev" },
};