⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.pm

📁 1. 记录每个帖子的访问人情况
💻 PM
字号:
# ======================================================================## Copyright (C) 2000-2001 Paul Kulchenko (paulclinger@yahoo.com)# SOAP::Lite is free software; you can redistribute it# and/or modify it under the same terms as Perl itself.## $Id: Test.pm,v 1.8 2001/09/19 22:02:01 paulk Exp $## ======================================================================package SOAP::Test;use 5.004;use vars qw($VERSION $TIMEOUT);$VERSION = eval sprintf("%d.%s", q$Name: release-0_52-public $ =~ /-(\d+)_([\d_]+)/);$TIMEOUT = 5;# ======================================================================package My::PingPong; # we'll use this package in our testssub new {   my $self = shift;  my $class = ref($self) || $self;  bless {_num=>shift} => $class;}sub next {  my $self = shift;  $self->{_num}++;}sub value {  my $self = shift;  $self->{_num};}# ======================================================================package SOAP::Test::Server;use strict;use Test;use SOAP::Lite;sub run_for {  my $proxy = shift or die "Proxy/endpoint is not specified";  # ------------------------------------------------------  my $s = SOAP::Lite->uri('http://something/somewhere')->proxy($proxy)->on_fault(sub{});  eval { $s->transport->timeout($SOAP::Test::TIMEOUT) };  my $r = $s->test_connection;  unless (defined $r && defined $r->envelope) {    print "1..0 # Skip: ", $s->transport->status, "\n";    exit;  }  # ------------------------------------------------------  plan tests => 53;  eval q!use SOAP::Lite on_fault => sub{ref $_[1] ? $_[1] : new SOAP::SOM}; 1! or die;  print "Perl SOAP server test(s)...\n";  $s = SOAP::Lite    -> uri('urn:/My/Examples')                    -> proxy($proxy)  ;  ok($s->getStateName(1)->result eq 'Alabama');   ok($s->getStateNames(1,4,6,13)->result =~ /^Alabama\s+Arkansas\s+Colorado\s+Illinois\s*$/);   $r = $s->getStateList([1,2,3,4])->result;  ok(ref $r && $r->[0] eq 'Alabama');   $r = $s->getStateStruct({item1 => 1, item2 => 4})->result;  ok(ref $r && $r->{item2} eq 'Arkansas');   {    my $autoresult = $s->autoresult;    $s->autoresult(1);    ok($s->getStateName(1) eq 'Alabama');    $s->autoresult($autoresult);  }  print "Autobinding of output parameters test(s)...\n";  $s->uri('urn:/My/Parameters');  my $param1 = 10;  my $param2 = SOAP::Data->name('myparam' => 12);  my $result = $s->autobind($param1, $param2)->result;  ok($result == $param1 && $param2->value == 24);   print "Header manipulation test(s)...\n";  $a = $s->addheader(2, SOAP::Header->name(my => 123));   ok(ref $a->header && $a->header->{my} eq '123123');   ok($a->headers eq '123123');   print "Echo untyped data test(s)...\n";  $a = $s->echotwo(11, 12);  ok($a->result == 11);   print "mustUnderstand test(s)...\n";  $s->echo(SOAP::Header->name(somethingelse => 123)                       ->mustUnderstand(1));  ok($s->call->faultstring =~ /[Hh]eader has mustUnderstand attribute/);  if ($proxy =~ /^http/) {    ok($s->transport->status =~ /^500/);  } else {    skip('No Status checks for non http protocols on server side' => undef);  }  $s->echo(SOAP::Header->name(somethingelse => 123)                       ->mustUnderstand(1)                       ->actor('http://notme/'));  ok(!defined $s->call->fault);  print "dispatch_from test(s)...\n";  eval "use SOAP::Lite    uri => 'http://my.own.site.com/My/Examples',    dispatch_from => ['A', 'B'],    proxy => '$proxy',  ; 1" or die;  eval { C->c };  ok($@ =~ /Can't locate object method "c"/);  eval { A->a };  ok(!$@ && SOAP::Lite->self->call->faultstring =~ /Failed to access class \(A\)/);  eval "use SOAP::Lite    dispatch_from => 'A',    uri => 'http://my.own.site.com/My/Examples',    proxy => '$proxy',  ; 1" or die;  eval { A->a };  ok(!$@ && SOAP::Lite->self->call->faultstring =~ /Failed to access class \(A\)/);  print "Object autobinding and SOAP:: prefix test(s)...\n";  eval "use SOAP::Lite +autodispatch =>    uri => 'urn:', proxy => '$proxy'; 1" or die;  ok(SOAP::Lite->autodispatched);  eval { SOAP->new(1) };  ok($@ =~ /^URI is not specified/);  eval "use SOAP::Lite +autodispatch =>    uri => 'urn:/A/B', proxy => '$proxy'; 1" or die;  # should call My::PingPong, not A::B  my $p = My::PingPong->SOAP::new(10);  ok(ref $p && $p->SOAP::next+1 == $p->value);  # forget everything  SOAP::Lite->self(undef);   $s = SOAP::Lite    -> uri('urn:/My/PingPong')                    -> proxy($proxy)  ;  # should return object EXACTLY as after My::PingPong->SOAP::new(10)  $p = $s->SOAP::new(10);   ok(ref $p && $s->SOAP::next($p)+1 == $p->value);  print "VersionMismatch test(s)...\n";  {    local $SOAP::Constants::NS_ENV = 'http://schemas.xmlsoap.org/new/envelope/';    my $s = SOAP::Lite      -> uri('http://my.own.site.com/My/Examples')                      -> proxy($proxy)      -> on_fault(sub{})    ;    $r = $s->dosomething;    ok(ref $r && $r->faultcode =~ /:VersionMismatch/);  }  print "Objects-by-reference test(s)...\n";  eval "use SOAP::Lite +autodispatch =>    uri => 'urn:', proxy => '$proxy'; 1" or die;  print "Session iterator\n";  $r = My::SessionIterator->new(10);   if (!ref $r || exists $r->{id}) {    ok(ref $r && $r->next && $r->next == 11);  } else {    skip('No persistent objects (o-b-r) supported on server side' => undef);  }  print "Persistent iterator\n";  $r = My::PersistentIterator->new(10);   if (!ref $r || exists $r->{id}) {    my $first = ($r->next, $r->next) if ref $r;       $r = My::PersistentIterator->new(10);    ok(ref $r && $r->next && $r->next == $first+2);  } else {    skip('No persistent objects (o-b-r) supported on server side' => undef);  }  { local $^W; # disable warnings about deprecated AUTOLOADing for nonmethods    print "Parameters-by-name test(s)...\n";    print "You can see warning about AUTOLOAD for non-method...\n" if $^W;    eval "use SOAP::Lite +autodispatch =>       uri => 'http://my.own.site.com/My/Parameters', proxy => '$proxy'; 1" or die;    my @parameters = (      SOAP::Data->name(b => 222),       SOAP::Data->name(c => 333),       SOAP::Data->name(a => 111)    );    # switch to 'main' package, because nonqualified methods should be there    ok(main::byname(@parameters) eq "a=111, b=222, c=333");    ok(main::bynameororder(@parameters) eq "a=111, b=222, c=333");    ok(main::bynameororder(111, 222, 333) eq "a=111, b=222, c=333");    print "Function call test(s)...\n";    print "You can see warning about AUTOLOAD for non-method...\n" if $^W;    ok(main::echo(11) == 11);  }  print "SOAPAction test(s)...\n";  if ($proxy =~ /^tcp:/) {    for (1..2) {skip('No SOAPAction checks for tcp: protocol on server side' => undef)}  } else {    my $s = SOAP::Lite      -> uri('http://my.own.site.com/My/Examples')                      -> proxy($proxy)      -> on_action(sub{'""'})    ;    ok($s->getStateName(1)->result eq 'Alabama');     $s->on_action(sub{'"wrong_SOAPAction_here"'});    ok($s->getStateName(1)->faultstring =~ /SOAPAction shall match/);   }  print "UTF8 test(s)...\n";  if (!eval "pack('U*', 0)") {    for (1) {skip('No UTF8 test. No support for pack("U*") modifier' => undef)}  } else {    $s = SOAP::Lite      -> uri('http://my.own.site.com/My/Parameters')                      -> proxy($proxy);     my $latin1 = '

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -