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