1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
# $Id: 05-rr-txt.t 657 2007-06-21 12:57:58Z olaf $
use Test::More tests => 33;
use strict;
my $uut;
BEGIN { use_ok('Net::DNS'); }
#------------------------------------------------------------------------------
# Canned data.
#------------------------------------------------------------------------------
my $name = 'foo.example.com';
my $class = 'IN';
my $type = 'TXT';
my $ttl = 43201;
my $rr_base = join(' ', $name, $ttl, $class, $type, " " );
#Stimulus, expected response, and test name:
my @Testlist = (
{ # 2-5
stim => q|""|,
rdatastr => q|""|,
char_str_list_r => ['',],
descr => 'Double-quoted null string',
},
{ # 6-9
stim => q|''|,
rdatastr => q|""|,
char_str_list_r => ['',],
descr => 'Single-quoted null string',
},
{ # 10-13
stim => qq|" \t"|,
rdatastr => qq|" \t"|,
char_str_list_r => [ qq| \t|, ],
descr => 'Double-quoted whitespace string',
},
{ # 14-17
stim => q|noquotes|,
rdatastr => q|"noquotes"|,
char_str_list_r => [ q|noquotes|, ],
descr => 'unquoted single string',
},
{ # 18-21
stim => q|"yes_quotes"|,
rdatastr => q|"yes_quotes"|,
char_str_list_r => [ q|yes_quotes|, ],
descr => 'Double-quoted single string',
},
{ # 22-25
stim => q|"escaped \" quote"|,
rdatastr => q|"escaped \" quote"|,
char_str_list_r => [ q|escaped " quote|, ],
descr => 'Quoted, escaped double-quote',
},
{ # 26-29
stim => q|two tokens|,
rdatastr => q|"two" "tokens"|,
char_str_list_r => [ q|two|, q|tokens|, ],
descr => 'Two unquoted strings',
},
{ # 30-33
stim => q|"missing quote|,
rdatastr => q||,
char_str_list_r => [],
descr => 'Unbalanced quotes work',
}
);
#------------------------------------------------------------------------------
# Run the tests
#------------------------------------------------------------------------------
foreach my $test_hr ( @Testlist ) {
ok( $uut = Net::DNS::RR->new($rr_base . $test_hr->{'stim'}),
$test_hr->{'descr'} . " -- Stimulus " );
is($uut->rdatastr(), $test_hr->{'rdatastr'},
$test_hr->{'descr'} . " -- Response ( rdatastr ) " );
my @list = $uut->char_str_list();
is_deeply(\@list, $test_hr->{'char_str_list_r'},
$test_hr->{'descr'} . " -- char_str_list equality" ) ;
}
my $string1 = q|no|;
my $string2 = q|quotes|;
my $rdata = pack("C", length $string1) . $string1;
$rdata .= pack("C", length $string2) . $string2;
# RR->new_from_hash() drops stuff straight into the hash and
# re-blesses it, breaking encapsulation.
my %work_hash = (
Name => $name,
TTL => $ttl,
Class => $class,
Type => $type,
);
# Don't break RR->new_from_hash (e.i. "See the manual pages for each RR
# type to see what fields the type requires.").
$work_hash{'txtdata'} = q|no quotes|;
ok( $uut = Net::DNS::RR->new(%work_hash), # 30
"RR->new_from_hash with txtdata -- Stimulus");
ok( $uut->rdatastr() eq q|"no" "quotes"|, # 31
"RR->new_from_hash with txtdata -- Response (rdatastr())");
ok( $uut->rr_rdata() eq $rdata , "TXT->rr_rdata" ); # 32
# And HINFO inherits its parsing from TXT and should therefore work OK as well
my $rr = Net::DNS::RR->new("SRI-NIC.ARPA. HINFO 'DEC-2060 2006' TOPS20");
is($rr->cpu,"DEC-2060 2006","Character string in quotes 1");
is($rr->os,"TOPS20","Character string in quotes 2");
my $rr2 = Net::DNS::RR->new("SRI-NIC.ARPA. HINFO DEC-2060 2006 TOPS20");
ok( !defined($rr2), "Failed parsing of to many HINFO strings");
my $rr3 = Net::DNS::RR->new("SRI-NIC.ARPA. HINFO DEC-2060 TOPS20");
is($rr3->cpu,"DEC-2060","Character string in quotes 3");
is($rr3->os,"TOPS20","Character string in quotes 4");
|