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 testfilecopy.c Makefile.in Makefile.win test_apr.h testall.c
Date Thu, 18 Mar 2004 03:30:58 GMT
rbb         2004/03/17 19:30:58

  Modified:    test     Makefile.in Makefile.win test_apr.h testall.c
  Added:       test     testfilecopy.c
  Log:
  Add an initial test for the file_copy APIs.
  
  Revision  Changes    Path
  1.155     +1 -1      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.154
  retrieving revision 1.155
  diff -u -r1.154 -r1.155
  --- Makefile.in	16 Mar 2004 21:26:54 -0000	1.154
  +++ Makefile.in	18 Mar 2004 03:30:58 -0000	1.155
  @@ -102,7 +102,7 @@
   	testhash.lo testargs.lo testnames.lo testuser.lo testpath.lo \
   	testenv.lo testprocmutex.lo testrand2.lo testfnmatch.lo \
           testatomic.lo testflock.lo testshm.lo testsock.lo testglobalmutex.lo \
  -        teststrnatcmp.lo
  +        teststrnatcmp.lo testfilecopy.lo
   
   testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
   	 readchild@EXEEXT@ CuTest.lo proc_child@EXEEXT@ \
  
  
  
  1.19      +1 -1      apr/test/Makefile.win
  
  Index: Makefile.win
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.win,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- Makefile.win	16 Mar 2004 21:26:54 -0000	1.18
  +++ Makefile.win	18 Mar 2004 03:30:58 -0000	1.19
  @@ -86,7 +86,7 @@
   	testhash.obj testargs.obj testnames.obj testuser.obj testpath.obj \
   	testenv.obj testprocmutex.obj testrand2.obj testfnmatch.obj \
           testatomic.obj testflock.obj testshm.obj testsock.obj \
  -        testglobalmutex.obj teststrnatcmp.obj
  +        testglobalmutex.obj teststrnatcmp.obj testfilecopy.obj
   
   testall.exe: $(TESTS) CuTest.obj $(LOCAL_LIBS)
   	$(LINK) /debug /subsystem:console /machine:I386 $(TESTS) CuTest.obj \
  
  
  
  1.54      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- test_apr.h	16 Mar 2004 21:26:54 -0000	1.53
  +++ test_apr.h	18 Mar 2004 03:30:58 -0000	1.54
  @@ -42,6 +42,7 @@
   CuSuite *testdup(void);
   CuSuite *testenv(void);
   CuSuite *testfile(void);
  +CuSuite *testfilecopy(void);
   CuSuite *testfileinfo(void);
   CuSuite *testflock(void);
   CuSuite *testfmt(void);
  
  
  
  1.58      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.57
  retrieving revision 1.58
  diff -u -r1.57 -r1.58
  --- testall.c	16 Mar 2004 21:26:54 -0000	1.57
  +++ testall.c	18 Mar 2004 03:30:58 -0000	1.58
  @@ -46,6 +46,7 @@
       {"testdup", testdup},
       {"testenv", testenv},
       {"testfile", testfile},
  +    {"testfilecopy", testfilecopy},
       {"testfileinfo", testfileinfo},
       {"testflock", testflock},
       {"testfmt", testfmt},
  
  
  
  1.1                  apr/test/testfilecopy.c
  
  Index: testfilecopy.c
  ===================================================================
  /* Copyright 2000-2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  #include "test_apr.h"
  #include "apr_file_io.h"
  #include "apr_file_info.h"
  #include "apr_errno.h"
  #include "apr_pools.h"
  
  static void copy_helper(CuTest *tc, const char *from, const char * to,
                          apr_fileperms_t perms, int append, apr_pool_t *p)
  {
      apr_status_t rv;
      apr_status_t dest_rv;
      apr_finfo_t copy;
      apr_finfo_t orig;
      apr_finfo_t dest;
      
      dest_rv = apr_stat(&dest, to, APR_FINFO_SIZE, p);
      
      if (!append) {
          rv = apr_file_copy(from, to, perms, p);
      }
      else {
          rv = apr_file_append(from, to, perms, p);
      }
      apr_assert_success(tc, "Error copying file", rv);
  
      rv = apr_stat(&orig, from, APR_FINFO_SIZE, p);
      apr_assert_success(tc, "Couldn't stat original file", rv);
  
      rv = apr_stat(&copy, to, APR_FINFO_SIZE, p);
      apr_assert_success(tc, "Couldn't stat copy file", rv);
  
      if (!append) {
          CuAssertIntEquals(tc, orig.size, copy.size);
      }
      else {
          CuAssertIntEquals(tc, 
                            ((dest_rv == APR_SUCCESS) ? dest.size : 0) + orig.size,
                            copy.size);
      }
  }
  
  static void copy_short_file(CuTest *tc)
  {
      apr_status_t rv;
  
      /* make absolutely sure that the dest file doesn't exist. */
      apr_file_remove("data/file_copy.txt", p);
      
      copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
                  APR_FILE_SOURCE_PERMS, 0, p);
      rv = apr_file_remove("data/file_copy.txt", p);
      apr_assert_success(tc, "Couldn't remove copy file", rv);
  }
  
  static void copy_over_existing(CuTest *tc)
  {
      apr_status_t rv;
      
      /* make absolutely sure that the dest file doesn't exist. */
      apr_file_remove("data/file_copy.txt", p);
      
      /* This is a cheat.  I don't want to create a new file, so I just copy
       * one file, then I copy another.  If the second copy succeeds, then
       * this works.
       */
      copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
                  APR_FILE_SOURCE_PERMS, 0, p);
      
      copy_helper(tc, "data/mmap_datafile.txt", "data/file_copy.txt", 
                  APR_FILE_SOURCE_PERMS, 0, p);
    
      rv = apr_file_remove("data/file_copy.txt", p);
      apr_assert_success(tc, "Couldn't remove copy file", rv);
  }
  
  static void append_nonexist(CuTest *tc)
  {
      apr_status_t rv;
  
      /* make absolutely sure that the dest file doesn't exist. */
      apr_file_remove("data/file_copy.txt", p);
  
      copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
                  APR_FILE_SOURCE_PERMS, 0, p);
      rv = apr_file_remove("data/file_copy.txt", p);
      apr_assert_success(tc, "Couldn't remove copy file", rv);
  }
  
  static void append_exist(CuTest *tc)
  {
      apr_status_t rv;
      
      /* make absolutely sure that the dest file doesn't exist. */
      apr_file_remove("data/file_copy.txt", p);
      
      /* This is a cheat.  I don't want to create a new file, so I just copy
       * one file, then I copy another.  If the second copy succeeds, then
       * this works.
       */
      copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
                  APR_FILE_SOURCE_PERMS, 0, p);
      
      copy_helper(tc, "data/mmap_datafile.txt", "data/file_copy.txt", 
                  APR_FILE_SOURCE_PERMS, 1, p);
    
      rv = apr_file_remove("data/file_copy.txt", p);
      apr_assert_success(tc, "Couldn't remove copy file", rv);
  }
  
  CuSuite *testfilecopy(void)
  {
      CuSuite *suite = CuSuiteNew("File Copy");
  
      SUITE_ADD_TEST(suite, copy_short_file);
      SUITE_ADD_TEST(suite, copy_over_existing);
  
      SUITE_ADD_TEST(suite, append_nonexist);
      SUITE_ADD_TEST(suite, append_exist);
  
      return suite;
  }
  
  
  
  

Mime
View raw message