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
|
use strict;
use warnings;
use Test::More tests => 13;
use URI ();
my $u = URI->new('sip:phone@domain.ext');
ok($u->user eq 'phone' &&
$u->host eq 'domain.ext' &&
$u->port eq '5060' &&
$u->host_port eq 'domain.ext:5060' &&
$u->authority eq 'phone@domain.ext' &&
$u eq 'sip:phone@domain.ext');
$u->host_port('otherdomain.int:9999');
ok($u->host eq 'otherdomain.int' &&
$u->port eq '9999' &&
$u->host_port eq 'otherdomain.int:9999' &&
$u->authority eq 'phone@otherdomain.int:9999' &&
$u eq 'sip:phone@otherdomain.int:9999');
$u->port('5060');
$u = $u->canonical;
ok($u->port eq '5060' &&
$u->host_port eq 'otherdomain.int:5060' &&
$u->authority eq 'phone@otherdomain.int' &&
$u eq 'sip:phone@otherdomain.int');
$u->user('voicemail');
ok($u->user eq 'voicemail' &&
$u->authority eq 'voicemail@otherdomain.int' &&
$u eq 'sip:voicemail@otherdomain.int');
$u->authority('fax@gateway.ext');
ok($u->user eq 'fax' &&
$u->host eq 'gateway.ext' &&
$u->host_port eq 'gateway.ext:5060' &&
$u->authority eq 'fax@gateway.ext' &&
$u eq 'sip:fax@gateway.ext');
$u = URI->new('sip:phone@domain.ext?Subject=Meeting&Priority=Urgent');
ok($u->query eq 'Subject=Meeting&Priority=Urgent');
$u->query_form(Subject => 'Lunch', Priority => 'Low');
my @q = $u->query_form;
ok($u->query eq 'Subject=Lunch&Priority=Low' &&
@q == 4 && "@q" eq 'Subject Lunch Priority Low' &&
$u eq 'sip:phone@domain.ext?Subject=Lunch&Priority=Low');
$u = URI->new('sip:phone@domain.ext;maddr=127.0.0.1;ttl=16');
ok($u->params eq 'maddr=127.0.0.1;ttl=16');
$u->params('maddr=127.0.0.1;ttl=16;x-addedparam=1');
ok($u->params eq 'maddr=127.0.0.1;ttl=16;x-addedparam=1' &&
$u eq 'sip:phone@domain.ext;maddr=127.0.0.1;ttl=16;x-addedparam=1');
$u = URI->new('sip:phone@domain.ext?Subject=Meeting&Priority=Urgent');
$u->params_form(maddr => '127.0.0.1', ttl => '16');
my @p = $u->params_form;
ok($u->query eq 'Subject=Meeting&Priority=Urgent' &&
$u->params eq 'maddr=127.0.0.1;ttl=16' &&
@p == 4 && "@p" eq "maddr 127.0.0.1 ttl 16");
$u = URI->new_abs('sip:phone@domain.ext', 'sip:foo@domain2.ext');
is($u, 'sip:phone@domain.ext');
$u = URI->new('sip:phone@domain.ext');
is($u, $u->abs('http://www.cpan.org/'));
is($u, $u->rel('http://www.cpan.org/'));
|