apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr/test Makefile.in testall.c testargs.c test_apr.h
Date Fri, 06 Dec 2002 16:04:58 GMT
rbb         2002/12/06 08:04:58

  Modified:    test     Makefile.in testall.c testargs.c test_apr.h
  Log:
  Migreate testargs to the new test suite.
  
  Revision  Changes    Path
  1.128     +1 -7      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.127
  retrieving revision 1.128
  diff -u -r1.127 -r1.128
  --- Makefile.in	4 Dec 2002 22:35:02 -0000	1.127
  +++ Makefile.in	6 Dec 2002 16:04:57 -0000	1.128
  @@ -13,12 +13,9 @@
   	testnames@EXEEXT@ \
   	testflock@EXEEXT@ \
   	testsock@EXEEXT@ \
  -	testlock@EXEEXT@ \
   	testlockperf@EXEEXT@ \
  -	testargs@EXEEXT@ \
   	testshmproducer@EXEEXT@ \
   	testshmconsumer@EXEEXT@ \
  -	testhash@EXEEXT@ \
   	testuser@EXEEXT@ \
   	testatomic@EXEEXT@ \
   	testmutexscope@EXEEXT@ \
  @@ -71,9 +68,6 @@
   libmod_test.la: mod_test.slo $(LOCAL_LIBS)
   	$(LINK) --mode=link $(COMPILE) -rpath `pwd` -avoid-version mod_test.lo $(LT_LDFLAGS) $(ALL_LDFLAGS)
