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