blob: e2d93e742ddc40e926e136dc46b4265efa72dcdf [file] [log] [blame]
dana2bfa042016-11-04 12:05:29 +00001# 2016 November 4
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# 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.
14#
15
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19set testprefix instrfault
20
21# Use big NEEDLE and HAYSTACK strings. Strings so large they cannot
22# use lookaside buffers.
23#
24set ::NEEDLE [string repeat "abcdefghijklmnopqrstuvwxyz" 10]
25set ::HAYSTACK "[string repeat 123 10]$NEEDLE[string repeat 456 10]"
26
27foreach {enc} {
28 utf8
29 utf16
30} {
31 reset_db
32 execsql "PRAGMA encoding = $enc"
33 do_execsql_test 1.$enc.1 {
34 CREATE TABLE t1(n, h);
35 INSERT INTO t1 VALUES($::NEEDLE, $::HAYSTACK);
36 } {}
37
38 do_faultsim_test 1.$enc.1 -faults oom-t* -prep {
39 execsql { SELECT instr(h, n) FROM t1 }
40 } -body {
41 execsql { SELECT instr(h, n) FROM t1 }
42 } -test {
43 faultsim_test_result {0 31}
44 }
45
46 do_faultsim_test 1.$enc.2 -faults oom-t* -prep {
47 execsql { SELECT instr($::HAYSTACK, $::NEEDLE) FROM t1 }
48 } -body {
49 execsql { SELECT instr($::HAYSTACK, $::NEEDLE) FROM t1 }
50 } -test {
51 faultsim_test_result {0 31}
52 }
53
54 do_faultsim_test 1.$enc.3 -faults oom-t* -prep {
55 set ::stmt [sqlite3_prepare_v2 db "SELECT instr(?, ?)" -1 dummy]
56 sqlite3_bind_text $::stmt 1 $::HAYSTACK [string length $::HAYSTACK]
57 sqlite3_bind_text $::stmt 2 $::NEEDLE [string length $::NEEDLE]
58 } -body {
59 set rc [sqlite3_step $::stmt]
60 if {$rc=="SQLITE_NOMEM"} { error "out of memory" }
61 sqlite3_column_int $::stmt 0
62 } -test {
63 faultsim_test_result {0 31}
64 sqlite3_finalize $::stmt
65 }
66}
67
68finish_test