fts5fault8.test 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # 2015 September 3
  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. # This file is focused on OOM errors.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. source $testdir/malloc_common.tcl
  16. set testprefix fts5fault8
  17. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. foreach_detail_mode $testprefix {
  23. fts5_aux_test_functions db
  24. do_execsql_test 1.0 {
  25. CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=%DETAIL%);
  26. INSERT INTO t1 VALUES('a b c d', '1 2 3 4');
  27. INSERT INTO t1 VALUES('a b a b', NULL);
  28. INSERT INTO t1 VALUES(NULL, '1 2 1 2');
  29. }
  30. do_faultsim_test 1 -faults oom-* -body {
  31. execsql {
  32. SELECT rowid, fts5_test_poslist(t1) FROM t1 WHERE t1 MATCH 'b OR 2'
  33. }
  34. } -test {
  35. faultsim_test_result {0 {1 {0.0.1 1.1.1} 2 {0.0.1 0.0.3} 3 {1.1.1 1.1.3}}} \
  36. {1 SQLITE_NOMEM}
  37. }
  38. do_faultsim_test 2 -faults oom-* -body {
  39. execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
  40. } -test {
  41. faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
  42. }
  43. if {[detail_is_none]==0} {
  44. do_faultsim_test 3 -faults oom-* -body {
  45. execsql { SELECT rowid FROM t1('b:2') }
  46. } -test {
  47. faultsim_test_result {0 {1 3}} {1 SQLITE_NOMEM}
  48. }
  49. }
  50. } ;# foreach_detail_mode...
  51. do_execsql_test 4.0 {
  52. CREATE VIRTUAL TABLE x2 USING fts5(a);
  53. INSERT INTO x2(x2, rank) VALUES('crisismerge', 2);
  54. INSERT INTO x2(x2, rank) VALUES('pgsz', 32);
  55. INSERT INTO x2 VALUES('a b c d');
  56. INSERT INTO x2 VALUES('e f g h');
  57. INSERT INTO x2 VALUES('i j k l');
  58. INSERT INTO x2 VALUES('m n o p');
  59. INSERT INTO x2 VALUES('q r s t');
  60. INSERT INTO x2 VALUES('u v w x');
  61. INSERT INTO x2 VALUES('y z a b');
  62. }
  63. faultsim_save_and_close
  64. do_faultsim_test 4 -faults oom-* -prep {
  65. faultsim_restore_and_reopen
  66. } -body {
  67. execsql { INSERT INTO x2(x2) VALUES('optimize') }
  68. } -test {
  69. faultsim_test_result {0 {}} {1 SQLITE_NOMEM}
  70. }
  71. set TMPDBERROR {1 {unable to open a temporary database file for storing temporary tables}}
  72. do_faultsim_test 5 -faults oom-t* -prep {
  73. faultsim_restore_and_reopen
  74. execsql { PRAGMA temp_store = memory }
  75. } -body {
  76. execsql { PRAGMA integrity_check }
  77. } -test {
  78. if {[string match {*error code=7*} $testresult]==0} {
  79. faultsim_test_result {0 ok} {1 SQLITE_NOMEM} $::TMPDBERROR
  80. }
  81. }
  82. finish_test