OLD | NEW |
1 # 2008 July 11 | 1 # 2008 July 11 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
11 # This file implements regression tests for SQLite library. | 11 # This file implements regression tests for SQLite library. |
12 # | 12 # |
13 # This file implements tests to make sure SQLite does not crash or | 13 # This file implements tests to make sure SQLite does not crash or |
14 # segfault if it sees a corrupt database file. It specifically focuses | 14 # segfault if it sees a corrupt database file. It specifically focuses |
15 # on corrupt database headers. | 15 # on corrupt database headers. |
16 # | 16 # |
17 # $Id: corruptA.test,v 1.1 2008/07/11 16:39:23 drh Exp $ | 17 # $Id: corruptA.test,v 1.1 2008/07/11 16:39:23 drh Exp $ |
18 | 18 |
19 set testdir [file dirname $argv0] | 19 set testdir [file dirname $argv0] |
20 source $testdir/tester.tcl | 20 source $testdir/tester.tcl |
21 | 21 |
| 22 # Do not use a codec for tests in this file, as the database file is |
| 23 # manipulated directly using tcl scripts (using the [hexio_write] command). |
| 24 # |
| 25 do_not_use_codec |
| 26 |
22 | 27 |
23 # Create a database to work with. | 28 # Create a database to work with. |
24 # | 29 # |
25 do_test corruptA-1.1 { | 30 do_test corruptA-1.1 { |
26 execsql { | 31 execsql { |
27 CREATE TABLE t1(x); | 32 CREATE TABLE t1(x); |
28 INSERT INTO t1(x) VALUES(1); | 33 INSERT INTO t1(x) VALUES(1); |
29 } | 34 } |
30 expr {[file size test.db]>=1024} | 35 expr {[file size test.db]>=1024} |
31 } {1} | 36 } {1} |
32 integrity_check corruptA-1.2 | 37 integrity_check corruptA-1.2 |
33 | 38 |
34 # Corrupt the file header in various ways and make sure the corruption | 39 # Corrupt the file header in various ways and make sure the corruption |
35 # is detected when opening the database file. | 40 # is detected when opening the database file. |
36 # | 41 # |
37 db close | 42 db close |
38 file copy -force test.db test.db-template | 43 file copy -force test.db test.db-template |
39 | 44 |
| 45 set unreadable_version 02 |
| 46 ifcapable wal { set unreadable_version 03 } |
40 do_test corruptA-2.1 { | 47 do_test corruptA-2.1 { |
41 file copy -force test.db-template test.db | 48 file copy -force test.db-template test.db |
42 hexio_write test.db 19 02 ;# the read format number | 49 hexio_write test.db 19 $unreadable_version ;# the read format number |
43 sqlite3 db test.db | 50 sqlite3 db test.db |
44 catchsql {SELECT * FROM t1} | 51 catchsql {SELECT * FROM t1} |
45 } {1 {file is encrypted or is not a database}} | 52 } {1 {file is encrypted or is not a database}} |
46 | 53 |
47 do_test corruptA-2.2 { | 54 do_test corruptA-2.2 { |
48 db close | 55 db close |
49 file copy -force test.db-template test.db | 56 file copy -force test.db-template test.db |
50 hexio_write test.db 21 41 ;# max embedded payload fraction | 57 hexio_write test.db 21 41 ;# max embedded payload fraction |
51 sqlite3 db test.db | 58 sqlite3 db test.db |
52 catchsql {SELECT * FROM t1} | 59 catchsql {SELECT * FROM t1} |
(...skipping 10 matching lines...) Expand all Loading... |
63 do_test corruptA-2.4 { | 70 do_test corruptA-2.4 { |
64 db close | 71 db close |
65 file copy -force test.db-template test.db | 72 file copy -force test.db-template test.db |
66 hexio_write test.db 23 21 ;# min leaf payload fraction | 73 hexio_write test.db 23 21 ;# min leaf payload fraction |
67 sqlite3 db test.db | 74 sqlite3 db test.db |
68 catchsql {SELECT * FROM t1} | 75 catchsql {SELECT * FROM t1} |
69 } {1 {file is encrypted or is not a database}} | 76 } {1 {file is encrypted or is not a database}} |
70 | 77 |
71 | 78 |
72 finish_test | 79 finish_test |
OLD | NEW |