blob: 7d9433205958301a7313062d0f945e5d72a0ea18 [file] [log] [blame]
dane25ac092010-10-25 19:01:25 +00001# 2010 June 15
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#
12
13set testdir [file dirname $argv0]
14source $testdir/tester.tcl
15
16set ::testprefix fts3fault
17
danacf19872010-11-11 11:43:01 +000018# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
19ifcapable !fts3 { finish_test ; return }
20
dana90579d2015-07-08 17:59:08 +000021if 0 {
22
dane25ac092010-10-25 19:01:25 +000023# Test error handling in the sqlite3Fts3Init() function. This is the
24# function that registers the FTS3 module and various support functions
25# with SQLite.
26#
27do_faultsim_test 1 -body {
28 sqlite3 db test.db
29 expr 0
30} -test {
31 catch { db close }
32}
33
34# Test error handling in an "ALTER TABLE ... RENAME TO" statement on an
35# FTS3 table. Specifically, test renaming the table within a transaction
36# after it has been written to.
37#
38faultsim_delete_and_reopen
39do_execsql_test 2.0 {
40 CREATE VIRTUAL TABLE t1 USING fts3;
41 INSERT INTO t1 VALUES('test renaming the table');
42 INSERT INTO t1 VALUES(' after it has been written');
43}
44do_faultsim_test 2 -prep {
45 sqlite3 db test.db
46 execsql {
47 BEGIN;
48 INSERT INTO t1 VALUES('registers the FTS3 module');
49 INSERT INTO t1 VALUES('various support functions');
50 }
51} -body {
52 execsql { ALTER TABLE t1 RENAME TO t2 }
53} -test {
54 faultsim_test_result {0 {}}
55}
56
57# Test error handling in the special case where a single prefix query
58# matches terms that reside on a large range of leaf nodes.
59#
60do_test fts3fault-3.0 {
61 sqlite3 db test.db
62 execsql { CREATE VIRTUAL TABLE t3 USING fts4; }
63 execsql { INSERT INTO t3(t3) VALUES('nodesize=50') }
64 execsql { BEGIN }
65 for {set i 0} {$i < 1000} {incr i} {
66 execsql { INSERT INTO t3 VALUES('aaa' || $i) }
67 }
68 execsql { COMMIT }
69} {}
70
71do_faultsim_test 3 -faults oom-transient -prep {
72 sqlite3 db test.db
73 execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' }
74} -body {
75 execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' }
76} -test {
77 faultsim_test_result {0 1000}
78}
79
80do_test fts3fault-4.0 {
81 faultsim_delete_and_reopen
82 execsql {
83 CREATE VIRTUAL TABLE t4 USING fts4;
84 INSERT INTO t4 VALUES('The British Government called on');
85 INSERT INTO t4 VALUES('as pesetas then became much');
86 }
87} {}
88faultsim_save_and_close
89do_faultsim_test 4 -prep {
90 faultsim_restore_and_reopen
91 execsql { SELECT content FROM t4 }
92} -body {
93 execsql { SELECT optimize(t4) FROM t4 LIMIT 1 }
94} -test {
95 faultsim_test_result {0 {{Index optimized}}}
96}
97
98do_test fts3fault-5.0 {
99 faultsim_delete_and_reopen
100 execsql {
101 CREATE VIRTUAL TABLE t5 USING fts4;
102 INSERT INTO t5 VALUES('The British Government called on');
103 INSERT INTO t5 VALUES('as pesetas then became much');
104 }
105} {}
106faultsim_save_and_close
107do_faultsim_test 5 -prep {
108 faultsim_restore_and_reopen
109 execsql {
110 BEGIN;
111 INSERT INTO t5 VALUES('influential in shaping his future outlook');
112 INSERT INTO t5 VALUES('might be acceptable to the British electorate');
113 }
114} -body {
115 execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' }
116} -test {
117 faultsim_test_result {0 {1 4}}
118}
119
120do_test fts3fault-6.0 {
121 faultsim_delete_and_reopen
122 execsql { CREATE VIRTUAL TABLE t6 USING fts4 }
123} {}
124faultsim_save_and_close
125do_faultsim_test 6 -prep {
126 faultsim_restore_and_reopen
127 execsql { SELECT rowid FROM t6 }
128} -body {
129 execsql { DROP TABLE t6 }
130} -test {
131 faultsim_test_result {0 {}}
132}
133
danaf4c2142010-11-02 17:41:52 +0000134# Test various malloc failures while processing FTS4 parameters.
135#
136do_faultsim_test 7.1 -prep {
137 faultsim_delete_and_reopen
138} -body {
139 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) }
140} -test {
141 faultsim_test_result {0 {}}
142}
143do_faultsim_test 7.2 -prep {
144 faultsim_delete_and_reopen
145} -body {
146 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) }
147} -test {
148 faultsim_test_result {1 {unrecognized matchinfo: fs3}} \
dan9fc160c2011-10-31 06:52:51 +0000149 {1 {vtable constructor failed: t1}} \
150 {1 {SQL logic error or missing database}}
danaf4c2142010-11-02 17:41:52 +0000151}
152do_faultsim_test 7.3 -prep {
153 faultsim_delete_and_reopen
154} -body {
155 execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) }
156} -test {
157 faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \
dan9fc160c2011-10-31 06:52:51 +0000158 {1 {vtable constructor failed: t1}} \
159 {1 {SQL logic error or missing database}}
danc2f16cb2010-11-25 17:49:28 +0000160}
161
dana90579d2015-07-08 17:59:08 +0000162
163}
164
danc2f16cb2010-11-25 17:49:28 +0000165proc mit {blob} {
166 set scan(littleEndian) i*
167 set scan(bigEndian) I*
168 binary scan $blob $scan($::tcl_platform(byteOrder)) r
169 return $r
170}
171
172do_test 8.0 {
173 faultsim_delete_and_reopen
174 execsql { CREATE VIRTUAL TABLE t8 USING fts4 }
175 execsql "INSERT INTO t8 VALUES('a b c')"
176 execsql "INSERT INTO t8 VALUES('b b b')"
177 execsql "INSERT INTO t8 VALUES('[string repeat {c } 50000]')"
178 execsql "INSERT INTO t8 VALUES('d d d')"
179 execsql "INSERT INTO t8 VALUES('e e e')"
180 execsql "INSERT INTO t8(t8) VALUES('optimize')"
181 faultsim_save_and_close
182} {}
183
dana90579d2015-07-08 17:59:08 +0000184do_faultsim_test 8.1 -faults oom-t* -prep {
danc2f16cb2010-11-25 17:49:28 +0000185 faultsim_restore_and_reopen
186 db func mit mit
187} -body {
188 execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' }
189} -test {
190 faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}}
191}
dana90579d2015-07-08 17:59:08 +0000192
danc2f16cb2010-11-25 17:49:28 +0000193do_faultsim_test 8.2 -faults oom-t* -prep {
194 faultsim_restore_and_reopen
195 db func mit mit
196} -body {
197 execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' }
198} -test {
199 faultsim_test_result {0 3}
200}
201do_faultsim_test 8.3 -prep {
202 faultsim_restore_and_reopen
203 db func mit mit
204} -body {
205 execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' }
206} -test {
207 faultsim_test_result {0 10002}
208}
209do_faultsim_test 8.4 -prep {
210 faultsim_restore_and_reopen
211 db func mit mit
212} -body {
213 execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' }
214} -test {
215 faultsim_test_result {0 3}
216}
217
218do_test 9.0 {
219 faultsim_delete_and_reopen
220 execsql {
221 CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter);
222 INSERT INTO t9 VALUES(
223 'this record is used toooooooooooooooooooooooooooooooooooooo try to'
224 );
225 SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*';
226 }
227 faultsim_save_and_close
228} {}
229do_faultsim_test 9.1 -prep {
230 faultsim_restore_and_reopen
231} -body {
232 execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' }
233} -test {
234 faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}}
235}
236
dane25ac092010-10-25 19:01:25 +0000237finish_test