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 jo...@apache.org on 2003/04/21 22:16:25 UTC

cvs commit: httpd-apreq-2/t params.c Makefile.am env.c test_apreq.h testall.c

joes        2003/04/21 13:16:25

  Modified:    env      mod_apreq.c
               src      apreq_params.c apreq_params.h
               t        Makefile.am env.c test_apreq.h testall.c
  Added:       t        params.c
  Log:
  Add simple param tests.
  
  Revision  Changes    Path
  1.6       +1 -1      httpd-apreq-2/env/mod_apreq.c
  
  Index: mod_apreq.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/env/mod_apreq.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- mod_apreq.c	17 Apr 2003 19:19:39 -0000	1.5
  +++ mod_apreq.c	21 Apr 2003 20:16:24 -0000	1.6
  @@ -195,7 +195,7 @@
               ctx->bb_parse = apr_brigade_create(r->pool, f->c->bucket_alloc);
           if (ctx->req == NULL) {
               apreq_parser_t *parser;
  -            ctx->req = apreq_request(r);
  +            ctx->req = apreq_request(r,r->args);
               parser = apreq_make_parser(r->pool, APREQ_URL_ENCTYPE,
                                          apreq_parse_urlencoded, NULL, ctx->req);
               apreq_register_parser(ctx->req, parser);
  
  
  
  1.11      +8 -6      httpd-apreq-2/src/apreq_params.c
  
  Index: apreq_params.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- apreq_params.c	21 Apr 2003 16:09:09 -0000	1.10
  +++ apreq_params.c	21 Apr 2003 20:16:24 -0000	1.11
  @@ -89,16 +89,16 @@
   }
   
   
  -APREQ_DECLARE(apreq_request_t *) apreq_request(void *ctx)
  +APREQ_DECLARE(apreq_request_t *) apreq_request(void *ctx, const char *args)
   {
   
       apreq_request_t *req, *old_req = apreq_env_request(ctx, NULL);
  -    const char *query_string, *ct;
  +    const char *ct;
       apr_pool_t *p;
       apr_status_t s;
       dAPREQ_LOG;
   
  -    if (old_req != NULL)
  +    if (args == NULL && old_req != NULL)
           return old_req;
   
       p = apreq_env_pool(ctx);
  @@ -137,10 +137,12 @@
   
       /* XXX need to install copy/merge callbacks for apreq_param_t */
       req->pool = p;
  -    query_string = apreq_env_args(ctx);
   
  -    s = (query_string == NULL) ? APR_SUCCESS : 
  -        apreq_split_params(p, req->args, query_string);
  +    if (args == NULL)
  +        args = apreq_env_args(ctx);
  +
  +    s = (args == NULL) ? APR_SUCCESS : 
  +        apreq_split_params(p, req->args, args);
   
       if (s == APR_SUCCESS)
           req->v.status = ct ? APR_INCOMPLETE : APR_SUCCESS;
  
  
  
  1.11      +1 -7      httpd-apreq-2/src/apreq_params.h
  
  Index: apreq_params.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_params.h,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- apreq_params.h	21 Apr 2003 16:09:09 -0000	1.10
  +++ apreq_params.h	21 Apr 2003 20:16:24 -0000	1.11
  @@ -110,7 +110,7 @@
    * @param ctx The current request context.
    */
   
  -APREQ_DECLARE(apreq_request_t *)apreq_request(void *ctx);
  +APREQ_DECLARE(apreq_request_t *)apreq_request(void *ctx, const char *args);
   
   
   /**
  @@ -151,12 +151,6 @@
   #define apreq_params_as_string(req,key,pool, mode) \
    apreq_join(pool, ", ", apreq_params(req,pool,key), mode)
   
  -/**
  - * Returns an array of param keys; the array elements are unique.
  - * @param req The current apreq_request_t object.
  - * @remark Also parses the request as necessary.
  - */
  -APREQ_DECLARE(apr_array_header_t *) apreq_keys(apreq_request_t *req);
   
   APREQ_DECLARE(apr_status_t)  apreq_split_params(apr_pool_t *pool,
                                                   apreq_table_t *t, 
  
  
  
  1.5       +1 -1      httpd-apreq-2/t/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/Makefile.am,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Makefile.am	21 Apr 2003 18:45:57 -0000	1.4
  +++ Makefile.am	21 Apr 2003 20:16:24 -0000	1.5
  @@ -2,7 +2,7 @@
   LIBS = -L../src
   
   noinst_LIBRARIES = libapreq_tests.a
  -libapreq_tests_a_SOURCES = CuTest.c env.c tables.c cookie.c
  +libapreq_tests_a_SOURCES = CuTest.c env.c tables.c cookie.c params.c
   libapreq_tests_a_LIBADD = ../src/libapreq.la
   
   check_PROGRAMS = testall
  
  
  
  1.5       +5 -29     httpd-apreq-2/t/env.c
  
  Index: env.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/env.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- env.c	21 Apr 2003 18:45:57 -0000	1.4
  +++ env.c	21 Apr 2003 20:16:24 -0000	1.5
  @@ -63,17 +63,8 @@
   #include <stdlib.h>
   #include "test_apreq.h"
   
  -#define dENV struct env_ctx *env = (struct env_ctx *)ctx
  -
   /* rigged environent for unit tests */
   
  -struct env_ctx {
  -    apr_pool_t         *pool;
  -    apreq_request_t    *req;
  -    apreq_jar_t        *jar;
  -    apr_bucket_brigade *bb;
  -};
  -
   static const char env_name[] = "CGI";
   #define CRLF "\015\012"
   
  @@ -84,7 +75,7 @@
   
   static const char *env_in(void *ctx, const char *name)
   {
  -    return getenv(name);
  +    return NULL;
   }
   
   static apr_status_t env_out(void *ctx, const char *name, char *value)
  @@ -94,35 +85,21 @@
   
   static const char *env_args(void *ctx)
   {
  -    return getenv("QUERY_STRING");
  +    return NULL;
   }
   
   static void *env_jar(void *ctx, void *jar)
   {
  -    dENV;
  -    if (jar != NULL) {
  -        apreq_jar_t *old_jar = env->jar;
  -        env->jar = jar;
  -        return old_jar;
  -    }
  -
  -    return env->jar;
  +    return NULL;
   }
   
   static void *env_request(void *ctx, void *req)
   {
  -    dENV;
  -    if (req != NULL) {
  -        apreq_request_t *old_req = env->req;
  -        env->req = req;
  -        return old_req;
  -    }
  -    return env->req;
  +    return NULL;
   }
   
   static apreq_cfg_t *env_cfg(void *ctx)
   {
  -    /* XXX: not implemented */
       return NULL;
   }
   
  @@ -143,9 +120,8 @@
   
   static int dump_table(void *ctx, const char *key, const char *value)
   {
  -    dENV;
       dAPREQ_LOG;
  -    apreq_log(APREQ_DEBUG 0, env, "%s => %s", key, value);
  +    apreq_log(APREQ_DEBUG 0, ctx, "%s => %s", key, value);
       return 1;
   }
   
  
  
  
  1.3       +1 -0      httpd-apreq-2/t/test_apreq.h
  
  Index: test_apreq.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/test_apreq.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- test_apreq.h	21 Apr 2003 18:45:57 -0000	1.2
  +++ test_apreq.h	21 Apr 2003 20:16:24 -0000	1.3
  @@ -69,6 +69,7 @@
   CuSuite *testtable(void);
   CuSuite *testcookie(void);
   CuSuite *testenv(void);
  +CuSuite *testparam(void);
   
   /* Assert that RV is an APR_SUCCESS value; else fail giving strerror
    * for RV and CONTEXT message. */
  
  
  
  1.5       +1 -0      httpd-apreq-2/t/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/testall.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- testall.c	21 Apr 2003 18:45:57 -0000	1.4
  +++ testall.c	21 Apr 2003 20:16:24 -0000	1.5
  @@ -80,6 +80,7 @@
   } tests[] = {
       {"tables", testtable},
       {"cookies", testcookie},
  +    {"params", testparam},
       {"LastTest", NULL}
   };
   
  
  
  
  1.1                  httpd-apreq-2/t/params.c
  
  Index: params.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "apreq_env.h"
  #include "test_apreq.h"
  #include "apreq.h"
  #include "apreq_params.h"
  #include "apr_strings.h"
  
  static apreq_request_t *r = NULL;
  
  static void request_make(CuTest *tc)
  {
      r = apreq_request(NULL,"a=1;quux=foo+bar&plus=%2B;okie=dokie");
  
      CuAssertPtrNotNull(tc, r);
  }
  
  static void request_args_get(CuTest *tc)
  {
      const char *val;
  
      val = apreq_table_get(r->args,"a");
      CuAssertStrEquals(tc,"1",val);
      val = apreq_table_get(r->args,"quux");
      CuAssertStrEquals(tc,"foo bar",val);
  
      val = apreq_table_get(r->args,"plus");
      CuAssertStrEquals(tc,"+",val);
      val = apreq_table_get(r->args,"okie");
      CuAssertStrEquals(tc,"dokie",val);
  
  }
  
  
  CuSuite *testparam(void)
  {
      CuSuite *suite = CuSuiteNew("Param");
  
      SUITE_ADD_TEST(suite, request_make);
      SUITE_ADD_TEST(suite, request_args_get);
      return suite;
  }