os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/diskfull.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/diskfull.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,115 @@
     1.4 +# 2001 October 12
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file implements regression tests for SQLite library.  The
    1.15 +# focus of this file is testing for correct handling of disk full
    1.16 +# errors.
    1.17 +# 
    1.18 +# $Id: diskfull.test,v 1.8 2008/07/12 14:52:20 drh Exp $
    1.19 +
    1.20 +set testdir [file dirname $argv0]
    1.21 +source $testdir/tester.tcl
    1.22 +
    1.23 +set sqlite_io_error_persist 0
    1.24 +set sqlite_io_error_hit 0
    1.25 +set sqlite_io_error_pending 0
    1.26 +do_test diskfull-1.1 {
    1.27 +  execsql {
    1.28 +    CREATE TABLE t1(x);
    1.29 +    INSERT INTO t1 VALUES(randstr(1000,1000));
    1.30 +    INSERT INTO t1 SELECT * FROM t1;
    1.31 +    INSERT INTO t1 SELECT * FROM t1;
    1.32 +    INSERT INTO t1 SELECT * FROM t1;
    1.33 +    INSERT INTO t1 SELECT * FROM t1;
    1.34 +    CREATE INDEX t1i1 ON t1(x);
    1.35 +    CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1;
    1.36 +    CREATE INDEX t2i1 ON t2(b);
    1.37 +  }
    1.38 +} {}
    1.39 +set sqlite_diskfull_pending 0
    1.40 +integrity_check diskfull-1.2
    1.41 +do_test diskfull-1.3 {
    1.42 +  set sqlite_diskfull_pending 1
    1.43 +  catchsql {
    1.44 +    INSERT INTO t1 SELECT * FROM t1;
    1.45 +  }
    1.46 +} {1 {database or disk is full}}
    1.47 +set sqlite_diskfull_pending 0
    1.48 +integrity_check diskfull-1.4
    1.49 +do_test diskfull-1.5 {
    1.50 +  set sqlite_diskfull_pending 1
    1.51 +  catchsql {
    1.52 +    DELETE FROM t1;
    1.53 +  }
    1.54 +} {1 {database or disk is full}}
    1.55 +set sqlite_diskfull_pending 0
    1.56 +set sqlite_io_error_hit 0
    1.57 +integrity_check diskfull-1.6
    1.58 +
    1.59 +proc do_diskfull_test {prefix sql} {
    1.60 +  set ::go 1
    1.61 +  set ::sql $sql
    1.62 +  set ::i 1
    1.63 +  while {$::go} {
    1.64 +    incr ::i
    1.65 +    do_test ${prefix}.$::i.1 {
    1.66 +      set ::sqlite_diskfull_pending $::i
    1.67 +      set ::sqlite_diskfull 0
    1.68 +      set r [catchsql $::sql]
    1.69 +      if {!$::sqlite_diskfull} {
    1.70 +        set r {1 {database or disk is full}}
    1.71 +        set ::go 0
    1.72 +      }
    1.73 +      if {$r=="1 {disk I/O error}"} {
    1.74 +        set r {1 {database or disk is full}}
    1.75 +      }
    1.76 +      set r
    1.77 +    } {1 {database or disk is full}}
    1.78 +    set ::sqlite_diskfull_pending 0
    1.79 +    db close
    1.80 +    sqlite3 db test.db
    1.81 +    integrity_check ${prefix}.$::i.2
    1.82 +  }
    1.83 +}
    1.84 +
    1.85 +do_diskfull_test diskfull-2 VACUUM
    1.86 +
    1.87 +# db close
    1.88 +# file delete -force test.db
    1.89 +# file delete -force test.db-journal
    1.90 +# sqlite3 db test.db
    1.91 +# 
    1.92 +# do_test diskfull-3.1 {
    1.93 +#   execsql {
    1.94 +#     PRAGMA default_cache_size = 10;
    1.95 +#     CREATE TABLE t3(a, b, UNIQUE(a, b));
    1.96 +#     INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
    1.97 +#     INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
    1.98 +#     INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
    1.99 +#     INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
   1.100 +#     INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
   1.101 +#     INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
   1.102 +#     INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
   1.103 +#     INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3;
   1.104 +#     UPDATE t3 
   1.105 +#     SET b = (SELECT a FROM t3 WHERE rowid = (SELECT max(rowid)-1 FROM t3))
   1.106 +#     WHERE rowid = (SELECT max(rowid) FROM t3);
   1.107 +#     PRAGMA cache_size;
   1.108 +#   }
   1.109 +# } {10}
   1.110 +# 
   1.111 +# do_diskfull_test diskfull-3.2 {
   1.112 +#   BEGIN;
   1.113 +#     INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) );
   1.114 +#     UPDATE t3 SET a = b;
   1.115 +#   COMMIT;
   1.116 +# }
   1.117 +
   1.118 +finish_test