xref: /sqlite-3.40.0/test/cffault.test (revision 6fa255fd)
1# 2011 November 16
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# This file contains fault-injection test cases for the
13# sqlite3_db_cacheflush API.
14#
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18set testprefix cacheflush
19source $testdir/malloc_common.tcl
20
21# Run the supplied SQL on a copy of the database currently stored on
22# disk in file $dbfile.
23proc diskquery {dbfile sql} {
24  forcecopy $dbfile dq.db
25  sqlite3 dq dq.db
26  set res [execsql $sql dq]
27  dq close
28  set res
29}
30
31do_execsql_test 1.0 {
32  CREATE TABLE t1(a PRIMARY KEY, b);
33  CREATE INDEX i1 ON t1(b);
34  INSERT INTO t1 VALUES(1, 2);
35  INSERT INTO t1 VALUES(3, 4);
36  INSERT INTO t1 VALUES(5, 6);
37  INSERT INTO t1 VALUES(7, 8);
38}
39faultsim_save_and_close
40
41do_faultsim_test 1 -prep {
42  faultsim_restore_and_reopen
43  db eval {
44    BEGIN;
45      UPDATE t1 SET b=b+1;
46  }
47} -body {
48  sqlite3_db_cacheflush db
49} -test {
50  faultsim_test_result {0 {}} {1 {disk I/O error}}
51  catch { db eval COMMIT }
52  faultsim_integrity_check
53}
54
55
56finish_test
57
58