Remove a lot of the text describing extended format options from the
[sqlite.git] / test / instrfault.test
blob0ddb12c84beb03adaddfb2db9820e1900242b550
1 # 2016 November 4
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.  The
12 # focus of this file is testing OOM error handling within the built-in 
13 # INSTR() function.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set testprefix instrfault
21 # Use big NEEDLE and HAYSTACK strings. Strings so large they cannot
22 # use lookaside buffers.
24 set ::NEEDLE [string repeat "abcdefghijklmnopqrstuvwxyz" 10]
25 set ::HAYSTACK "[string repeat 123 10]$NEEDLE[string repeat 456 10]"
27 foreach {enc} {
28   utf8
29   utf16
30 } {
31   reset_db
32   sqlite3_db_config_lookaside db 0 0 0
34   execsql "PRAGMA encoding = $enc"
35   do_execsql_test 1.$enc.1 {
36     CREATE TABLE t1(n, h);
37     INSERT INTO t1 VALUES($::NEEDLE, $::HAYSTACK);
38   } {}
40   do_faultsim_test 1.$enc.1 -faults oom-t* -prep {
41     execsql { SELECT instr(h, n) FROM t1 }
42   } -body {
43     execsql { SELECT instr(h, n) FROM t1 }
44   } -test {
45     faultsim_test_result {0 31}
46   }
48   do_faultsim_test 1.$enc.2 -faults oom-t* -prep {
49     execsql { SELECT instr($::HAYSTACK, $::NEEDLE) FROM t1 }
50   } -body {
51     execsql { SELECT instr($::HAYSTACK, $::NEEDLE) FROM t1 }
52   } -test {
53     faultsim_test_result {0 31}
54   }
56   do_faultsim_test 1.$enc.3 -faults oom-t* -prep {
57     set ::stmt [sqlite3_prepare_v2 db "SELECT instr(?, ?)" -1 dummy]
58     sqlite3_bind_text $::stmt 1 $::HAYSTACK [string length $::HAYSTACK]
59     sqlite3_bind_text $::stmt 2 $::NEEDLE [string length $::NEEDLE]
60   } -body {
61     set rc [sqlite3_step $::stmt]
62     if {$rc=="SQLITE_NOMEM"} { error "out of memory" }
63     sqlite3_column_int $::stmt 0
64   } -test {
65     faultsim_test_result {0 31}
66     sqlite3_finalize $::stmt
67   }
69   do_faultsim_test 1.$enc.4 -faults oom-t* -prep {
70     set ::stmt [sqlite3_prepare_v2 db "SELECT instr(?, ?)" -1 dummy]
71     sqlite3_bind_blob $::stmt 1 $::HAYSTACK [string length $::HAYSTACK]
72     sqlite3_bind_text $::stmt 2 $::NEEDLE [string length $::NEEDLE]
73   } -body {
74     set rc [sqlite3_step $::stmt]
75     if {$rc=="SQLITE_NOMEM"} { error "out of memory" }
76     sqlite3_column_int $::stmt 0
77   } -test {
78     faultsim_test_result {0 31}
79     sqlite3_finalize $::stmt
80   }
82   do_execsql_test 1.$enc.5.0 {
83     CREATE TABLE h1(a, b);
84     INSERT INTO h1 VALUES('abcdefg%200hijkl', randomblob(200));
85     INSERT INTO h1 SELECT b, a FROM h1;
86   }
87   do_faultsim_test 1.$enc.5 -faults oom-t* -body {
88     execsql { SELECT rowid FROM h1 WHERE instr(a,b) }
89   } -test {}
92 finish_test