Same fix as r45172 for classes/iconimage:
[AROS-Contrib.git] / sqlite3 / test / corrupt2.test
blob074dad7ac773f522f302aba4e59f7c795e676474
1 # 2004 August 30
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests to make sure SQLite does not crash or
14 # segfault if it sees a corrupt database file.
16 # $Id: corrupt2.test,v 1.2 2005/01/22 03:39:39 danielk1977 Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # The following tests - corrupt2-1.* - create some databases corrupted in
22 # specific ways and ensure that SQLite detects them as corrupt.
24 do_test corrupt2-1.1 {
25   execsql {
26     CREATE TABLE abc(a, b, c);
27   }
28 } {}
30 do_test corrupt2-1.2 {
32   # Corrupt the 16 byte magic string at the start of the file
33   file delete -force corrupt.db
34   file delete -force corrupt.db-journal
35   copy_file test.db corrupt.db
36   set f [open corrupt.db a]
37   seek $f 8 start
38   puts $f blah
39   close $f
41   sqlite3 db2 corrupt.db
42   catchsql {
43     SELECT * FROM sqlite_master;
44   } db2
45 } {1 {file is encrypted or is not a database}}
47 do_test corrupt2-1.3 {
48   db2 close
50   # Corrupt the page-size (bytes 16 and 17 of page 1).
51   file delete -force corrupt.db
52   file delete -force corrupt.db-journal
53   copy_file test.db corrupt.db
54   set f [open corrupt.db a]
55   fconfigure $f -encoding binary
56   seek $f 16 start
57   puts -nonewline $f "\x00\xFF"
58   close $f
60   sqlite3 db2 corrupt.db
61   catchsql {
62     SELECT * FROM sqlite_master;
63   } db2
64 } {1 {file is encrypted or is not a database}}
66 do_test corrupt2-1.4 {
67   db2 close
69   # Corrupt the free-block list on page 1.
70   file delete -force corrupt.db
71   file delete -force corrupt.db-journal
72   copy_file test.db corrupt.db
73   set f [open corrupt.db a]
74   fconfigure $f -encoding binary
75   seek $f 101 start
76   puts -nonewline $f "\xFF\xFF"
77   close $f
79   sqlite3 db2 corrupt.db
80   catchsql {
81     SELECT * FROM sqlite_master;
82   } db2
83 } {1 {database disk image is malformed}}
85 do_test corrupt2-1.5 {
86   db2 close
88   # Corrupt the free-block list on page 1.
89   file delete -force corrupt.db
90   file delete -force corrupt.db-journal
91   copy_file test.db corrupt.db
92   set f [open corrupt.db a]
93   fconfigure $f -encoding binary
94   seek $f 101 start
95   puts -nonewline $f "\x00\xC8"
96   seek $f 200 start
97   puts -nonewline $f "\x00\x00"
98   puts -nonewline $f "\x10\x00"
99   close $f
101   sqlite3 db2 corrupt.db
102   catchsql {
103     SELECT * FROM sqlite_master;
104   } db2
105 } {1 {database disk image is malformed}}
106 db2 close
108 finish_test