You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-cvs@httpd.apache.org by ra...@apache.org on 2003/10/14 06:21:58 UTC

cvs commit: httpd-apreq-2/env/cgi_test/t cgi.t

randyk      2003/10/13 21:21:58

  Modified:    env/cgi_test cgi_test.c
               env/cgi_test/t cgi.t
  Log:
  add some long query and big post tests for the libapreq_cgi tests.
  
  Revision  Changes    Path
  1.2       +20 -15    httpd-apreq-2/env/cgi_test/cgi_test.c
  
  Index: cgi_test.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/cgi_test/cgi_test.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- cgi_test.c	12 Oct 2003 04:46:19 -0000	1.1
  +++ cgi_test.c	14 Oct 2003 04:21:58 -0000	1.2
  @@ -62,7 +62,7 @@
   #include "apr_lib.h"
   #include "apr_tables.h"
   
  -typedef struct env_ctx {
  +typedef struct {
       apr_pool_t         *pool;
       apreq_request_t    *req;
       apreq_jar_t        *jar;
  @@ -71,19 +71,21 @@
       apr_status_t        status;
   } env_ctx;
   
  -static int dump_table(void *ctx, const char *key, const char *value)
  +static int dump_table(void *count, const char *key, const char *value)
   {
  -    env_ctx *c = (env_ctx *) ctx;
  -    apreq_log(APREQ_DEBUG 0, c, "%s => %s", key, value);
  -    printf("\t%s => %s\n", key, value);
  +    int *c = (int *) count;
  +    *c = *c + strlen(key) + strlen(value);
       return 1;
   }
   
   int main(void)
   {
  -    apreq_request_t *req;
       env_ctx *ctx;
       apr_pool_t *pool;
  +    const apreq_param_t *foo, *bar;
  +    apr_table_t *params;
  +    int count = 0;
  +
       if (apr_initialize() != APR_SUCCESS) {
           fprintf(stderr, "apr_initialize failed\n");
           exit(-1);
  @@ -92,21 +94,24 @@
           fprintf(stderr, "apr_pool_create failed\n");
           exit(-1);
       }
  +
       ctx = (env_ctx *) apr_palloc(pool, sizeof(*ctx));
       ctx->loglevel = 0;
       ctx->pool = pool;
       apreq_log(APREQ_DEBUG 0, ctx, "%s", "Creating apreq_request");
  -    req = apreq_request(ctx, NULL);
  +    ctx->req = apreq_request(ctx, NULL);
  +
       printf("%s", "Content-Type: text/plain\n\n");
       apreq_log(APREQ_DEBUG 0, ctx, "%s", "Fetching the parameters");
  -    printf("ARGS:\n");
  -    apr_table_do(dump_table, ctx, req->args, NULL);
  -    if (req->body) {
  -        printf("BODY:\n");
  -        apr_table_do(dump_table, ctx, req->body, NULL);
  +    foo = apreq_param(ctx->req, "foo");
  +    bar = apreq_param(ctx->req, "bar");
  +    if (foo || bar) {
  +      if(foo) printf("\t%s => %s\n", "foo", foo->v.data);
  +      if(bar) printf("\t%s => %s\n", "bar", bar->v.data);
  +      return 0;
       }
  -    
  -    apreq_log(APREQ_DEBUG 0, ctx, "%s", "Done!");
  +    params = apreq_params(ctx->pool, ctx->req);
  +    apr_table_do(dump_table, &count, params, NULL);
  +    printf("%d", count);
       return 0;
   }
  -
  
  
  
  1.2       +73 -5     httpd-apreq-2/env/cgi_test/t/cgi.t
  
  Index: cgi.t
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/cgi_test/t/cgi.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- cgi.t	12 Oct 2003 04:46:19 -0000	1.1
  +++ cgi.t	14 Oct 2003 04:21:58 -0000	1.2
  @@ -7,12 +7,80 @@
   use Apache::TestRequest qw(GET_BODY UPLOAD_BODY POST_BODY GET_RC);
   use constant WIN32 => Apache::TestConfig::WIN32;
   
  -plan tests => 2;
  +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 => 5 + @key_len * @key_num + @big_key_len * @big_key_num;
   
   my $script = WIN32 ? '/cgi-bin/cgi_test.exe' : '/cgi-bin/cgi_test';
   my $line_end = WIN32 ? "\r\n" : "\n";
   
  -ok t_cmp("ARGS:$line_end\tfoo => 1$line_end", 
  -         GET_BODY("$script?foo=1"), "simple get");
  -ok t_cmp("ARGS:$line_end\tbar => hello world$line_end\tfoo => ?$line_end", 
  -         GET_BODY("$script?bar=hello+world;foo=%3F"), "simple get");
  +ok t_cmp("\tfoo => 1$line_end", 
  +         POST_BODY("$script?foo=1"), "simple get");
  +ok t_cmp("\tfoo => ?$line_end\tbar => hello world$line_end", 
  +         GET_BODY("$script?foo=%3F&bar=hello+world"), "simple get");
  +
  +my $filler = "0123456789" x 5; # < 64K
  +
  +my $body = POST_BODY("/$script", content => 
  +                     "aaa=$filler;foo=1;bar=2;filler=$filler");
  +ok t_cmp("\tfoo => 1$line_end\tbar => 2$line_end", 
  +         $body, "simple post");
  +
  +$body = POST_BODY("/$script?foo=1", content => 
  +                  "intro=$filler&bar=2&conclusion=$filler");
  +ok t_cmp("\tfoo => 1$line_end\tbar => 2$line_end", 
  +         $body, "simple post");
  +
  +$body = UPLOAD_BODY("/$script?foo=0", content => $filler);
  +ok t_cmp("\tfoo => 0$line_end", 
  +         $body, "simple upload");
  +
  +# GET
  +for my $key_len (@key_len) {
  +    for my $key_num (@key_num) {
  +        my @query = ();
  +        my $len = 0;
  +
  +        for my $key (@keys[0..($key_num-1)]) {
  +            my $pair = "$key=" . 'd' x $key_len;
  +            $len += length($pair) - 1;
  +            push @query, $pair;
  +        }
  +        my $query = join ";", @query;
  +
  +        t_debug "# of keys : $key_num, key_len $key_len";
  +        my $body = GET_BODY "$script?$query";
  +        ok t_cmp($len,
  +                 $body,
  +                 "GET long query");
  +    }
  +
  +}
  +
  +# POST
  +for my $big_key_len (@big_key_len) {
  +    for my $big_key_num (@big_key_num) {
  +        my @query = ();
  +        my $len = 0;
  +
  +        for my $big_key (@big_keys[0..($big_key_num-1)]) {
  +            my $pair = "$big_key=" . 'd' x $big_key_len;
  +            $len += length($pair) - 1;
  +            push @query, $pair;
  +        }
  +        my $query = join ";", @query;
  +
  +        t_debug "# of keys : $big_key_num, big_key_len $big_key_len";
  +        $body = POST_BODY($script, content => "$query;$filler");
  +        ok t_cmp($len,
  +                 $body,
  +                 "POST big data");
  +    }
  +
  +}