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 testmmap.c
Date Sun, 13 Oct 2002 05:28:15 GMT
rbb         2002/10/12 22:28:15

  Modified:    test     Makefile.in test_apr.h testall.c testmmap.c
  Log:
  Port testmmap to the new test suite.
  
  Revision  Changes    Path
  1.93      +2 -2      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.92
  retrieving revision 1.93
  diff -u -r1.92 -r1.93
  --- Makefile.in	13 Oct 2002 02:20:34 -0000	1.92
  +++ Makefile.in	13 Oct 2002 05:28:15 -0000	1.93
  @@ -209,8 +209,8 @@
   testtable@EXEEXT@: testtable.lo $(LOCAL_LIBS)
   	$(LINK) testtable.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testall: testall.lo testtime.lo teststr.lo testvsn.lo CuTest.lo $(LOCAL_LIBS)
  -	$(LINK) testall.lo testtime.lo teststr.lo testvsn.lo CuTest.lo $(LOCAL_LIBS) $(ALL_LIBS)
  +testall: testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo testmmap.lo CuTest.lo
$(LOCAL_LIBS)
  +	$(LINK) testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo testmmap.lo CuTest.lo
$(LOCAL_LIBS) $(ALL_LIBS)
   
   
   # DO NOT REMOVE
  
  
  
  1.13      +5 -11     apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- test_apr.h	13 Oct 2002 03:59:52 -0000	1.12
  +++ test_apr.h	13 Oct 2002 05:28:15 -0000	1.13
  @@ -52,23 +52,16 @@
    * <http://www.apache.org/>.
    */
   
  -/* Some simple functions to make the test apps easier to write and
  - * a bit more consistent...
  - */
  -
  -/* Things to bear in mind when using these...
  - *
  - * If you include '\t' within the string passed in it won't be included
  - * in the spacing, so use spaces instead :)
  - * 
  - */ 
  -
   #ifndef APR_TEST_INCLUDES
   #define APR_TEST_INCLUDES
   
   #include "CuTest.h"
   #include "apr_pools.h"
   
  +/* Some simple functions to make the test apps easier to write and
  + * a bit more consistent...
  + */
  +
   extern apr_pool_t *p;
   
   CuSuite *getsuite(void);
  @@ -77,6 +70,7 @@
   CuSuite *testtime(void);
   CuSuite *testvsn(void);
   CuSuite *testipsub(void);
  +CuSuite *testmmap(void);
   
   
   
  
  
  
  1.5       +3 -2      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- testall.c	13 Oct 2002 03:59:52 -0000	1.4
  +++ testall.c	13 Oct 2002 05:28:15 -0000	1.5
  @@ -57,7 +57,7 @@
   
   #include "test_apr.h"
   
  -#define NUM_TESTS 4
  +#define NUM_TESTS 5
   
   apr_pool_t *p;
   
  @@ -67,7 +67,8 @@
       teststr,
       testtime,
       testvsn,
  -    testipsub
  +    testipsub,
  +    testmmap
   };
   
   int main(int argc, char *argv[])
  
  
  
  1.33      +99 -80    apr/test/testmmap.c
  
  Index: testmmap.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testmmap.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- testmmap.c	13 Mar 2002 20:39:27 -0000	1.32
  +++ testmmap.c	13 Oct 2002 05:28:15 -0000	1.33
  @@ -52,100 +52,119 @@
    * <http://www.apache.org/>.
    */
   
  +#include "test_apr.h"
   #include "apr_mmap.h"
   #include "apr_errno.h"
   #include "apr_general.h"
   #include "apr_lib.h"
   #include "apr_file_io.h"
   #include "apr_strings.h"
  -#if APR_HAVE_UNISTD_H
  -#include <unistd.h>
  -#endif
  -#include <stdio.h>
  -#include <stdlib.h>
  -#include <string.h>
   
   /* hmmm, what is a truly portable define for the max path
    * length on a platform?
    */
   #define PATH_LEN 255
   
  -int main(void)
  +#if !APR_HAS_MMAP
  +static void not_implemented(CuTest *tc)
  +{
  +    CuNotImpl(tc, "User functions");
  +}
  +
  +#else
  +
  +apr_mmap_t *themmap = NULL;
  +apr_file_t *thefile = NULL;
  +char *file1;
  +apr_finfo_t finfo;
  +
  +static void create_filename(CuTest *tc)
  +{
  +    char *oldfileptr;
  +
  +    apr_filepath_get(&file1, 0, p);
  +    CuAssertTrue(tc, file1[0] == '/');
  +    CuAssertTrue(tc, file1[strlen(file1) - 1] != '/');
  +
  +    oldfileptr = file1;
  +    file1 = apr_pstrcat(p, file1,"/data/mmap_datafile.txt" ,NULL);
  +    CuAssertTrue(tc, oldfileptr != file1);
  +}
  +
  +static void test_file_open(CuTest *tc)
   {
  -#if APR_HAS_MMAP    
  -    apr_pool_t *context;
  -    apr_mmap_t *themmap = NULL;
  -    apr_file_t *thefile = NULL;
  -    apr_finfo_t finfo;
  -    apr_int32_t flag = APR_READ;
       apr_status_t rv;
  -    char *file1;
  -    char errmsg[120];
  -    
  -    fprintf (stdout,"APR MMAP Test\n*************\n\n");
  -    
  -    fprintf(stdout,"Initializing........................");
  -    if (apr_initialize() != APR_SUCCESS) {
  -        fprintf(stderr, "Failed.\n");
  -        exit(-1);
  -    }
  -    fprintf(stdout,"OK\n");
  -    atexit(apr_terminate);
  -
  -    fprintf(stdout,"Creating context....................");    
  -    if (apr_pool_create(&context, NULL) != APR_SUCCESS) {
  -        fprintf(stderr, "Failed.\n");
  -        exit(-1);
  -    }
  -    fprintf(stdout,"OK\n");
  -    
  -    apr_filepath_get(&file1, 0, context);
  -    file1 = apr_pstrcat(context,file1,"/testmmap",NULL);
  -
  -    fprintf(stdout, "Opening file........................");
  -    rv = apr_file_open(&thefile, file1, flag, APR_UREAD | APR_GREAD, context);
  -    if (rv != APR_SUCCESS) {
  -        fprintf(stderr,
  -                "couldn't open file `%s': %d/%s\n",
  -                file1, rv, apr_strerror(rv, errmsg, sizeof errmsg));
  -        exit(-1);
  -    }
  -    else {
  -        fprintf(stdout, "OK\n");
  -    }
  -    
  -    fprintf(stderr, "Getting file size...................");
  +
  +    rv = apr_file_open(&thefile, file1, APR_READ, APR_UREAD | APR_GREAD, p);
  +    CuAssertIntEquals(tc, rv, APR_SUCCESS);
  +    CuAssertPtrNotNull(tc, thefile);
  +}
  +   
  +static void test_get_filesize(CuTest *tc)
  +{
  +    apr_status_t rv;
  +
       rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile);
  -    if (rv != APR_SUCCESS) {
  -        fprintf(stderr,
  -                "Didn't get file information: %d/%s\n",
  -                rv, apr_strerror(rv, errmsg, sizeof errmsg));
  -        exit(-1);
  -    }
  -    else {
  -        fprintf(stdout, "%d bytes\n", (int)finfo.size);
  -    }  
  -    
  -    fprintf(stdout,"Trying to mmap the file.............");
  -    if (apr_mmap_create(&themmap, thefile, 0, finfo.size, APR_MMAP_READ, context) !=
APR_SUCCESS) {
  -        fprintf(stderr,"Failed!\n");
  -        exit(-1);
  -    }
  -    fprintf(stdout,"OK\n");
  -
  -    fprintf(stdout,"Trying to delete the mmap file......");
  -    if (apr_mmap_delete(themmap) != APR_SUCCESS) {
  -        fprintf(stderr,"Failed!\n");
  -        exit (-1);
  -    }
  -    fprintf(stdout,"OK\n");
  -    
  -    fprintf (stdout,"\nTest Complete\n");
  -
  -    return 0;
  -#else    
  -    fprintf(stdout,"APR MMAP Test\n*************\n\n");
  -    fprintf(stdout,"Failed!  APR was not built with MMAP.\n");
  -    return -1;
  +    CuAssertIntEquals(tc, rv, APR_SUCCESS);
  +    CuAssertIntEquals(tc, finfo.size, 28);
  +}
  +
  +static void test_mmap_create(CuTest *tc)
  +{
  +    apr_status_t rv;
  +
  +    rv = apr_mmap_create(&themmap, thefile, 0, finfo.size, APR_MMAP_READ, p);
  +    CuAssertPtrNotNull(tc, themmap);
  +    CuAssertIntEquals(tc, rv, APR_SUCCESS);
  +}
  +
  +static void test_mmap_contents(CuTest *tc)
  +{
  +    CuAssertPtrNotNull(tc, themmap->mm);
  +    CuAssertIntEquals(tc, themmap->size, 28);
  +    CuAssertStrEquals(tc, themmap->mm, "This is the MMAP data file.\n");
  +}
  +
  +static void test_mmap_delete(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    rv = apr_mmap_delete(themmap);
  +    CuAssertIntEquals(tc, rv, APR_SUCCESS);
  +}
  +
  +static void test_mmap_offset(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    void *addr;
  +
  +    rv = apr_mmap_offset(&addr, themmap, 5);
  +    CuAssertStrEquals(tc, addr, "This is the MMAP data file.\n" + 5);
  +}
   #endif
  +
  +CuSuite *testmmap(void)
  +{
  +    CuSuite *suite = CuSuiteNew("Test MMAP");
  +
  +#if APR_HAS_MMAP    
  +    SUITE_ADD_TEST(suite, create_filename);
  +    SUITE_ADD_TEST(suite, test_file_open);
  +    SUITE_ADD_TEST(suite, test_get_filesize);
  +    SUITE_ADD_TEST(suite, test_mmap_create);
  +    SUITE_ADD_TEST(suite, test_mmap_contents);
  +    SUITE_ADD_TEST(suite, test_mmap_offset);
  +    SUITE_ADD_TEST(suite, test_mmap_delete);
  +#else
  +    SUITE_ADD_TEST(suite, not_implemented);
  +#endif
  +
  +    return suite;
   }
  +
  +#ifdef SINGLE_PROG
  +CuSuite *getsuite(void)
  +{
  +    return testmmap();
  +}
  +#endif
  +
  
  
  

Mime
View raw message