1 /* $NetBSD: t_names.c,v 1.9 2014/12/10 04:37:53 christos Exp $ */
4 * Copyright (C) 2004-2009, 2011-2014 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.52 2011/03/12 04:59:46 tbox Exp */
27 #include <isc/buffer.h>
29 #include <isc/string.h>
31 #include <dns/compress.h>
32 #include <dns/fixedname.h>
34 #include <dns/result.h>
36 #include <tests/t_api.h>
40 #define BIGBUFLEN 4096
42 static char *Tokens
[MAXTOKS
+ 1];
48 * get a hex formatted dns message from a data
49 * file into an isc_buffer_t
50 * caller supplies data storage and the isc_buffer
51 * we read the file, convert, setup the buffer
52 * and return the data length
56 ctoh(unsigned char c
) {
60 val
= (c
>> 4) & 0x0f;
61 if ((0 <= val
) && (val
<= 9))
63 else if ((10 <= val
) && (val
<= 16))
64 buf
[0] = 'a' + val
- 10;
66 if ((0 <= val
) && (val
<= 9))
68 else if ((10 <= val
) && (val
<= 16))
69 buf
[1] = 'a' + val
- 10;
75 pbuf(isc_buffer_t
*pbuf
) {
81 while (len
< pbuf
->length
) {
82 printf("%s", ctoh(*p
));
90 #endif /* NEED_PBUF */
93 * Compare data at buf with data in hex representation at exp_data,
94 * of length exp_data_len, for equality.
95 * Return 0 if equal, else non-zero.
99 chkdata(unsigned char *buf
, size_t buflen
, char *exp_data
,
109 if (buflen
== exp_data_len
) {
110 data
= (unsigned char *)malloc(exp_data_len
*
111 sizeof(unsigned char));
113 t_info("malloc failed unexpectedly\n");
118 * First convert exp_data from hex format.
123 while (cnt
< exp_data_len
) {
125 if (('0' <= *q
) && (*q
<= '9'))
127 else if (('a' <= *q
) && (*q
<= 'f'))
129 else if (('A' <= *q
) && (*q
<= 'F'))
132 t_info("malformed comparison data\n");
140 if (('0' <= *q
) && (*q
<= '9'))
141 *p
|= ((*q
- '0') & 0x0f);
142 else if (('a' <= *q
) && (*q
<= 'f'))
143 *p
|= ((*q
- 'a' + 10) & 0x0f);
144 else if (('A' <= *q
) && (*q
<= 'F'))
145 *p
|= ((*q
- 'A' + 10) & 0x0f);
147 t_info("malformed comparison data\n");
161 for (cnt
= 0; cnt
< exp_data_len
; ++cnt
) {
167 if (cnt
== exp_data_len
)
170 t_info("bad data at position %lu, "
171 "got 0x%.2x, expected 0x%.2x\n",
172 (unsigned long)cnt
, *p
, *v
);
173 result
= (int)cnt
+ 1;
177 t_info("data length error, expected %lu, got %lu\n",
178 (unsigned long)exp_data_len
, (unsigned long)buflen
);
179 result
= (int)(exp_data_len
- buflen
);
185 * Get a hex formatted dns message from a data file into an isc_buffer_t.
186 * Caller supplies data storage and the isc_buffer. We read the file, convert,
187 * setup the buffer and return the data length.
190 getmsg(char *datafile_name
, isc_buffer_t
*pbuf
)
199 fp
= fopen(datafile_name
, "r");
201 t_info("No such file %s\n", datafile_name
);
205 p
= isc_buffer_used(pbuf
);
206 buflen
= isc_buffer_availablelength(pbuf
);
209 while ((c
= getc(fp
)) != EOF
) {
211 if ( (c
== ' ') || (c
== '\t') ||
212 (c
== '\r') || (c
== '\n'))
215 while ((c
= getc(fp
)) != '\n')
219 if (('0' <= c
) && (c
<= '9'))
221 else if (('a' <= c
) && (c
<= 'f'))
223 else if (('A' <= c
) && (c
<= 'F'))
227 t_info("Bad format in datafile\n");
230 if ((len
% 2) == 0) {
241 t_info("Buffer overflow error\n");
250 t_info("Bad format in %s\n", datafile_name
);
255 isc_buffer_add(pbuf
, cnt
);
260 bustline(char *line
, char **toks
) {
266 while ((p
= strtok(line
, "\t")) && (cnt
< MAXTOKS
)) {
276 #ifdef NEED_HNAME_TO_TNAME
279 * convert a name from hex representation to text form
280 * format of hex notation is:
285 hname_to_tname(char *src
, char *target
, size_t len
) {
295 if ((srclen
>= 2) && ((*p
!= '%') || (*(p
+1) != 'x'))) {
297 * No conversion needed.
301 memmove(target
, src
, srclen
+ 1);
310 if (('0' < c
) && (c
<= '9'))
312 else if (('a' <= c
) && (c
<= 'z'))
314 else if (('A' <= c
) && (c
<= 'Z'))
335 #endif /* NEED_HNAME_TO_TNAME */
337 static const char *a3
= "dns_name_init initializes 'name' to the empty name";
340 t_dns_name_init(void) {
344 unsigned char offsets
[1];
347 t_assert("dns_name_init", 1, T_REQUIRED
, "%s", a3
);
349 dns_name_init(&name
, offsets
);
350 /* magic is hidden in name.c ...
351 if (name.magic != NAME_MAGIC) {
352 t_info("name.magic is not set to NAME_MAGIC\n");
356 if (name
.ndata
!= NULL
) {
357 t_info("name.ndata is not NULL\n");
360 if (name
.length
!= 0) {
361 t_info("name.length is not 0\n");
364 if (name
.labels
!= 0) {
365 t_info("name.labels is not 0\n");
368 if (name
.attributes
!= 0) {
369 t_info("name.attributes is not 0\n");
372 if (name
.offsets
!= offsets
) {
373 t_info("name.offsets is incorrect\n");
376 if (name
.buffer
!= NULL
) {
377 t_info("name.buffer is not NULL\n");
388 static const char *a4
= "dns_name_invalidate invalidates 'name'";
391 t_dns_name_invalidate(void) {
395 unsigned char offsets
[1];
397 t_assert("dns_name_invalidate", 1, T_REQUIRED
, "%s", a4
);
400 dns_name_init(&name
, offsets
);
401 dns_name_invalidate(&name
);
403 /* magic is hidden in name.c ...
404 if (name.magic != 0) {
405 t_info("name.magic is not set to NAME_MAGIC\n");
409 if (name
.ndata
!= NULL
) {
410 t_info("name.ndata is not NULL\n");
413 if (name
.length
!= 0) {
414 t_info("name.length is not 0\n");
417 if (name
.labels
!= 0) {
418 t_info("name.labels is not 0\n");
421 if (name
.attributes
!= 0) {
422 t_info("name.attributes is not 0\n");
425 if (name
.offsets
!= NULL
) {
426 t_info("name.offsets is not NULL\n");
429 if (name
.buffer
!= NULL
) {
430 t_info("name.buffer is not NULL\n");
441 static const char *a5
= "dns_name_setbuffer dedicates a buffer for use "
445 t_dns_name_setbuffer(void) {
447 unsigned char junk
[BUFLEN
];
451 t_assert("dns_name_setbuffer", 1, T_REQUIRED
, "%s", a5
);
453 isc_buffer_init(&buffer
, junk
, BUFLEN
);
454 dns_name_init(&name
, NULL
);
455 dns_name_setbuffer(&name
, &buffer
);
456 if (name
.buffer
== &buffer
)
464 static const char *a6
= "dns_name_hasbuffer returns ISC_TRUE if 'name' has a "
465 "dedicated buffer, otherwise it returns ISC_FALSE";
468 t_dns_name_hasbuffer(void) {
471 unsigned char junk
[BUFLEN
];
475 t_assert("dns_name_hasbuffer", 1, T_REQUIRED
, "%s", a6
);
478 isc_buffer_init(&buffer
, junk
, BUFLEN
);
479 dns_name_init(&name
, NULL
);
480 if (dns_name_hasbuffer(&name
) != ISC_FALSE
)
482 dns_name_setbuffer(&name
, &buffer
);
483 if (dns_name_hasbuffer(&name
) != ISC_TRUE
)
493 static const char *a7
= "dns_name_isabsolute returns ISC_TRUE if 'name' ends "
497 test_dns_name_isabsolute(char *test_name
, isc_boolean_t expected
) {
501 unsigned char junk
[BUFLEN
];
504 isc_boolean_t isabs_p
;
509 t_info("testing name %s\n", test_name
);
510 len
= strlen(test_name
);
511 isc_buffer_init(&buf
, test_name
, len
);
512 isc_buffer_add(&buf
, len
);
513 isc_buffer_init(&binbuf
, &junk
[0], BUFLEN
);
514 dns_name_init(&name
, NULL
);
515 dns_name_setbuffer(&name
, &binbuf
);
516 result
= dns_name_fromtext(&name
, &buf
, NULL
, 0, NULL
);
517 if (result
== ISC_R_SUCCESS
) {
518 isabs_p
= dns_name_isabsolute(&name
);
519 if (isabs_p
== expected
)
524 t_info("dns_name_fromtext %s failed, result = %s\n",
525 test_name
, dns_result_totext(result
));
531 t_dns_name_isabsolute(void) {
538 t_assert("dns_name_isabsolute", 1, T_REQUIRED
, "%s", a7
);
540 result
= T_UNRESOLVED
;
541 fp
= fopen("dns_name_isabsolute_data", "r");
544 while ((p
= t_fgetbs(fp
)) != NULL
) {
549 * Skip comment lines.
551 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
556 cnt
= bustline(p
, Tokens
);
559 * label, bitpos, expected value.
561 result
= test_dns_name_isabsolute(Tokens
[0],
567 t_info("bad datafile format at line %d\n",
576 t_info("Missing datafile dns_name_isabsolute_data\n");
581 static const char *a8
= "dns_name_hash(name, case_sensitive) returns "
582 "a hash of 'name' which is case_sensitive if case_sensitive "
590 test_dns_name_hash(char *test_name1
, char *test_name2
,
591 isc_boolean_t csh_match
, isc_boolean_t cish_match
) {
597 dns_fixedname_t fixed1
;
598 dns_fixedname_t fixed2
;
599 dns_name_t
*dns_name1
;
600 dns_name_t
*dns_name2
;
606 t_info("testing names %s and %s\n", test_name1
, test_name2
);
608 dns_fixedname_init(&fixed1
);
609 dns_fixedname_init(&fixed2
);
610 dns_name1
= dns_fixedname_name(&fixed1
);
611 dns_name2
= dns_fixedname_name(&fixed2
);
612 result
= dns_name_fromstring2(dns_name1
, test_name1
, NULL
, 0, NULL
);
613 if (result
== ISC_R_SUCCESS
) {
614 result
= dns_name_fromstring2(dns_name2
, test_name2
, NULL
,
616 if (result
== ISC_R_SUCCESS
) {
617 hash1
= dns_name_hash(dns_name1
, ISC_TRUE
);
618 hash2
= dns_name_hash(dns_name2
, ISC_TRUE
);
622 if (match
!= csh_match
) {
624 t_info("hash mismatch when ISC_TRUE\n");
626 hash1
= dns_name_hash(dns_name1
, ISC_FALSE
);
627 hash2
= dns_name_hash(dns_name2
, ISC_FALSE
);
631 if (match
!= cish_match
) {
633 t_info("hash mismatch when ISC_FALSE\n");
640 t_info("dns_name_fromstring2 %s failed, result = %s\n",
641 test_name2
, dns_result_totext(result
));
644 t_info("dns_name_fromstring2 %s failed, result = %s\n",
645 test_name1
, dns_result_totext(result
));
651 t_dns_name_hash(void) {
658 t_assert("dns_name_hash", 1, T_REQUIRED
, "%s", a8
);
660 result
= T_UNRESOLVED
;
661 fp
= fopen("dns_name_hash_data", "r");
664 while ((p
= t_fgetbs(fp
)) != NULL
) {
669 * Skip comment lines.
671 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
676 cnt
= bustline(p
, Tokens
);
679 * name1, name2, exp match value if
680 * case_sensitive true,
681 * exp match value of case_sensitive false
683 result
= test_dns_name_hash(
686 atoi(Tokens
[2]) == 0 ?
687 ISC_FALSE
: ISC_TRUE
,
688 atoi(Tokens
[3]) == 0 ?
689 ISC_FALSE
: ISC_TRUE
);
691 t_info("bad datafile format at line %d\n",
700 t_info("Missing datafile dns_name_hash_data\n");
705 static const char *a10
=
706 "dns_name_fullcompare(name1, name2, orderp, nlabelsp) "
707 "returns the DNSSEC ordering relationship between name1 and "
708 "name2, sets orderp to -1 if name1 < name2, to 0 if "
709 "name1 == name2, or to 1 if name1 > name2, sets nlabelsp "
710 "to the number of labels name1 and name2 have in common, "
711 "and sets nbitsp to the number of bits name1 and name2 "
715 * a11 thru a22 merged into a10.
718 dns_namereln_to_text(dns_namereln_t reln
) {
721 if (reln
== dns_namereln_contains
)
723 else if (reln
== dns_namereln_subdomain
)
725 else if (reln
== dns_namereln_equal
)
727 else if (reln
== dns_namereln_none
)
729 else if (reln
== dns_namereln_commonancestor
)
730 p
= "commonancestor";
738 test_dns_name_fullcompare(char *name1
, char *name2
,
739 dns_namereln_t exp_dns_reln
,
740 int exp_order
, int exp_nlabels
)
745 unsigned int nlabels
;
746 dns_fixedname_t fixed1
;
747 dns_fixedname_t fixed2
;
748 dns_name_t
*dns_name1
;
749 dns_name_t
*dns_name2
;
750 isc_result_t dns_result
;
751 dns_namereln_t dns_reln
;
754 result
= T_UNRESOLVED
;
757 t_info("testing names %s and %s for relation %s\n", name1
, name2
,
758 dns_namereln_to_text(exp_dns_reln
));
760 dns_fixedname_init(&fixed1
);
761 dns_fixedname_init(&fixed2
);
762 dns_name1
= dns_fixedname_name(&fixed1
);
763 dns_name2
= dns_fixedname_name(&fixed2
);
764 dns_result
= dns_name_fromstring2(dns_name1
, name1
, NULL
, 0, NULL
);
765 if (dns_result
== ISC_R_SUCCESS
) {
766 dns_result
= dns_name_fromstring2(dns_name2
, name2
, NULL
,
768 if (dns_result
== ISC_R_SUCCESS
) {
769 dns_reln
= dns_name_fullcompare(dns_name1
, dns_name2
,
772 if (dns_reln
!= exp_dns_reln
) {
774 t_info("expected relationship of %s, got %s\n",
775 dns_namereln_to_text(exp_dns_reln
),
776 dns_namereln_to_text(dns_reln
));
785 if (order
!= exp_order
) {
787 t_info("expected ordering %d, got %d\n",
790 if ((exp_nlabels
>= 0) &&
791 (nlabels
!= (unsigned int)exp_nlabels
)) {
793 t_info("expecting %d labels, got %d\n",
794 exp_nlabels
, nlabels
);
801 t_info("dns_name_fromstring2 failed, result == %s\n",
802 dns_result_totext(result
));
805 t_info("dns_name_fromstring2 failed, result == %s\n",
806 dns_result_totext(result
));
813 t_dns_name_fullcompare(void) {
821 t_assert("dns_name_fullcompare", 1, T_REQUIRED
, "%s", a10
);
823 result
= T_UNRESOLVED
;
824 fp
= fopen("dns_name_fullcompare_data", "r");
827 while ((p
= t_fgetbs(fp
)) != NULL
) {
831 * Skip comment lines.
833 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
838 cnt
= bustline(p
, Tokens
);
841 * name1, name2, exp_reln, exp_order,
844 if (!strcmp(Tokens
[2], "none"))
845 reln
= dns_namereln_none
;
846 else if (!strcmp(Tokens
[2], "contains"))
847 reln
= dns_namereln_contains
;
848 else if (!strcmp(Tokens
[2], "subdomain"))
849 reln
= dns_namereln_subdomain
;
850 else if (!strcmp(Tokens
[2], "equal"))
851 reln
= dns_namereln_equal
;
852 else if (!strcmp(Tokens
[2], "commonancestor"))
853 reln
= dns_namereln_commonancestor
;
855 t_info("bad format at line %d\n", line
);
859 result
= test_dns_name_fullcompare(
866 t_info("bad format at line %d\n", line
);
874 t_info("Missing datafile dns_name_fullcompare_data\n");
879 static const char *a23
=
880 "dns_name_compare(name1, name2) returns information about "
881 "the relative ordering under the DNSSEC ordering relationship "
882 "of name1 and name2";
885 * a24 thru a29 merged into a23.
889 test_dns_name_compare(char *name1
, char *name2
, int exp_order
) {
892 isc_result_t dns_result
;
893 dns_fixedname_t fixed1
;
894 dns_fixedname_t fixed2
;
895 dns_name_t
*dns_name1
;
896 dns_name_t
*dns_name2
;
898 result
= T_UNRESOLVED
;
900 t_info("testing %s %s %s\n", name1
,
901 exp_order
== 0 ? "==": (exp_order
== -1 ? "<" : ">"),
904 dns_fixedname_init(&fixed1
);
905 dns_fixedname_init(&fixed2
);
906 dns_name1
= dns_fixedname_name(&fixed1
);
907 dns_name2
= dns_fixedname_name(&fixed2
);
908 dns_result
= dns_name_fromstring2(dns_name1
, name1
, NULL
, 0, NULL
);
909 if (dns_result
== ISC_R_SUCCESS
) {
910 dns_result
= dns_name_fromstring2(dns_name2
, name2
, NULL
,
912 if (dns_result
== ISC_R_SUCCESS
) {
913 order
= dns_name_compare(dns_name1
, dns_name2
);
921 if (order
!= exp_order
) {
922 t_info("expected order of %d, got %d\n",
928 t_info("dns_name_fromstring2 failed, result == %s\n",
929 dns_result_totext(result
));
932 t_info("dns_name_fromstring2 failed, result == %s\n",
933 dns_result_totext(result
));
940 t_dns_name_compare(void) {
947 t_assert("dns_name_compare", 1, T_REQUIRED
, "%s", a23
);
949 result
= T_UNRESOLVED
;
950 fp
= fopen("dns_name_compare_data", "r");
953 while ((p
= t_fgetbs(fp
)) != NULL
) {
958 * Skip comment lines.
960 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
965 cnt
= bustline(p
, Tokens
);
968 * name1, name2, order.
970 result
= test_dns_name_compare(
975 t_info("bad datafile format at line %d\n",
984 t_info("Missing datafile dns_name_compare_data\n");
989 static const char *a30
=
990 "dns_name_rdatacompare(name1, name2) returns information "
991 "about the relative ordering of name1 and name2 as if they "
992 "are part of rdata in DNSSEC canonical form";
995 * a31, a32 merged into a30.
999 test_dns_name_rdatacompare(char *name1
, char *name2
, int exp_order
) {
1002 isc_result_t dns_result
;
1003 dns_fixedname_t fixed1
;
1004 dns_fixedname_t fixed2
;
1005 dns_name_t
*dns_name1
;
1006 dns_name_t
*dns_name2
;
1008 result
= T_UNRESOLVED
;
1010 t_info("testing %s %s %s\n", name1
,
1011 exp_order
== 0 ? "==": (exp_order
== -1 ? "<" : ">"), name2
);
1013 dns_fixedname_init(&fixed1
);
1014 dns_fixedname_init(&fixed2
);
1015 dns_name1
= dns_fixedname_name(&fixed1
);
1016 dns_name2
= dns_fixedname_name(&fixed2
);
1017 dns_result
= dns_name_fromstring2(dns_name1
, name1
, NULL
, 0, NULL
);
1018 if (dns_result
== ISC_R_SUCCESS
) {
1019 dns_result
= dns_name_fromstring2(dns_name2
, name2
, NULL
,
1021 if (dns_result
== ISC_R_SUCCESS
) {
1022 order
= dns_name_rdatacompare(dns_name1
, dns_name2
);
1030 if (order
!= exp_order
) {
1031 t_info("expected order of %d, got %d\n",
1037 t_info("dns_name_fromstring2 failed, result == %s\n",
1038 dns_result_totext(result
));
1041 t_info("dns_name_fromstring2 failed, result == %s\n",
1042 dns_result_totext(result
));
1049 t_dns_name_rdatacompare(void) {
1056 t_assert("dns_name_rdatacompare", 1, T_REQUIRED
, "%s", a30
);
1058 result
= T_UNRESOLVED
;
1059 fp
= fopen("dns_name_rdatacompare_data", "r");
1062 while ((p
= t_fgetbs(fp
)) != NULL
) {
1067 * Skip comment lines.
1069 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1074 cnt
= bustline(p
, Tokens
);
1077 * name1, name2, order.
1079 result
= test_dns_name_rdatacompare(
1084 t_info("bad datafile format at line %d\n",
1093 t_info("Missing datafile dns_name_rdatacompare_data\n");
1099 static const char *a33
=
1100 "when name1 is a subdomain of name2, "
1101 "dns_name_issubdomain(name1, name2) returns true, "
1102 "otherwise it returns false.";
1105 * a34 merged into a33.
1109 test_dns_name_issubdomain(char *name1
, char *name2
, isc_boolean_t exp_rval
) {
1112 isc_result_t dns_result
;
1113 dns_fixedname_t fixed1
;
1114 dns_fixedname_t fixed2
;
1115 dns_name_t
*dns_name1
;
1116 dns_name_t
*dns_name2
;
1118 result
= T_UNRESOLVED
;
1120 t_info("testing %s %s a subdomain of %s\n", name1
,
1121 exp_rval
== 0 ? "is not" : "is", name2
);
1123 dns_fixedname_init(&fixed1
);
1124 dns_fixedname_init(&fixed2
);
1125 dns_name1
= dns_fixedname_name(&fixed1
);
1126 dns_name2
= dns_fixedname_name(&fixed2
);
1127 dns_result
= dns_name_fromstring2(dns_name1
, name1
, NULL
, 0, NULL
);
1128 if (dns_result
== ISC_R_SUCCESS
) {
1129 dns_result
= dns_name_fromstring2(dns_name2
, name2
, NULL
,
1131 if (dns_result
== ISC_R_SUCCESS
) {
1132 rval
= dns_name_issubdomain(dns_name1
, dns_name2
);
1134 if (rval
!= exp_rval
) {
1135 t_info("expected return value of %s, got %s\n",
1136 exp_rval
== ISC_TRUE
? "true" : "false",
1137 rval
== ISC_TRUE
? "true" : "false");
1142 t_info("dns_name_fromstring2 failed, result == %s\n",
1143 dns_result_totext(result
));
1146 t_info("dns_name_fromstring2 failed, result == %s\n",
1147 dns_result_totext(result
));
1154 t_dns_name_issubdomain(void) {
1161 t_assert("dns_name_issubdomain", 1, T_REQUIRED
, "%s", a33
);
1163 result
= T_UNRESOLVED
;
1164 fp
= fopen("dns_name_issubdomain_data", "r");
1167 while ((p
= t_fgetbs(fp
)) != NULL
) {
1172 * Skip comment lines.
1174 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1179 cnt
= bustline(p
, Tokens
);
1182 * name1, name2, issubdomain_p.
1184 result
= test_dns_name_issubdomain(
1187 atoi(Tokens
[2]) == 0 ?
1188 ISC_FALSE
: ISC_TRUE
);
1190 t_info("bad datafile format at line %d\n",
1199 t_info("Missing datafile dns_name_issubdomain_data\n");
1204 static const char *a35
=
1205 "dns_name_countlabels(name) returns the number "
1206 "of labels in name";
1209 test_dns_name_countlabels(char *test_name
, unsigned int exp_nlabels
) {
1211 unsigned int nlabels
;
1212 isc_result_t dns_result
;
1213 dns_fixedname_t fixed
;
1214 dns_name_t
*dns_name
;
1216 result
= T_UNRESOLVED
;
1218 t_info("testing %s\n", test_name
);
1220 dns_fixedname_init(&fixed
);
1221 dns_name
= dns_fixedname_name(&fixed
);
1222 dns_result
= dns_name_fromstring2(dns_name
, test_name
, NULL
, 0, NULL
);
1223 if (dns_result
== ISC_R_SUCCESS
) {
1224 nlabels
= dns_name_countlabels(dns_name
);
1226 if (nlabels
!= exp_nlabels
) {
1227 t_info("expected %d, got %d\n", exp_nlabels
, nlabels
);
1232 t_info("dns_name_fromstring2 failed, result == %s\n",
1233 dns_result_totext(dns_result
));
1240 t_dns_name_countlabels(void) {
1247 t_assert("dns_name_countlabels", 1, T_REQUIRED
, "%s", a35
);
1249 result
= T_UNRESOLVED
;
1250 fp
= fopen("dns_name_countlabels_data", "r");
1253 while ((p
= t_fgetbs(fp
)) != NULL
) {
1258 * Skip comment lines.
1260 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1265 cnt
= bustline(p
, Tokens
);
1270 result
= test_dns_name_countlabels(Tokens
[0],
1273 t_info("bad format at line %d\n", line
);
1281 t_info("Missing datafile dns_name_countlabels_data\n");
1286 static const char *a36
=
1287 "when n is less than the number of labels in name, "
1288 "dns_name_getlabel(name, n, labelp) initializes labelp "
1289 "to point to the nth label in name";
1292 * The strategy here is two take two dns names with a shared label in
1293 * different positions, get the two labels and compare them for equality.
1294 * If they don't match, dns_name_getlabel failed.
1298 test_dns_name_getlabel(char *test_name1
, int label1_pos
, char *test_name2
,
1306 dns_fixedname_t fixed1
;
1307 dns_fixedname_t fixed2
;
1308 dns_name_t
*dns_name1
;
1309 dns_name_t
*dns_name2
;
1310 dns_label_t dns_label1
;
1311 dns_label_t dns_label2
;
1312 isc_result_t dns_result
;
1315 result
= T_UNRESOLVED
;
1317 t_info("testing with %s and %s\n", test_name1
, test_name2
);
1319 dns_fixedname_init(&fixed1
);
1320 dns_fixedname_init(&fixed2
);
1321 dns_name1
= dns_fixedname_name(&fixed1
);
1322 dns_name2
= dns_fixedname_name(&fixed2
);
1323 dns_result
= dns_name_fromstring2(dns_name1
, test_name1
, NULL
,
1325 if (dns_result
== ISC_R_SUCCESS
) {
1326 dns_result
= dns_name_fromstring2(dns_name2
, test_name2
, NULL
,
1328 if (dns_result
== ISC_R_SUCCESS
) {
1329 dns_name_getlabel(dns_name1
, label1_pos
, &dns_label1
);
1330 dns_name_getlabel(dns_name2
, label2_pos
, &dns_label2
);
1331 if (dns_label1
.length
!= dns_label2
.length
) {
1332 t_info("label lengths differ\n");
1335 p
= dns_label1
.base
;
1336 q
= dns_label2
.base
;
1337 for (cnt
= 0; cnt
< dns_label1
.length
; ++cnt
) {
1339 t_info("labels differ at position %d",
1349 t_info("dns_name_fromstring2 failed, result == %s",
1350 dns_result_totext(result
));
1353 t_info("dns_name_fromstring2 failed, result == %s",
1354 dns_result_totext(result
));
1360 t_dns_name_getlabel(void) {
1367 t_assert("dns_name_getlabel", 1, T_REQUIRED
, "%s", a36
);
1369 result
= T_UNRESOLVED
;
1370 fp
= fopen("dns_name_getlabel_data", "r");
1373 while ((p
= t_fgetbs(fp
)) != NULL
) {
1378 * Skip comment lines.
1380 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1385 cnt
= bustline(p
, Tokens
);
1388 * name1, name2, nlabels.
1390 result
= test_dns_name_getlabel(Tokens
[0],
1395 t_info("bad format at line %d\n", line
);
1403 t_info("Missing datafile dns_name_getlabel_data\n");
1408 static const char *a37
=
1409 "when source contains at least first + n labels, "
1410 "dns_name_getlabelsequence(source, first, n, target) "
1411 "initializes target to point to the n label sequence of "
1412 "labels in source starting with first";
1415 * We adopt a similiar strategy to that used by the dns_name_getlabel test.
1419 test_dns_name_getlabelsequence(char *test_name1
, int label1_start
,
1420 char *test_name2
, int label2_start
, int range
)
1427 dns_fixedname_t fixed1
;
1428 dns_fixedname_t fixed2
;
1429 dns_name_t
*dns_name1
;
1430 dns_name_t
*dns_name2
;
1431 dns_name_t dns_targetname1
;
1432 dns_name_t dns_targetname2
;
1433 isc_result_t dns_result
;
1434 isc_buffer_t buffer1
;
1435 isc_buffer_t buffer2
;
1436 unsigned char junk1
[BUFLEN
];
1437 unsigned char junk2
[BUFLEN
];
1440 result
= T_UNRESOLVED
;
1441 dns_fixedname_init(&fixed1
);
1442 dns_fixedname_init(&fixed2
);
1443 dns_name1
= dns_fixedname_name(&fixed1
);
1444 dns_name2
= dns_fixedname_name(&fixed2
);
1445 dns_result
= dns_name_fromstring2(dns_name1
, test_name1
, NULL
,
1447 if (dns_result
== ISC_R_SUCCESS
) {
1448 dns_result
= dns_name_fromstring2(dns_name2
, test_name2
, NULL
,
1450 if (dns_result
== ISC_R_SUCCESS
) {
1451 t_info("testing %s %s\n", test_name1
, test_name2
);
1452 dns_name_init(&dns_targetname1
, NULL
);
1453 dns_name_init(&dns_targetname2
, NULL
);
1454 dns_name_getlabelsequence(dns_name1
, label1_start
,
1455 range
, &dns_targetname1
);
1456 dns_name_getlabelsequence(dns_name2
, label2_start
,
1457 range
, &dns_targetname2
);
1460 * Now convert both targets to text for comparison.
1462 isc_buffer_init(&buffer1
, junk1
, BUFLEN
);
1463 isc_buffer_init(&buffer2
, junk2
, BUFLEN
);
1464 dns_name_totext(&dns_targetname1
, ISC_TRUE
, &buffer1
);
1465 dns_name_totext(&dns_targetname2
, ISC_TRUE
, &buffer2
);
1466 if (buffer1
.used
== buffer2
.used
) {
1469 for (cnt
= 0; cnt
< buffer1
.used
; ++cnt
) {
1472 t_info("names differ at %d\n",
1480 t_info("lengths differ\n");
1487 t_info("dns_name_fromstring2 failed, result == %s",
1488 dns_result_totext(dns_result
));
1491 t_info("dns_name_fromstring2 failed, result == %s",
1492 dns_result_totext(dns_result
));
1498 t_dns_name_getlabelsequence(void) {
1505 t_assert("dns_name_getlabelsequence", 1, T_REQUIRED
, "%s", a37
);
1507 result
= T_UNRESOLVED
;
1508 fp
= fopen("dns_name_getlabelsequence_data", "r");
1511 while ((p
= t_fgetbs(fp
)) != NULL
) {
1516 * Skip comment lines.
1518 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1523 cnt
= bustline(p
, Tokens
);
1526 * name1, name2, nlabels.
1528 result
= test_dns_name_getlabelsequence(
1535 t_info("bad format at line %d\n", line
);
1543 t_info("Missing datafile dns_name_getlabelsequence_data\n");
1548 static const char *a38
=
1549 "dns_name_fromregion(name, region) converts a DNS name "
1550 "from a region representation to a name representation";
1553 test_dns_name_fromregion(char *test_name
) {
1556 unsigned int nlabels
;
1557 isc_result_t dns_result
;
1558 dns_fixedname_t fixed1
;
1559 dns_name_t
*dns_name1
;
1560 dns_name_t dns_name2
;
1561 dns_namereln_t dns_namereln
;
1562 isc_region_t region
;
1564 result
= T_UNRESOLVED
;
1566 t_info("testing %s\n", test_name
);
1568 dns_fixedname_init(&fixed1
);
1569 dns_name1
= dns_fixedname_name(&fixed1
);
1570 dns_result
= dns_name_fromstring2(dns_name1
, test_name
, NULL
, 0, NULL
);
1571 if (dns_result
== ISC_R_SUCCESS
) {
1573 dns_name_toregion(dns_name1
, ®ion
);
1575 dns_name_init(&dns_name2
, NULL
);
1576 dns_name_fromregion(&dns_name2
, ®ion
);
1577 dns_namereln
= dns_name_fullcompare(dns_name1
, &dns_name2
,
1579 if (dns_namereln
== dns_namereln_equal
)
1584 t_info("dns_name_fromstring2 failed, result == %s\n",
1585 dns_result_totext(result
));
1591 t_dns_name_fromregion(void) {
1598 t_assert("dns_name_fromregion", 1, T_REQUIRED
, "%s", a38
);
1600 result
= T_UNRESOLVED
;
1601 fp
= fopen("dns_name_fromregion_data", "r");
1604 while ((p
= t_fgetbs(fp
)) != NULL
) {
1609 * Skip comment lines.
1611 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1616 cnt
= bustline(p
, Tokens
);
1621 result
= test_dns_name_fromregion(Tokens
[0]);
1623 t_info("bad format at line %d\n", line
);
1631 t_info("Missing datafile dns_name_fromregion_data\n");
1636 static const char *a39
=
1637 "dns_name_toregion(name, region) converts a DNS name "
1638 "from a region representation to a name representation";
1641 t_dns_name_toregion(void) {
1648 t_assert("dns_name_toregion", 1, T_REQUIRED
, "%s", a39
);
1650 result
= T_UNRESOLVED
;
1651 fp
= fopen("dns_name_toregion_data", "r");
1654 while ((p
= t_fgetbs(fp
)) != NULL
) {
1659 * Skip comment lines.
1661 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1666 cnt
= bustline(p
, Tokens
);
1671 result
= test_dns_name_fromregion(Tokens
[0]);
1673 t_info("bad format at line %d\n", line
);
1681 t_info("Missing datafile dns_name_toregion_data\n");
1686 static const char *a40
=
1687 "dns_name_fromtext(name, source, origin, downcase, target) "
1688 "converts the textual representation of a DNS name at source "
1689 "into uncompressed wire form at target, appending origin to "
1690 "the converted name if origin is non-NULL and converting "
1691 "upper case to lower case during conversion "
1692 "if downcase is true.";
1695 test_dns_name_fromtext(char *test_name1
, char *test_name2
, char *test_origin
,
1696 unsigned int downcase
)
1700 unsigned int nlabels
;
1701 unsigned char junk1
[BUFLEN
];
1702 unsigned char junk2
[BUFLEN
];
1703 unsigned char junk3
[BUFLEN
];
1704 isc_buffer_t binbuf1
;
1705 isc_buffer_t binbuf2
;
1706 isc_buffer_t binbuf3
;
1707 isc_buffer_t txtbuf1
;
1708 isc_buffer_t txtbuf2
;
1709 isc_buffer_t txtbuf3
;
1710 dns_name_t dns_name1
;
1711 dns_name_t dns_name2
;
1712 dns_name_t dns_name3
;
1713 isc_result_t dns_result
;
1714 dns_namereln_t dns_namereln
;
1716 t_info("testing %s %s %s\n", test_name1
, test_name2
, test_origin
);
1718 isc_buffer_init(&binbuf1
, junk1
, BUFLEN
);
1719 isc_buffer_init(&binbuf2
, junk2
, BUFLEN
);
1720 isc_buffer_init(&binbuf3
, junk3
, BUFLEN
);
1722 isc_buffer_init(&txtbuf1
, test_name1
, strlen(test_name1
));
1723 isc_buffer_add(&txtbuf1
, strlen(test_name1
));
1725 isc_buffer_init(&txtbuf2
, test_name2
, strlen(test_name2
));
1726 isc_buffer_add(&txtbuf2
, strlen(test_name2
));
1728 isc_buffer_init(&txtbuf3
, test_origin
, strlen(test_origin
));
1729 isc_buffer_add(&txtbuf3
, strlen(test_origin
));
1730 dns_name_init(&dns_name1
, NULL
);
1731 dns_name_init(&dns_name2
, NULL
);
1732 dns_name_init(&dns_name3
, NULL
);
1733 dns_name_setbuffer(&dns_name1
, &binbuf1
);
1734 dns_name_setbuffer(&dns_name2
, &binbuf2
);
1735 dns_name_setbuffer(&dns_name3
, &binbuf3
);
1737 dns_result
= dns_name_fromtext(&dns_name3
, &txtbuf3
, NULL
, 0,
1739 if (dns_result
!= ISC_R_SUCCESS
) {
1740 t_info("dns_name_fromtext(dns_name3) failed, result == %s\n",
1741 dns_result_totext(dns_result
));
1745 dns_result
= dns_name_fromtext(&dns_name1
, &txtbuf1
, &dns_name3
,
1746 downcase
, &binbuf1
);
1747 if (dns_result
!= ISC_R_SUCCESS
) {
1748 t_info("dns_name_fromtext(dns_name1) failed, result == %s\n",
1749 dns_result_totext(dns_result
));
1753 dns_result
= dns_name_fromtext(&dns_name2
, &txtbuf2
, NULL
, 0,
1755 if (dns_result
!= ISC_R_SUCCESS
) {
1756 t_info("dns_name_fromtext(dns_name2) failed, result == %s\n",
1757 dns_result_totext(dns_result
));
1761 dns_namereln
= dns_name_fullcompare(&dns_name1
, &dns_name2
, &order
,
1764 if (dns_namereln
== dns_namereln_equal
)
1767 t_info("dns_name_fullcompare returned %s\n",
1768 dns_namereln_to_text(dns_namereln
));
1776 t_dns_name_fromtext(void) {
1783 t_assert("dns_name_fromtext", 1, T_REQUIRED
, "%s", a40
);
1785 result
= T_UNRESOLVED
;
1786 fp
= fopen("dns_name_fromtext_data", "r");
1789 while ((p
= t_fgetbs(fp
)) != NULL
) {
1794 * Skip comment lines.
1796 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1801 cnt
= bustline(p
, Tokens
);
1804 * test_name1, test_name2, test_origin,
1807 result
= test_dns_name_fromtext(Tokens
[0],
1815 t_info("bad format at line %d\n", line
);
1823 t_info("Missing datafile dns_name_fromtext\n");
1828 static const char *a41
=
1829 "dns_name_totext(name, omit_final_dot, target) converts "
1830 "the DNS name 'name' in wire format to textual format "
1831 "at target, and adds a final '.' to the name if "
1832 "omit_final_dot is false";
1835 test_dns_name_totext(char *test_name
, isc_boolean_t omit_final
) {
1839 unsigned int nlabels
;
1840 unsigned char junk1
[BUFLEN
];
1841 unsigned char junk2
[BUFLEN
];
1842 unsigned char junk3
[BUFLEN
];
1846 dns_name_t dns_name1
;
1847 dns_name_t dns_name2
;
1848 isc_result_t dns_result
;
1849 dns_namereln_t dns_namereln
;
1851 t_info("testing %s\n", test_name
);
1853 len
= strlen(test_name
);
1854 isc_buffer_init(&buf1
, test_name
, len
);
1855 isc_buffer_add(&buf1
, len
);
1857 dns_name_init(&dns_name1
, NULL
);
1858 isc_buffer_init(&buf2
, junk2
, BUFLEN
);
1861 * Out of the data file to dns_name1.
1863 dns_result
= dns_name_fromtext(&dns_name1
, &buf1
, NULL
, 0, &buf2
);
1864 if (dns_result
!= ISC_R_SUCCESS
) {
1865 t_info("dns_name_fromtext failed, result == %s\n",
1866 dns_result_totext(dns_result
));
1867 return (T_UNRESOLVED
);
1871 * From dns_name1 into a text buffer.
1873 isc_buffer_invalidate(&buf1
);
1874 isc_buffer_init(&buf1
, junk1
, BUFLEN
);
1875 dns_result
= dns_name_totext(&dns_name1
, omit_final
, &buf1
);
1876 if (dns_result
!= ISC_R_SUCCESS
) {
1877 t_info("dns_name_totext failed, result == %s\n",
1878 dns_result_totext(dns_result
));
1883 * From the text buffer into dns_name2.
1885 dns_name_init(&dns_name2
, NULL
);
1886 isc_buffer_init(&buf3
, junk3
, BUFLEN
);
1887 dns_result
= dns_name_fromtext(&dns_name2
, &buf1
, NULL
, 0, &buf3
);
1888 if (dns_result
!= ISC_R_SUCCESS
) {
1889 t_info("dns_name_fromtext failed, result == %s\n",
1890 dns_result_totext(dns_result
));
1891 return (T_UNRESOLVED
);
1894 dns_namereln
= dns_name_fullcompare(&dns_name1
, &dns_name2
,
1896 if (dns_namereln
== dns_namereln_equal
)
1899 t_info("dns_name_fullcompare returned %s\n",
1900 dns_namereln_to_text(dns_namereln
));
1908 t_dns_name_totext(void) {
1915 t_assert("dns_name_totext", 1, T_REQUIRED
, "%s", a41
);
1917 result
= T_UNRESOLVED
;
1918 fp
= fopen("dns_name_totext_data", "r");
1921 while ((p
= t_fgetbs(fp
)) != NULL
) {
1926 * Skip comment lines.
1928 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
1933 cnt
= bustline(p
, Tokens
);
1936 * test_name, omit_final.
1938 result
= test_dns_name_totext(Tokens
[0],
1939 atoi(Tokens
[1]) == 0 ?
1943 t_info("bad format at line %d\n", line
);
1951 t_info("Missing datafile dns_name_totext\n");
1956 static const char *a42
=
1957 "dns_name_fromwire(name, source, dctx, downcase, target) "
1958 "converts the possibly compressed DNS name 'name' in wire "
1959 "format to canonicalized form at target, performing upper to "
1960 "lower case conversion if downcase is true, and returns "
1965 * XXXRTH these tests appear to be broken, so I have
1968 static const char *a43
=
1969 "when a label length is invalid, dns_name_fromwire() "
1970 "returns DNS_R_FORMERR";
1972 static const char *a44
=
1973 "when a label type is invalid, dns_name_fromwire() "
1974 "returns DNS_R_BADLABELTYPE";
1977 static const char *a45
=
1978 "when a name length is invalid, dns_name_fromwire() "
1979 "returns DNS_R_FORMERR";
1981 static const char *a46
=
1982 "when a compression type is invalid, dns_name_fromwire() "
1983 "returns DNS_R_DISALLOWED";
1985 static const char *a47
=
1986 "when a bad compression pointer is encountered, "
1987 "dns_name_fromwire() returns DNS_R_BADPOINTER";
1989 static const char *a48
=
1990 "when input ends unexpected, dns_name_fromwire() "
1991 "returns ISC_R_UNEXPECTEDEND";
1993 static const char *a49
=
1994 "when there is not enough space in target, "
1995 "dns_name_fromwire(name, source, dcts, downcase, target) "
1996 "returns ISC_R_NOSPACE";
1999 test_dns_name_fromwire(char *datafile_name
, int testname_offset
, int downcase
,
2000 unsigned int dc_method
, char *exp_name
,
2001 isc_result_t exp_result
, size_t buflen
)
2005 unsigned int nlabels
;
2007 unsigned char buf1
[BIGBUFLEN
];
2009 isc_buffer_t iscbuf1
;
2010 isc_buffer_t iscbuf2
;
2011 dns_fixedname_t fixed2
;
2012 dns_name_t dns_name1
;
2013 dns_name_t
*dns_name2
;
2014 isc_result_t dns_result
;
2015 dns_namereln_t dns_namereln
;
2016 dns_decompress_t dctx
;
2018 t_info("testing using %s\n", datafile_name
);
2019 isc_buffer_init(&iscbuf1
, buf1
, sizeof(buf1
));
2020 len
= getmsg(datafile_name
, &iscbuf1
);
2024 isc_buffer_setactive(&iscbuf1
, len
);
2025 iscbuf1
.current
= testname_offset
;
2027 isc_buffer_init(&iscbuf2
, buf2
, (unsigned int)buflen
);
2028 dns_name_init(&dns_name1
, NULL
);
2029 dns_decompress_init(&dctx
, -1, DNS_DECOMPRESS_STRICT
);
2030 dns_decompress_setmethods(&dctx
, dc_method
);
2031 dns_result
= dns_name_fromwire(&dns_name1
, &iscbuf1
,
2032 &dctx
, downcase
? ISC_TRUE
: ISC_FALSE
,
2035 if ((dns_result
== exp_result
) && (exp_result
== ISC_R_SUCCESS
)) {
2037 dns_fixedname_init(&fixed2
);
2038 dns_name2
= dns_fixedname_name(&fixed2
);
2039 dns_result
= dns_name_fromstring2(dns_name2
, exp_name
, NULL
,
2041 if (dns_result
== ISC_R_SUCCESS
) {
2042 dns_namereln
= dns_name_fullcompare(&dns_name1
,
2045 if (dns_namereln
!= dns_namereln_equal
) {
2046 t_info("dns_name_fullcompare returned %s\n",
2047 dns_namereln_to_text(dns_namereln
));
2053 t_info("dns_name_fromtext %s failed, result = %s\n",
2054 exp_name
, dns_result_totext(dns_result
));
2055 result
= T_UNRESOLVED
;
2057 } else if (dns_result
== exp_result
) {
2060 t_info("dns_name_fromwire returned %s\n",
2061 dns_result_totext(dns_result
));
2069 t_dns_name_fromwire_x(const char *testfile
, size_t buflen
) {
2073 unsigned int dc_method
;
2074 isc_result_t exp_result
;
2079 result
= T_UNRESOLVED
;
2080 fp
= fopen(testfile
, "r");
2083 while ((p
= t_fgetbs(fp
)) != NULL
) {
2088 * Skip comment lines.
2090 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
2095 cnt
= bustline(p
, Tokens
);
2098 * datafile_name, testname_offset,
2099 * downcase, dc_method,
2100 * exp_name, exp_result.
2104 exp_result
= ISC_R_SUCCESS
;
2105 if (! strcmp(tok
, "ISC_R_SUCCESS"))
2106 exp_result
= ISC_R_SUCCESS
;
2107 else if (! strcmp(tok
, "ISC_R_NOSPACE"))
2108 exp_result
= ISC_R_NOSPACE
;
2109 else if (! strcmp(tok
, "DNS_R_BADLABELTYPE"))
2110 exp_result
= DNS_R_BADLABELTYPE
;
2111 else if (! strcmp(tok
, "DNS_R_FORMERR"))
2112 exp_result
= DNS_R_FORMERR
;
2113 else if (! strcmp(tok
, "DNS_R_BADPOINTER"))
2114 exp_result
= DNS_R_BADPOINTER
;
2115 else if (! strcmp(tok
, "ISC_R_UNEXPECTEDEND"))
2116 exp_result
= ISC_R_UNEXPECTEDEND
;
2117 else if (! strcmp(tok
, "DNS_R_TOOMANYHOPS"))
2118 exp_result
= DNS_R_TOOMANYHOPS
;
2119 else if (! strcmp(tok
, "DNS_R_DISALLOWED"))
2120 exp_result
= DNS_R_DISALLOWED
;
2121 else if (! strcmp(tok
, "DNS_R_NAMETOOLONG"))
2122 exp_result
= DNS_R_NAMETOOLONG
;
2125 dc_method
= DNS_COMPRESS_NONE
;
2126 if (! strcmp(tok
, "DNS_COMPRESS_GLOBAL14"))
2127 dc_method
= DNS_COMPRESS_GLOBAL14
;
2128 else if (! strcmp(tok
, "DNS_COMPRESS_ALL"))
2129 dc_method
= DNS_COMPRESS_ALL
;
2131 result
= test_dns_name_fromwire(Tokens
[0],
2139 t_info("bad format at line %d\n", line
);
2147 t_info("Missing datafile %s\n", testfile
);
2153 t_dns_name_fromwire(void) {
2154 t_assert("dns_name_fromwire", 1, T_REQUIRED
, "%s", a42
);
2155 t_dns_name_fromwire_x("dns_name_fromwire_1_data", BUFLEN
);
2159 * XXXRTH these tests appear to be broken, so I have
2162 t_assert("dns_name_fromwire", 2, T_REQUIRED
, "%s", a43
);
2163 t_dns_name_fromwire_x("dns_name_fromwire_2_data", BUFLEN
);
2165 t_assert("dns_name_fromwire", 3, T_REQUIRED
, "%s", a44
);
2166 t_dns_name_fromwire_x("dns_name_fromwire_3_data", BUFLEN
);
2169 t_assert("dns_name_fromwire", 4, T_REQUIRED
, "%s", a45
);
2170 t_dns_name_fromwire_x("dns_name_fromwire_4_data", BUFLEN
);
2172 t_assert("dns_name_fromwire", 5, T_REQUIRED
, "%s", a46
);
2173 t_dns_name_fromwire_x("dns_name_fromwire_5_data", BUFLEN
);
2175 t_assert("dns_name_fromwire", 6, T_REQUIRED
, "%s", a47
);
2176 t_dns_name_fromwire_x("dns_name_fromwire_6_data", BUFLEN
);
2178 t_assert("dns_name_fromwire", 7, T_REQUIRED
, "%s", a48
);
2179 t_dns_name_fromwire_x("dns_name_fromwire_7_data", BUFLEN
);
2181 t_assert("dns_name_fromwire", 9, T_REQUIRED
, "%s", a49
);
2182 t_dns_name_fromwire_x("dns_name_fromwire_8_data", 2);
2186 static const char *a51
=
2187 "dns_name_towire(name, cctx, target) converts the DNS name "
2188 "'name' into wire format, compresses it as specified "
2189 "by the compression context cctx, stores the result in "
2190 "target and returns DNS_SUCCESS";
2192 static const char *a52
=
2193 "when not enough space exists in target, "
2194 "dns_name_towire(name, cctx, target) returns ISC_R_NOSPACE";
2197 test_dns_name_towire(char *testname
, unsigned int dc_method
, char *exp_data
,
2198 size_t exp_data_len
, isc_result_t exp_result
,
2204 unsigned char buf2
[BUFLEN
];
2205 unsigned char buf3
[BUFLEN
];
2206 isc_buffer_t iscbuf1
;
2207 isc_buffer_t iscbuf2
;
2208 isc_buffer_t iscbuf3
;
2209 dns_name_t dns_name
;
2210 isc_result_t dns_result
;
2211 isc_result_t isc_result
;
2212 dns_compress_t cctx
;
2215 t_info("testing using %s\n", testname
);
2217 result
= T_UNRESOLVED
;
2220 isc_result
= isc_mem_create(0, 0, &mctx
);
2221 if (isc_result
!= ISC_R_SUCCESS
) {
2222 t_info("isc_mem_create failed\n");
2225 dns_compress_init(&cctx
, -1, mctx
);
2226 dns_compress_setmethods(&cctx
, dc_method
);
2227 dns_name_init(&dns_name
, NULL
);
2228 len
= strlen(testname
);
2229 isc_buffer_init(&iscbuf1
, testname
, len
);
2230 isc_buffer_add(&iscbuf1
, len
);
2231 isc_buffer_init(&iscbuf2
, buf2
, BUFLEN
);
2232 dns_result
= dns_name_fromtext(&dns_name
, &iscbuf1
, NULL
, 0, &iscbuf2
);
2233 if (dns_result
== ISC_R_SUCCESS
) {
2234 isc_buffer_init(&iscbuf3
, buf3
, (unsigned int)buflen
);
2235 dns_result
= dns_name_towire(&dns_name
, &cctx
, &iscbuf3
);
2236 if (dns_result
== exp_result
) {
2237 if (exp_result
== ISC_R_SUCCESS
) {
2239 * Compare results with expected data.
2241 val
= chkdata(buf3
, iscbuf3
.used
, exp_data
,
2250 t_info("dns_name_towire unexpectedly returned %s\n",
2251 dns_result_totext(dns_result
));
2255 t_info("dns_name_fromtext %s failed, result = %s\n",
2256 testname
, dns_result_totext(dns_result
));
2262 t_dns_name_towire_x(const char *testfile
, size_t buflen
) {
2266 unsigned int dc_method
;
2267 isc_result_t exp_result
;
2268 size_t exp_data_len
;
2272 result
= T_UNRESOLVED
;
2273 fp
= fopen(testfile
, "r");
2276 while ((p
= t_fgetbs(fp
)) != NULL
) {
2281 * Skip comment lines.
2283 if ((isspace((unsigned char)*p
)) || (*p
== '#')) {
2288 cnt
= bustline(p
, Tokens
);
2291 * testname, dc_method,
2292 * exp_data, exp_data_len,
2296 dc_method
= t_dc_method_fromtext(Tokens
[3]);
2297 exp_result
= t_dns_result_fromtext(Tokens
[4]);
2298 exp_data_len
= strtoul(Tokens
[3], NULL
, 10);
2300 result
= test_dns_name_towire(Tokens
[0],
2307 t_info("bad format at line %d\n", line
);
2315 t_info("Missing datafile %s\n", testfile
);
2321 t_dns_name_towire_1(void) {
2322 t_assert("dns_name_towire", 1, T_REQUIRED
, "%s", a51
);
2323 t_dns_name_towire_x("dns_name_towire_1_data", BUFLEN
);
2327 t_dns_name_towire_2(void) {
2328 t_assert("dns_name_towire", 2, T_REQUIRED
, "%s", a52
);
2329 t_dns_name_towire_x("dns_name_towire_2_data", 2);
2333 t_dns_name_towire(void) {
2334 t_dns_name_towire_1();
2335 t_dns_name_towire_2();
2338 #if 0 /* This is silly. A test should either exist, or not, but not
2339 * one that just returns "UNTESTED."
2341 static const char *a53
=
2342 "dns_name_concatenate(prefix, suffix, name, target) "
2343 "concatenates prefix and suffix, stores the result "
2344 "in target, canonicalizes any bitstring labels "
2345 "and returns ISC_R_SUCCESS";
2348 t_dns_name_concatenate(void) {
2349 t_assert("dns_name_concatenate", 1, T_REQUIRED
, "%s", a53
);
2350 t_result(T_UNTESTED
);
2354 testspec_t T_testlist
[] = {
2355 { (PFV
) t_dns_name_init
, "dns_name_init" },
2356 { (PFV
) t_dns_name_invalidate
, "dns_name_invalidate" },
2357 { (PFV
) t_dns_name_setbuffer
, "dns_name_setbuffer" },
2358 { (PFV
) t_dns_name_hasbuffer
, "dns_name_hasbuffer" },
2359 { (PFV
) t_dns_name_isabsolute
, "dns_name_isabsolute" },
2360 { (PFV
) t_dns_name_hash
, "dns_name_hash" },
2361 { (PFV
) t_dns_name_fullcompare
, "dns_name_fullcompare" },
2362 { (PFV
) t_dns_name_compare
, "dns_name_compare" },
2363 { (PFV
) t_dns_name_rdatacompare
, "dns_name_rdatacompare" },
2364 { (PFV
) t_dns_name_issubdomain
, "dns_name_issubdomain" },
2365 { (PFV
) t_dns_name_countlabels
, "dns_name_countlabels" },
2366 { (PFV
) t_dns_name_getlabel
, "dns_name_getlabel" },
2367 { (PFV
) t_dns_name_getlabelsequence
, "dns_name_getlabelsequence" },
2368 { (PFV
) t_dns_name_fromregion
, "dns_name_fromregion" },
2369 { (PFV
) t_dns_name_toregion
, "dns_name_toregion" },
2370 { (PFV
) t_dns_name_fromwire
, "dns_name_fromwire" },
2371 { (PFV
) t_dns_name_towire
, "dns_name_towire" },
2372 { (PFV
) t_dns_name_fromtext
, "dns_name_fromtext" },
2373 { (PFV
) t_dns_name_totext
, "dns_name_totext" },
2375 { (PFV
) t_dns_name_concatenate
, "dns_name_concatenate" },
2382 main(int argc
, char **argv
) {
2383 t_settests(T_testlist
);
2384 return (t_main(argc
, argv
));