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 testfileinfo.c Makefile.in test_apr.h testall.c
Date Fri, 22 Nov 2002 06:19:24 GMT
rbb         2002/11/21 22:19:24

  Modified:    test     Makefile.in test_apr.h testall.c
  Added:       test     testfileinfo.c
  Log:
  Add a new test, testfileinfo.  This came from the old testfile program,
  but I split it up to make the tests more managable.
  
  Revision  Changes    Path
  1.105     +2 -2      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.104
  retrieving revision 1.105
  diff -u -r1.104 -r1.105
  --- Makefile.in	15 Nov 2002 01:20:52 -0000	1.104
  +++ Makefile.in	22 Nov 2002 06:19:24 -0000	1.105
  @@ -161,8 +161,8 @@
   testmutexscope@EXEEXT@: testmutexscope.lo $(LOCAL_LIBS)
   	$(LINK) testmutexscope.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testall: testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo testmmap.lo testud.lo
testtable.lo testsleep.lo testpools.lo testfmt.lo testfile.lo testdir.lo CuTest.lo $(LOCAL_LIBS)
  -	$(LINK) testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo testmmap.lo testud.lo
testtable.lo testsleep.lo testpools.lo testfmt.lo testfile.lo testdir.lo CuTest.lo $(LOCAL_LIBS)
$(ALL_LIBS)
  +testall: testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo testmmap.lo testud.lo
testtable.lo testsleep.lo testpools.lo testfmt.lo testfile.lo testdir.lo testfileinfo.lo CuTest.lo
$(LOCAL_LIBS)
  +	$(LINK) testall.lo testtime.lo teststr.lo testvsn.lo testipsub.lo testmmap.lo testud.lo
