Debian Codegraph @

test/incrblobfault.test

raw
1 # 2010 October 26
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 #
13
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16
17 ifcapable !incrblob {
18 finish_test
19 return
20 }
21
22 set testprefix incrblobfault
23
24 do_execsql_test 1.0 {
25 CREATE TABLE blob(x INTEGER PRIMARY KEY, v BLOB);
26 INSERT INTO blob VALUES(1, 'hello world');
27 INSERT INTO blob VALUES(2, 'world hello');
28 INSERT INTO blob SELECT NULL, v FROM blob;
29 INSERT INTO blob SELECT NULL, v FROM blob;
30 INSERT INTO blob SELECT NULL, v FROM blob;
31 INSERT INTO blob SELECT NULL, v FROM blob;
32 INSERT INTO blob SELECT NULL, v FROM blob;
33 INSERT INTO blob SELECT NULL, v FROM blob;
34 INSERT INTO blob SELECT NULL, v FROM blob;
35 INSERT INTO blob SELECT NULL, v FROM blob;
36 INSERT INTO blob SELECT NULL, v FROM blob;
37 INSERT INTO blob SELECT NULL, v FROM blob;
38 }
39
40 do_faultsim_test 1 -prep {
41 sqlite3 db test.db
42 set ::blob [db incrblob blob v 1]
43 } -body {
44 if {[catch {sqlite3_blob_reopen $::blob 1000}]} {
45 error [sqlite3_errmsg db]
46 }
47 } -test {
48 faultsim_test_result {0 {}}
49 close $::blob
50 }
51
52 do_faultsim_test 2 -prep {
53 sqlite3 db test.db
54 set ::blob [db incrblob blob v 1]
55 } -body {
56 if {[catch {sqlite3_blob_reopen $::blob -1}]} {
57 error [sqlite3_errmsg db]
58 }
59 } -test {
60 faultsim_test_result {1 {no such rowid: -1}} {1 {disk I/O error}}
61 close $::blob
62 }
63
64 do_faultsim_test 3 -prep {
65 sqlite3 db test.db
66 } -body {
67 set ::blob [db incrblob blob v 1]
68 gets $::blob
69 } -test {
70 faultsim_test_result {0 {hello world}}
71 catch { close $::blob }
72 }
73
74 finish_test