sl@0: # 2007 April 6 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests to verify database file format. sl@0: # sl@0: # $Id: filefmt.test,v 1.2 2007/04/06 21:42:22 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: db close sl@0: file delete -force test.db test.db-journal sl@0: sl@0: # Database begins with valid 16-byte header string. sl@0: # sl@0: do_test filefmt-1.1 { sl@0: sqlite3 db test.db sl@0: db eval {CREATE TABLE t1(x)} sl@0: db close sl@0: hexio_read test.db 0 16 sl@0: } {53514C69746520666F726D6174203300} sl@0: sl@0: # If the 16-byte header is changed, the file will not open sl@0: # sl@0: do_test filefmt-1.2 { sl@0: hexio_write test.db 0 54 sl@0: set x [catch {sqlite3 db test.db} err] sl@0: lappend x $err sl@0: } {0 {}} sl@0: do_test filefmt-1.3 { sl@0: catchsql { sl@0: SELECT count(*) FROM sqlite_master sl@0: } sl@0: } {1 {file is encrypted or is not a database}} sl@0: do_test filefmt-1.4 { sl@0: db close sl@0: hexio_write test.db 0 53 sl@0: sqlite3 db test.db sl@0: catchsql { sl@0: SELECT count(*) FROM sqlite_master sl@0: } sl@0: } {0 1} sl@0: sl@0: # The page-size is stored at offset 16 sl@0: # sl@0: ifcapable pager_pragmas { sl@0: foreach pagesize {512 1024 2048 4096 8192 16384 32768} { sl@0: if {[info exists SQLITE_MAX_PAGE_SIZE] sl@0: && $pagesize>$SQLITE_MAX_PAGE_SIZE} continue sl@0: do_test filefmt-1.5.$pagesize.1 { sl@0: db close sl@0: file delete -force test.db sl@0: sqlite3 db test.db sl@0: db eval "PRAGMA auto_vacuum=OFF" sl@0: db eval "PRAGMA page_size=$pagesize" sl@0: db eval {CREATE TABLE t1(x)} sl@0: file size test.db sl@0: } [expr $pagesize*2] sl@0: do_test filefmt-1.5.$pagesize.2 { sl@0: hexio_get_int [hexio_read test.db 16 2] sl@0: } $pagesize sl@0: } sl@0: } sl@0: sl@0: # The page-size must be a power of 2 sl@0: # sl@0: do_test filefmt-1.6 { sl@0: db close sl@0: hexio_write test.db 16 [hexio_render_int16 1025] sl@0: sqlite3 db test.db sl@0: catchsql { sl@0: SELECT count(*) FROM sqlite_master sl@0: } sl@0: } {1 {file is encrypted or is not a database}} sl@0: sl@0: sl@0: # The page-size must be at least 512 bytes sl@0: # sl@0: do_test filefmt-1.7 { sl@0: db close sl@0: hexio_write test.db 16 [hexio_render_int16 256] sl@0: sqlite3 db test.db sl@0: catchsql { sl@0: SELECT count(*) FROM sqlite_master sl@0: } sl@0: } {1 {file is encrypted or is not a database}} sl@0: sl@0: # Usable space per page (page-size minus unused space per page) sl@0: # must be at least 500 bytes sl@0: # sl@0: ifcapable pager_pragmas { sl@0: do_test filefmt-1.8 { sl@0: db close sl@0: file delete -force test.db sl@0: sqlite3 db test.db sl@0: db eval {PRAGMA page_size=512; CREATE TABLE t1(x)} sl@0: db close sl@0: hexio_write test.db 20 10 sl@0: sqlite3 db test.db sl@0: catchsql { sl@0: SELECT count(*) FROM sqlite_master sl@0: } sl@0: } {1 {file is encrypted or is not a database}} sl@0: } sl@0: sl@0: sl@0: finish_test