CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
corruptA.test84 linesDownload Raw Back to test
1# 2008 July 112#3# The author disclaims copyright to this source code.  In place of4# 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# This file implements regression tests for SQLite library.12#13# This file implements tests to make sure SQLite does not crash or14# segfault if it sees a corrupt database file.  It specifically focuses15# on corrupt database headers.16#17# $Id: corruptA.test,v 1.1 2008/07/11 16:39:23 drh Exp $18 19set testdir [file dirname $argv0]20source $testdir/tester.tcl21 22# Do not use a codec for tests in this file, as the database file is23# manipulated directly using tcl scripts (using the [hexio_write] command).24#25do_not_use_codec26 27# These tests deal with corrupt database files28#29database_may_be_corrupt30 31 32# Create a database to work with.33#34do_test corruptA-1.1 {35  execsql {36    CREATE TABLE t1(x);37    INSERT INTO t1(x) VALUES(1);38  }39  expr {[file size test.db]>=1024}40} {1}41integrity_check corruptA-1.242 43# Corrupt the file header in various ways and make sure the corruption44# is detected when opening the database file.45#46db close47forcecopy test.db test.db-template48 49set unreadable_version 0250ifcapable wal { set unreadable_version 03 }51do_test corruptA-2.1 {52  forcecopy test.db-template test.db53  hexio_write test.db 19 $unreadable_version   ;# the read format number54  sqlite3 db test.db55  catchsql {SELECT * FROM t1}  56} {1 {file is not a database}}57 58do_test corruptA-2.2 {59  db close60  forcecopy test.db-template test.db61  hexio_write test.db 21 41   ;# max embedded payload fraction62  sqlite3 db test.db63  catchsql {SELECT * FROM t1}  64} {1 {file is not a database}}65 66do_test corruptA-2.3 {67  db close68  forcecopy test.db-template test.db69  hexio_write test.db 22 1f   ;# min embedded payload fraction70  sqlite3 db test.db71  catchsql {SELECT * FROM t1}  72} {1 {file is not a database}}73 74do_test corruptA-2.4 {75  db close76  forcecopy test.db-template test.db77  hexio_write test.db 23 21   ;# min leaf payload fraction78  sqlite3 db test.db79  catchsql {SELECT * FROM t1}  80} {1 {file is not a database}}81 82 83finish_test84