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