stas        2004/05/25 01:25:44

  Modified:    t/apr    .cvsignore
               t/response/TestAPI rutil.pm
  Added:       t/response/TestAPR uri.pm
  Log:
  write APR::URI tests, move some of the existing sub-tests out of
  TestAPI/rutil.pm since they belong to TestAPR/uri.pm
  
  Revision  Changes    Path
  1.1                  modperl-2.0/t/response/TestAPR/uri.pm
  
  Index: uri.pm
  ===================================================================
  package TestAPR::uri;
  
  # Testing APR::URI (more tests in TestAPI::uri)
  
  # XXX: this test could use more sub-tests to test various flags to
  # unparse,
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use APR::URI ();
  
  use Apache::Const -compile => 'OK';
  use APR::Const    -compile => qw(URI_UNP_REVEALPASSWORD);
  
  my %default_ports = (
      ftp      => 21,
      gopher   => 70,
      http     => 80,
      https    => 443,
      nntp     => 119,
      prospero => 191,
      snews    => 563,
      wais     => 210,
  );
  
  my %url = (
      scheme   => ["http",            "ftp"            ],
      user     => ["user",            "log"            ],
      password => ["password",        "pass"           ],
      hostname => ["www.example.com", "ftp.example.com"],
      port     => [8000,               21              ],
      path     => ["/path/file.pl",   "/pub"           ],
      query    => ["query",           undef            ],
      fragment => ["fragment",        undef            ],
  );
  
  my @keys_urls = qw(scheme user password hostname port path query fragment);
  my @keys_hostinfo = qw(user password hostname port);
  
  sub handler {
      my $r = shift;
  
      plan $r, tests => 22;
  
      ### parse ###
      my $url0 = sprintf "%s://%s:[EMAIL PROTECTED]:%d%s?%s#%s",
          map { $url{$_}[0] } @keys_urls;
      # warn "URL: $url\n";
      my $hostinfo0 =  sprintf "%s:[EMAIL PROTECTED]:%d",
          map { $url{$_}[0] } @keys_hostinfo;
  
      my $parsed = APR::URI->parse($r->pool, $url0);
      ok $parsed;
      ok $parsed->isa('APR::URI');
  
      for my $method (keys %url) {
          no strict 'refs';
          ok t_cmp($url{$method}[0], $parsed->$method, $method);
      }
  
      ok t_cmp($hostinfo0, $parsed->hostinfo, "hostinfo");
  
      for my $method (keys %url) {
          no strict 'refs';
          $parsed->$method($url{$method}[1]);
          t_debug("$method: $url{$method}[1] => " . $parsed->$method);
      }
  
      ### unparse ###
      my $url_unparsed = $parsed->unparse;
  
      # hostinfo is unaffected, since it's simply a field in the parsed
      # record, and it's populated when parse is called, but when
      # individual fields used to compose it are updated, it doesn't get
      # updated: so we see the old value here
      ok t_cmp($hostinfo0, $parsed->hostinfo, "hostinfo");
  
      # - since the port is 21 which is the default for ftp, unparse
      #   omits it
      # - if no flags are passed to unparse, APR::URI_UNP_OMITPASSWORD
      #   is passed by default -- it hides the password
      my $url1 = sprintf "%s://[EMAIL PROTECTED]",
          map { $url{$_}[1] } grep !/^(password|port)$/, @keys_urls;
      ok t_cmp($url1, $url_unparsed, "unparsed url");
  
      # this time the password should appear
      my $url_unparsed = $parsed->unparse(APR::URI_UNP_REVEALPASSWORD);
      my $url2 = sprintf "%s://%s:[EMAIL PROTECTED]",
          map { $url{$_}[1] } grep !/^port$/, @keys_urls;
      ok t_cmp($url2, $url_unparsed, "unparsed url");
  
  
      ### port_of_scheme ###
      while(my($scheme, $port) = each %default_ports) {
          my $apr_port = APR::URI::port_of_scheme($scheme);
          ok t_cmp($port, $apr_port, "scheme: $scheme");
      }
  
      Apache::OK;
  }
  
  
  
  1;
  
  
  
  1.14      +1 -0      modperl-2.0/t/apr/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/apr/.cvsignore,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -u -r1.13 -r1.14
  --- .cvsignore        21 May 2004 19:25:46 -0000      1.13
  +++ .cvsignore        25 May 2004 08:25:44 -0000      1.14
  @@ -15,5 +15,6 @@
   string.t
   table.t
   threadmutex.t
  +uri.t
   util.t
   uuid.t
  
  
  
  1.12      +1 -19     modperl-2.0/t/response/TestAPI/rutil.pm
  
  Index: rutil.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/response/TestAPI/rutil.pm,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -u -r1.11 -r1.12
  --- rutil.pm  19 Jan 2004 19:19:45 -0000      1.11
  +++ rutil.pm  25 May 2004 08:25:44 -0000      1.12
  @@ -6,26 +6,14 @@
   use Apache::Test;
   use Apache::TestUtil;
   
  -use APR::URI ();
   use Apache::RequestUtil ();
   
   use Apache::Const -compile => 'OK';
   
  -my %default_ports = (
  -    http => 80,
  -    https => 443,
  -    ftp => 21,
  -    gopher => 70,
  -    wais => 210,
  -    nntp => 119,
  -    snews => 563,
  -    prospero => 191,
  -);
  -
   sub handler {
       my $r = shift;
   
  -    plan $r, tests => 15;
  +    plan $r, tests => 7;
   
       ok $r->default_type;
   
  @@ -36,12 +24,6 @@
       ok $r->get_server_port;
   
       ok $r->get_limit_req_body || 1;
  -
  -    while(my($scheme, $port) = each %default_ports) {
  -        my $apr_port = APR::URI::port_of_scheme($scheme);
  -        #$r->puts("$scheme => expect: $port, got: $apr_port\n");
  -        ok $apr_port == $port;
  -    }
   
       ok $r->is_initial_req;
   
  
  
  

Reply via email to