SQLite

Check-in [b914ece0d1]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add further fts5 tests. 100% code coverage is finally restored.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b914ece0d146cfc8adba4dc4e8633e14f174d6ea
User & Date: dan 2016-01-19 16:06:23.776
Context
2016-01-19
17:54
Fix two harmless compiler warnings about comparisons of dangling pointers. (check-in: 86944f193f user: drh tags: trunk)
16:06
Add further fts5 tests. 100% code coverage is finally restored. (check-in: b914ece0d1 user: dan tags: trunk)
2016-01-18
17:48
Add tests for fts5. Fix a crash that can occur in fts5 if the database content is corrupted. (check-in: acaf426449 user: dan tags: trunk)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to ext/fts5/test/fts5_common.tcl.
10
11
12
13
14
15
16





17
18
19
20
21
22
23
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28







+
+
+
+
+







#***********************************************************************
#

if {![info exists testdir]} {
  set testdir [file join [file dirname [info script]] .. .. .. test]
}
source $testdir/tester.tcl

ifcapable !fts5 {
  finish_test
  return
}

catch { 
  sqlite3_fts5_may_be_corrupt 0 
  reset_db
}

# If SQLITE_ENABLE_FTS5 is not defined, skip this test.
Added ext/fts5/test/fts5bigtok.test.



































































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
# 2016 Jan 19
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is testing the FTS5 module.
#

source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5bigtok

proc rndterm {} {
  set L [list a b c d e f g h i j k l m n o p q r s t u v w x y z]
  set l [lindex $L [expr int(rand() * [llength $L])]]
  string repeat $l [expr int(rand() * 5) + 60]
}

proc rnddoc {n} {
  set res [list]
  for {set i 0} {$i < $n} {incr i} {
    lappend res [rndterm]
  }
  set res
}

foreach_detail_mode $::testprefix {
  db func rnddoc rnddoc
  do_execsql_test 1.0 {
    CREATE VIRTUAL TABLE t1 USING fts5(x, detail=%DETAIL%);
    INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
    CREATE VIRTUAL TABLE t1vocab USING fts5vocab(t1, row);

    WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10 )
    INSERT INTO t1 SELECT rnddoc(3) FROM s;

    WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10 )
    INSERT INTO t1 SELECT rnddoc(3) FROM s;
  }

  foreach v [db eval {SELECT term FROM t1vocab}] {
    set res [db eval {SELECT rowid FROM t1($v)}]
    do_execsql_test 1.[string range $v 0 0] {
      SELECT rowid FROM t1($v) ORDER BY rowid DESC
    } [lsort -integer -decr $res]
  }

  do_execsql_test 2.0 {
    INSERT INTO t1(t1) VALUES('optimize');
  }

  foreach v [db eval {SELECT term FROM t1vocab}] {
    set res [db eval {SELECT rowid FROM t1($v)}]
    do_execsql_test 2.[string range $v 0 0] {
      SELECT rowid FROM t1($v) ORDER BY rowid DESC
    } [lsort -integer -decr $res]
  }
}

finish_test


Changes to ext/fts5/test/fts5integrity.test.
141
142
143
144
145
146
147
148
149
150
151




























































152
153
154
141
142
143
144
145
146
147

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213







-



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



  INSERT INTO gg(gg) VALUES('integrity-check');
}

do_execsql_test 5.2 {
  INSERT INTO gg(gg) VALUES('optimize');
}

breakpoint
do_execsql_test 5.3 {
  INSERT INTO gg(gg) VALUES('integrity-check');
}

do_test 5.4.1 {
  set ok 0
  for {set i 0} {$i < 10000} {incr i} {
    set T [format %.5d $i]
    set res  [db eval { SELECT rowid FROM gg($T) ORDER BY rowid ASC  }]
    set res2 [db eval { SELECT rowid FROM gg($T) ORDER BY rowid DESC }]
    if {$res == [lsort -integer $res2]} { incr ok }
  }
  set ok
} {10000}

do_test 5.4.2 {
  set ok 0
  for {set i 0} {$i < 100} {incr i} {
    set T "[format %.3d $i]*"
    set res  [db eval { SELECT rowid FROM gg($T) ORDER BY rowid ASC  }]
    set res2 [db eval { SELECT rowid FROM gg($T) ORDER BY rowid DESC }]
    if {$res == [lsort -integer $res2]} { incr ok }
  }
  set ok
} {100}

#-------------------------------------------------------------------------
# Similar to 5.*.
#
foreach {tn pgsz} {
  1  32
  2  36
  3  40
  4  44
  5  48
} {
  do_execsql_test 6.$tn.1 {
    DROP TABLE IF EXISTS hh;
    CREATE VIRTUAL TABLE hh USING fts5(y);
    INSERT INTO hh(hh, rank) VALUES('pgsz', $pgsz);

    WITH s(i) AS (SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<999)
     INSERT INTO hh SELECT printf("%.3d%.3d%.3d %.3d%.3d%.3d",i,i,i,i+1,i+1,i+1)
     FROM s;

    WITH s(i) AS (SELECT 0 UNION ALL SELECT i+1 FROM s WHERE i<999)
     INSERT INTO hh SELECT printf("%.3d%.3d%.3d %.3d%.3d%.3d",i,i,i,i+1,i+1,i+1)
     FROM s;

    INSERT INTO hh(hh) VALUES('optimize');
  }

  do_test 6.$tn.2 {
    set ok 0
    for {set i 0} {$i < 1000} {incr i} {
      set T [format %.3d%.3d%.3d $i $i $i]
      set res  [db eval { SELECT rowid FROM hh($T) ORDER BY rowid ASC  }]
      set res2 [db eval { SELECT rowid FROM hh($T) ORDER BY rowid DESC }]
      if {$res == [lsort -integer $res2]} { incr ok }
    }
    set ok
  } {1000}
}

finish_test

Changes to ext/fts5/test/fts5rowid.test.
198
199
200
201
202
203
204
205
206






207
208
209
210
211
212
213
198
199
200
201
202
203
204


205
206
207
208
209
210
211
212
213
214
215
216
217







-
-
+
+
+
+
+
+







      SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
    ) INSERT INTO x5 SELECT 'a b c d e f' FROM s;
  COMMIT;
  SELECT count(fts5_decode_none(rowid, block)) FROM x5_data;
} {32}

do_execsql_test 6.1 {
  DELETE FROM x5 WHERE rowid=1;
  UPDATE x5 SET x='a b c d e f' WHERE rowid=2;
  DELETE FROM x5 WHERE rowid <= 2;
  SELECT count(fts5_decode_none(rowid, block)) FROM x5_data;
} {34}

do_execsql_test 6.2 {
  UPDATE x5 SET x='a b c d e f' WHERE rowid=3;
  SELECT count(fts5_decode_none(rowid, block)) FROM x5_data;
} {36}

#db eval {SELECT rowid, fts5_decode_none(rowid, block) aS r FROM x5_data} {puts $r}