1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/filefmt.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,115 @@
1.4 +# 2007 April 6
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library.
1.15 +#
1.16 +# This file implements tests to verify database file format.
1.17 +#
1.18 +# $Id: filefmt.test,v 1.2 2007/04/06 21:42:22 drh Exp $
1.19 +
1.20 +set testdir [file dirname $argv0]
1.21 +source $testdir/tester.tcl
1.22 +db close
1.23 +file delete -force test.db test.db-journal
1.24 +
1.25 +# Database begins with valid 16-byte header string.
1.26 +#
1.27 +do_test filefmt-1.1 {
1.28 + sqlite3 db test.db
1.29 + db eval {CREATE TABLE t1(x)}
1.30 + db close
1.31 + hexio_read test.db 0 16
1.32 +} {53514C69746520666F726D6174203300}
1.33 +
1.34 +# If the 16-byte header is changed, the file will not open
1.35 +#
1.36 +do_test filefmt-1.2 {
1.37 + hexio_write test.db 0 54
1.38 + set x [catch {sqlite3 db test.db} err]
1.39 + lappend x $err
1.40 +} {0 {}}
1.41 +do_test filefmt-1.3 {
1.42 + catchsql {
1.43 + SELECT count(*) FROM sqlite_master
1.44 + }
1.45 +} {1 {file is encrypted or is not a database}}
1.46 +do_test filefmt-1.4 {
1.47 + db close
1.48 + hexio_write test.db 0 53
1.49 + sqlite3 db test.db
1.50 + catchsql {
1.51 + SELECT count(*) FROM sqlite_master
1.52 + }
1.53 +} {0 1}
1.54 +
1.55 +# The page-size is stored at offset 16
1.56 +#
1.57 +ifcapable pager_pragmas {
1.58 + foreach pagesize {512 1024 2048 4096 8192 16384 32768} {
1.59 + if {[info exists SQLITE_MAX_PAGE_SIZE]
1.60 + && $pagesize>$SQLITE_MAX_PAGE_SIZE} continue
1.61 + do_test filefmt-1.5.$pagesize.1 {
1.62 + db close
1.63 + file delete -force test.db
1.64 + sqlite3 db test.db
1.65 + db eval "PRAGMA auto_vacuum=OFF"
1.66 + db eval "PRAGMA page_size=$pagesize"
1.67 + db eval {CREATE TABLE t1(x)}
1.68 + file size test.db
1.69 + } [expr $pagesize*2]
1.70 + do_test filefmt-1.5.$pagesize.2 {
1.71 + hexio_get_int [hexio_read test.db 16 2]
1.72 + } $pagesize
1.73 + }
1.74 +}
1.75 +
1.76 +# The page-size must be a power of 2
1.77 +#
1.78 +do_test filefmt-1.6 {
1.79 + db close
1.80 + hexio_write test.db 16 [hexio_render_int16 1025]
1.81 + sqlite3 db test.db
1.82 + catchsql {
1.83 + SELECT count(*) FROM sqlite_master
1.84 + }
1.85 +} {1 {file is encrypted or is not a database}}
1.86 +
1.87 +
1.88 +# The page-size must be at least 512 bytes
1.89 +#
1.90 +do_test filefmt-1.7 {
1.91 + db close
1.92 + hexio_write test.db 16 [hexio_render_int16 256]
1.93 + sqlite3 db test.db
1.94 + catchsql {
1.95 + SELECT count(*) FROM sqlite_master
1.96 + }
1.97 +} {1 {file is encrypted or is not a database}}
1.98 +
1.99 +# Usable space per page (page-size minus unused space per page)
1.100 +# must be at least 500 bytes
1.101 +#
1.102 +ifcapable pager_pragmas {
1.103 + do_test filefmt-1.8 {
1.104 + db close
1.105 + file delete -force test.db
1.106 + sqlite3 db test.db
1.107 + db eval {PRAGMA page_size=512; CREATE TABLE t1(x)}
1.108 + db close
1.109 + hexio_write test.db 20 10
1.110 + sqlite3 db test.db
1.111 + catchsql {
1.112 + SELECT count(*) FROM sqlite_master
1.113 + }
1.114 + } {1 {file is encrypted or is not a database}}
1.115 +}
1.116 +
1.117 +
1.118 +finish_test