-o $@
   
  -testargs@EXEEXT@: testargs.lo $(LOCAL_LIBS)
  -	$(LINK) testargs.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
   testlockperf@EXEEXT@: testlockperf.lo $(LOCAL_LIBS)
   	$(LINK) testlockperf.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  @@ -118,7 +112,7 @@
   	testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
   	testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \
   	testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \
  -	testhash.lo
  +	testhash.lo testargs.lo
   
   testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
   	 CuTest.lo proc_child@EXEEXT@ $(LOCAL_LIBS)
  
  
  
  1.32      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- testall.c	4 Dec 2002 22:33:08 -0000	1.31
  +++ testall.c	6 Dec 2002 16:04:58 -0000	1.32
  @@ -89,6 +89,7 @@
       {"testpoll", testpoll},
       {"testlock", testlock},
       {"testthread", testthread},
  +    {"testargs", testgetopt},
       {"LastTest", NULL}
   };
   
  
  
  
  1.25      +190 -32   apr/test/testargs.c
  
  Index: testargs.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testargs.c,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- testargs.c	13 Mar 2002 20:39:27 -0000	1.24
  +++ testargs.c	6 Dec 2002 16:04:58 -0000	1.25
  @@ -52,65 +52,223 @@
    * <http://www.apache.org/>.
    */
   
  -#include "apr_file_io.h"
   #include "apr_errno.h"
   #include "apr_general.h"
  -#include "apr_lib.h"
   #include "apr_getopt.h"
  -#include <stdio.h>
  -#include <stdlib.h>
  -#ifdef BEOS
  -#include <unistd.h>
  -#endif
  +#include "apr_strings.h"
  +#include "test_apr.h"
   
  -static void maybe_arg(const char *arg)
  +static void format_arg(char *str, char option, const char *arg)
   {
       if (arg) {
  -        printf(" with %s\n", arg);
  +        apr_snprintf(str, 8196, "%soption: %c with %s\n", str, option, arg);
       }
       else {
  -        printf("\n");
  +        apr_snprintf(str, 8196, "%soption: %c\n", str, option);
       }
   }
   
  -int main(int argc, const char * const argv[])
  +static void unknown_arg(void *str, const char *err, ...)
  +{
  +    va_list va;
  +
  +    va_start(va, err);
  +    apr_vsnprintf(str, 8196, err, va);
  +    va_end(va);
  +}
  +
  +static void no_options_found(CuTest *tc)
   {
  -    apr_pool_t *context;
  +    int largc = 5;
  +    const char * const largv[] = {"testprog", "-a", "-b", "-c", "-d"};
       apr_getopt_t *opt;
  +    apr_status_t rv;
       char data;
       const char *optarg;
  +    char str[8196];
   
  -    apr_initialize();
  -    atexit(apr_terminate);
  -    apr_pool_create(&context, NULL);
  -
  -    if (apr_getopt_init(&opt, context, argc, argv))
  -    {
  -        printf("failed to initialize opts");
  -        exit(1);
  +    str[0] = '\0';
  +    rv = apr_getopt_init(&opt, p, largc, largv);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +   
  +    while (apr_getopt(opt, "abcd", &data, &optarg) == APR_SUCCESS) {
  +        switch (data) {
  +            case 'a':
  +            case 'b':
  +            case 'c':
  +            case 'd':
  +            default:
  +                format_arg(str, data, optarg);
  +        }
       }
  -    while (apr_getopt(opt, "abc:d::", &data, &optarg) == APR_SUCCESS) {
  +    CuAssertStrEquals(tc, "option: a\n"
  +                          "option: b\n"
  +                          "option: c\n"
  +                          "option: d\n", str);
  +}
  +
  +static void no_options(CuTest *tc)
  +{
  +    int largc = 5;
  +    const char * const largv[] = {"testprog", "-a", "-b", "-c", "-d"};
  +    apr_getopt_t *opt;
  +    apr_status_t rv;
  +    char data;
  +    const char *optarg;
  +    char str[8196];
  +
  +    str[0] = '\0';
  +    rv = apr_getopt_init(&opt, p, largc, largv);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    opt->errfn = unknown_arg;
  +    opt->errarg = str;
  +   
  +    while (apr_getopt(opt, "efgh", &data, &optarg) == APR_SUCCESS) {
           switch (data) {
               case 'a':
               case 'b':
  -                printf("option %c\n", data);
  -                break;
               case 'c':
  -                printf("option %c with %s\n", data, optarg);
  -                break;
               case 'd':
  -                printf("option %c", data);
  -                maybe_arg(optarg);
  +                format_arg(str, data, optarg);
  +                break;
  +            default:
  +                break;
  +        }
  +    }
  +    CuAssertStrEquals(tc, "testprog: illegal option -- a\n", str);
  +}
  +
  +static void required_option(CuTest *tc)
  +{
  +    int largc = 3;
  +    const char * const largv[] = {"testprog", "-a", "foo"};
  +    apr_getopt_t *opt;
  +    apr_status_t rv;
  +    char data;
  +    const char *optarg;
  +    char str[8196];
  +
  +    str[0] = '\0';
  +    rv = apr_getopt_init(&opt, p, largc, largv);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    opt->errfn = unknown_arg;
  +    opt->errarg = str;
  +   
  +    while (apr_getopt(opt, "a:", &data, &optarg) == APR_SUCCESS) {
  +        switch (data) {
  +            case 'a':
  +                format_arg(str, data, optarg);
  +                break;
  +            default:
  +                break;
  +        }
  +    }
  +    CuAssertStrEquals(tc, "option: a with foo\n", str);
  +}
  +
  +static void required_option_notgiven(CuTest *tc)
  +{
  +    int largc = 2;
  +    const char * const largv[] = {"testprog", "-a"};
  +    apr_getopt_t *opt;
  +    apr_status_t rv;
  +    char data;
  +    const char *optarg;
  +    char str[8196];
  +
  +    str[0] = '\0';
  +    rv = apr_getopt_init(&opt, p, largc, largv);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    opt->errfn = unknown_arg;
  +    opt->errarg = str;
  +   
  +    while (apr_getopt(opt, "a:", &data, &optarg) == APR_SUCCESS) {
  +        switch (data) {
  +            case 'a':
  +                format_arg(str, data, optarg);
                   break;
               default:
  -                printf("unknown option: %c", data);
  -                maybe_arg(optarg);
                   break;
           }
       }
  +    CuAssertStrEquals(tc, "testprog: option requires an argument -- a\n", str);
  +}
  +
  +static void optional_option(CuTest *tc)
  +{
  +    int largc = 3;
  +    const char * const largv[] = {"testprog", "-a", "foo"};
  +    apr_getopt_t *opt;
  +    apr_status_t rv;
  +    char data;
  +    const char *optarg;
  +    char str[8196];
  +
  +    str[0] = '\0';
  +    rv = apr_getopt_init(&opt, p, largc, largv);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    opt->errfn = unknown_arg;
  +    opt->errarg = str;
  +   
  +    while (apr_getopt(opt, "a::", &data, &optarg) == APR_SUCCESS) {
  +        switch (data) {
  +            case 'a':
  +                format_arg(str, data, optarg);
  +                break;
  +            default:
  +                break;
  +        }
  +    }
  +    CuAssertStrEquals(tc, "option: a with foo\n", str);
  +}
  +
  +static void optional_option_notgiven(CuTest *tc)
  +{
  +    int largc = 2;
  +    const char * const largv[] = {"testprog", "-a"};
  +    apr_getopt_t *opt;
  +    apr_status_t rv;
  +    char data;
  +    const char *optarg;
  +    char str[8196];
  +
  +    str[0] = '\0';
  +    rv = apr_getopt_init(&opt, p, largc, largv);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    opt->errfn = unknown_arg;
  +    opt->errarg = str;
  +   
  +    while (apr_getopt(opt, "a::", &data, &optarg) == APR_SUCCESS) {
  +        switch (data) {
  +            case 'a':
  +                format_arg(str, data, optarg);
  +                break;
  +            default:
  +                break;
  +        }
  +    }
  +#if 0
  +/*  Our version of getopt doesn't allow for optional arguments.  */
  +    CuAssertStrEquals(tc, "option: a\n", str);
  +#endif
  +    CuAssertStrEquals(tc, "testprog: option requires an argument -- a\n", str);
  +}
  +
  +CuSuite *testgetopt(void)
  +{
  +    CuSuite *suite = CuSuiteNew("Getopt");
   
  -    while (opt->ind < opt->argc)
  -        printf("extra arg: %s\n", opt->argv[opt->ind++]);
  +    SUITE_ADD_TEST(suite, no_options);
  +    SUITE_ADD_TEST(suite, no_options_found);
  +    SUITE_ADD_TEST(suite, required_option);
  +    SUITE_ADD_TEST(suite, required_option_notgiven);
  +    SUITE_ADD_TEST(suite, optional_option);
  +    SUITE_ADD_TEST(suite, optional_option_notgiven);
   
  -    return 0;
  +    return suite;
   }
  
  
  
  1.35      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- test_apr.h	4 Dec 2002 22:33:08 -0000	1.34
  +++ test_apr.h	6 Dec 2002 16:04:58 -0000	1.35
  @@ -91,5 +91,6 @@
   CuSuite *testsockopt(void);
   CuSuite *testpipe(void);
   CuSuite *testthread(void);
  +CuSuite *testgetopt(void);
   
   #endif /* APR_TEST_INCLUDES */
  
  
  

Mime
View raw message