OLD | NEW |
| (Empty) |
1 # 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 | |
13 set testdir [file dirname $argv0] | |
14 source $testdir/tester.tcl | |
15 | |
16 set ::testprefix fts3fault | |
17 | |
18 # If SQLITE_ENABLE_FTS3 is not defined, omit this file. | |
19 ifcapable !fts3 { finish_test ; return } | |
20 | |
21 if 0 { | |
22 | |
23 # 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 # | |
27 do_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 # | |
38 faultsim_delete_and_reopen | |
39 do_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 } | |
44 do_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 # | |
60 do_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 | |
71 do_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 | |
80 do_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 } {} | |
88 faultsim_save_and_close | |
89 do_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 | |
98 do_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 } {} | |
106 faultsim_save_and_close | |
107 do_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 | |
120 do_test fts3fault-6.0 { | |
121 faultsim_delete_and_reopen | |
122 execsql { CREATE VIRTUAL TABLE t6 USING fts4 } | |
123 } {} | |
124 faultsim_save_and_close | |
125 do_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 | |
134 # Test various malloc failures while processing FTS4 parameters. | |
135 # | |
136 do_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 } | |
143 do_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}} \ | |
149 {1 {vtable constructor failed: t1}} \ | |
150 {1 {SQL logic error or missing database}} | |
151 } | |
152 do_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}} \ | |
158 {1 {vtable constructor failed: t1}} \ | |
159 {1 {SQL logic error or missing database}} | |
160 } | |
161 | |
162 | |
163 } | |
164 | |
165 proc 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 | |
172 do_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 | |
184 do_faultsim_test 8.1 -faults oom-t* -prep { | |
185 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 } | |
192 | |
193 do_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 } | |
201 do_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 } | |
209 do_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 | |
218 do_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 } {} | |
229 do_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 | |
237 finish_test | |
OLD | NEW |