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 test_apr.h testall.c testpipe.c
Date Tue, 03 Dec 2002 22:01:01 GMT
rbb         2002/12/03 14:01:01

  Modified:    test     Makefile.in test_apr.h testall.c testpipe.c
  Log:
  migrate testpipe to the new test suite.
  
  Revision  Changes    Path
  1.123     +1 -7      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.122
  retrieving revision 1.123
  diff -u -r1.122 -r1.123
  --- Makefile.in	3 Dec 2002 06:32:13 -0000	1.122
  +++ Makefile.in	3 Dec 2002 22:01:00 -0000	1.123
  @@ -104,12 +104,6 @@
   testshmconsumer@EXEEXT@: testshmconsumer.lo $(LOCAL_LIBS)
   	$(LINK) testshmconsumer.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testpipe@EXEEXT@: testpipe.lo $(LOCAL_LIBS)
  -	$(LINK) testpipe.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
  -testsockopt@EXEEXT@: testsockopt.lo $(LOCAL_LIBS)
  -	$(LINK) testsockopt.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
   testhash@EXEEXT@: testhash.lo $(LOCAL_LIBS)
   	$(LINK) testhash.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  @@ -132,7 +126,7 @@
   	testmmap.lo testud.lo testtable.lo testsleep.lo testpools.lo \
   	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
  +	testpoll.lo testlock.lo testsockopt.lo testpipe.lo
   
   testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
   	 CuTest.lo proc_child@EXEEXT@ $(LOCAL_LIBS)
  
  
  
  1.32      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- test_apr.h	3 Dec 2002 06:32:13 -0000	1.31
  +++ test_apr.h	3 Dec 2002 22:01:00 -0000	1.32
  @@ -88,5 +88,6 @@
   CuSuite *testpoll(void);
   CuSuite *testlock(void);
   CuSuite *testsockopt(void);
  +CuSuite *testpipe(void);
   
   #endif /* APR_TEST_INCLUDES */
  
  
  
  1.29      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- testall.c	3 Dec 2002 06:32:13 -0000	1.28
  +++ testall.c	3 Dec 2002 22:01:00 -0000	1.29
  @@ -76,6 +76,7 @@
       {"testfmt", testfmt},
       {"testfile", testfile},
       {"testfileinfo", testfileinfo},
  +    {"testpipe", testpipe},
       {"testdup", testdup},
       {"testdir", testdir},
       {"testrand", testrand},
  
  
  
  1.20      +77 -50    apr/test/testpipe.c
  
  Index: testpipe.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testpipe.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- testpipe.c	5 Jul 2002 00:11:10 -0000	1.19
  +++ testpipe.c	3 Dec 2002 22:01:00 -0000	1.20
  @@ -52,67 +52,94 @@
    * <http://www.apache.org/>.
    */
   
  -#include <stdio.h>
  +#include "test_apr.h"
   #include "apr_file_io.h"
   #include "apr_errno.h"
   #include "apr_general.h"
   #include "apr_lib.h"
  -#include <stdlib.h>
  -#ifdef BEOS
  -#include <unistd.h>
  -#endif
   
  -int main(void)
  +static apr_file_t *readp = NULL;
  +static apr_file_t *writep = NULL;
  +
  +static void create_pipe(CuTest *tc)
  +{
  +    apr_status_t rv;
  +
  +    rv = apr_file_pipe_create(&readp, &writep, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, readp);
  +    CuAssertPtrNotNull(tc, writep);
  +}   
  +
  +static void close_pipe(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    apr_size_t nbytes = 256;
  +    char buf[256];
  +
  +    rv = apr_file_close(readp);
  +    rv = apr_file_close(writep);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    rv = apr_file_read(readp, buf, &nbytes);
  +    CuAssertIntEquals(tc, 1, APR_STATUS_IS_EBADF(rv));
  +}   
  +
  +static void set_timeout(CuTest *tc)
   {
  -    apr_pool_t *context;
  +    apr_status_t rv;
       apr_file_t *readp = NULL;
       apr_file_t *writep = NULL;
  -    apr_size_t nbytes;
  +    apr_interval_time_t timeout;
  +
  +    rv = apr_file_pipe_create(&readp, &writep, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, readp);
  +    CuAssertPtrNotNull(tc, writep);
  +
  +    rv = apr_file_pipe_timeout_get(readp, &timeout);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertIntEquals(tc, -1, timeout);
  +
  +    rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1));
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    rv = apr_file_pipe_timeout_get(readp, &timeout);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertIntEquals(tc, apr_time_from_sec(1), timeout);
  +}
  +
  +static void read_write(CuTest *tc)
  +{
       apr_status_t rv;
       char *buf;
  -    char msgbuf[120];
  -
  -    if (apr_initialize() != APR_SUCCESS) {
  -        fprintf(stderr, "Couldn't initialize.");
  -        exit(-1);
  -    }
  -    atexit(apr_terminate);
  -    if (apr_pool_create(&context, NULL) != APR_SUCCESS) {
  -        fprintf(stderr, "Couldn't allocate context.");
  -        exit(-1);
  -    }
  -
  -    fprintf(stdout, "Testing pipe functions.\n");
  -
  -    fprintf(stdout, "\tCreating pipes.......");
  -    if ((rv = apr_file_pipe_create(&readp, &writep, context)) != APR_SUCCESS) {
  -        fprintf(stderr, "apr_file_pipe_create()->%d/%s\n",
  -                rv, apr_strerror(rv, msgbuf, sizeof msgbuf));
  -        exit(-1);
  -    }
  -    else {
  -        fprintf(stdout, "OK\n");
  -    }
  -    
  -    fprintf(stdout, "\tSetting pipe timeout.......");
  -    if ((rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1))) != APR_SUCCESS) {
  -        fprintf(stderr, "apr_file_pipe_timeout_set()->%d/%s\n",
  -                rv, apr_strerror(rv, msgbuf, sizeof msgbuf));
  -        exit(-1);
  -    } else {
  -        fprintf(stdout, "OK\n");
  -    }        
  +    apr_size_t nbytes;
   
  -    fprintf(stdout, "\tReading from the pipe.......");
       nbytes = strlen("this is a test");
  -    buf = (char *)apr_palloc(context, nbytes + 1);
  -    if (apr_file_read(readp, buf, &nbytes) == APR_TIMEUP) {
  -        fprintf(stdout, "OK\n");
  -    }
  -    else {
  -        fprintf(stdout, "The timeout didn't work  :-(\n");
  -        exit(-1);
  -    }
  +    buf = (char *)apr_palloc(p, nbytes + 1);
   
  -    return 0;
  +    rv = apr_file_pipe_create(&readp, &writep, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, readp);
  +    CuAssertPtrNotNull(tc, writep);
  +
  +    rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1));
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    rv = apr_file_read(readp, buf, &nbytes);
  +    CuAssertIntEquals(tc, 1, APR_STATUS_IS_TIMEUP(rv));
  +    CuAssertIntEquals(tc, 0, nbytes);
   }
  +
  +CuSuite *testpipe(void)
  +{
  +    CuSuite *suite = CuSuiteNew("Pipes");
  +
  +    SUITE_ADD_TEST(suite, create_pipe);
  +    SUITE_ADD_TEST(suite, close_pipe);
  +    SUITE_ADD_TEST(suite, set_timeout);
  +    SUITE_ADD_TEST(suite, read_write);
  +
  +    return suite;
  +}
  +
  
  
  

Mime
View raw message