Fix a case where a corrupt stat4 record could go unrecognized due to integer overflow.
[sqlite.git] / test / fts4growth2.test
blobbcccf89c87a53f63431450659bbfa0727eedf272
1 # 2014 May 12
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #*************************************************************************
11 # This file implements regression tests for SQLite library.  The
12 # focus of this script is testing the FTS4 module.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix fts4growth2
20 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
21 ifcapable !fts3 {
22   finish_test
23   return
26 source $testdir/genesis.tcl
28 do_execsql_test 1.0 { CREATE TABLE t1(docid, words); }
29 fts_kjv_genesis 
31 proc structure {} {
32   puts [ db eval {SELECT level, count(*) FROM x1_segdir GROUP BY level} ]
35 proc tt {val} {
36   execsql {
37     DELETE FROM x1 
38       WHERE docid IN (SELECT docid FROM t1 WHERE (rowid-1)%4==$val+0);
39   }
40   execsql {
41     INSERT INTO x1(docid, content) 
42       SELECT docid, words FROM t1 WHERE (rowid%4)==$val+0;
43   }
46 do_execsql_test 1.1 {
47   CREATE VIRTUAL TABLE x1 USING fts4;
48   INSERT INTO x1(x1) VALUES('automerge=2');
51 do_test 1.2 {
52   for {set i 0} {$i < 40} {incr i} {
53     tt 0 ; tt 1 ; tt 2 ; tt 3
54   }
55   execsql { 
56     SELECT max(level) FROM x1_segdir; 
57     SELECT count(*) FROM x1_segdir WHERE level=2;
58   }
59 } {2 1}
61 do_test 1.3 {
62   for {set i 0} {$i < 40} {incr i} {
63     tt 0 ; tt 1 ; tt 2 ; tt 3
64   }
65   execsql { 
66     SELECT max(level) FROM x1_segdir; 
67     SELECT count(*) FROM x1_segdir WHERE level=2;
68   }
69 } {2 1}
71 #-------------------------------------------------------------------------
73 do_execsql_test 2.1 {
74   DELETE FROM t1 WHERE rowid>16;
75   DROP TABLE IF EXISTS x1;
76   CREATE VIRTUAL TABLE x1 USING fts4;
79 db func second second
80 proc second {L} {lindex $L 1}
82 for {set tn 0} {$tn < 40} {incr tn} {
83   do_test 2.2.$tn {
84     for {set i 0} {$i < 100} {incr i} {
85       tt 0 ; tt 1 ; tt 2 ; tt 3
86     }
87     execsql { SELECT max(level) FROM x1_segdir }
88   } {1}
92 finish_test