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 testfile.c
Date Sun, 15 Dec 2002 19:01:16 GMT
rbb         2002/12/15 11:01:16

  Modified:    test     testfile.c
  Log:
  We were leaking file descriptors from the testfile program.  That
  interfered with testpoll on some platforms.  All tests need to clean up
  after themselves.  testfile now finishes without any leaks.
  
  Revision  Changes    Path
  1.60      +81 -3     apr/test/testfile.c
  
  Index: testfile.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testfile.c,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- testfile.c	11 Dec 2002 20:38:01 -0000	1.59
  +++ testfile.c	15 Dec 2002 19:01:16 -0000	1.60
  @@ -68,7 +68,6 @@
   #define APR_BUFFERSIZE   4096 /* This should match APR's buffer size. */
   
   
  -static apr_file_t *filetest = NULL;
   
   static void test_open_noreadwrite(CuTest *tc)
   {
  @@ -87,6 +86,7 @@
        */
       CuAssertPtrEquals(tc, NULL, thefile); 
   #endif
  +    apr_file_close(thefile);
   }
   
   static void test_open_excl(CuTest *tc)
  @@ -106,17 +106,20 @@
        */
       CuAssertPtrEquals(tc, NULL, thefile); 
   #endif
  +    apr_file_close(thefile);
   }
   
   static void test_open_read(CuTest *tc)
   {
       apr_status_t rv;
  +    apr_file_t *filetest = NULL;
   
       rv = apr_file_open(&filetest, FILENAME, 
                          APR_READ, 
                          APR_UREAD | APR_UWRITE | APR_GREAD, p);
       CuAssertIntEquals(tc, rv, APR_SUCCESS);
       CuAssertPtrNotNull(tc, filetest);
  +    apr_file_close(filetest);
   }
   
   static void test_read(CuTest *tc)
  @@ -124,21 +127,35 @@
       apr_status_t rv;
       apr_size_t nbytes = 256;
       char *str = apr_pcalloc(p, nbytes + 1);
  +    apr_file_t *filetest = NULL;
       
  +    rv = apr_file_open(&filetest, FILENAME, 
  +                       APR_READ, 
  +                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
  +
       rv = apr_file_read(filetest, str, &nbytes);
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
       CuAssertIntEquals(tc, strlen(TESTSTR), nbytes);
       CuAssertStrEquals(tc, TESTSTR, str);
  +
  +    apr_file_close(filetest);
   }
   
   static void test_filename(CuTest *tc)
   {
       const char *str;
       apr_status_t rv;
  +    apr_file_t *filetest = NULL;
  +    
  +    rv = apr_file_open(&filetest, FILENAME, 
  +                       APR_READ, 
  +                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
   
       rv = apr_file_name_get(&str, filetest);
       CuAssertIntEquals(tc, rv, APR_SUCCESS);
       CuAssertStrEquals(tc, FILENAME, str);
  +
  +    apr_file_close(filetest);
   }
       
   static void test_fileclose(CuTest *tc)
  @@ -146,6 +163,12 @@
       char str;
       apr_status_t rv;
       apr_size_t one = 1;
  +    apr_file_t *filetest = NULL;
  +    
  +    rv = apr_file_open(&filetest, FILENAME, 
  +                       APR_READ, 
  +                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
  +
   
       rv = apr_file_close(filetest);
       CuAssertIntEquals(tc, rv, APR_SUCCESS);
  @@ -157,6 +180,7 @@
   static void test_file_remove(CuTest *tc)
   {
       apr_status_t rv;
  +    apr_file_t *filetest = NULL;
   
       rv = apr_file_remove(FILENAME, p);
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
  @@ -169,45 +193,60 @@
   static void test_open_write(CuTest *tc)
   {
       apr_status_t rv;
  +    apr_file_t *filetest = NULL;
   
       filetest = NULL;
       rv = apr_file_open(&filetest, FILENAME, 
                          APR_WRITE, 
                          APR_UREAD | APR_UWRITE | APR_GREAD, p);
       CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv));
  +    apr_file_close(filetest);
   }
   
   static void test_open_writecreate(CuTest *tc)
   {
       apr_status_t rv;
  +    apr_file_t *filetest = NULL;
   
       filetest = NULL;
       rv = apr_file_open(&filetest, FILENAME, 
                          APR_WRITE | APR_CREATE, 
                          APR_UREAD | APR_UWRITE | APR_GREAD, p);
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    apr_file_close(filetest);
   }
   
   static void test_write(CuTest *tc)
   {
       apr_status_t rv;
       apr_size_t bytes = strlen(TESTSTR);
  +    apr_file_t *filetest = NULL;
  +
  +    rv = apr_file_open(&filetest, FILENAME, 
  +                       APR_WRITE | APR_CREATE, 
  +                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
   
       rv = apr_file_write(filetest, TESTSTR, &bytes);
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    apr_file_close(filetest);
   }
   
   static void test_open_readwrite(CuTest *tc)
   {
       apr_status_t rv;
  +    apr_file_t *filetest = NULL;
   
  -    apr_file_close(filetest);
       filetest = NULL;
       rv = apr_file_open(&filetest, FILENAME, 
                          APR_READ | APR_WRITE, 
                          APR_UREAD | APR_UWRITE | APR_GREAD, p);
       CuAssertIntEquals(tc, rv, APR_SUCCESS);
       CuAssertPtrNotNull(tc, filetest);
  +
  +    apr_file_close(filetest);
   }
   
   static void test_seek(CuTest *tc)
  @@ -216,6 +255,18 @@
       apr_off_t offset = 5;
       apr_size_t nbytes = 256;
       char *str = apr_pcalloc(p, nbytes + 1);
  +    apr_file_t *filetest = NULL;
  +
  +    rv = apr_file_open(&filetest, FILENAME, 
  +                       APR_READ, 
  +                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
  +
  +    rv = apr_file_read(filetest, str, &nbytes);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertIntEquals(tc, strlen(TESTSTR), nbytes);
  +    CuAssertStrEquals(tc, TESTSTR, str);
  +
  +    memset(str, 0, nbytes + 1);
   
       rv = apr_file_seek(filetest, SEEK_SET, &offset);
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
  @@ -224,36 +275,63 @@
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
       CuAssertIntEquals(tc, strlen(TESTSTR) - 5, nbytes);
       CuAssertStrEquals(tc, TESTSTR + 5, str);
  -}                
   
  +    apr_file_close(filetest);
  +}                
   
   static void test_userdata_set(CuTest *tc)
   {
       apr_status_t rv;
  +    apr_file_t *filetest = NULL;
  +
  +    rv = apr_file_open(&filetest, FILENAME, 
  +                       APR_WRITE, 
  +                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
   
       rv = apr_file_data_set(filetest, "This is a test",
                              "test", apr_pool_cleanup_null);
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    apr_file_close(filetest);
   }
   
   static void test_userdata_get(CuTest *tc)
   {
       apr_status_t rv;
       char *teststr;
  +    apr_file_t *filetest = NULL;
  +
  +    rv = apr_file_open(&filetest, FILENAME, 
  +                       APR_WRITE, 
  +                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    rv = apr_file_data_set(filetest, "This is a test",
  +                           "test", apr_pool_cleanup_null);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
   
       rv = apr_file_data_get((void **)&teststr, "test", filetest);
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
       CuAssertStrEquals(tc, "This is a test", teststr);
  +
  +    apr_file_close(filetest);
   }
   
   static void test_userdata_getnokey(CuTest *tc)
   {
       apr_status_t rv;
       char *teststr;
  +    apr_file_t *filetest = NULL;
  +
  +    rv = apr_file_open(&filetest, FILENAME, 
  +                       APR_WRITE, 
  +                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
   
       rv = apr_file_data_get((void **)&teststr, "nokey", filetest);
       CuAssertIntEquals(tc, APR_SUCCESS, rv);
       CuAssertPtrEquals(tc, NULL, teststr);
  +    apr_file_close(filetest);
   }
   
   static void test_getc(CuTest *tc)
  
  
  

Mime
View raw message