testtable.lo testsleep.lo testpools.lo testfmt.lo testfile.lo testdir.lo testfileinfo.lo CuTest.lo
$(LOCAL_LIBS) $(ALL_LIBS)
   
   
   # DO NOT REMOVE
  
  
  
  1.21      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- test_apr.h	11 Nov 2002 04:54:45 -0000	1.20
  +++ test_apr.h	22 Nov 2002 06:19:24 -0000	1.21
  @@ -78,6 +78,7 @@
   CuSuite *testfmt(void);
   CuSuite *testfile(void);
   CuSuite *testdir(void);
  +CuSuite *testfileinfo(void);
   
   
   
  
  
  
  1.16      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- testall.c	14 Nov 2002 12:25:56 -0000	1.15
  +++ testall.c	22 Nov 2002 06:19:24 -0000	1.16
  @@ -77,6 +77,7 @@
       testfmt,
       testfile,
       testdir,
  +    testfileinfo,
       NULL
   };
   
  
  
  
  1.1                  apr/test/testfileinfo.c
  
  Index: testfileinfo.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "apr_file_io.h"
  #include "apr_file_info.h"
  #include "apr_strings.h"
  #include "apr_errno.h"
  #include "apr_general.h"
  #include "apr_poll.h"
  #include "apr_lib.h"
  #include "test_apr.h"
  
  #define FILENAME "data/file_datafile.txt"
  
  struct view_fileinfo
  {
      apr_int32_t bits;
      char *description;
  } vfi[] = {
      {APR_FINFO_MTIME,  "MTIME"},
      {APR_FINFO_CTIME,  "CTIME"},
      {APR_FINFO_ATIME,  "ATIME"},
      {APR_FINFO_SIZE,   "SIZE"},
      {APR_FINFO_DEV,    "DEV"},
      {APR_FINFO_INODE,  "INODE"},
      {APR_FINFO_NLINK,  "NLINK"},
      {APR_FINFO_TYPE,   "TYPE"},
      {APR_FINFO_USER,   "USER"}, 
      {APR_FINFO_GROUP,  "GROUP"}, 
      {APR_FINFO_UPROT,  "UPROT"}, 
      {APR_FINFO_GPROT,  "GPROT"},
      {APR_FINFO_WPROT,  "WPROT"},
      {0,                NULL}
  }; 
  
  int finfo_equal(apr_finfo_t f1, apr_finfo_t f2)
  {
      return (f1.valid == f2.valid &&
              f1.protection == f2.protection &&
              f1.filetype == f2.filetype &&
              f1.user == f2.user &&
              f1.group == f2.group &&
              f1.inode == f2.inode &&
              f1.device == f2.device &&
              f1.nlink == f2.nlink &&
              f1.size == f2.size &&
  /*  Can't check csize, we don't fill it out, which makes me wonder why it
   *  is still there.
   *          f1.csize == f2.csize &&
   */
              f1.atime == f2.atime &&
              f1.mtime == f2.mtime &&
              f1.ctime == f2.ctime &&
              !strcmp(f1.fname, f2.fname));
  /*  We also can't check name, because it is only ever set on Unix.  This 
   *  means that we have non-portable fields in a transparant structure.
              !strcmp(f1.name, f2.name));
   */
  }
  
  static void test_info_get(CuTest *tc)
  {
      apr_file_t *thefile;
      apr_finfo_t finfo;
      apr_status_t rv;
  
      rv = apr_file_open(&thefile, FILENAME, APR_READ, APR_OS_DEFAULT, p);
      CuAssertIntEquals(tc, APR_SUCCESS, rv);
  
      rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile);
      if (rv  == APR_INCOMPLETE) {
          char *str =  apr_palloc(p, 256);
  	int i;
          str = apr_pstrdup(p, "APR_INCOMPLETE:  Missing ");
          for (i = 0; vfi[i].bits; ++i) {
              if (vfi[i].bits & ~finfo.valid) {
                  str = apr_pstrcat(p, str, vfi[i].description);
              }
          }
          CuFail(tc, str);
      }
      CuAssertIntEquals(tc, APR_SUCCESS, rv);
      apr_file_close(thefile);
  }
  
  static void test_stat(CuTest *tc)
  {
      apr_file_t *thefile;
      apr_finfo_t finfo;
      apr_status_t rv;
  
      rv = apr_stat(&finfo, FILENAME, APR_FINFO_NORM, p);
      if (rv  == APR_INCOMPLETE) {
          char *str =  apr_palloc(p, 256);
  	int i;
          str = apr_pstrdup(p, "APR_INCOMPLETE:  Missing ");
          for (i = 0; vfi[i].bits; ++i) {
              if (vfi[i].bits & ~finfo.valid) {
                  str = apr_pstrcat(p, str, vfi[i].description);
              }
          }
          CuFail(tc, str);
      }
      CuAssertIntEquals(tc, APR_SUCCESS, rv);
      apr_file_close(thefile);
  }
  
  static void test_stat_eq_finfo(CuTest *tc)
  {
      apr_file_t *thefile;
      apr_finfo_t finfo;
      apr_finfo_t stat_finfo;
      apr_status_t rv;
  
      rv = apr_stat(&stat_finfo, FILENAME, APR_FINFO_NORM, p);
      CuAssertIntEquals(tc, APR_SUCCESS, rv);
  
      rv = apr_file_open(&thefile, FILENAME, APR_READ, APR_OS_DEFAULT, p);
      CuAssertIntEquals(tc, APR_SUCCESS, rv);
      rv = apr_file_info_get(&finfo, APR_FINFO_NORM, thefile);
      apr_file_close(thefile);
  
      CuAssert(tc, "results from apr_stat are not identical to results "
                   "from apr_finfo", finfo_equal(stat_finfo, finfo));
  }
  
  CuSuite *testfileinfo(void)
  {
      CuSuite *suite = CuSuiteNew("Test File Info");
  
      SUITE_ADD_TEST(suite, test_info_get);
      SUITE_ADD_TEST(suite, test_stat);
      SUITE_ADD_TEST(suite, test_stat_eq_finfo);
  
      return suite;
  }
  
  #ifdef SINGLE_PROG
  CuSuite *getsuite(void)
  {
      return testfileinfo();
  }
  #endif
  
  
  
  

Mime
View raw message