blob: 86e52d91e30db6cd491d856387054b05a52f2471 [file] [log] [blame]
danielk197792d4d7a2007-05-04 12:05:56 +00001# 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#
danielk1977cdc3a6b2007-08-25 13:09:26 +000012# $Id: incrblob_err.test,v 1.4 2007/08/25 13:09:26 danielk1977 Exp $
danielk197792d4d7a2007-05-04 12:05:56 +000013#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
danielk197732a0d8b2007-05-04 19:03:02 +000018ifcapable {!incrblob} {
19 finish_test
20 return
21}
22
danielk19776338c762007-05-17 16:38:30 +000023# Only run these tests if memory debugging is turned on.
24#
danielk1977cdc3a6b2007-08-25 13:09:26 +000025if {[info command sqlite3_memdebug_fail]==""} {
danielk19776338c762007-05-17 16:38:30 +000026 puts "Skipping incrblob_err tests: not compiled with -DSQLITE_MEMDEBUG..."
27 finish_test
28 return
29}
30
danielk1977cdc3a6b2007-08-25 13:09:26 +000031source $testdir/malloc_common.tcl
danielk197792d4d7a2007-05-04 12:05:56 +000032
33set ::fd [open [info script]]
34set ::data [read $::fd]
35close $::fd
36
37do_malloc_test 1 -tclprep {
38 set bytes [file size [info script]]
39 execsql {
40 CREATE TABLE blobs(k, v BLOB);
41 INSERT INTO blobs VALUES(1, zeroblob($::bytes));
42 }
43} -tclbody {
44 set ::blob [db incrblob blobs v 1]
45 set rc [catch {puts -nonewline $::blob $::data}]
46 if {$rc} { error "out of memory" }
47}
48
49do_malloc_test 2 -tclprep {
50 execsql {
51 CREATE TABLE blobs(k, v BLOB);
52 INSERT INTO blobs VALUES(1, $::data);
53 }
54} -tclbody {
55 set ::blob [db incrblob blobs v 1]
56 set rc [catch {set ::r [read $::blob]}]
57 if {$rc} {
58 error "out of memory"
59 } elseif {$::r ne $::data} {
60 error "Bad data read..."
61 }
62}
63
64do_malloc_test 3 -tclprep {
65 execsql {
66 CREATE TABLE blobs(k, v BLOB);
67 INSERT INTO blobs VALUES(1, $::data);
68 }
69} -tclbody {
70 set ::blob [db incrblob blobs v 1]
71 set rc [catch {set ::r [read $::blob]}]
72 if {$rc} {
73 error "out of memory"
74 } elseif {$::r ne $::data} {
75 error "Bad data read..."
76 }
77 set rc [catch {close $::blob}]
78 if {$rc} {
79 error "out of memory"
80 }
81}
danielk1977cdc3a6b2007-08-25 13:09:26 +000082sqlite3_memdebug_fail -1 0
danielk197792d4d7a2007-05-04 12:05:56 +000083
84do_ioerr_test incrblob_err-4 -cksum 1 -sqlprep {
85 CREATE TABLE blobs(k, v BLOB);
86 INSERT INTO blobs VALUES(1, $::data);
87} -tclbody {
88 set ::blob [db incrblob blobs v 1]
89 read $::blob
90}
91
92do_ioerr_test incrblob_err-5 -cksum 1 -sqlprep {
93 CREATE TABLE blobs(k, v BLOB);
94 INSERT INTO blobs VALUES(1, zeroblob(length(CAST($::data AS BLOB))));
95} -tclbody {
96 set ::blob [db incrblob blobs v 1]
97 puts -nonewline $::blob $::data
98 close $::blob
99}
100
101do_ioerr_test incrblob_err-6 -cksum 1 -sqlprep {
102 CREATE TABLE blobs(k, v BLOB);
103 INSERT INTO blobs VALUES(1, $::data || $::data || $::data);
104} -tclbody {
105 set ::blob [db incrblob blobs v 1]
106 seek $::blob -20 end
107 puts -nonewline $::blob "12345678900987654321"
108 close $::blob
109}
110
111finish_test