1#!perl -w
2
3print "1..11\n";
4
5use URI;
6use strict;
7
8my $u = URI->new('sip:phone@domain.ext');
9print "not " unless $u->user eq 'phone' &&
10		    $u->host eq 'domain.ext' &&
11		    $u->port eq '5060' &&
12		    $u eq 'sip:phone@domain.ext';
13print "ok 1\n";
14
15$u->host_port('otherdomain.int:9999');
16print "not " unless $u->host eq 'otherdomain.int' &&
17		    $u->port eq '9999' &&
18		    $u eq 'sip:phone@otherdomain.int:9999';
19print "ok 2\n";
20
21$u->port('5060');
22$u = $u->canonical;
23print "not " unless $u->host eq 'otherdomain.int' &&
24		    $u->port eq '5060' &&
25		    $u eq 'sip:phone@otherdomain.int';
26print "ok 3\n";
27
28$u->user('voicemail');
29print "not " unless $u->user eq 'voicemail' &&
30		    $u eq 'sip:voicemail@otherdomain.int';
31print "ok 4\n";
32
33$u = URI->new('sip:phone@domain.ext?Subject=Meeting&Priority=Urgent');
34print "not " unless $u->host eq 'domain.ext' &&
35		    $u->query eq 'Subject=Meeting&Priority=Urgent';
36print "ok 5\n";
37
38$u->query_form(Subject => 'Lunch', Priority => 'Low');
39my @q = $u->query_form;
40print "not " unless $u->host eq 'domain.ext' &&
41		    $u->query eq 'Subject=Lunch&Priority=Low' &&
42		    @q == 4 && "@q" eq "Subject Lunch Priority Low";
43print "ok 6\n";
44
45$u = URI->new('sip:phone@domain.ext;maddr=127.0.0.1;ttl=16');
46print "not " unless $u->host eq 'domain.ext' &&
47		    $u->params eq 'maddr=127.0.0.1;ttl=16';
48print "ok 7\n";
49
50$u = URI->new('sip:phone@domain.ext?Subject=Meeting&Priority=Urgent');
51$u->params_form(maddr => '127.0.0.1', ttl => '16');
52my @p = $u->params_form;
53print "not " unless $u->host eq 'domain.ext' &&
54		    $u->query eq 'Subject=Meeting&Priority=Urgent' &&
55		    $u->params eq 'maddr=127.0.0.1;ttl=16' &&
56		    @p == 4 && "@p" eq "maddr 127.0.0.1 ttl 16";
57
58print "ok 8\n";
59
60$u = URI->new_abs('sip:phone@domain.ext', 'sip:foo@domain2.ext');
61print "not " unless $u eq 'sip:phone@domain.ext';
62print "ok 9\n";
63
64$u = URI->new('sip:phone@domain.ext');
65print "not " unless $u eq $u->abs('http://www.cpan.org/');
66print "ok 10\n";
67
68print "not " unless $u eq $u->rel('http://www.cpan.org/');
69print "ok 11\n";
70