From 6257efc35455318993208bef65a551ac6039f51f Mon Sep 17 00:00:00 2001 From: "Internet Software Consortium, Inc" <@isc.org> Date: Fri, 7 Sep 2007 14:08:17 -0600 Subject: 9.0.0b2 --- bin/tests/name_test.c | 70 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 18 deletions(-) (limited to 'bin/tests/name_test.c') diff --git a/bin/tests/name_test.c b/bin/tests/name_test.c index 8dc8eb3c..3305ed93 100644 --- a/bin/tests/name_test.c +++ b/bin/tests/name_test.c @@ -47,6 +47,28 @@ print_wirename(isc_region_t *name) { printf("\n"); } +static void +print_name(dns_name_t *name) { + isc_result_t result; + isc_buffer_t source; + isc_region_t r; + char s[1000]; + + isc_buffer_init(&source, s, sizeof s, ISC_BUFFERTYPE_TEXT); + if (dns_name_countlabels(name) > 0) + result = dns_name_totext(name, ISC_FALSE, &source); + else + result = DNS_R_SUCCESS; + if (result == DNS_R_SUCCESS) { + isc_buffer_used(&source, &r); + if (r.length > 0) + printf("%.*s\n", (int)r.length, r.base); + else + printf("\n"); + } else + printf("error: %s\n", dns_result_totext(result)); +} + int main(int argc, char *argv[]) { char s[1000]; @@ -64,9 +86,13 @@ main(int argc, char *argv[]) { isc_boolean_t check_wildcard = ISC_FALSE; isc_boolean_t test_downcase = ISC_FALSE; isc_boolean_t inplace = ISC_FALSE; + isc_boolean_t want_split = ISC_FALSE; + unsigned int depth, split_depth = 0; + dns_fixedname_t fprefix, fsuffix; + dns_name_t *prefix, *suffix; int ch; - while ((ch = isc_commandline_parse(argc, argv, "acdiqw")) != -1) { + while ((ch = isc_commandline_parse(argc, argv, "acdiqs:w")) != -1) { switch (ch) { case 'a': check_absolute = ISC_TRUE; @@ -83,6 +109,10 @@ main(int argc, char *argv[]) { case 'q': quiet = ISC_TRUE; break; + case 's': + want_split = ISC_TRUE; + split_depth = atoi(isc_commandline_argument); + break; case 'w': check_wildcard = ISC_TRUE; break; @@ -264,23 +294,7 @@ main(int argc, char *argv[]) { } isc_buffer_init(&source, s, sizeof s, ISC_BUFFERTYPE_TEXT); - if (dns_name_countlabels(down) > 0) - result = dns_name_totext(down, ISC_FALSE, - &source); - else - result = DNS_R_SUCCESS; - if (result == DNS_R_SUCCESS) { - isc_buffer_used(&source, &r); - if (r.length > 0) - printf("%.*s\n", (int)r.length, - r.base); - else - printf("\n"); - if (!quiet) { - printf("%u bytes.\n", source.used); - } - } else - printf("%s\n", dns_result_totext(result)); + print_name(down); } if (comp != NULL && dns_name_countlabels(name) > 0) { @@ -320,6 +334,26 @@ main(int argc, char *argv[]) { dns_name_equal(name, comp) ? "TRUE" : "FALSE"); } + depth = dns_name_depth(name); + if (want_split && split_depth < depth) { + dns_fixedname_init(&fprefix); + prefix = dns_fixedname_name(&fprefix); + dns_fixedname_init(&fsuffix); + suffix = dns_fixedname_name(&fsuffix); + printf("splitting at depth %u: ", split_depth); + result = dns_name_splitatdepth(name, split_depth, + prefix, suffix); + if (result == ISC_R_SUCCESS) { + printf("\n prefix = "); + print_name(prefix); + printf(" suffix = "); + print_name(suffix); + } else { + printf("failed: %s\n", + isc_result_totext(result)); + } + } + if (concatenate) { if (got_name) name = &wname2.name; -- cgit v1.2.3