/ Check-in [19fc3d78]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Extra test cases to improve coverage of main.c. (CVS 3755)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:19fc3d78962d225d42372b9298be5921ec1fc8a1
User & Date: danielk1977 2007-03-30 07:10:51
Context
2007-03-30
09:13
Test coverage a few extra lines in where.c. (CVS 3756) check-in: ea49ddf6 user: danielk1977 tags: trunk
07:10
Extra test cases to improve coverage of main.c. (CVS 3755) check-in: 19fc3d78 user: danielk1977 tags: trunk
2007-03-29
20:19
Assume any return code from fcntl() other than -1 is success. Formerly we only assumed that 0 was success. Ticket #2173. (CVS 3754) check-in: 8d0073c0 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.363 2007/03/29 15:00:53 danielk1977 Exp $
           17  +** $Id: main.c,v 1.364 2007/03/30 07:10:51 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** The following constant value is used by the SQLITE_BIGENDIAN and
................................................................................
   132    132     }
   133    133     assert( !sqlite3SafetyCheck(db) );
   134    134   
   135    135     /* FIX ME: db->magic may be set to SQLITE_MAGIC_CLOSED if the database
   136    136     ** cannot be opened for some reason. So this routine needs to run in
   137    137     ** that case. But maybe there should be an extra magic value for the
   138    138     ** "failed to open" state.
          139  +  **
          140  +  ** TODO: Coverage tests do not test the case where this condition is
          141  +  ** true. It's hard to see how to cause it without messing with threads.
   139    142     */
   140    143     if( db->magic!=SQLITE_MAGIC_CLOSED && sqlite3SafetyOn(db) ){
   141    144       /* printf("DID NOT CLOSE\n"); fflush(stdout); */
   142    145       return SQLITE_ERROR;
   143    146     }
   144    147   
   145    148     sqlite3VtabRollback(db);

Changes to test/malloc.test.

    10     10   #***********************************************************************
    11     11   # This file attempts to check the library in an out-of-memory situation.
    12     12   # When compiled with -DSQLITE_DEBUG=1, the SQLite library accepts a special
    13     13   # command (sqlite_malloc_fail N) which causes the N-th malloc to fail.  This
    14     14   # special feature is used to see what happens in the library if a malloc
    15     15   # were to really fail due to an out-of-memory situation.
    16     16   #
    17         -# $Id: malloc.test,v 1.39 2007/03/29 17:07:53 danielk1977 Exp $
           17  +# $Id: malloc.test,v 1.40 2007/03/30 07:10:52 danielk1977 Exp $
    18     18   
    19     19   set testdir [file dirname $argv0]
    20     20   source $testdir/tester.tcl
    21     21   
    22     22   # Only run these tests if memory debugging is turned on.
    23     23   #
    24     24   if {[info command sqlite_malloc_stat]==""} {
................................................................................
   542    542     }
   543    543   } -sqlbody {
   544    544     ATTACH DATABASE 'test2.db' AS t2;
   545    545     SELECT * FROM t1;
   546    546     DETACH DATABASE t2;
   547    547   } 
   548    548   
   549         -# Test malloc failure whilst installing a foriegn key.
          549  +# Test malloc failure whilst installing a foreign key.
   550    550   #
   551    551   do_malloc_test 21 -sqlbody {
   552    552     CREATE TABLE abc(a, b, c, FOREIGN KEY(a) REFERENCES abc(b))
   553    553   } 
   554         -
   555    554   
   556    555   # Ensure that no file descriptors were leaked.
   557    556   do_test malloc-99.X {
   558    557     catch {db close}
   559    558     set sqlite_open_file_count
   560    559   } {0}
   561    560   
   562    561   puts open-file-count=$sqlite_open_file_count
   563    562   sqlite_malloc_fail 0
   564    563   finish_test

Changes to test/misc7.test.

     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13         -# $Id: misc7.test,v 1.2 2007/03/29 17:07:53 danielk1977 Exp $
           13  +# $Id: misc7.test,v 1.3 2007/03/30 07:10:52 danielk1977 Exp $
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   
    18     18   do_test misc7-1 {
    19     19     c_misuse_test
    20     20   } {}
................................................................................
    64     64     }
    65     65     return $ret
    66     66   }
    67     67   
    68     68   execsql { CREATE TABLE abc(a PRIMARY KEY, b, c); }
    69     69   db close
    70     70   set fd_list [use_up_files]
    71         -
    72     71   set ::go 1
    73     72   set ::n 1
    74     73   while {$::go} {
    75     74     catch {db close}
    76     75     do_test misc7-6.$::n {
    77     76       set rc [catch {
    78     77         sqlite db test.db
................................................................................
    92     91     close [lindex $fd_list 0]
    93     92     set fd_list [lrange $fd_list 1 end]
    94     93     incr ::n
    95     94   }
    96     95   foreach fd $fd_list {
    97     96     close $fd
    98     97   }
           98  +db close
           99  +#
          100  +# End of tests for out-of-file-descriptors condition.
          101  +#--------------------------------------------------------------------
          102  +
          103  +#--------------------------------------------------------------------
          104  +# Test that the sqlite3_busy_timeout call seems to delay approximately
          105  +# the right amount of time.
          106  +#
          107  +do_test misc7-6 {
          108  +  sqlite3 db2 test.db
          109  +  sqlite3 db test.db
          110  +  sqlite3_busy_timeout [sqlite3_connection_pointer db] 2000
          111  +  execsql {
          112  +    BEGIN EXCLUSIVE;
          113  +  } db2
          114  +
          115  +  # Now db2 has an exclusive lock on the database file, and db has
          116  +  # a busy-timeout of 2000 milliseconds. So check that trying to
          117  +  # access the database using connection db delays for at least 1500 ms.
          118  +  #
          119  +  set c1 [clock clicks -milliseconds]
          120  +  catchsql {
          121  +    SELECT * FROM sqlite_master;
          122  +  } db
          123  +  expr {([clock clicks -milliseconds]-$c1) > 1500 ? 1 : 0}
          124  +} {1}
          125  +db2 close
          126  +
          127  +#--------------------------------------------------------------------
          128  +# Test that nothing goes horribly wrong when attaching a database
          129  +# after the omit_readlock pragma has been exercised.
          130  +#
          131  +do_test misc7-7 {
          132  +  file delete -force test2.db
          133  +  file delete -force test2.db-journal
          134  +  execsql {
          135  +    PRAGMA omit_readlock = 1;
          136  +    ATTACH 'test2.db' AS aux;
          137  +    CREATE TABLE aux.hello(world);
          138  +    SELECT name FROM aux.sqlite_master;
          139  +  }
          140  +} {hello}
          141  +
          142  +# Test malloc failure whilst installing a foriegn key.
          143  +#
          144  +ifcapable utf16 {
          145  +  do_test misc7-8 {
          146  +    encoding convertfrom unicode [sqlite3_errmsg16 0x00000000]
          147  +  } {out of memory}
          148  +}
          149  +
          150  +
    99    151   
   100    152   finish_test
   101    153