1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
# 2007 April 6
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to verify database file format.
#
# $Id: filefmt.test,v 1.2 2007/04/06 21:42:22 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
db close
file delete -force test.db test.db-journal
# Database begins with valid 16-byte header string.
#
do_test filefmt-1.1 {
sqlite3 db test.db
db eval {CREATE TABLE t1(x)}
db close
hexio_read test.db 0 16
} {53514C69746520666F726D6174203300}
# If the 16-byte header is changed, the file will not open
#
do_test filefmt-1.2 {
hexio_write test.db 0 54
set x [catch {sqlite3 db test.db} err]
lappend x $err
} {0 {}}
do_test filefmt-1.3 {
catchsql {
SELECT count(*) FROM sqlite_master
}
} {1 {file is encrypted or is not a database}}
do_test filefmt-1.4 {
db close
hexio_write test.db 0 53
sqlite3 db test.db
catchsql {
SELECT count(*) FROM sqlite_master
}
} {0 1}
# The page-size is stored at offset 16
#
ifcapable pager_pragmas {
foreach pagesize {512 1024 2048 4096 8192 16384 32768} {
if {[info exists SQLITE_MAX_PAGE_SIZE]
&& $pagesize>$SQLITE_MAX_PAGE_SIZE} continue
do_test filefmt-1.5.$pagesize.1 {
db close
file delete -force test.db
sqlite3 db test.db
db eval "PRAGMA auto_vacuum=OFF"
db eval "PRAGMA page_size=$pagesize"
db eval {CREATE TABLE t1(x)}
file size test.db
} [expr $pagesize*2]
do_test filefmt-1.5.$pagesize.2 {
hexio_get_int [hexio_read test.db 16 2]
} $pagesize
}
}
# The page-size must be a power of 2
#
do_test filefmt-1.6 {
db close
hexio_write test.db 16 [hexio_render_int16 1025]
sqlite3 db test.db
catchsql {
SELECT count(*) FROM sqlite_master
}
} {1 {file is encrypted or is not a database}}
# The page-size must be at least 512 bytes
#
do_test filefmt-1.7 {
db close
hexio_write test.db 16 [hexio_render_int16 256]
sqlite3 db test.db
catchsql {
SELECT count(*) FROM sqlite_master
}
} {1 {file is encrypted or is not a database}}
# Usable space per page (page-size minus unused space per page)
# must be at least 500 bytes
#
ifcapable pager_pragmas {
do_test filefmt-1.8 {
db close
file delete -force test.db
sqlite3 db test.db
db eval {PRAGMA page_size=512; CREATE TABLE t1(x)}
db close
hexio_write test.db 20 10
sqlite3 db test.db
catchsql {
SELECT count(*) FROM sqlite_master
}
} {1 {file is encrypted or is not a database}}
}
finish_test
|