fts3fault.test 6.2 KB

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