update tags for podspec
[sqlcipher.git] / ext / repair / test / checkfreelist01.test
blob7e2dd51c3730e399cc923bf37a1ab61ee8e7d181
1 # 2017-10-11
3 set testprefix checkfreelist
5 do_execsql_test 1.0 {
6   PRAGMA page_size=1024;
7   CREATE TABLE t1(a, b);
10 do_execsql_test 1.2 { SELECT checkfreelist('main') } {ok}
11 do_execsql_test 1.3 {
12   WITH s(i) AS (
13     SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10000
14   )
15   INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM s;
16   DELETE FROM t1 WHERE rowid%3;
17   PRAGMA freelist_count;
18 } {6726}
20 do_execsql_test 1.4 { SELECT checkfreelist('main') } {ok}
21 do_execsql_test 1.5 {
22   WITH freelist_trunk(i, d, n) AS (
23     SELECT 1, NULL, sqlite_readint32(data, 32) FROM sqlite_dbpage WHERE pgno=1
24       UNION ALL
25     SELECT n, data, sqlite_readint32(data) 
26     FROM freelist_trunk, sqlite_dbpage WHERE pgno=n
27   )
28   SELECT i FROM freelist_trunk WHERE i!=1;
29 } {
30   10009 9715 9343 8969 8595 8222 7847 7474 7102 6727 6354 5982 5608 5234
31   4860 4487 4112 3740 3367 2992 2619 2247 1872 1499 1125 752 377 5
34 do_execsql_test 1.6 { SELECT checkfreelist('main') } {ok}
36 proc set_int {blob idx newval} {
37   binary scan $blob I* ints
38   lset ints $idx $newval
39   binary format I* $ints
41 db func set_int set_int
43 proc get_int {blob idx} {
44   binary scan $blob I* ints
45   lindex $ints $idx
47 db func get_int get_int
49 do_execsql_test 1.7 {
50   BEGIN;
51     UPDATE sqlite_dbpage 
52       SET data = set_int(data, 1, get_int(data, 1)-1) 
53       WHERE pgno=4860;
54     SELECT checkfreelist('main');
55   ROLLBACK;
56 } {{free-list count mismatch: actual=6725 header=6726}}
58 do_execsql_test 1.8 {
59   BEGIN;
60     UPDATE sqlite_dbpage 
61       SET data = set_int(data, 5, (SELECT * FROM pragma_page_count)+1)
62       WHERE pgno=4860;
63     SELECT checkfreelist('main');
64   ROLLBACK;
65 } {{leaf page 10092 is out of range (child 3 of trunk page 4860)}}
67 do_execsql_test 1.9 {
68   BEGIN;
69     UPDATE sqlite_dbpage 
70       SET data = set_int(data, 5, 0)
71       WHERE pgno=4860;
72     SELECT checkfreelist('main');
73   ROLLBACK;
74 } {{leaf page 0 is out of range (child 3 of trunk page 4860)}}
76 do_execsql_test 1.10 {
77   BEGIN;
78     UPDATE sqlite_dbpage 
79       SET data = set_int(data, get_int(data, 1)+1, 0)
80       WHERE pgno=5;
81     SELECT checkfreelist('main');
82   ROLLBACK;
83 } {{leaf page 0 is out of range (child 247 of trunk page 5)}}
85 do_execsql_test 1.11 {
86   BEGIN;
87     UPDATE sqlite_dbpage 
88       SET data = set_int(data, 1, 249)
89       WHERE pgno=5;
90     SELECT checkfreelist('main');
91   ROLLBACK;
92 } {{leaf count out of range (249) on trunk page 5}}