⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_rbt.c

📁 package of develop dns
💻 C
📖 第 1 页 / 共 3 页
字号:
	dns_fixedname_t	origin;	dns_fixedname_t	fullname1;	dns_fixedname_t	fullname2;	cnt = 0;	nprobs = 0;	do {		if (cnt == 0) {			dns_fixedname_init(&name);			dns_fixedname_init(&origin);			dns_result = dns_rbtnodechain_first(chain, rbt,						dns_fixedname_name(&name),						dns_fixedname_name(&origin));			if (dns_result != DNS_R_NEWORIGIN) {				t_info("dns_rbtnodechain_first returned %s, "				       "expecting DNS_R_NEWORIGIN\n",				       dns_result_totext(dns_result));				++nprobs;				break;			}			t_info("first name:\t<%s>\n", fixedname_totext(&name));			t_info("first origin:\t<%s>\n",			       fixedname_totext(&origin));		} else {			dns_fixedname_init(&fullname1);			dns_result = dns_name_concatenate(			       dns_fixedname_name(&name),			       dns_name_isabsolute(dns_fixedname_name(&name)) ?					    NULL : dns_fixedname_name(&origin),			       dns_fixedname_name(&fullname1), NULL);			if (dns_result != ISC_R_SUCCESS) {				t_info("dns_name_concatenate failed %s\n",				       dns_result_totext(dns_result));				++nprobs;				break;			}			/*			 * Expecting origin not to get touched if next			 * doesn't return NEWORIGIN.			 */			dns_fixedname_init(&name);			dns_result = dns_rbtnodechain_next(chain,						  dns_fixedname_name(&name),						  dns_fixedname_name(&origin));			if ((dns_result != ISC_R_SUCCESS) &&			    (dns_result != DNS_R_NEWORIGIN)) {				if (dns_result != ISC_R_NOMORE) {					t_info("dns_rbtnodechain_next "					       "failed %s\n",					       dns_result_totext(dns_result));					++nprobs;				}				break;			}			t_info("next name:\t<%s>\n", fixedname_totext(&name));			t_info("next origin:\t<%s>\n",			       fixedname_totext(&origin));			dns_fixedname_init(&fullname2);			dns_result = dns_name_concatenate(			       dns_fixedname_name(&name),			       dns_name_isabsolute(dns_fixedname_name(&name)) ?			                    NULL : dns_fixedname_name(&origin),			       dns_fixedname_name(&fullname2), NULL);			if (dns_result != ISC_R_SUCCESS) {				t_info("dns_name_concatenate failed %s\n",				       dns_result_totext(dns_result));				++nprobs;				break;			}			t_info("comparing\t<%s>\n",			       fixedname_totext(&fullname1));			t_info("\twith\t<%s>\n", fixedname_totext(&fullname2));			(void)dns_name_fullcompare(						dns_fixedname_name(&fullname1),						dns_fixedname_name(&fullname2),						&order, &nlabels);			if (order >= 0) {			    t_info("unexpected order %s %s %s\n",			       dnsname_totext(dns_fixedname_name(&fullname1)),			       order == -1 ? "<" : (order == 0 ? "==" : ">"),			       dnsname_totext(dns_fixedname_name(&fullname2)));				++nprobs;			}		}		++cnt;	} while (1);	return (nprobs);}/* * Test by exercising the first|last|next|prev funcs in useful ways. */static intt_namechk(isc_result_t dns_result, dns_fixedname_t *dns_name, char *exp_name,	  dns_fixedname_t *dns_origin, char *exp_origin,	  isc_result_t exp_result){	int	nfails;	nfails = 0;	if (fixedname_cmp(dns_name, exp_name)) {		t_info("\texpected name of %s, got %s\n",				exp_name, fixedname_totext(dns_name));		++nfails;	}	if (exp_origin != NULL) {		t_info("checking for DNS_R_NEWORIGIN\n");		if (dns_result == exp_result) {			if (fixedname_cmp(dns_origin, exp_origin)) {				t_info("\torigin %s, expected %s\n",				       fixedname_totext(dns_origin),				       exp_origin);				++nfails;			}		} else {			t_info("\tgot %s\n", dns_result_totext(dns_result));			++nfails;		}	}	return(nfails);}static intt_dns_rbtnodechain_init(char *dbfile, char *findname,			char *nextname, char *nextorigin,			char *prevname, char *prevorigin,			char *firstname, char *firstorigin,			char *lastname, char *lastorigin){	int			result;	int			len;	int			nfails;	dns_rbt_t		*rbt;	dns_rbtnode_t		*node;	dns_rbtnodechain_t	chain;	isc_mem_t		*mctx;	isc_entropy_t		*ectx;	isc_result_t		isc_result;	isc_result_t		dns_result;	dns_fixedname_t		dns_findname;	dns_fixedname_t		dns_foundname;	dns_fixedname_t		dns_firstname;	dns_fixedname_t		dns_lastname;	dns_fixedname_t		dns_prevname;	dns_fixedname_t		dns_nextname;	dns_fixedname_t		dns_origin;	isc_buffer_t		isc_buffer;	result = T_UNRESOLVED;	nfails = 0;	mctx = NULL;	ectx = NULL;	isc_result = isc_mem_create(0, 0, &mctx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mem_create failed %s\n",		       isc_result_totext(isc_result));		return(result);	}	isc_result = isc_entropy_create(mctx, &ectx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_entropy_create: %s: exiting\n",		       dns_result_totext(isc_result));		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	isc_result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_hash_create: %s: exiting\n",		       dns_result_totext(isc_result));		isc_entropy_detach(&ectx);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	dns_rbtnodechain_init(&chain, mctx);	rbt = NULL;	if (rbt_init(dbfile, &rbt, mctx)) {		t_info("rbt_init %s failed\n", dbfile);		isc_hash_destroy();		isc_entropy_detach(&ectx);		isc_mem_destroy(&mctx);		return(result);	}	len = strlen(findname);	isc_buffer_init(&isc_buffer, findname, len);	isc_buffer_add(&isc_buffer, len);	dns_fixedname_init(&dns_foundname);	dns_fixedname_init(&dns_findname);	dns_fixedname_init(&dns_firstname);	dns_fixedname_init(&dns_origin);	dns_fixedname_init(&dns_lastname);	dns_fixedname_init(&dns_prevname);	dns_fixedname_init(&dns_nextname);	dns_result = dns_name_fromtext(dns_fixedname_name(&dns_findname),					&isc_buffer, NULL, ISC_FALSE, NULL);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_name_fromtext failed %s\n",		       dns_result_totext(dns_result));		return(result);	}	/*	 * Set the starting node.	 */	node = NULL;	dns_result = dns_rbt_findnode(rbt, dns_fixedname_name(&dns_findname),				      dns_fixedname_name(&dns_foundname),				      &node, &chain, DNS_RBTFIND_EMPTYDATA,				      NULL, NULL);	if (dns_result != ISC_R_SUCCESS) {		t_info("dns_rbt_findnode failed %s\n",		       dns_result_totext(dns_result));		return(result);	}	/*	 * Check next.	 */	t_info("checking for next name of %s and new origin of %s\n",	       nextname, nextorigin);	dns_result = dns_rbtnodechain_next(&chain,					   dns_fixedname_name(&dns_nextname),					   dns_fixedname_name(&dns_origin));	if ((dns_result != ISC_R_SUCCESS) &&	    (dns_result != DNS_R_NEWORIGIN)) {		t_info("dns_rbtnodechain_next unexpectedly returned %s\n",		       dns_result_totext(dns_result));	}	nfails += t_namechk(dns_result, &dns_nextname, nextname, &dns_origin,			    nextorigin, DNS_R_NEWORIGIN);	/*	 * Set the starting node again.	 */	node = NULL;	dns_fixedname_init(&dns_foundname);	dns_result = dns_rbt_findnode(rbt, dns_fixedname_name(&dns_findname),				      dns_fixedname_name(&dns_foundname),				      &node, &chain, DNS_RBTFIND_EMPTYDATA,				      NULL, NULL);	if (dns_result != ISC_R_SUCCESS) {		t_info("\tdns_rbt_findnode failed %s\n",		       dns_result_totext(dns_result));		return(result);	}	/*	 * Check previous.	 */	t_info("checking for previous name of %s and new origin of %s\n",	       prevname, prevorigin);	dns_fixedname_init(&dns_origin);	dns_result = dns_rbtnodechain_prev(&chain,					   dns_fixedname_name(&dns_prevname),					   dns_fixedname_name(&dns_origin));	if ((dns_result != ISC_R_SUCCESS) &&	    (dns_result != DNS_R_NEWORIGIN)) {		t_info("dns_rbtnodechain_prev unexpectedly returned %s\n",		       dns_result_totext(dns_result));	}	nfails += t_namechk(dns_result, &dns_prevname, prevname, &dns_origin,			    prevorigin, DNS_R_NEWORIGIN);	/*	 * Check first.	 */	t_info("checking for first name of %s and new origin of %s\n",	       firstname, firstorigin);	dns_result = dns_rbtnodechain_first(&chain, rbt,					    dns_fixedname_name(&dns_firstname),					    dns_fixedname_name(&dns_origin));	if (dns_result != DNS_R_NEWORIGIN) {		t_info("dns_rbtnodechain_first unexpectedly returned %s\n",		       dns_result_totext(dns_result));	}	nfails += t_namechk(dns_result, &dns_firstname, firstname,			    &dns_origin, firstorigin, DNS_R_NEWORIGIN);	/*	 * Check last.	 */	t_info("checking for last name of %s\n", lastname);	dns_result = dns_rbtnodechain_last(&chain, rbt,					   dns_fixedname_name(&dns_lastname),					   dns_fixedname_name(&dns_origin));	if (dns_result != DNS_R_NEWORIGIN) {		t_info("dns_rbtnodechain_last unexpectedly returned %s\n",		       dns_result_totext(dns_result));	}	nfails += t_namechk(dns_result, &dns_lastname, lastname, &dns_origin,			    lastorigin, DNS_R_NEWORIGIN);	/*	 * Check node ordering.	 */	t_info("checking node ordering\n");	nfails += t9_walkchain(&chain, rbt);	if (nfails)		result = T_FAIL;	else		result = T_PASS;	dns_rbtnodechain_invalidate(&chain);	dns_rbt_destroy(&rbt);	isc_hash_destroy();	isc_entropy_detach(&ectx);	isc_mem_destroy(&mctx);	return(result);}static inttest_dns_rbtnodechain_init(const char *filename) {	FILE		*fp;	char		*p;	int		line;	int		cnt;	int		result;	int		nfails;	int		nprobs;	nfails = 0;	nprobs = 0;	fp = fopen(filename, "r");	if (fp != NULL) {		line = 0;		while ((p = t_fgetbs(fp)) != NULL) {			++line;			/*			 * Skip comment lines.			 */			if ((isspace((unsigned char)*p)) || (*p == '#'))				continue;			cnt = t_bustline(p, Tokens);			if (cnt == 10) {				result = t_dns_rbtnodechain_init(						Tokens[0],  /* dbfile */						Tokens[1],  /* startname */						Tokens[2],  /* nextname */						Tokens[3],  /* nextorigin */						Tokens[4],  /* prevname */						Tokens[5],  /* prevorigin */						Tokens[6],  /* firstname */						Tokens[7],  /* firstorigin */						Tokens[8],  /* lastname */						Tokens[9]); /* lastorigin */				if (result != T_PASS) {					if (result == T_FAIL)						++nfails;					else						++nprobs;				}			} else {				t_info("bad format in %s at line %d\n",						filename, line);				++nprobs;			}			(void)free(p);		}		(void)fclose(fp);	} else {		t_info("Missing datafile %s\n", filename);		++nprobs;	}	result = T_UNRESOLVED;	if ((nfails == 0) && (nprobs == 0))		result = T_PASS;	else if (nfails)		result = T_FAIL;	return(result);}static voidt9() {	int	result;	t_assert("dns_rbtnodechain_init", 9, T_REQUIRED, a9);	result = test_dns_rbtnodechain_init("dns_rbtnodechain_init_data");	t_result(result);}static intt_dns_rbtnodechain_first(char *dbfile, char *expected_firstname,				char *expected_firstorigin,				char *expected_nextname,				char *expected_nextorigin){	int			result;	int			nfails;	dns_rbt_t		*rbt;	dns_rbtnodechain_t	chain;	isc_mem_t		*mctx;	isc_entropy_t		*ectx;	isc_result_t		isc_result;	isc_result_t		dns_result;	dns_fixedname_t		dns_name;	dns_fixedname_t		dns_origin;	isc_result_t		expected_result;	result = T_UNRESOLVED;	nfails = 0;	mctx = NULL;	ectx = NULL;	dns_fixedname_init(&dns_name);	dns_fixedname_init(&dns_origin);	isc_result = isc_mem_create(0, 0, &mctx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_mem_create failed %s\n",		       isc_result_totext(isc_result));		return(result);	}	isc_result = isc_entropy_create(mctx, &ectx);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_entropy_create: %s: exiting\n",		       dns_result_totext(isc_result));		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	isc_result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);	if (isc_result != ISC_R_SUCCESS) {		t_info("isc_hash_create: %s: exiting\n",		       dns_result_totext(isc_result));		isc_entropy_detach(&ectx);		isc_mem_destroy(&mctx);		return(T_UNRESOLVED);	}	dns_rbtnodechain_init(&chain, mctx);	rbt = NULL;	if (rbt_init(dbfile, &rbt, mctx)) {		t_info("rbt_init %s failed\n", dbfile);		isc_hash_destroy();		isc_entropy_detach(&ectx);		isc_mem_destroy(&mctx);		return(result);	}	t_info("testing for first name of %s, origin of %s\n",	       expected_firstname, expected_firstorigin);	dns_result = dns_rbtnodechain_first(&chain, rbt,					    dns_fixedname_name(&dns_name),					    dns_fixedname_name(&dns_origin));	if (dns_result != DNS_R_NEWORIGIN)		t_info("dns_rbtnodechain_first unexpectedly returned %s\n",		       dns_result_totext(dns_result));	nfails = t_namechk(dns_result, &dns_name, expected_firstname,			   &dns_origin, expected_firstorigin, DNS_R_NEWORIGIN);	dns_fixedname_init(&dns_name);	dns_result = dns_rbtnodechain_next(&chain,			dns_fixedname_name(&dns_name),			dns_fixedname_name(&dns_origin));	t_info("testing for next name of %s, origin of %s\n",			expected_nextname, expected_nextorigin);	if ((dns_result != ISC_R_SUCCESS) && (dns_result != DNS_R_NEWORIGIN))		t_info("dns_rbtnodechain_next unexpectedly returned %s\n",		       dns_result_totext(dns_result));	if (strcasecmp(expected_firstorigin, expected_nextorigin) == 0)		expected_result = ISC_R_SUCCESS;	else		expected_result = DNS_R_NEWORIGIN;	nfails += t_namechk(dns_result, &dns_name, expected_nextname,			    &dns_origin, expected_nextorigin, expected_result);	if (nfails)		result = T_FAIL;	else		result = T_PASS;	dns_rbtnodechain_invalidate(&chain);	dns_rbt_destroy(&rbt);	isc_hash_destroy();	isc_entropy_detach(&ectx);	isc_mem_destroy(&mctx);	return(result);}static inttest_dns_rbtnodechain_first(const char *filename) {	FILE		*fp;	char		*p;	int		line;	int		cnt;	int		result;	int		nfails;	int		nprobs;	nfails = 0;	nprobs = 0;	fp = fopen(filename, "r");	if (fp != NULL) {		line = 0;		while ((p = t_fgetbs(fp)) != NULL) {			++line;			/*			 * Skip comment lines.			 */			if ((isspace((unsigned char)*p)) || (*p == '#'))				continue;			cnt = t_bustline(p, Tokens);			if (cnt == 5) {				result = t_dns_rbtnodechain_first(						Tokens[0],  /* dbfile */						Tokens[1],  /* firstname */						Tokens[2],  /* firstorigin */						Tokens[3],  /* nextname */						Tokens[4]); /* nextorigin */				if (result != T_PASS) {					if (result == T_FAIL)						++nfails;					else						++nprobs;				}			} else {				t_info("bad format in %s at line %d\n",						filename, line);				++nprobs;			}			(void)free(p);		}		(void)fclose(fp);	} else {		t_info("Missing datafile %s\n", filename);		++nprobs;	}	result = T_UNRESOLVED;	if ((nfails == 0) && (nprobs == 0))		result = T_PASS;	else if (nfails)		result = T_FAIL;	return(result);}static const 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 voidt10() {	int	result;	t_assert("dns_rbtnodechain_first", 10, T_REQUIRED, a10);	result = test_dns_rbtnodechain_first("dns_rbtnodechain_first_data");	t_result(result);}static intt_dns_rbtnodechain_last(char *dbfile, char *expected_lastname,			char *expected_lastorigin,			char *expected_prevname,			char *expected_prevorigin){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -