apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: apr/test testfileinfo.c
Date Mon, 03 Feb 2003 23:51:56 GMT
brane       2003/02/03 15:51:56

  Modified:    test     testfileinfo.c
  Log:
  Added a new test to check the behaviour of apr_file_info_get in
  combination with buffered writes. At the moment, this test will
  probably fail on all plaforms.
  
  Revision  Changes    Path
  1.9       +33 -0     apr/test/testfileinfo.c
  
  Index: testfileinfo.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testfileinfo.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- testfileinfo.c	1 Jan 2003 00:01:56 -0000	1.8
  +++ testfileinfo.c	3 Feb 2003 23:51:56 -0000	1.9
  @@ -62,6 +62,8 @@
   #include "test_apr.h"
   
   #define FILENAME "data/file_datafile.txt"
  +#define NEWFILENAME "data/new_datafile.txt"
  +#define NEWFILEDATA "This is new text in a new file."
   
   static const struct view_fileinfo
   {
  @@ -207,6 +209,36 @@
       finfo_equal(tc, stat_finfo, finfo);
   }
   
  +static void test_buffered_write_size(CuTest *tc)
  +{
  +    const apr_size_t data_len = strlen(NEWFILEDATA);
  +    apr_file_t *thefile;
  +    apr_finfo_t finfo;
  +    apr_status_t rv;
  +    apr_size_t bytes;
  +
  +    rv = apr_file_open(&thefile, NEWFILENAME,
  +                       APR_READ | APR_WRITE | APR_CREATE | APR_EXCL
  +                       | APR_BUFFERED | APR_DELONCLOSE,
  +                       APR_OS_DEFAULT, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    /* A funny thing happened to me the other day: I wrote something
  +     * into a buffered file, then asked for its size using
  +     * apr_file_info_get; and guess what? The size was 0! That's not a
  +     * nice way to behave.
  +     */
  +    bytes = data_len;
  +    rv = apr_file_write(thefile, NEWFILEDATA, &bytes);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertTrue(tc, data_len == bytes);
  +
  +    rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, thefile);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertTrue(tc, bytes == (apr_size_t) finfo.size);
  +    apr_file_close(thefile);
  +}
  +
   CuSuite *testfileinfo(void)
   {
       CuSuite *suite = CuSuiteNew("File Info");
  @@ -214,6 +246,7 @@
       SUITE_ADD_TEST(suite, test_info_get);
       SUITE_ADD_TEST(suite, test_stat);
       SUITE_ADD_TEST(suite, test_stat_eq_finfo);
  +    SUITE_ADD_TEST(suite, test_buffered_write_size);
   
       return suite;
   }
  
  
  

Mime
View raw message