📄 t_names.c
字号:
} else { t_info("bad datafile format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_issubdomain_data\n"); t_result(result); }}static const char *a35 = "dns_name_countlabels(name) returns the number " "of labels in name";static inttest_dns_name_countlabels(char *test_name, unsigned int exp_nlabels) { int result; unsigned int nlabels; isc_result_t dns_result; dns_name_t dns_name; result = T_UNRESOLVED; t_info("testing %s\n", test_name); dns_result = dname_from_tname(test_name, &dns_name); if (dns_result == ISC_R_SUCCESS) { nlabels = dns_name_countlabels(&dns_name); if (nlabels != exp_nlabels) { t_info("expected %d, got %d\n", exp_nlabels, nlabels); result = T_FAIL; } else result = T_PASS; } else { t_info("dname_from_tname failed, result == %s\n", dns_result_totext(dns_result)); } return (result);}static voidt_dns_name_countlabels(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_countlabels", 1, T_REQUIRED, a35); result = T_UNRESOLVED; fp = fopen("dns_name_countlabels_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 2) { /* * name, nlabels. */ result = test_dns_name_countlabels(Tokens[0], atoi(Tokens[1])); } else { t_info("bad format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_countlabels_data\n"); t_result(result); }}static const char *a36 = "when n is less than the number of labels in name, " "dns_name_getlabel(name, n, labelp) initializes labelp " "to point to the nth label in name";/* * The strategy here is two take two dns names with a shared label in * different positions, get the two labels and compare them for equality. * If they don't match, dns_name_getlabel failed. */static inttest_dns_name_getlabel(char *test_name1, int label1_pos, char *test_name2, int label2_pos){ int result; int nfails; unsigned int cnt; unsigned char *p; unsigned char *q; dns_name_t dns_name1; dns_name_t dns_name2; dns_label_t dns_label1; dns_label_t dns_label2; isc_result_t dns_result; nfails = 0; result = T_UNRESOLVED; t_info("testing with %s and %s\n", test_name1, test_name2); dns_result = dname_from_tname(test_name1, &dns_name1); if (dns_result == ISC_R_SUCCESS) { dns_result = dname_from_tname(test_name2, &dns_name2); if (dns_result == ISC_R_SUCCESS) { dns_name_getlabel(&dns_name1, label1_pos, &dns_label1); dns_name_getlabel(&dns_name2, label2_pos, &dns_label2); if (dns_label1.length != dns_label2.length) { t_info("label lengths differ\n"); ++nfails; } p = dns_label1.base; q = dns_label2.base; for (cnt = 0; cnt < dns_label1.length; ++cnt) { if (*p++ != *q++) { t_info("labels differ at position %d", cnt); ++nfails; } } if (nfails == 0) result = T_PASS; else result = T_FAIL; } else { t_info("dname_from_tname failed, result == %s", dns_result_totext(result)); } } else { t_info("dname_from_tname failed, result == %s", dns_result_totext(result)); } return (result);}static voidt_dns_name_getlabel(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_getlabel", 1, T_REQUIRED, a36); result = T_UNRESOLVED; fp = fopen("dns_name_getlabel_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 4) { /* * name1, name2, nlabels. */ result = test_dns_name_getlabel(Tokens[0], atoi(Tokens[1]), Tokens[2], atoi(Tokens[3])); } else { t_info("bad format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_getlabel_data\n"); t_result(result); }}static const char *a37 = "when source contains at least first + n labels, " "dns_name_getlabelsequence(source, first, n, target) " "initializes target to point to the n label sequence of " "labels in source starting with first";/* * We adopt a similiar strategy to that used by the dns_name_getlabel test. */static inttest_dns_name_getlabelsequence(char *test_name1, int label1_start, char *test_name2, int label2_start, int range){ int result; int nfails; unsigned int cnt; unsigned char *p; unsigned char *q; dns_name_t dns_name1; dns_name_t dns_name2; dns_name_t dns_targetname1; dns_name_t dns_targetname2; isc_result_t dns_result; isc_buffer_t buffer1; isc_buffer_t buffer2; unsigned char junk1[BUFLEN]; unsigned char junk2[BUFLEN]; nfails = 0; result = T_UNRESOLVED; dns_result = dname_from_tname(test_name1, &dns_name1); if (dns_result == ISC_R_SUCCESS) { dns_result = dname_from_tname(test_name2, &dns_name2); if (dns_result == ISC_R_SUCCESS) { t_info("testing %s %s\n", test_name1, test_name2); dns_name_init(&dns_targetname1, NULL); dns_name_init(&dns_targetname2, NULL); dns_name_getlabelsequence(&dns_name1, label1_start, range, &dns_targetname1); dns_name_getlabelsequence(&dns_name2, label2_start, range, &dns_targetname2); /* * Now convert both targets to text for comparison. */ isc_buffer_init(&buffer1, junk1, BUFLEN); isc_buffer_init(&buffer2, junk2, BUFLEN); dns_name_totext(&dns_targetname1, ISC_TRUE, &buffer1); dns_name_totext(&dns_targetname2, ISC_TRUE, &buffer2); if (buffer1.used == buffer2.used) { p = buffer1.base; q = buffer2.base; for (cnt = 0; cnt < buffer1.used; ++cnt) { if (*p != *q) { ++nfails; t_info("names differ at %d\n", cnt); break; } ++p; ++q; } } else { ++nfails; t_info("lengths differ\n"); } if (nfails == 0) result = T_PASS; else result = T_FAIL; } else { t_info("dname_from_tname failed, result == %s", dns_result_totext(dns_result)); } } else { t_info("dname_from_tname failed, result == %s", dns_result_totext(dns_result)); } return (result);}static voidt_dns_name_getlabelsequence(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_getlabelsequence", 1, T_REQUIRED, a37); result = T_UNRESOLVED; fp = fopen("dns_name_getlabelsequence_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 5) { /* * name1, name2, nlabels. */ result = test_dns_name_getlabelsequence( Tokens[0], atoi(Tokens[1]), Tokens[2], atoi(Tokens[3]), atoi(Tokens[4])); } else { t_info("bad format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_getlabelsequence_data\n"); t_result(result); }}static const char *a38 = "dns_name_fromregion(name, region) converts a DNS name " "from a region representation to a name representation";static inttest_dns_name_fromregion(char *test_name) { int result; int order; unsigned int nlabels; isc_result_t dns_result; dns_name_t dns_name1; dns_name_t dns_name2; dns_namereln_t dns_namereln; isc_region_t region; result = T_UNRESOLVED; t_info("testing %s\n", test_name); dns_result = dname_from_tname(test_name, &dns_name1); if (dns_result == ISC_R_SUCCESS) { dns_name_toregion(&dns_name1, ®ion); dns_name_init(&dns_name2, NULL); dns_name_fromregion(&dns_name2, ®ion); dns_namereln = dns_name_fullcompare(&dns_name1, &dns_name2, &order, &nlabels); if (dns_namereln == dns_namereln_equal) result = T_PASS; else result = T_FAIL; } else { t_info("dname_from_tname failed, result == %s\n", dns_result_totext(result)); } return (result);}static voidt_dns_name_fromregion(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_fromregion", 1, T_REQUIRED, a38); result = T_UNRESOLVED; fp = fopen("dns_name_fromregion_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 1) { /* * test_name. */ result = test_dns_name_fromregion(Tokens[0]); } else { t_info("bad format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_fromregion_data\n"); t_result(result); }}static const char *a39 = "dns_name_toregion(name, region) converts a DNS name " "from a region representation to a name representation";static voidt_dns_name_toregion(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_toregion", 1, T_REQUIRED, a39); result = T_UNRESOLVED; fp = fopen("dns_name_toregion_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue; cnt = bustline(p, Tokens); if (cnt == 1) { /* * test_name. */ result = test_dns_name_fromregion(Tokens[0]); } else { t_info("bad format at line %d\n", line); } (void)free(p); t_result(result); } (void)fclose(fp); } else { t_info("Missing datafile dns_name_toregion_data\n"); t_result(result); }}static const char *a40 = "dns_name_fromtext(name, source, origin, downcase, target) " "converts the textual representation of a DNS name at source " "into uncompressed wire form at target, appending origin to " "the converted name if origin is non-NULL and converting " "upper case to lower case during conversion " "if downcase is true.";static inttest_dns_name_fromtext(char *test_name1, char *test_name2, char *test_origin, isc_boolean_t downcase){ int result; int order; unsigned int nlabels; unsigned char junk1[BUFLEN]; unsigned char junk2[BUFLEN]; unsigned char junk3[BUFLEN]; isc_buffer_t binbuf1; isc_buffer_t binbuf2; isc_buffer_t binbuf3; isc_buffer_t txtbuf1; isc_buffer_t txtbuf2; isc_buffer_t txtbuf3; dns_name_t dns_name1; dns_name_t dns_name2; dns_name_t dns_name3; isc_result_t dns_result; dns_namereln_t dns_namereln; result = T_UNRESOLVED; t_info("testing %s %s %s\n", test_name1, test_name2, test_origin); isc_buffer_init(&binbuf1, junk1, BUFLEN); isc_buffer_init(&binbuf2, junk2, BUFLEN); isc_buffer_init(&binbuf3, junk3, BUFLEN); isc_buffer_init(&txtbuf1, test_name1, strlen(test_name1)); isc_buffer_add(&txtbuf1, strlen(test_name1)); isc_buffer_init(&txtbuf2, test_name2, strlen(test_name2)); isc_buffer_add(&txtbuf2, strlen(test_name2)); isc_buffer_init(&txtbuf3, test_origin, strlen(test_origin)); isc_buffer_add(&txtbuf3, strlen(test_origin)); dns_name_init(&dns_name1, NULL); dns_name_init(&dns_name2, NULL); dns_name_init(&dns_name3, NULL); dns_name_setbuffer(&dns_name1, &binbuf1); dns_name_setbuffer(&dns_name2, &binbuf2); dns_name_setbuffer(&dns_name3, &binbuf3); dns_result = dns_name_fromtext(&dns_name3, &txtbuf3, NULL, ISC_FALSE, &binbuf3); if (dns_result != ISC_R_SUCCESS) { t_info("dns_name_fromtext(dns_name3) failed, result == %s\n", dns_result_totext(dns_result)); return (T_FAIL); } dns_result = dns_name_fromtext(&dns_name1, &txtbuf1, &dns_name3, downcase, &binbuf1); if (dns_result != ISC_R_SUCCESS) { t_info("dns_name_fromtext(dns_name1) failed, result == %s\n", dns_result_totext(dns_result)); return (T_FAIL); } dns_result = dns_name_fromtext(&dns_name2, &txtbuf2, NULL, ISC_FALSE, &binbuf2); if (dns_result != ISC_R_SUCCESS) { t_info("dns_name_fromtext(dns_name2) failed, result == %s\n", dns_result_totext(dns_result)); return (T_FAIL); } dns_namereln = dns_name_fullcompare(&dns_name1, &dns_name2, &order, &nlabels); if (dns_namereln == dns_namereln_equal) result = T_PASS; else { t_info("dns_name_fullcompare returned %s\n", dns_namereln_to_text(dns_namereln)); result = T_FAIL; } return (result);}static voidt_dns_name_fromtext(void) { int line; int cnt; int result; char *p; FILE *fp; t_assert("dns_name_fromtext", 1, T_REQUIRED, a40); result = T_UNRESOLVED; fp = fopen("dns_name_fromtext_data", "r"); if (fp != NULL) { line = 0; while ((p = t_fgetbs(fp)) != NULL) { ++line; /* * Skip comment lines. */ if ((isspace((unsigned char)*p)) || (*p == '#')) continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -