Annotation of embedaddon/sqlite3/test/incrblob_err.test, revision 1.1.1.1

1.1       misho       1: # 2007 May 1
                      2: #
                      3: # The author disclaims copyright to this source code.  In place of
                      4: # a legal notice, here is a blessing:
                      5: #
                      6: #    May you do good and not evil.
                      7: #    May you find forgiveness for yourself and forgive others.
                      8: #    May you share freely, never taking more than you give.
                      9: #
                     10: #***********************************************************************
                     11: #
                     12: # $Id: incrblob_err.test,v 1.14 2008/07/18 17:16:27 drh Exp $
                     13: #
                     14: 
                     15: set testdir [file dirname $argv0]
                     16: source $testdir/tester.tcl
                     17: 
                     18: ifcapable {!incrblob  || !memdebug || !tclvar} {
                     19:   finish_test
                     20:   return
                     21: }
                     22: 
                     23: source $testdir/malloc_common.tcl
                     24: 
                     25: unset -nocomplain ::fd ::data
                     26: set ::fd [open [info script]]
                     27: set ::data [read $::fd]
                     28: close $::fd
                     29: 
                     30: do_malloc_test 1 -tclprep {
                     31:   set bytes [file size [info script]]
                     32:   execsql {
                     33:     CREATE TABLE blobs(k, v BLOB);
                     34:     INSERT INTO blobs VALUES(1, zeroblob($::bytes));
                     35:   }
                     36: } -tclbody {
                     37:   set ::blob [db incrblob blobs v 1]
                     38:   fconfigure $::blob -translation binary
                     39:   set rc [catch {puts -nonewline $::blob $::data}]
                     40:   if {$rc} { error "out of memory" }
                     41: } 
                     42: 
                     43: do_malloc_test 2 -tclprep {
                     44:   execsql {
                     45:     CREATE TABLE blobs(k, v BLOB);
                     46:     INSERT INTO blobs VALUES(1, $::data);
                     47:   }
                     48: } -tclbody {
                     49:   set ::blob [db incrblob blobs v 1]
                     50:   set rc [catch {set ::r [read $::blob]}]
                     51:   if {$rc} { 
                     52:     error "out of memory" 
                     53:   } elseif {$::r ne $::data} {
                     54:     error "Bad data read..."
                     55:   }
                     56: }
                     57: 
                     58: do_malloc_test 3 -tclprep {
                     59:   execsql {
                     60:     CREATE TABLE blobs(k, v BLOB);
                     61:     INSERT INTO blobs VALUES(1, $::data);
                     62:   }
                     63: } -tclbody {
                     64:   set ::blob [db incrblob blobs v 1]
                     65:   set rc [catch {set ::r [read $::blob]}]
                     66:   if {$rc} { 
                     67:     error "out of memory" 
                     68:   } elseif {$::r ne $::data} {
                     69:     error "Bad data read..."
                     70:   }
                     71:   set rc [catch {close $::blob}]
                     72:   if {$rc} { 
                     73:     error "out of memory" 
                     74:   }
                     75: }
                     76: 
                     77: do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep {
                     78:   CREATE TABLE blobs(k, v BLOB);
                     79:   INSERT INTO blobs VALUES(1, $::data);
                     80: } -tclbody {
                     81:   set ::blob [db incrblob blobs v 1]
                     82:   read $::blob
                     83: }
                     84: 
                     85: do_ioerr_test incrblob_err-5 -cksum 1 -sqlprep {
                     86:   CREATE TABLE blobs(k, v BLOB);
                     87:   INSERT INTO blobs VALUES(1, zeroblob(length(CAST($::data AS BLOB))));
                     88: } -tclbody {
                     89:   set ::blob [db incrblob blobs v 1]
                     90:   fconfigure $::blob -translation binary
                     91:   puts -nonewline $::blob $::data
                     92:   close $::blob
                     93: }
                     94: 
                     95: do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep {
                     96:   CREATE TABLE blobs(k, v BLOB);
                     97:   INSERT INTO blobs VALUES(1, $::data || $::data || $::data);
                     98: } -tclbody {
                     99:   set ::blob [db incrblob blobs v 1]
                    100:   fconfigure $::blob -translation binary
                    101:   seek $::blob -20 end
                    102:   puts -nonewline $::blob "12345678900987654321"
                    103:   close $::blob
                    104: }
                    105: 
                    106: do_ioerr_test incrblob_err-7 -cksum 1 -sqlprep {
                    107:   PRAGMA auto_vacuum = 1;
                    108:   CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
                    109:   INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
                    110: } -tclbody {
                    111:   # Read some data from the end of the large blob inserted into table 
                    112:   # "blobs". This forces the IO error to occur while reading a pointer
                    113:   # map page for the purposes of seeking to the end of the blob.
                    114:   #
                    115:   sqlite3 db2 test.db
                    116:   set ::blob [db2 incrblob blobs v 1]
                    117:   sqlite3_blob_read $::blob [expr 500*1020-20] 20
                    118:   close $::blob
                    119: }
                    120: catch {db2 close}
                    121: 
                    122: do_ioerr_test incrblob_err-8 -cksum 1 -sqlprep {
                    123:   PRAGMA auto_vacuum = 1;
                    124:   CREATE TABLE blobs(k INTEGER PRIMARY KEY, v BLOB);
                    125:   INSERT INTO blobs VALUES(1, zeroblob(500 * 1020));
                    126: } -tclbody {
                    127:   # Read some data from the end of the large blob inserted into table 
                    128:   # "blobs". This forces the IO error to occur while reading a pointer
                    129:   # map page for the purposes of seeking to the end of the blob.
                    130:   #
                    131:   sqlite3 db2 test.db
                    132:   set ::blob [db2 incrblob blobs v 1]
                    133:   sqlite3_blob_write $::blob [expr 500*1020-20] 12345678900987654321
                    134:   close $::blob
                    135: }
                    136: 
                    137: catch {db2 close}
                    138: 
                    139: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>