1# $Id: 05-rr-rrsort.t 682 2007-09-27 07:50:27Z olaf $   -*-perl-*-
2
3use Test::More;
4use strict;
5use Net::DNS qw(rrsort);
6
7plan tests => 22;
8
9my $rr1=Net::DNS::RR->new("example.com.  600     IN      SRV     0 0 5060 A.example.com.");
10is(ref($rr1),"Net::DNS::RR::SRV","SRV RR1 created");
11my $rr2=Net::DNS::RR->new("example.com.  600     IN      SRV     1 0 5060 A.example.com.");
12is(ref($rr2),"Net::DNS::RR::SRV","SRV RR2 created");
13my $rr3=Net::DNS::RR->new("example.com.  600     IN      SRV     2 0 5060 A.example.com.");
14is(ref($rr3),"Net::DNS::RR::SRV","SRV RR3 created");
15my $rr4=Net::DNS::RR->new("example.com.  600     IN      SRV     3 0 5060 A.example.com.");
16is(ref($rr4),"Net::DNS::RR::SRV","SRV RR4 created");
17my $rr5=Net::DNS::RR->new("example.com.  600     IN      SRV     3 1 5060 A.example.com.");
18is(ref($rr5),"Net::DNS::RR::SRV","SRV RR5 created");
19my $rr6=Net::DNS::RR->new("example.com.  600     IN      SRV     3 2 5060 A.example.com.");
20is(ref($rr6),"Net::DNS::RR::SRV","SRV RR6 created");
21my $rr7=Net::DNS::RR->new("example.com.  600     IN      SRV     1 3 5070 A.example.com.");
22is(ref($rr7),"Net::DNS::RR::SRV","SRV RR7 created");
23my $rr8=Net::DNS::RR->new("example.com.  600     IN      SRV     3 3 5070 A.example.com.");
24is(ref($rr8),"Net::DNS::RR::SRV","SRV RR8 created");
25my $rr9=Net::DNS::RR->new("example.com.  600     IN     A 192.168.0.1");
26is(ref($rr9),"Net::DNS::RR::A","A RR9 created");
27
28
29my @rrarray=($rr1, $rr2, $rr3, $rr4, $rr5, $rr6, $rr7, $rr8, $rr9);
30my @expectedrdata=($rr1, $rr2, $rr3, $rr7, $rr4, $rr5, $rr6,  $rr8);
31my @expectedpriority=($rr1, $rr7, $rr2, $rr3, $rr8, $rr6, $rr5, $rr4);
32my @expectedweight=($rr7, $rr8, $rr6, $rr5, $rr1, $rr2, $rr3, $rr4);
33
34
35
36is (rrsort("SRV"),undef,"rrsort returns rrerly whith undefined arguments");
37
38is (rrsort("SRV",@rrarray),8,"rrsort returns properly whith undefined attribute (1)");
39
40is (rrsort("SRV",,@rrarray),8,"rrsort returns properly whith undefined attribute (2)");
41
42is (rrsort("SRV","",@rrarray),8,"rrsort returns properly whith undefined attribute (3)");
43
44my @prioritysorted= rrsort("SRV","priority",@rrarray);
45my @weightsorted= rrsort("SRV","weight",@rrarray);
46my @defaultsorted= rrsort("SRV",@rrarray);
47my @portsorted= rrsort("SRV","port",@rrarray);
48
49my @foosorted= rrsort("SRV","foo",@rrarray);
50is (@foosorted,8,"rrsort returns properly whith undefined attribute (3)");
51
52is ( @prioritysorted,8,"rrsort correctly maintains RRs test 2");
53
54
55ok (eq_array(\@expectedpriority, \@prioritysorted), "Sorting on SRV priority works");
56ok (eq_array(\@expectedpriority, \@defaultsorted), "Default SRV sort works");
57ok (eq_array(\@expectedweight, \@weightsorted), "Weight sorted SRV sort works");
58
59
60is (rrsort("A","priority",@rrarray),1,"rrsort correctly maintains RRs test 1");
61is (rrsort("MX","priority",@rrarray),undef,"rrsort correctly maintains RRs test 3");
62
63
64#
65# Test with MX RRs.
66#
67
68my $mxrr1=Net::DNS::RR->new("example.com.  600     IN      MX 10 mx1.example.com");
69my $mxrr2=Net::DNS::RR->new("example.com.  600     IN      MX 6 mx2.example.com");
70
71my $mxrr3=Net::DNS::RR->new("example.com.  600     IN      MX 66 mx3.example.com");
72my $mxrr4=Net::DNS::RR->new("example.com.  600     IN      RT 6 rt1.example.com");
73
74
75my @mxrrarray=($mxrr1, $mxrr2, $mxrr3, $mxrr4);
76my @expectedmxarray=($mxrr2,$mxrr1,$mxrr3);
77my @sortedmxarray=rrsort("MX",@mxrrarray);
78
79ok (eq_array(\@expectedmxarray,\@sortedmxarray),"MX sorting");
80
81
82
83
84my $nsrr1=Net::DNS::RR->new("example.com.  600     IN      NS ns2.example.com");
85my $nsrr2=Net::DNS::RR->new("example.com.  600     IN      NS ns4.example.com");
86my $nsrr3=Net::DNS::RR->new("example.com.  600     IN      NS ns1.example.com");
87my $nsrr4=Net::DNS::RR->new("example.com.  600     IN      RT 6 rt1.example.com");
88
89my @nsrrarray=($nsrr1, $nsrr2, $nsrr3, $nsrr4);
90my @expectednsarray=($nsrr3,$nsrr1,$nsrr2);
91my @sortednsarray=rrsort("NS",@nsrrarray);
92
93
94
95
96ok (eq_array(\@expectednsarray,\@sortednsarray),"NS sorting");
97