stas        02/04/05 11:42:20

  Added:       t        TEST.PL
               t/apreq  big_input.t cookie.t request.t
               t/response/TestApReq big_input.pm cookie.pm request.pm
  Log:
  add two basic tests for processing forms and cookies
  add one test that tries inputs of various sizes up to the allowed max
  
  Revision  Changes    Path
  1.1                  httpd-apreq/t/TEST.PL
  
  Index: TEST.PL
  ===================================================================
  #!perl
  
  use strict;
  use warnings FATAL => 'all';
  
  use lib qw(lib Apache-Test/lib);
  
  use Apache::TestRunPerl ();
  
  Apache::TestRunPerl->new->run(@ARGV);
  
  
  
  1.1                  httpd-apreq/t/apreq/big_input.t
  
  Index: big_input.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  # test the processing of variations of the key lengths and the keys
  # numbers
   
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::TestRequest qw(GET_BODY POST_BODY);
  
  my $location = "/TestApReq::big_input";
  
  my @key_len = (5, 100, 305);
  my @key_num = (5, 15, 26);
  my @keys    = ('a'..'z');
  
  my @big_key_len = (100, 500, 5000, 10000);
  my @big_key_num = (5, 15, 25);
  my @big_keys    = ('a'..'z');
  
  plan tests => @key_len * @key_num + @big_key_len * @big_key_num;
  
  
  # GET
  my $len = 0;
  for my $key_len (@key_len) {
      for my $key_num (@key_num) {
          my @query = ();
  
          for my $key (@keys[0..($key_num-1)]) {
              my $pair = "$key=" . 'd' x $key_len;
              $len += length $pair;
              push @query, $pair;
          }
          my $query = join "&", @query;
          $len += @query - 1;  # the stick with two ends one '&' char off
  
          my $body = GET_BODY "$location?$query";
          t_debug "# of keys : $key_num, key_len $key_len";
          ok t_cmp(( ($key_len + 3) * $key_num - 1),
                   $body,
                   "GET long query");
      }
  
  }
  
  # POST
  $len = 0;
  for my $big_key_len (@big_key_len) {
      for my $big_key_num (@big_key_num) {
          my @query = ();
  
          for my $big_key (@big_keys[0..($big_key_num-1)]) {
              my $pair = "$big_key=" . 'd' x $big_key_len;
              $len += length $pair;
              push @query, $pair;
          }
          my $query = join "&", @query;
          $len += @query - 1;  # the stick with two ends one '&' char off
  
          my $body = POST_BODY $location, content => $query;
          t_debug "# of keys : $big_key_num, key_len $big_key_len";
          ok t_cmp(( ($big_key_len + 3) * $big_key_num - 1),
                   $body,
                   "POST big data");
      }
  
  }
  
  
  
  1.1                  httpd-apreq/t/apreq/cookie.t
  
  Index: cookie.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  
  use Apache::TestUtil;
  use Apache::TestRequest qw(GET_BODY);
  use HTTP::Cookies;
  
  plan tests => 1;
  
  my $location = "/TestApReq::cookie";
  
  {
      # basic param() test
      my $test  = 'basic';
      my $key   = 'apache';
      my $value = 'ok';
      my $cookie = qq{\$Version="1"; $key="$value"; \$Path="$location"};
      ok t_cmp(qq{"$value"},
               GET_BODY("$location?test=$test&key=$key", Cookie => $cookie),
               $test);
  }
  
  
  
  
  1.1                  httpd-apreq/t/apreq/request.t
  
  Index: request.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  
  use Apache::TestUtil;
  use Apache::TestRequest qw(GET_BODY UPLOAD_BODY);
  
  plan tests => 2;
  
  my $location = "/TestApReq::request";
  #print GET_BODY $location;
  
  {
      # basic param() test
      my $test  = 'param';
      my $value = '42.5';
      ok t_cmp($value,
               GET_BODY("$location?test=$test&value=$value"),
               "basic param");
  }
  {
      # upload a string as a file
      my $test  = 'upload';
      my $value = 'data upload';
      ok t_cmp($value,
               UPLOAD_BODY("$location?test=$test", content => $value),
               "basic upload");
  }
  
  
  
  1.1                  httpd-apreq/t/response/TestApReq/big_input.pm
  
  Index: big_input.pm
  ===================================================================
  package TestApReq::big_input;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use Apache::Cookie ();
  use Apache::Request ();
  
  
  sub handler {
      my $r = shift;
      my $apr = Apache::Request->new($r);
  
      my $len = 0;
      for ($apr->param) {
          $len += length($_) + length($apr->param($_)) + 2; # +2 ('=' and '&')
      }
      $len--; # the stick with two ends one '&' char off
  
      $r->send_http_header('text/plain');
      $r->print($len);
  
      return 0;
  }
  
  1;
  
  __END__
  
  
  
  1.1                  httpd-apreq/t/response/TestApReq/cookie.pm
  
  Index: cookie.pm
  ===================================================================
  package TestApReq::cookie;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use Apache::Cookie ();
  use Apache::Request ();
  
  
  sub handler {
      my $r = shift;
      my $apr = Apache::Request->new($r);
      my %cookies = Apache::Cookie->fetch;
  
      $r->send_http_header('text/plain');
  
      my $test = $apr->param('test');
      my $key  = $apr->param('key');
  
  #    return DECLINED unless defined $test;
  
      if ($test eq 'basic') {
          if ($cookies{$key}) {
              $r->print($cookies{$key}->value);
          }
      }
  
  
      return 0;
  }
  
  1;
  
  __END__
  
  
  
  1.1                  httpd-apreq/t/response/TestApReq/request.pm
  
  Index: request.pm
  ===================================================================
  package TestApReq::request;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::Constants qw(OK M_POST DECLINED);
  
  use Apache::Request ();
  
  sub handler {
      my $r = shift;
      my $apr = Apache::Request->new($r);
  
      $r->send_http_header('text/plain');
  
      my $test  = $apr->param('test');
      my $value = $apr->param('value');
  
      return DECLINED unless defined $test;
  
      if ($test eq 'param') {
          $r->print($value);
      }
      elsif ($test eq 'upload') {
          my $upload = $apr->upload;
          my $fh = $upload->fh;
          local $/;
          my $data = <$fh>;
          $r->print($data);
      } 
      else {
          
      }
  
      return OK;
  }
  1;
  __END__
  
  
  

Reply via email to