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