| 1 |
use Test::More tests => 18; |
| 2 |
|
| 3 |
use DNS::LDNS ':all'; |
| 4 |
|
| 5 |
BEGIN { use_ok('DNS::LDNS') }; |
| 6 |
|
| 7 |
# Integer data |
| 8 |
my $i = new DNS::LDNS::RData(LDNS_RDF_TYPE_INT32, '1237654'); |
| 9 |
is($i->to_string, '1237654', 'Integer value rdata'); |
| 10 |
|
| 11 |
my $ii = new DNS::LDNS::RData(LDNS_RDF_TYPE_INT32, '1237654X'); |
| 12 |
is($ii, undef, '1237654X is invalid'); |
| 13 |
|
| 14 |
# Period data |
| 15 |
my $p1 = new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '3h3m3s'); |
| 16 |
is($p1->to_string, sprintf("%d", 3600*3 + 60*3 + 3), 'Normalizing period'); |
| 17 |
|
| 18 |
my $pi = new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '3h3X3s'); |
| 19 |
is($pi, undef, 'Invalid period value 3h3X3s'); |
| 20 |
|
| 21 |
# DNames |
| 22 |
my $dn1 = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'azone.org'); |
| 23 |
my $dn2 = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'other.org'); |
| 24 |
my $dn3 = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'sub.other.org'); |
| 25 |
my $dn4 = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'adder.org'); |
| 26 |
|
| 27 |
$dn1->cat($dn2); |
| 28 |
is($dn1->to_string, 'azone.org.other.org.', 'Concatenating two domain names'); |
| 29 |
my $chopped = $dn1->left_chop; |
| 30 |
is($chopped->to_string, 'org.other.org.', 'Chop off left domain name label'); |
| 31 |
ok($dn3->is_subdomain($dn2), 'sub.other.org is subdomain of other.org'); |
| 32 |
ok(!$dn2->is_subdomain($dn3), 'other.org is not subdomain of sub.other.org'); |
| 33 |
is($dn3->label_count, 3, 'sub.other.org has 3 labels'); |
| 34 |
is($dn3->label(1)->to_string, 'other.', 'label 1 of sub.other.org is other.'); |
| 35 |
|
| 36 |
my $dni = new DNS::LDNS::RData( |
| 37 |
LDNS_RDF_TYPE_DNAME, 'not..valid.org'); |
| 38 |
is($dni, undef, 'Invalid dname not_valid.org'); |
| 39 |
|
| 40 |
my $wc = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, '*.other.org'); |
| 41 |
ok($wc->is_wildcard, '*.other.org is a wildcard'); |
| 42 |
ok(!$dn3->is_wildcard, 'sub.other.org is not a wildcard'); |
| 43 |
ok($dn3->matches_wildcard($wc), 'sub.other.org matches *.other.org'); |
| 44 |
ok(!$dn4->matches_wildcard($wc), 'adder.org does not match *.other.org'); |
| 45 |
|
| 46 |
is($dn3->compare($dn4), 1, 'sub.other.org > adder.org'); |
| 47 |
is($dn4->compare($dn3), -1, 'adder.org < sub.other.org'); |