File: 04-packet-unique-push.t

package info (click to toggle)
libnet-dns-perl 0.63-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 836 kB
  • ctags: 425
  • sloc: perl: 6,796; sh: 109; ansic: 104; makefile: 59
file content (117 lines) | stat: -rw-r--r-- 3,129 bytes parent folder | download | duplicates (2)
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
# $Id: 04-packet-unique-push.t 704 2008-02-06 21:30:59Z olaf $

use Test::More tests => 77;
use strict;

BEGIN { use_ok('Net::DNS'); }     #1


# Matching of RR name is not case sensitive 
my $packet=Net::DNS::Packet->new();

my $rr_1=Net::DNS::RR->new('bla.FOO  100 IN TXT "lower case"');
my $rr_2=Net::DNS::RR->new('bla.foo  100 IN TXT "lower case"');
my $rr_3=Net::DNS::RR->new('bla.foo 100 IN TXT "MIXED CASE"');
my $rr_4=Net::DNS::RR->new('bla.foo 100 IN TXT "mixed case"');

$packet->unique_push("answer",$rr_1);
$packet->unique_push("answer",$rr_2);
is($packet->header->ancount,1,"unique_push, case sensitivity test 1");

$packet->unique_push("answer",$rr_3);
$packet->unique_push("answer",$rr_4);
is($packet->header->ancount,3,"unique_push, case sensitivity test 2");



my $tests = sub {
	my ($method) = @_;
	my $domain = 'example.com';

	my @tests = (
		[ 
			1,
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
		],
		[
			2,
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
			Net::DNS::RR->new_from_string('bar.example.com 60 IN A 10.0.0.1'),
		],
		[ 
			1,
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
			Net::DNS::RR->new_from_string('foo.example.com 90 IN A 10.0.0.1'),
		],
		[ 
			3,
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.2'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.3'),
		],
		[ 
			3,
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.2'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.3'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
		],
		[ 
			3,
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.2'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.1'),
			Net::DNS::RR->new_from_string('foo.example.com 60 IN A 10.0.0.4'),
		],
	);
	
	my %sections = (
		answer     => 'ancount',
		authority  => 'nscount',
		additional => 'arcount',
	);
	
	foreach my $try (@tests) {
		my ($count, @rrs) = @$try;
	
		while (my ($section, $count_meth) = each %sections) {
		
			my $packet = Net::DNS::Packet->new($domain);
			
			$packet->$method($section, @rrs);
		
			is($packet->header->$count_meth(), $count, "$section right");
	
		}
	
		#
		# Now do it again calling safe_push() for each RR.
		# 
		while (my ($section, $count_meth) = each %sections) {
		
			my $packet = Net::DNS::Packet->new($domain);
			
			foreach (@rrs) {
				$packet->$method($section, $_);
			}
		
			is($packet->header->$count_meth(), $count, "$section right");
		}
	}
};

$tests->('unique_push');

{
	my @warnings;
	local $SIG{__WARN__} = sub { push(@warnings, "@_"); };
	
	$tests->('safe_push');
	
	is(scalar @warnings, 72);
	
	ok(!grep { $_ !~ m/deprecated/ } @warnings);
}