XMLRPC/Test.pm

filter: Statementstmt 28.4% 25 / 88 Branchbran 11.1% 2 / 18 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 58.3% 7 / 12 Podpod n/a totaltotal 25.3% 35 / 138 CC 14 SCAR 39.9
CC
14
Cov
24%
run_for
109.8
new
6.0
__ANON__
6.0
CRAP 54.2
↑ Summary XMLRPC/Lite.pm »
1 # ======================================================================
2 #
3 # Copyright (C) 2000-2001 Paul Kulchenko (paulclinger@yahoo.com)
4 # SOAP::Lite is free software; you can redistribute it
5 # and/or modify it under the same terms as Perl itself.
6 #
7 # $Id$
8 #
9 # ======================================================================
10  
11 package XMLRPC::Test;
12  
13 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use vars qw($VERSION $TIMEOUT);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 our $VERSION = 0.717;
16  
17 1 $TIMEOUT = 5;
18  
19 # ======================================================================
20  
21 package My::PingPong; # we'll use this package in our tests
22  
23 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
24 0 my $self = shift;
25 0 ▶ my $class = ref($self) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
26 0 bless {_num=>shift} => $class;
27 }
28  
29 0 ▶sub next {
Subroutine next: not called CC=1 SCAR=6.9
30 0 my $self = shift;
31 0 $self->{_num}++;
32 }
33  
34 0 ▶sub value {
Subroutine value: not called CC=1 SCAR=6.9
35 0 my $self = shift;
36 0 $self->{_num};
37 }
38  
39 # ======================================================================
40  
41 package XMLRPC::Test::Server;
42  
43 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use XMLRPC::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 1 ▶sub run_for {
Subroutine run_for: called CC=12 SCAR=47.0
48 1 ▶ my $proxy = shift or die "Proxy/endpoint is not specified";
Branch: 1 branch
BranchTrueFalseTotal
my $proxy = shift() or die "Proxy/endpoint is not specified" 1 0 1
49  
50 # ------------------------------------------------------
51 1 ▶ my $s = XMLRPC::Lite->proxy($proxy)->on_fault(sub{});
Subroutine __ANON__: called CC=1 SCAR=0.0
52 1 eval { $s->transport->timeout($XMLRPC::Test::TIMEOUT) };
53 1 my $r = $s->test_connection;
54  
55 1 ▶ unless (defined $r && defined $r->envelope) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $r and defined $r->envelope) 1 0 1
Condition33%1/3
defined $r and defined $r->envelope
!ll&&!rl&&r
100
MC/DC0%0/2
defined $r and defined $r->envelope
defined $r defined $r->envelope
Truth table33%1/3
A and B
A= defined $rB= defined $r->envelope
ABresult
0X0
100
111
56 1 print "1..0 # Skip: ", $s->transport->status, "\n";
57 1 exit;
58 }
59 # ------------------------------------------------------
60  
61 0 plan tests => 17;
62  
63 0 ▶ eval q!use XMLRPC::Lite on_fault => sub{ref $_[1] ? $_[1] : new XMLRPC::SOM}; 1! or die;
Branch: 1 branch
BranchTrueFalseTotal
eval "use XMLRPC::Lite on_fault => sub{ref \$_[1] ? \$_[1] : new XMLRPC::SOM}; 1" or die 0 0 0
64  
65 0 print "Perl XMLRPC server test(s)...\n";
66  
67 0 $s = XMLRPC::Lite
68 -> proxy($proxy)
69 ;
70  
71 0 ok($s->call('My.Examples.getStateName', 1)->result eq 'Alabama');
72 0 ok($s->call('My.Examples.getStateNames', 1,4,6,13)->result =~ /^Alabama\s+Arkansas\s+Colorado\s+Illinois\s*$/);
73  
74 0 $r = $s->call('My.Examples.getStateList', [1,2,3,4])->result;
75 0 ▶ ok(ref $r && $r->[0] eq 'Alabama');
Condition0%0/3
ref $r && $r->[0] eq 'Alabama'
!ll&&!rl&&r
000
MC/DC0%0/2
ref $r && $r->[0] eq 'Alabama'
ref $r $r->[0] eq 'Alabama'
Truth table0%0/3
A && B
A= ref $rB= $r->[0] eq 'Alabama'
ABresult
0X0
100
111
76  
77 0 $r = $s->call('My.Examples.getStateStruct', {item1 => 1, item2 => 4})->result;
78 0 ▶ ok(ref $r && $r->{item2} eq 'Arkansas');
Condition0%0/3
ref $r && $r->{'item2'} eq 'Arkansas'
!ll&&!rl&&r
000
MC/DC0%0/2
ref $r && $r->{'item2'} eq 'Arkansas'
ref $r $r->{'item2'} eq 'Arkansas'
Truth table0%0/3
A && B
A= ref $rB= $r->{'item2'} eq 'Arkansas'
ABresult
0X0
100
111
79  
80 0 print "dispatch_from test(s)...\n";
81 0 ▶ eval "use XMLRPC::Lite
Branch: 1 branch
BranchTrueFalseTotal
eval "use XMLRPC::Lite\n dispatch_from => ['A', 'B'],\n proxy => '${proxy}',\n ; 1" or die 0 0 0
82 dispatch_from => ['A', 'B'],
83 proxy => '$proxy',
84 ; 1" or die;
85  
86 0 eval { C->c };
87 0 ok($@ =~ /Can't locate object method "c"/);
88  
89 0 print "Object autobinding and XMLRPC:: prefix test(s)...\n";
90  
91 0 ▶ eval "use XMLRPC::Lite +autodispatch =>
Branch: 1 branch
BranchTrueFalseTotal
eval "use XMLRPC::Lite +autodispatch =>\n proxy => '${proxy}'; 1" or die 0 0 0
92 proxy => '$proxy'; 1" or die;
93  
94 0 ok(XMLRPC::Lite->autodispatched);
95  
96 # forget everything
97 0 XMLRPC::Lite->self(undef);
98  
99 {
100 0 my $on_fault_was_called = 0;
101 0 print "Die in server method test(s)...\n";
102 my $s = XMLRPC::Lite
103 -> proxy($proxy)
104 0 ▶ -> on_fault(sub{$on_fault_was_called++;return})
Subroutine __ANON__: not called CC=1 SCAR=6.9
105 0 ;
106 0 ok($s->call('My.Parameters.die_simply')->faultstring =~ /Something bad/);
107 0 ok($on_fault_was_called > 0);
108  
109 # get Fault as hash of subelements
110 0 my $fault = $s->call('My.Parameters.die_with_fault');
111 0 ok($fault->faultcode =~ 'Server\.Custom');
112 0 ok($fault->faultstring eq 'Died in server method');
113 }
114  
115 0 print "Number of parameters test(s)...\n";
116  
117 0 $s = XMLRPC::Lite
118 -> proxy($proxy)
119 ;
120 0 { my @all = $s->call('My.Parameters.echo')->paramsall; ok(@all == 0) }
121 0 { my @all = $s->call('My.Parameters.echo', 1)->paramsall; ok(@all == 1) }
122 0 { my @all = $s->call('My.Parameters.echo', (1) x 10)->paramsall; ok(@all == 10) }
123  
124 0 print "Memory refresh test(s)...\n";
125  
126 # Funny test.
127 # Let's forget about ALL settings we did before with 'use XMLRPC::Lite...'
128 0 XMLRPC::Lite->self(undef);
129 0 ok(!defined XMLRPC::Lite->self);
130  
131 0 ▶ eval "use XMLRPC::Lite
Branch: 1 branch
BranchTrueFalseTotal
eval "use XMLRPC::Lite\n proxy => '${proxy}'; 1" or die 0 0 0
132 proxy => '$proxy'; 1" or die;
133  
134 0 print "Global settings test(s)...\n";
135 0 $s = new XMLRPC::Lite;
136  
137 0 ok($s->call('My.Examples.getStateName', 1)->result eq 'Alabama');
138  
139 SOAP::Trace->import(transport =>
140 0 ▶ sub {$_[0]->content_type('something/wrong') if UNIVERSAL::isa($_[0] => 'HTTP::Request')}
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($_[0], "HTTP::Request") 0 0 0
141 0 );
142  
143 0 ▶ if ($proxy =~ /^tcp:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy =~ /^tcp:/) { } 0 0 0
144 0 skip('No Content-Type checks for tcp: protocol on server side' => undef);
145 } else {
146 0 ok($s->call('My.Examples.getStateName', 1)->faultstring =~ /Content-Type must be/);
147 }
148  
149 # check status for fault messages
150 0 ▶ if ($proxy =~ /^http/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy =~ /^http/) { } 0 0 0
151 0 ok($s->transport->status =~ /^200/);
152 } else {
153 0 skip('No Status checks for non http protocols on server side' => undef);
154 }
155 }
156  
157 # ======================================================================
158  
159 1 1;
160  
161 __END__
↑ Summary XMLRPC/Lite.pm »