4 * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: t_names.c,v 1.50 2009/09/01 23:47:44 tbox Exp */
27 #include <isc/buffer.h>
29 #include <isc/string.h>
31 #include <dns/compress.h>
33 #include <dns/result.h>
35 #include <tests/t_api.h>
39 #define BIGBUFLEN 4096
41 static char *Tokens
[MAXTOKS
+ 1];
47 * get a hex formatted dns message from a data
48 * file into an isc_buffer_t
49 * caller supplies data storage and the isc_buffer
50 * we read the file, convert, setup the buffer
51 * and return the data length
55 ctoh(unsigned char c
) {
59 val
= (c
>> 4) & 0x0f;
60 if ((0 <= val
) && (val
<= 9))
62 else if ((10 <= val
) && (val
<= 16))
63 buf
[0] = 'a' + val
- 10;
65 if ((0 <= val
) && (val
<= 9))
67 else if ((10 <= val
) && (val
<= 16))
68 buf
[1] = 'a' + val
- 10;
74 pbuf(isc_buffer_t
*pbuf
) {
80 while (len
< pbuf
->length
) {
81 printf("%s", ctoh(*p
));
89 #endif /* NEED_PBUF */
92 * Compare data at buf with data in hex representation at exp_data,
93 * of length exp_data_len, for equality.
94 * Return 0 if equal, else non-zero.
98 chkdata(unsigned char *buf
, size_t buflen
, char *exp_data
,
108 if (buflen
== exp_data_len
) {
109 data
= (unsigned char *)malloc(exp_data_len
*
110 sizeof(unsigned char));
112 t_info("malloc failed unexpectedly\n");
117 * First convert exp_data from hex format.
122 while (cnt
< exp_data_len
) {
124 if (('0' <= *q
) && (*q
<= '9'))
126 else if (('a' <= *q
) && (*q
<= 'z'))
128 else if (('A' <= *q
) && (*q
<= 'Z'))
134 if (('0' <= *q
) && (*q
<= '9'))
135 *p
|= ((*q
- '0') & 0x0f);
136 else if (('a' <= *q
) && (*q
<= 'z'))
137 *p
|= ((*q
- 'a' + 10) & 0x0f);
138 else if (('A' <= *q
) && (*q
<= 'Z'))
139 *p
|= ((*q
- 'A' + 10) & 0x0f);
150 for (cnt
= 0; cnt
< exp_data_len
; ++cnt
) {
156 if (cnt
== exp_data_len
)
159 t_info("bad data at position %lu, "
160 "got 0x%.2x, expected 0x%.2x\n",
161 (unsigned long)cnt
, *p
, *q
);
166 t_info("data length error, expected %lu, got %lu\n",
167 (unsigned long)exp_data_len
, (unsigned long)buflen
);
168 result
= exp_data_len
- buflen
;
174 * Get a hex formatted dns message from a data file into an isc_buffer_t.
175 * Caller supplies data storage and the isc_buffer. We read the file, convert,
176 * setup the buffer and return the data length.
179 getmsg(char *datafile_name
, unsigned char *buf
, int buflen
, isc_buffer_t
*pbuf
)
188 fp
= fopen(datafile_name
, "r");
190 t_info("No such file %s\n", datafile_name
);
198 while ((c
= getc(fp
)) != EOF
) {
199 if ( (c
== ' ') || (c
== '\t') ||
200 (c
== '\r') || (c
== '\n'))
203 while ((c
= getc(fp
)) != '\n')
207 if (('0' <= c
) && (c
<= '9'))
209 else if (('a' <= c
) && (c
<= 'z'))
211 else if (('A' <= c
) && (c
<= 'Z'))
215 t_info("Bad format in datafile\n");
218 if ((len
% 2) == 0) {
229 t_info("Buffer overflow error\n");
238 t_info("Bad format in %s\n", datafile_name
);
243 isc_buffer_init(pbuf
, buf
, cnt
);
244 isc_buffer_add(pbuf
, cnt
);
249 bustline(char *line
, char **toks
) {
255 while ((p
= strtok(line
, "\t")) && (cnt
< MAXTOKS
)) {
265 #ifdef NEED_HNAME_TO_TNAME
268 * convert a name from hex representation to text form
269 * format of hex notation is:
274 hname_to_tname(char *src
, char *target
, size_t len
) {
284 if ((srclen
>= 2) && ((*p
!= '%') || (*(p
+1) != 'x'))) {
286 * No conversion needed.
290 memcpy(target
, src
, srclen
+ 1);
299 if (('0' < c
) && (c
<= '9'))
301 else if (('a' <= c
) && (c
<= 'z'))
303 else if (('A' <= c
) && (c
<= 'Z'))
324 #endif /* NEED_HNAME_TO_TNAME */
327 * initialize a dns_name_t from a text name, hiding all
328 * buffer and other object initialization from the caller
333 dname_from_tname(char *name
, dns_name_t
*dns_name
) {
336 isc_buffer_t
*binbuf
;
341 isc_buffer_init(&txtbuf
, name
, len
);
342 isc_buffer_add(&txtbuf
, len
);
343 junk
= (unsigned char *)malloc(sizeof(unsigned char) * BUFLEN
);
344 binbuf
= (isc_buffer_t
*)malloc(sizeof(isc_buffer_t
));
345 if ((junk
!= NULL
) && (binbuf
!= NULL
)) {
346 isc_buffer_init(binbuf
, junk
, BUFLEN
);
347 dns_name_init(dns_name
, NULL
);
348 dns_name_setbuffer(dns_name
, binbuf
);
349 result
= dns_name_fromtext(dns_name
, &txtbuf
, NULL
, 0, NULL
);
351 result
= ISC_R_NOSPACE
;
360 static const char *a3
= "dns_name_init initializes 'name' to the empty name";
363 t_dns_name_init(void) {
367 unsigned char offsets
[1];
370 t_assert("dns_name_init", 1, T_REQUIRED
, "%s", a3
);
372 dns_name_init(&name
, offsets
);
373 /* magic is hidden in name.c ...
374 if (name.magic != NAME_MAGIC) {
375 t_info("name.magic is not set to NAME_MAGIC\n");
379 if (name
.ndata
!= NULL
) {
380 t_info("name.ndata is not NULL\n");
383 if (name
.length
!= 0) {
384 t_info("name.length is not 0\n");
387 if (name
.labels
!= 0) {
388 t_info("name.labels is not 0\n");
391 if (name
.attributes
!= 0) {
392 t_info("name.attributes is not 0\n");
395 if (name
.offsets
!= offsets
) {
396 t_info("name.offsets is incorrect\n");
399 if (name
.buffer
!= NULL
) {
400 t_info("name.buffer is not NULL\n");
411 static const char *a4
= "dns_name_invalidate invalidates 'name'";
414 t_dns_name_invalidate(void) {
418 unsigned char offsets
[1];
420 t_assert("dns_name_invalidate", 1, T_REQUIRED
, "%s", a4
);
423 dns_name_init(&name
, offsets
);
424 dns_name_invalidate(&name
);
426 /* magic is hidden in name.c ...
427 if (name.magic != 0) {
428 t_info("name.magic is not set to NAME_MAGIC\n");
432 if (name
.ndata
!= NULL
) {
433 t_info("name.ndata is not NULL\n");
436 if (name
.length
!= 0) {
437 t_info("name.length is not 0\n");
440 if (name
.labels
!= 0) {
441 t_info("name.labels is not 0\n");
444 if (name
.attributes
!= 0) {
445 t_info("name.attributes is not 0\n");
448 if (name
.offsets
!= NULL
) {
449 t_info("name.offsets is not NULL\n");
452 if (name
.buffer
!= NULL
) {
453 t_info("name.buffer is not NULL\n");
464 static const char *a5
= "dns_name_setbuffer dedicates a buffer for use "
468 t_dns_name_setbuffer(void) {
470 unsigned char junk
[BUFLEN
];
474 t_assert("dns_name_setbuffer", 1, T_REQUIRED
, "%s", a5
);
476 isc_buffer_init(&buffer
, junk
, BUFLEN
);
477 dns_name_init(&name
, NULL
);
478 dns_name_setbuffer(&name
, &buffer
);
479 if (name
.buffer
== &buffer
)
487 static const char *a6
= "dns_name_hasbuffer returns ISC_TRUE if 'name' has a "
488 "dedicated buffer, otherwise it returns ISC_FALSE";
491 t_dns_name_hasbuffer(void) {
494 unsigned char junk
[BUFLEN
];
498 t_assert("dns_name_hasbuffer", 1, T_REQUIRED
, "%s", a6
);
501 isc_buffer_init(&buffer
, junk
, BUFLEN
);
502 dns_name_init(&name
, NULL
);
503 if (dns_name_hasbuffer(&name
) != ISC_FALSE
)
505 dns_name_setbuffer(&name
, &buffer
);
506 if (dns_name_hasbuffer(&name
) != ISC_TRUE
)
516 static const char *a7
= "dns_name_isabsolute returns ISC_TRUE if 'name' ends "
520 test_dns_name_isabsolute(char *test_name
, isc_boolean_t expected
) {
524 unsigned char junk
[BUFLEN
];
527 isc_boolean_t isabs_p
;
532 t_info("testing name %s\n", test_name
);
533 len
= strlen(test_name
);
534 isc_buffer_init(&buf
, test_name
, len
);
535 isc_buffer_add(&buf
, len
);
536 isc_buffer_init(&binbuf
, &junk
[0], BUFLEN
);
537 dns_name_init(&name
, NULL
);
538 dns_name_setbuffer(&name
, &binbuf
);
539 result
= dns_name_fromtext(&name
, &buf
, NULL
, 0, NULL
);
540 if (result
== ISC_R_SUCCESS
) {
541 isabs_p
= dns_name_isabsolute(&name
);
542 if (isabs_p
== expected
)
547 t_info("dns_name_fromtext %s failed, result = %s\n",
548 test_name
, dns_result_totext(result
));
554 t_dns_name_isabsolute(void) {
561 t_assert("dns_name_isabsolute", 1, T_REQUIRED
, "%s", a7
);
563 result
= T_UNRESOLVED
;
564 fp
= fopen("dns_name_isabsolute_data", "r");
567 while ((p
= t_fgetbs(fp
)) != NULL
) {
572 * Skip comment lines.
574 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
579 cnt
= bustline(p
, Tokens
);
582 * label, bitpos, expected value.
584 result
= test_dns_name_isabsolute(Tokens
[0],
590 t_info("bad datafile format at line %d\n",
599 t_info("Missing datafile dns_name_isabsolute_data\n");
604 static const char *a8
= "dns_name_hash(name, case_sensitive) returns "
605 "a hash of 'name' which is case_sensitive if case_sensitive "
613 test_dns_name_hash(char *test_name1
, char *test_name2
,
614 isc_boolean_t csh_match
, isc_boolean_t cish_match
) {
620 dns_name_t dns_name1
;
621 dns_name_t dns_name2
;
627 t_info("testing names %s and %s\n", test_name1
, test_name2
);
629 result
= dname_from_tname(test_name1
, &dns_name1
);
630 if (result
== ISC_R_SUCCESS
) {
631 result
= dname_from_tname(test_name2
, &dns_name2
);
632 if (result
== ISC_R_SUCCESS
) {
633 hash1
= dns_name_hash(&dns_name1
, ISC_TRUE
);
634 hash2
= dns_name_hash(&dns_name2
, ISC_TRUE
);
638 if (match
!= csh_match
) {
640 t_info("hash mismatch when ISC_TRUE\n");
642 hash1
= dns_name_hash(&dns_name1
, ISC_FALSE
);
643 hash2
= dns_name_hash(&dns_name2
, ISC_FALSE
);
647 if (match
!= cish_match
) {
649 t_info("hash mismatch when ISC_FALSE\n");
656 t_info("dns_fromtext %s failed, result = %s\n",
657 test_name2
, dns_result_totext(result
));
660 t_info("dns_fromtext %s failed, result = %s\n",
661 test_name1
, dns_result_totext(result
));
667 t_dns_name_hash(void) {
674 t_assert("dns_name_hash", 1, T_REQUIRED
, "%s", a8
);
676 result
= T_UNRESOLVED
;
677 fp
= fopen("dns_name_hash_data", "r");
680 while ((p
= t_fgetbs(fp
)) != NULL
) {
685 * Skip comment lines.
687 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
692 cnt
= bustline(p
, Tokens
);
695 * name1, name2, exp match value if
696 * case_sensitive true,
697 * exp match value of case_sensitive false
699 result
= test_dns_name_hash(
702 atoi(Tokens
[2]) == 0 ?
703 ISC_FALSE
: ISC_TRUE
,
704 atoi(Tokens
[3]) == 0 ?
705 ISC_FALSE
: ISC_TRUE
);
707 t_info("bad datafile format at line %d\n",
716 t_info("Missing datafile dns_name_hash_data\n");
721 static const char *a10
=
722 "dns_name_fullcompare(name1, name2, orderp, nlabelsp) "
723 "returns the DNSSEC ordering relationship between name1 and "
724 "name2, sets orderp to -1 if name1 < name2, to 0 if "
725 "name1 == name2, or to 1 if name1 > name2, sets nlabelsp "
726 "to the number of labels name1 and name2 have in common, "
727 "and sets nbitsp to the number of bits name1 and name2 "
731 * a11 thru a22 merged into a10.
734 dns_namereln_to_text(dns_namereln_t reln
) {
737 if (reln
== dns_namereln_contains
)
739 else if (reln
== dns_namereln_subdomain
)
741 else if (reln
== dns_namereln_equal
)
743 else if (reln
== dns_namereln_none
)
745 else if (reln
== dns_namereln_commonancestor
)
746 p
= "commonancestor";
754 test_dns_name_fullcompare(char *name1
, char *name2
,
755 dns_namereln_t exp_dns_reln
,
756 int exp_order
, int exp_nlabels
)
761 unsigned int nlabels
;
762 dns_name_t dns_name1
;
763 dns_name_t dns_name2
;
764 isc_result_t dns_result
;
765 dns_namereln_t dns_reln
;
768 result
= T_UNRESOLVED
;
771 t_info("testing names %s and %s for relation %s\n", name1
, name2
,
772 dns_namereln_to_text(exp_dns_reln
));
774 dns_result
= dname_from_tname(name1
, &dns_name1
);
775 if (dns_result
== ISC_R_SUCCESS
) {
776 dns_result
= dname_from_tname(name2
, &dns_name2
);
777 if (dns_result
== ISC_R_SUCCESS
) {
778 dns_reln
= dns_name_fullcompare(&dns_name1
, &dns_name2
,
781 if (dns_reln
!= exp_dns_reln
) {
783 t_info("expected relationship of %s, got %s\n",
784 dns_namereln_to_text(exp_dns_reln
),
785 dns_namereln_to_text(dns_reln
));
794 if (order
!= exp_order
) {
796 t_info("expected ordering %d, got %d\n",
799 if ((exp_nlabels
>= 0) &&
800 (nlabels
!= (unsigned int)exp_nlabels
)) {
802 t_info("expecting %d labels, got %d\n",
803 exp_nlabels
, nlabels
);
810 t_info("dname_from_tname failed, result == %s\n",
811 dns_result_totext(result
));
814 t_info("dname_from_tname failed, result == %s\n",
815 dns_result_totext(result
));
822 t_dns_name_fullcompare(void) {
830 t_assert("dns_name_fullcompare", 1, T_REQUIRED
, "%s", a10
);
832 result
= T_UNRESOLVED
;
833 fp
= fopen("dns_name_fullcompare_data", "r");
836 while ((p
= t_fgetbs(fp
)) != NULL
) {
841 * Skip comment lines.
843 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
848 cnt
= bustline(p
, Tokens
);
851 * name1, name2, exp_reln, exp_order,
854 if (!strcmp(Tokens
[2], "none"))
855 reln
= dns_namereln_none
;
856 else if (!strcmp(Tokens
[2], "contains"))
857 reln
= dns_namereln_contains
;
858 else if (!strcmp(Tokens
[2], "subdomain"))
859 reln
= dns_namereln_subdomain
;
860 else if (!strcmp(Tokens
[2], "equal"))
861 reln
= dns_namereln_equal
;
862 else if (!strcmp(Tokens
[2], "commonancestor"))
863 reln
= dns_namereln_commonancestor
;
865 t_info("bad format at line %d\n",
869 result
= test_dns_name_fullcompare(
876 t_info("bad format at line %d\n", line
);
884 t_info("Missing datafile dns_name_fullcompare_data\n");
889 static const char *a23
=
890 "dns_name_compare(name1, name2) returns information about "
891 "the relative ordering under the DNSSEC ordering relationship "
892 "of name1 and name2";
895 * a24 thru a29 merged into a23.
899 test_dns_name_compare(char *name1
, char *name2
, int exp_order
) {
902 isc_result_t dns_result
;
903 dns_name_t dns_name1
;
904 dns_name_t dns_name2
;
906 result
= T_UNRESOLVED
;
908 t_info("testing %s %s %s\n", name1
,
909 exp_order
== 0 ? "==": (exp_order
== -1 ? "<" : ">"),
912 dns_result
= dname_from_tname(name1
, &dns_name1
);
913 if (dns_result
== ISC_R_SUCCESS
) {
914 dns_result
= dname_from_tname(name2
, &dns_name2
);
915 if (dns_result
== ISC_R_SUCCESS
) {
916 order
= dns_name_compare(&dns_name1
, &dns_name2
);
924 if (order
!= exp_order
) {
925 t_info("expected order of %d, got %d\n",
931 t_info("dname_from_tname failed, result == %s\n",
932 dns_result_totext(result
));
935 t_info("dname_from_tname failed, result == %s\n",
936 dns_result_totext(result
));
943 t_dns_name_compare(void) {
950 t_assert("dns_name_compare", 1, T_REQUIRED
, "%s", a23
);
952 result
= T_UNRESOLVED
;
953 fp
= fopen("dns_name_compare_data", "r");
956 while ((p
= t_fgetbs(fp
)) != NULL
) {
961 * Skip comment lines.
963 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
968 cnt
= bustline(p
, Tokens
);
971 * name1, name2, order.
973 result
= test_dns_name_compare(
978 t_info("bad datafile format at line %d\n",
987 t_info("Missing datafile dns_name_compare_data\n");
992 static const char *a30
=
993 "dns_name_rdatacompare(name1, name2) returns information "
994 "about the relative ordering of name1 and name2 as if they "
995 "are part of rdata in DNSSEC canonical form";
998 * a31, a32 merged into a30.
1002 test_dns_name_rdatacompare(char *name1
, char *name2
, int exp_order
) {
1005 isc_result_t dns_result
;
1006 dns_name_t dns_name1
;
1007 dns_name_t dns_name2
;
1009 result
= T_UNRESOLVED
;
1011 t_info("testing %s %s %s\n", name1
,
1012 exp_order
== 0 ? "==": (exp_order
== -1 ? "<" : ">"), name2
);
1014 dns_result
= dname_from_tname(name1
, &dns_name1
);
1015 if (dns_result
== ISC_R_SUCCESS
) {
1016 dns_result
= dname_from_tname(name2
, &dns_name2
);
1017 if (dns_result
== ISC_R_SUCCESS
) {
1018 order
= dns_name_rdatacompare(&dns_name1
, &dns_name2
);
1026 if (order
!= exp_order
) {
1027 t_info("expected order of %d, got %d\n",
1033 t_info("dname_from_tname failed, result == %s\n",
1034 dns_result_totext(result
));
1037 t_info("dname_from_tname failed, result == %s\n",
1038 dns_result_totext(result
));
1045 t_dns_name_rdatacompare(void) {
1052 t_assert("dns_name_rdatacompare", 1, T_REQUIRED
, "%s", a30
);
1054 result
= T_UNRESOLVED
;
1055 fp
= fopen("dns_name_rdatacompare_data", "r");
1058 while ((p
= t_fgetbs(fp
)) != NULL
) {
1063 * Skip comment lines.
1065 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1070 cnt
= bustline(p
, Tokens
);
1073 * name1, name2, order.
1075 result
= test_dns_name_rdatacompare(
1080 t_info("bad datafile format at line %d\n",
1089 t_info("Missing datafile dns_name_rdatacompare_data\n");
1095 static const char *a33
=
1096 "when name1 is a subdomain of name2, "
1097 "dns_name_issubdomain(name1, name2) returns true, "
1098 "otherwise it returns false.";
1101 * a34 merged into a33.
1105 test_dns_name_issubdomain(char *name1
, char *name2
, isc_boolean_t exp_rval
) {
1108 isc_result_t dns_result
;
1109 dns_name_t dns_name1
;
1110 dns_name_t dns_name2
;
1112 result
= T_UNRESOLVED
;
1114 t_info("testing %s %s a subdomain of %s\n", name1
,
1115 exp_rval
== 0 ? "is not" : "is", name2
);
1117 dns_result
= dname_from_tname(name1
, &dns_name1
);
1118 if (dns_result
== ISC_R_SUCCESS
) {
1119 dns_result
= dname_from_tname(name2
, &dns_name2
);
1120 if (dns_result
== ISC_R_SUCCESS
) {
1121 rval
= dns_name_issubdomain(&dns_name1
, &dns_name2
);
1123 if (rval
!= exp_rval
) {
1124 t_info("expected return value of %s, got %s\n",
1125 exp_rval
== ISC_TRUE
? "true" : "false",
1126 rval
== ISC_TRUE
? "true" : "false");
1131 t_info("dname_from_tname failed, result == %s\n",
1132 dns_result_totext(result
));
1135 t_info("dname_from_tname failed, result == %s\n",
1136 dns_result_totext(result
));
1143 t_dns_name_issubdomain(void) {
1150 t_assert("dns_name_issubdomain", 1, T_REQUIRED
, "%s", a33
);
1152 result
= T_UNRESOLVED
;
1153 fp
= fopen("dns_name_issubdomain_data", "r");
1156 while ((p
= t_fgetbs(fp
)) != NULL
) {
1161 * Skip comment lines.
1163 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1168 cnt
= bustline(p
, Tokens
);
1171 * name1, name2, issubdomain_p.
1173 result
= test_dns_name_issubdomain(
1176 atoi(Tokens
[2]) == 0 ?
1177 ISC_FALSE
: ISC_TRUE
);
1179 t_info("bad datafile format at line %d\n",
1188 t_info("Missing datafile dns_name_issubdomain_data\n");
1193 static const char *a35
=
1194 "dns_name_countlabels(name) returns the number "
1195 "of labels in name";
1198 test_dns_name_countlabels(char *test_name
, unsigned int exp_nlabels
) {
1200 unsigned int nlabels
;
1201 isc_result_t dns_result
;
1202 dns_name_t dns_name
;
1204 result
= T_UNRESOLVED
;
1206 t_info("testing %s\n", test_name
);
1208 dns_result
= dname_from_tname(test_name
, &dns_name
);
1209 if (dns_result
== ISC_R_SUCCESS
) {
1210 nlabels
= dns_name_countlabels(&dns_name
);
1212 if (nlabels
!= exp_nlabels
) {
1213 t_info("expected %d, got %d\n", exp_nlabels
, nlabels
);
1218 t_info("dname_from_tname failed, result == %s\n",
1219 dns_result_totext(dns_result
));
1226 t_dns_name_countlabels(void) {
1233 t_assert("dns_name_countlabels", 1, T_REQUIRED
, "%s", a35
);
1235 result
= T_UNRESOLVED
;
1236 fp
= fopen("dns_name_countlabels_data", "r");
1239 while ((p
= t_fgetbs(fp
)) != NULL
) {
1244 * Skip comment lines.
1246 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1251 cnt
= bustline(p
, Tokens
);
1256 result
= test_dns_name_countlabels(Tokens
[0],
1259 t_info("bad format at line %d\n", line
);
1267 t_info("Missing datafile dns_name_countlabels_data\n");
1272 static const char *a36
=
1273 "when n is less than the number of labels in name, "
1274 "dns_name_getlabel(name, n, labelp) initializes labelp "
1275 "to point to the nth label in name";
1278 * The strategy here is two take two dns names with a shared label in
1279 * different positions, get the two labels and compare them for equality.
1280 * If they don't match, dns_name_getlabel failed.
1284 test_dns_name_getlabel(char *test_name1
, int label1_pos
, char *test_name2
,
1292 dns_name_t dns_name1
;
1293 dns_name_t dns_name2
;
1294 dns_label_t dns_label1
;
1295 dns_label_t dns_label2
;
1296 isc_result_t dns_result
;
1299 result
= T_UNRESOLVED
;
1301 t_info("testing with %s and %s\n", test_name1
, test_name2
);
1303 dns_result
= dname_from_tname(test_name1
, &dns_name1
);
1304 if (dns_result
== ISC_R_SUCCESS
) {
1305 dns_result
= dname_from_tname(test_name2
, &dns_name2
);
1306 if (dns_result
== ISC_R_SUCCESS
) {
1307 dns_name_getlabel(&dns_name1
, label1_pos
, &dns_label1
);
1308 dns_name_getlabel(&dns_name2
, label2_pos
, &dns_label2
);
1309 if (dns_label1
.length
!= dns_label2
.length
) {
1310 t_info("label lengths differ\n");
1313 p
= dns_label1
.base
;
1314 q
= dns_label2
.base
;
1315 for (cnt
= 0; cnt
< dns_label1
.length
; ++cnt
) {
1317 t_info("labels differ at position %d",
1327 t_info("dname_from_tname failed, result == %s",
1328 dns_result_totext(result
));
1331 t_info("dname_from_tname failed, result == %s",
1332 dns_result_totext(result
));
1338 t_dns_name_getlabel(void) {
1345 t_assert("dns_name_getlabel", 1, T_REQUIRED
, "%s", a36
);
1347 result
= T_UNRESOLVED
;
1348 fp
= fopen("dns_name_getlabel_data", "r");
1351 while ((p
= t_fgetbs(fp
)) != NULL
) {
1356 * Skip comment lines.
1358 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1363 cnt
= bustline(p
, Tokens
);
1366 * name1, name2, nlabels.
1368 result
= test_dns_name_getlabel(Tokens
[0],
1373 t_info("bad format at line %d\n", line
);
1381 t_info("Missing datafile dns_name_getlabel_data\n");
1386 static const char *a37
=
1387 "when source contains at least first + n labels, "
1388 "dns_name_getlabelsequence(source, first, n, target) "
1389 "initializes target to point to the n label sequence of "
1390 "labels in source starting with first";
1393 * We adopt a similiar strategy to that used by the dns_name_getlabel test.
1397 test_dns_name_getlabelsequence(char *test_name1
, int label1_start
,
1398 char *test_name2
, int label2_start
, int range
)
1405 dns_name_t dns_name1
;
1406 dns_name_t dns_name2
;
1407 dns_name_t dns_targetname1
;
1408 dns_name_t dns_targetname2
;
1409 isc_result_t dns_result
;
1410 isc_buffer_t buffer1
;
1411 isc_buffer_t buffer2
;
1412 unsigned char junk1
[BUFLEN
];
1413 unsigned char junk2
[BUFLEN
];
1416 result
= T_UNRESOLVED
;
1417 dns_result
= dname_from_tname(test_name1
, &dns_name1
);
1418 if (dns_result
== ISC_R_SUCCESS
) {
1419 dns_result
= dname_from_tname(test_name2
, &dns_name2
);
1420 if (dns_result
== ISC_R_SUCCESS
) {
1421 t_info("testing %s %s\n", test_name1
, test_name2
);
1422 dns_name_init(&dns_targetname1
, NULL
);
1423 dns_name_init(&dns_targetname2
, NULL
);
1424 dns_name_getlabelsequence(&dns_name1
, label1_start
,
1425 range
, &dns_targetname1
);
1426 dns_name_getlabelsequence(&dns_name2
, label2_start
,
1427 range
, &dns_targetname2
);
1430 * Now convert both targets to text for comparison.
1432 isc_buffer_init(&buffer1
, junk1
, BUFLEN
);
1433 isc_buffer_init(&buffer2
, junk2
, BUFLEN
);
1434 dns_name_totext(&dns_targetname1
, ISC_TRUE
, &buffer1
);
1435 dns_name_totext(&dns_targetname2
, ISC_TRUE
, &buffer2
);
1436 if (buffer1
.used
== buffer2
.used
) {
1439 for (cnt
= 0; cnt
< buffer1
.used
; ++cnt
) {
1442 t_info("names differ at %d\n",
1450 t_info("lengths differ\n");
1457 t_info("dname_from_tname failed, result == %s",
1458 dns_result_totext(dns_result
));
1461 t_info("dname_from_tname failed, result == %s",
1462 dns_result_totext(dns_result
));
1468 t_dns_name_getlabelsequence(void) {
1475 t_assert("dns_name_getlabelsequence", 1, T_REQUIRED
, "%s", a37
);
1477 result
= T_UNRESOLVED
;
1478 fp
= fopen("dns_name_getlabelsequence_data", "r");
1481 while ((p
= t_fgetbs(fp
)) != NULL
) {
1486 * Skip comment lines.
1488 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1493 cnt
= bustline(p
, Tokens
);
1496 * name1, name2, nlabels.
1498 result
= test_dns_name_getlabelsequence(
1505 t_info("bad format at line %d\n", line
);
1513 t_info("Missing datafile dns_name_getlabelsequence_data\n");
1518 static const char *a38
=
1519 "dns_name_fromregion(name, region) converts a DNS name "
1520 "from a region representation to a name representation";
1523 test_dns_name_fromregion(char *test_name
) {
1526 unsigned int nlabels
;
1527 isc_result_t dns_result
;
1528 dns_name_t dns_name1
;
1529 dns_name_t dns_name2
;
1530 dns_namereln_t dns_namereln
;
1531 isc_region_t region
;
1533 result
= T_UNRESOLVED
;
1535 t_info("testing %s\n", test_name
);
1537 dns_result
= dname_from_tname(test_name
, &dns_name1
);
1538 if (dns_result
== ISC_R_SUCCESS
) {
1540 dns_name_toregion(&dns_name1
, ®ion
);
1542 dns_name_init(&dns_name2
, NULL
);
1543 dns_name_fromregion(&dns_name2
, ®ion
);
1544 dns_namereln
= dns_name_fullcompare(&dns_name1
, &dns_name2
,
1546 if (dns_namereln
== dns_namereln_equal
)
1551 t_info("dname_from_tname failed, result == %s\n",
1552 dns_result_totext(result
));
1558 t_dns_name_fromregion(void) {
1565 t_assert("dns_name_fromregion", 1, T_REQUIRED
, "%s", a38
);
1567 result
= T_UNRESOLVED
;
1568 fp
= fopen("dns_name_fromregion_data", "r");
1571 while ((p
= t_fgetbs(fp
)) != NULL
) {
1576 * Skip comment lines.
1578 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1583 cnt
= bustline(p
, Tokens
);
1588 result
= test_dns_name_fromregion(Tokens
[0]);
1590 t_info("bad format at line %d\n", line
);
1598 t_info("Missing datafile dns_name_fromregion_data\n");
1603 static const char *a39
=
1604 "dns_name_toregion(name, region) converts a DNS name "
1605 "from a region representation to a name representation";
1608 t_dns_name_toregion(void) {
1615 t_assert("dns_name_toregion", 1, T_REQUIRED
, "%s", a39
);
1617 result
= T_UNRESOLVED
;
1618 fp
= fopen("dns_name_toregion_data", "r");
1621 while ((p
= t_fgetbs(fp
)) != NULL
) {
1626 * Skip comment lines.
1628 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1633 cnt
= bustline(p
, Tokens
);
1638 result
= test_dns_name_fromregion(Tokens
[0]);
1640 t_info("bad format at line %d\n", line
);
1648 t_info("Missing datafile dns_name_toregion_data\n");
1653 static const char *a40
=
1654 "dns_name_fromtext(name, source, origin, downcase, target) "
1655 "converts the textual representation of a DNS name at source "
1656 "into uncompressed wire form at target, appending origin to "
1657 "the converted name if origin is non-NULL and converting "
1658 "upper case to lower case during conversion "
1659 "if downcase is true.";
1662 test_dns_name_fromtext(char *test_name1
, char *test_name2
, char *test_origin
,
1663 unsigned int downcase
)
1667 unsigned int nlabels
;
1668 unsigned char junk1
[BUFLEN
];
1669 unsigned char junk2
[BUFLEN
];
1670 unsigned char junk3
[BUFLEN
];
1671 isc_buffer_t binbuf1
;
1672 isc_buffer_t binbuf2
;
1673 isc_buffer_t binbuf3
;
1674 isc_buffer_t txtbuf1
;
1675 isc_buffer_t txtbuf2
;
1676 isc_buffer_t txtbuf3
;
1677 dns_name_t dns_name1
;
1678 dns_name_t dns_name2
;
1679 dns_name_t dns_name3
;
1680 isc_result_t dns_result
;
1681 dns_namereln_t dns_namereln
;
1683 result
= T_UNRESOLVED
;
1685 t_info("testing %s %s %s\n", test_name1
, test_name2
, test_origin
);
1687 isc_buffer_init(&binbuf1
, junk1
, BUFLEN
);
1688 isc_buffer_init(&binbuf2
, junk2
, BUFLEN
);
1689 isc_buffer_init(&binbuf3
, junk3
, BUFLEN
);
1691 isc_buffer_init(&txtbuf1
, test_name1
, strlen(test_name1
));
1692 isc_buffer_add(&txtbuf1
, strlen(test_name1
));
1694 isc_buffer_init(&txtbuf2
, test_name2
, strlen(test_name2
));
1695 isc_buffer_add(&txtbuf2
, strlen(test_name2
));
1697 isc_buffer_init(&txtbuf3
, test_origin
, strlen(test_origin
));
1698 isc_buffer_add(&txtbuf3
, strlen(test_origin
));
1699 dns_name_init(&dns_name1
, NULL
);
1700 dns_name_init(&dns_name2
, NULL
);
1701 dns_name_init(&dns_name3
, NULL
);
1702 dns_name_setbuffer(&dns_name1
, &binbuf1
);
1703 dns_name_setbuffer(&dns_name2
, &binbuf2
);
1704 dns_name_setbuffer(&dns_name3
, &binbuf3
);
1706 dns_result
= dns_name_fromtext(&dns_name3
, &txtbuf3
, NULL
, 0,
1708 if (dns_result
!= ISC_R_SUCCESS
) {
1709 t_info("dns_name_fromtext(dns_name3) failed, result == %s\n",
1710 dns_result_totext(dns_result
));
1714 dns_result
= dns_name_fromtext(&dns_name1
, &txtbuf1
, &dns_name3
,
1715 downcase
, &binbuf1
);
1716 if (dns_result
!= ISC_R_SUCCESS
) {
1717 t_info("dns_name_fromtext(dns_name1) failed, result == %s\n",
1718 dns_result_totext(dns_result
));
1722 dns_result
= dns_name_fromtext(&dns_name2
, &txtbuf2
, NULL
, 0,
1724 if (dns_result
!= ISC_R_SUCCESS
) {
1725 t_info("dns_name_fromtext(dns_name2) failed, result == %s\n",
1726 dns_result_totext(dns_result
));
1730 dns_namereln
= dns_name_fullcompare(&dns_name1
, &dns_name2
, &order
,
1733 if (dns_namereln
== dns_namereln_equal
)
1736 t_info("dns_name_fullcompare returned %s\n",
1737 dns_namereln_to_text(dns_namereln
));
1745 t_dns_name_fromtext(void) {
1752 t_assert("dns_name_fromtext", 1, T_REQUIRED
, "%s", a40
);
1754 result
= T_UNRESOLVED
;
1755 fp
= fopen("dns_name_fromtext_data", "r");
1758 while ((p
= t_fgetbs(fp
)) != NULL
) {
1763 * Skip comment lines.
1765 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1770 cnt
= bustline(p
, Tokens
);
1773 * test_name1, test_name2, test_origin,
1776 result
= test_dns_name_fromtext(Tokens
[0],
1784 t_info("bad format at line %d\n", line
);
1792 t_info("Missing datafile dns_name_fromtext\n");
1797 static const char *a41
=
1798 "dns_name_totext(name, omit_final_dot, target) converts "
1799 "the DNS name 'name' in wire format to textual format "
1800 "at target, and adds a final '.' to the name if "
1801 "omit_final_dot is false";
1804 test_dns_name_totext(char *test_name
, isc_boolean_t omit_final
) {
1808 unsigned int nlabels
;
1809 unsigned char junk1
[BUFLEN
];
1810 unsigned char junk2
[BUFLEN
];
1811 unsigned char junk3
[BUFLEN
];
1815 dns_name_t dns_name1
;
1816 dns_name_t dns_name2
;
1817 isc_result_t dns_result
;
1818 dns_namereln_t dns_namereln
;
1820 result
= T_UNRESOLVED
;
1822 t_info("testing %s\n", test_name
);
1824 len
= strlen(test_name
);
1825 isc_buffer_init(&buf1
, test_name
, len
);
1826 isc_buffer_add(&buf1
, len
);
1828 dns_name_init(&dns_name1
, NULL
);
1829 isc_buffer_init(&buf2
, junk2
, BUFLEN
);
1832 * Out of the data file to dns_name1.
1834 dns_result
= dns_name_fromtext(&dns_name1
, &buf1
, NULL
, 0, &buf2
);
1835 if (dns_result
!= ISC_R_SUCCESS
) {
1836 t_info("dns_name_fromtext failed, result == %s\n",
1837 dns_result_totext(dns_result
));
1838 return (T_UNRESOLVED
);
1842 * From dns_name1 into a text buffer.
1844 isc_buffer_invalidate(&buf1
);
1845 isc_buffer_init(&buf1
, junk1
, BUFLEN
);
1846 dns_result
= dns_name_totext(&dns_name1
, omit_final
, &buf1
);
1847 if (dns_result
!= ISC_R_SUCCESS
) {
1848 t_info("dns_name_totext failed, result == %s\n",
1849 dns_result_totext(dns_result
));
1854 * From the text buffer into dns_name2.
1856 dns_name_init(&dns_name2
, NULL
);
1857 isc_buffer_init(&buf3
, junk3
, BUFLEN
);
1858 dns_result
= dns_name_fromtext(&dns_name2
, &buf1
, NULL
, 0, &buf3
);
1859 if (dns_result
!= ISC_R_SUCCESS
) {
1860 t_info("dns_name_fromtext failed, result == %s\n",
1861 dns_result_totext(dns_result
));
1862 return (T_UNRESOLVED
);
1865 dns_namereln
= dns_name_fullcompare(&dns_name1
, &dns_name2
,
1867 if (dns_namereln
== dns_namereln_equal
)
1870 t_info("dns_name_fullcompare returned %s\n",
1871 dns_namereln_to_text(dns_namereln
));
1879 t_dns_name_totext(void) {
1886 t_assert("dns_name_totext", 1, T_REQUIRED
, "%s", a41
);
1888 result
= T_UNRESOLVED
;
1889 fp
= fopen("dns_name_totext_data", "r");
1892 while ((p
= t_fgetbs(fp
)) != NULL
) {
1897 * Skip comment lines.
1899 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1904 cnt
= bustline(p
, Tokens
);
1907 * test_name, omit_final.
1909 result
= test_dns_name_totext(Tokens
[0],
1910 atoi(Tokens
[1]) == 0 ?
1914 t_info("bad format at line %d\n", line
);
1922 t_info("Missing datafile dns_name_totext\n");
1927 static const char *a42
=
1928 "dns_name_fromwire(name, source, dctx, downcase, target) "
1929 "converts the possibly compressed DNS name 'name' in wire "
1930 "format to canonicalized form at target, performing upper to "
1931 "lower case conversion if downcase is true, and returns "
1936 * XXXRTH these tests appear to be broken, so I have
1939 static const char *a43
=
1940 "when a label length is invalid, dns_name_fromwire() "
1941 "returns DNS_R_FORMERR";
1943 static const char *a44
=
1944 "when a label type is invalid, dns_name_fromwire() "
1945 "returns DNS_R_BADLABELTYPE";
1948 static const char *a45
=
1949 "when a name length is invalid, dns_name_fromwire() "
1950 "returns DNS_R_FORMERR";
1952 static const char *a46
=
1953 "when a compression type is invalid, dns_name_fromwire() "
1954 "returns DNS_R_DISALLOWED";
1956 static const char *a47
=
1957 "when a bad compression pointer is encountered, "
1958 "dns_name_fromwire() returns DNS_R_BADPOINTER";
1960 static const char *a48
=
1961 "when input ends unexpected, dns_name_fromwire() "
1962 "returns ISC_R_UNEXPECTEDEND";
1964 static const char *a49
=
1965 "when there is not enough space in target, "
1966 "dns_name_fromwire(name, source, dcts, downcase, target) "
1967 "returns ISC_R_NOSPACE";
1970 test_dns_name_fromwire(char *datafile_name
, int testname_offset
, int downcase
,
1971 unsigned int dc_method
, char *exp_name
,
1972 isc_result_t exp_result
, size_t buflen
)
1976 unsigned int nlabels
;
1978 unsigned char buf1
[BIGBUFLEN
];
1980 isc_buffer_t iscbuf1
;
1981 isc_buffer_t iscbuf2
;
1982 dns_name_t dns_name1
;
1983 dns_name_t dns_name2
;
1984 isc_result_t dns_result
;
1985 dns_namereln_t dns_namereln
;
1986 dns_decompress_t dctx
;
1988 result
= T_UNRESOLVED
;
1990 t_info("testing using %s\n", datafile_name
);
1991 len
= getmsg(datafile_name
, buf1
, BIGBUFLEN
, &iscbuf1
);
1993 isc_buffer_setactive(&iscbuf1
, len
);
1994 iscbuf1
.current
= testname_offset
;
1996 isc_buffer_init(&iscbuf2
, buf2
, buflen
);
1997 dns_name_init(&dns_name1
, NULL
);
1998 dns_decompress_init(&dctx
, -1, DNS_DECOMPRESS_STRICT
);
1999 dns_decompress_setmethods(&dctx
, dc_method
);
2000 dns_result
= dns_name_fromwire(&dns_name1
, &iscbuf1
,
2001 &dctx
, downcase
? ISC_TRUE
: ISC_FALSE
,
2004 if ((dns_result
== exp_result
) && (exp_result
== ISC_R_SUCCESS
)) {
2006 dns_result
= dname_from_tname(exp_name
, &dns_name2
);
2007 if (dns_result
== ISC_R_SUCCESS
) {
2008 dns_namereln
= dns_name_fullcompare(&dns_name1
,
2011 if (dns_namereln
!= dns_namereln_equal
) {
2012 t_info("dns_name_fullcompare returned %s\n",
2013 dns_namereln_to_text(dns_namereln
));
2019 t_info("dns_name_fromtext %s failed, result = %s\n",
2020 exp_name
, dns_result_totext(dns_result
));
2021 result
= T_UNRESOLVED
;
2023 } else if (dns_result
== exp_result
) {
2026 t_info("dns_name_fromwire returned %s\n",
2027 dns_result_totext(dns_result
));
2035 t_dns_name_fromwire_x(const char *testfile
, size_t buflen
) {
2039 unsigned int dc_method
;
2040 isc_result_t exp_result
;
2045 result
= T_UNRESOLVED
;
2046 fp
= fopen(testfile
, "r");
2049 while ((p
= t_fgetbs(fp
)) != NULL
) {
2054 * Skip comment lines.
2056 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
2061 cnt
= bustline(p
, Tokens
);
2064 * datafile_name, testname_offset,
2065 * downcase, dc_method,
2066 * exp_name, exp_result.
2070 exp_result
= ISC_R_SUCCESS
;
2071 if (! strcmp(tok
, "ISC_R_SUCCESS"))
2072 exp_result
= ISC_R_SUCCESS
;
2073 else if (! strcmp(tok
, "ISC_R_NOSPACE"))
2074 exp_result
= ISC_R_NOSPACE
;
2075 else if (! strcmp(tok
, "DNS_R_BADLABELTYPE"))
2076 exp_result
= DNS_R_BADLABELTYPE
;
2077 else if (! strcmp(tok
, "DNS_R_FORMERR"))
2078 exp_result
= DNS_R_FORMERR
;
2079 else if (! strcmp(tok
, "DNS_R_BADPOINTER"))
2080 exp_result
= DNS_R_BADPOINTER
;
2081 else if (! strcmp(tok
, "ISC_R_UNEXPECTEDEND"))
2082 exp_result
= ISC_R_UNEXPECTEDEND
;
2083 else if (! strcmp(tok
, "DNS_R_TOOMANYHOPS"))
2084 exp_result
= DNS_R_TOOMANYHOPS
;
2085 else if (! strcmp(tok
, "DNS_R_DISALLOWED"))
2086 exp_result
= DNS_R_DISALLOWED
;
2087 else if (! strcmp(tok
, "DNS_R_NAMETOOLONG"))
2088 exp_result
= DNS_R_NAMETOOLONG
;
2091 dc_method
= DNS_COMPRESS_NONE
;
2092 if (! strcmp(tok
, "DNS_COMPRESS_GLOBAL14"))
2093 dc_method
= DNS_COMPRESS_GLOBAL14
;
2094 else if (! strcmp(tok
, "DNS_COMPRESS_ALL"))
2095 dc_method
= DNS_COMPRESS_ALL
;
2097 result
= test_dns_name_fromwire(Tokens
[0],
2105 t_info("bad format at line %d\n", line
);
2113 t_info("Missing datafile %s\n", testfile
);
2119 t_dns_name_fromwire(void) {
2120 t_assert("dns_name_fromwire", 1, T_REQUIRED
, "%s", a42
);
2121 t_dns_name_fromwire_x("dns_name_fromwire_1_data", BUFLEN
);
2125 * XXXRTH these tests appear to be broken, so I have
2128 t_assert("dns_name_fromwire", 2, T_REQUIRED
, "%s", a43
);
2129 t_dns_name_fromwire_x("dns_name_fromwire_2_data", BUFLEN
);
2131 t_assert("dns_name_fromwire", 3, T_REQUIRED
, "%s", a44
);
2132 t_dns_name_fromwire_x("dns_name_fromwire_3_data", BUFLEN
);
2135 t_assert("dns_name_fromwire", 4, T_REQUIRED
, "%s", a45
);
2136 t_dns_name_fromwire_x("dns_name_fromwire_4_data", BUFLEN
);
2138 t_assert("dns_name_fromwire", 5, T_REQUIRED
, "%s", a46
);
2139 t_dns_name_fromwire_x("dns_name_fromwire_5_data", BUFLEN
);
2141 t_assert("dns_name_fromwire", 6, T_REQUIRED
, "%s", a47
);
2142 t_dns_name_fromwire_x("dns_name_fromwire_6_data", BUFLEN
);
2144 t_assert("dns_name_fromwire", 7, T_REQUIRED
, "%s", a48
);
2145 t_dns_name_fromwire_x("dns_name_fromwire_7_data", BUFLEN
);
2147 t_assert("dns_name_fromwire", 9, T_REQUIRED
, "%s", a49
);
2148 t_dns_name_fromwire_x("dns_name_fromwire_8_data", 2);
2152 static const char *a51
=
2153 "dns_name_towire(name, cctx, target) converts the DNS name "
2154 "'name' into wire format, compresses it as specified "
2155 "by the compression context cctx, stores the result in "
2156 "target and returns DNS_SUCCESS";
2158 static const char *a52
=
2159 "when not enough space exists in target, "
2160 "dns_name_towire(name, cctx, target) returns ISC_R_NOSPACE";
2163 test_dns_name_towire(char *testname
, unsigned int dc_method
, char *exp_data
,
2164 int exp_data_len
, isc_result_t exp_result
, size_t buflen
)
2169 unsigned char buf2
[BUFLEN
];
2170 unsigned char buf3
[BUFLEN
];
2171 isc_buffer_t iscbuf1
;
2172 isc_buffer_t iscbuf2
;
2173 isc_buffer_t iscbuf3
;
2174 dns_name_t dns_name
;
2175 isc_result_t dns_result
;
2176 isc_result_t isc_result
;
2177 dns_compress_t cctx
;
2180 t_info("testing using %s\n", testname
);
2182 result
= T_UNRESOLVED
;
2185 isc_result
= isc_mem_create(0, 0, &mctx
);
2186 if (isc_result
!= ISC_R_SUCCESS
) {
2187 t_info("isc_mem_create failed\n");
2190 dns_compress_init(&cctx
, -1, mctx
);
2191 dns_compress_setmethods(&cctx
, dc_method
);
2192 dns_name_init(&dns_name
, NULL
);
2193 len
= strlen(testname
);
2194 isc_buffer_init(&iscbuf1
, testname
, len
);
2195 isc_buffer_add(&iscbuf1
, len
);
2196 isc_buffer_init(&iscbuf2
, buf2
, BUFLEN
);
2197 dns_result
= dns_name_fromtext(&dns_name
, &iscbuf1
, NULL
, 0, &iscbuf2
);
2198 if (dns_result
== ISC_R_SUCCESS
) {
2199 isc_buffer_init(&iscbuf3
, buf3
, buflen
);
2200 dns_result
= dns_name_towire(&dns_name
, &cctx
, &iscbuf3
);
2201 if (dns_result
== exp_result
) {
2202 if (exp_result
== ISC_R_SUCCESS
) {
2204 * Compare results with expected data.
2206 val
= chkdata(buf3
, iscbuf3
.used
, exp_data
,
2215 t_info("dns_name_towire unexpectedly returned %s\n",
2216 dns_result_totext(dns_result
));
2220 t_info("dns_name_fromtext %s failed, result = %s\n",
2221 testname
, dns_result_totext(dns_result
));
2227 t_dns_name_towire_x(const char *testfile
, size_t buflen
) {
2231 unsigned int dc_method
;
2232 isc_result_t exp_result
;
2236 result
= T_UNRESOLVED
;
2237 fp
= fopen(testfile
, "r");
2240 while ((p
= t_fgetbs(fp
)) != NULL
) {
2245 * Skip comment lines.
2247 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
2252 cnt
= bustline(p
, Tokens
);
2255 * testname, dc_method,
2256 * exp_data, exp_data_len,
2260 dc_method
= t_dc_method_fromtext(Tokens
[3]);
2261 exp_result
= t_dns_result_fromtext(Tokens
[4]);
2263 result
= test_dns_name_towire(Tokens
[0],
2270 t_info("bad format at line %d\n", line
);
2278 t_info("Missing datafile %s\n", testfile
);
2284 t_dns_name_towire_1(void) {
2285 t_assert("dns_name_towire", 1, T_REQUIRED
, "%s", a51
);
2286 t_dns_name_towire_x("dns_name_towire_1_data", BUFLEN
);
2290 t_dns_name_towire_2(void) {
2291 t_assert("dns_name_towire", 2, T_REQUIRED
, "%s", a52
);
2292 t_dns_name_towire_x("dns_name_towire_2_data", 2);
2296 t_dns_name_towire(void) {
2297 t_dns_name_towire_1();
2298 t_dns_name_towire_2();
2301 #if 0 /* This is silly. A test should either exist, or not, but not
2302 * one that just returns "UNTESTED."
2304 static const char *a53
=
2305 "dns_name_concatenate(prefix, suffix, name, target) "
2306 "concatenates prefix and suffix, stores the result "
2307 "in target, canonicalizes any bitstring labels "
2308 "and returns ISC_R_SUCCESS";
2311 t_dns_name_concatenate(void) {
2312 t_assert("dns_name_concatenate", 1, T_REQUIRED
, "%s", a53
);
2313 t_result(T_UNTESTED
);
2317 testspec_t T_testlist
[] = {
2318 { t_dns_name_init
, "dns_name_init" },
2319 { t_dns_name_invalidate
, "dns_name_invalidate" },
2320 { t_dns_name_setbuffer
, "dns_name_setbuffer" },
2321 { t_dns_name_hasbuffer
, "dns_name_hasbuffer" },
2322 { t_dns_name_isabsolute
, "dns_name_isabsolute" },
2323 { t_dns_name_hash
, "dns_name_hash" },
2324 { t_dns_name_fullcompare
, "dns_name_fullcompare" },
2325 { t_dns_name_compare
, "dns_name_compare" },
2326 { t_dns_name_rdatacompare
, "dns_name_rdatacompare" },
2327 { t_dns_name_issubdomain
, "dns_name_issubdomain" },
2328 { t_dns_name_countlabels
, "dns_name_countlabels" },
2329 { t_dns_name_getlabel
, "dns_name_getlabel" },
2330 { t_dns_name_getlabelsequence
, "dns_name_getlabelsequence" },
2331 { t_dns_name_fromregion
, "dns_name_fromregion" },
2332 { t_dns_name_toregion
, "dns_name_toregion" },
2333 { t_dns_name_fromwire
, "dns_name_fromwire" },
2334 { t_dns_name_towire
, "dns_name_towire" },
2335 { t_dns_name_fromtext
, "dns_name_fromtext" },
2336 { t_dns_name_totext
, "dns_name_totext" },
2338 { t_dns_name_concatenate
, "dns_name_concatenate" },