Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.8 KiB

  1. # ======================================================================
  2. #
  3. # Copyright (C) 2000-2001 Paul Kulchenko ([email protected])
  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: XMLRPC::Test.pm,v 0.51 2001/07/18 15:15:14 $
  8. #
  9. # ======================================================================
  10. package XMLRPC::Test;
  11. use 5.004;
  12. use vars qw($VERSION $TIMEOUT);
  13. $VERSION = '0.51';
  14. $TIMEOUT = 5;
  15. # ======================================================================
  16. package My::PingPong; # we'll use this package in our tests
  17. sub new {
  18. my $self = shift;
  19. my $class = ref($self) || $self;
  20. bless {_num=>shift} => $class;
  21. }
  22. sub next {
  23. my $self = shift;
  24. $self->{_num}++;
  25. }
  26. sub value {
  27. my $self = shift;
  28. $self->{_num};
  29. }
  30. # ======================================================================
  31. package XMLRPC::Test::Server;
  32. use strict;
  33. use Test;
  34. use XMLRPC::Lite;
  35. sub run_for {
  36. my $proxy = shift or die "Proxy/endpoint is not specified";
  37. # ------------------------------------------------------
  38. my $s = XMLRPC::Lite->proxy($proxy)->on_fault(sub{});
  39. eval { $s->transport->timeout($XMLRPC::Test::TIMEOUT) };
  40. my $r = $s->test_connection;
  41. unless (defined $r && defined $r->envelope) {
  42. print "1..0 # Skip: ", $s->transport->status, "\n";
  43. exit;
  44. }
  45. # ------------------------------------------------------
  46. plan tests => 16;
  47. eval q!use XMLRPC::Lite on_fault => sub{ref $_[1] ? $_[1] : new XMLRPC::SOM}; 1! or die;
  48. print "Perl XMLRPC server test(s)...\n";
  49. $s = XMLRPC::Lite
  50. -> proxy($proxy)
  51. ;
  52. ok($s->call('My.Examples.getStateName', 1)->result eq 'Alabama');
  53. ok($s->call('My.Examples.getStateNames', 1,4,6,13)->result =~ /^Alabama\s+Arkansas\s+Colorado\s+Illinois\s*$/);
  54. $r = $s->call('My.Examples.getStateList', [1,2,3,4])->result;
  55. ok(ref $r && $r->[0] eq 'Alabama');
  56. $r = $s->call('My.Examples.getStateStruct', {item1 => 1, item2 => 4})->result;
  57. ok(ref $r && $r->{item2} eq 'Arkansas');
  58. print "dispatch_from test(s)...\n";
  59. eval "use XMLRPC::Lite
  60. dispatch_from => ['A', 'B'],
  61. proxy => '$proxy',
  62. ; 1" or die;
  63. eval { C->c };
  64. ok($@ =~ /Can't locate object method "c"/);
  65. print "Object autobinding and XMLRPC:: prefix test(s)...\n";
  66. eval "use XMLRPC::Lite +autodispatch =>
  67. proxy => '$proxy'; 1" or die;
  68. ok(XMLRPC::Lite->autodispatched);
  69. # forget everything
  70. XMLRPC::Lite->self(undef);
  71. {
  72. my $on_fault_was_called = 0;
  73. print "Die in server method test(s)...\n";
  74. my $s = XMLRPC::Lite
  75. -> proxy($proxy)
  76. -> on_fault(sub{$on_fault_was_called++;return})
  77. ;
  78. ok($s->call('My.Parameters.die_simply')->faultstring =~ /Something bad/);
  79. ok($on_fault_was_called > 0);
  80. # get Fault as hash of subelements
  81. my $fault = $s->call('My.Parameters.die_with_fault');
  82. ok($fault->faultcode =~ 'Server\.Custom');
  83. ok($fault->faultstring eq 'Died in server method');
  84. }
  85. print "Number of parameters test(s)...\n";
  86. $s = XMLRPC::Lite
  87. -> proxy($proxy)
  88. ;
  89. { my @all = $s->call('My.Parameters.echo')->paramsall; ok(@all == 0) }
  90. { my @all = $s->call('My.Parameters.echo', 1)->paramsall; ok(@all == 1) }
  91. { my @all = $s->call('My.Parameters.echo', (1) x 10)->paramsall; ok(@all == 10) }
  92. print "Memory refresh test(s)...\n";
  93. # Funny test.
  94. # Let's forget about ALL settings we did before with 'use XMLRPC::Lite...'
  95. XMLRPC::Lite->self(undef);
  96. ok(!defined XMLRPC::Lite->self);
  97. eval "use XMLRPC::Lite
  98. proxy => '$proxy'; 1" or die;
  99. print "Global settings test(s)...\n";
  100. $s = new XMLRPC::Lite;
  101. ok($s->call('My.Examples.getStateName', 1)->result eq 'Alabama');
  102. SOAP::Trace->import(transport =>
  103. sub {$_[0]->content_type('something/wrong') if UNIVERSAL::isa($_[0] => 'HTTP::Request')}
  104. );
  105. if ($proxy =~ /^tcp:/) {
  106. skip('No Content-Type checks for tcp: protocol on server side' => undef);
  107. } else {
  108. ok($s->call('My.Examples.getStateName', 1)->faultstring =~ /Content-Type must be/);
  109. 1;
  110. }
  111. }
  112. # ======================================================================
  113. 1;
  114. __END__
  115. =head1 NAME
  116. XMLRPC::Test - Test framework for XMLRPC::Lite
  117. =head1 SYNOPSIS
  118. use XMLRPC::Test;
  119. XMLRPC::Test::Server::run_for('http://localhost/cgi-bin/XMLRPC.cgi');
  120. =head1 DESCRIPTION
  121. XMLRPC::Test provides simple framework for testing server implementations.
  122. Specify your address (endpoint) and run provided tests against your server.
  123. See t/1*.t for examples.
  124. =head1 COPYRIGHT
  125. Copyright (C) 2000-2001 Paul Kulchenko. All rights reserved.
  126. This library is free software; you can redistribute it and/or modify
  127. it under the same terms as Perl itself.
  128. =head1 AUTHOR
  129. Paul Kulchenko (paulclinger@yahoo.com)
  130. =cut