drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 1 | # 2007 Aug 29 |
| 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 test script checks malloc failures in various obscure operations. |
| 13 | # |
drh | 4cfb22f | 2008-08-01 18:47:01 +0000 | [diff] [blame] | 14 | # $Id: mallocG.test,v 1.5 2008/08/01 18:47:02 drh Exp $ |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 18 | source $testdir/malloc_common.tcl |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 19 | |
| 20 | # Only run these tests if memory debugging is turned on. |
| 21 | # |
drh | eee4c8c | 2008-02-18 22:24:57 +0000 | [diff] [blame] | 22 | if {!$MEMDEBUG} { |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 23 | puts "Skipping mallocG tests: not compiled with -DSQLITE_MEMDEBUG..." |
| 24 | finish_test |
| 25 | return |
| 26 | } |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 27 | |
| 28 | # Malloc failures while opening a database connection. |
| 29 | # |
drh | 4cfb22f | 2008-08-01 18:47:01 +0000 | [diff] [blame] | 30 | do_malloc_test mallocG-1 -tclbody { |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 31 | db close |
| 32 | sqlite3 db test.db |
| 33 | } |
| 34 | |
| 35 | do_malloc_test mallocG-2 -sqlprep { |
| 36 | CREATE TABLE t1(x, y); |
| 37 | CREATE TABLE t2(x INTEGER PRIMARY KEY); |
| 38 | } -sqlbody { |
| 39 | SELECT y FROM t1 WHERE x IN t2; |
| 40 | } |
| 41 | |
drh | 01495b9 | 2008-01-23 12:52:40 +0000 | [diff] [blame] | 42 | do_malloc_test mallocG-3 -sqlprep { |
| 43 | CREATE TABLE t1(x UNIQUE); |
| 44 | INSERT INTO t1 VALUES ('hello'); |
| 45 | INSERT INTO t1 VALUES ('out there'); |
| 46 | } -sqlbody { |
| 47 | SELECT * FROM t1 |
| 48 | WHERE x BETWEEN 'a' AND 'z' |
| 49 | AND x BETWEEN 'c' AND 'w' |
| 50 | AND x BETWEEN 'e' AND 'u' |
| 51 | AND x BETWEEN 'g' AND 'r' |
| 52 | AND x BETWEEN 'i' AND 'q' |
| 53 | AND x BETWEEN 'i' AND 'm' |
| 54 | } |
| 55 | |
mistachkin | 5acefe7 | 2013-03-07 09:39:18 +0000 | [diff] [blame] | 56 | ifcapable !utf16 { |
| 57 | finish_test |
| 58 | return |
| 59 | } |
| 60 | |
drh | bd0b1b5 | 2008-07-07 19:52:09 +0000 | [diff] [blame] | 61 | proc utf16 {utf8} { |
| 62 | set utf16 [encoding convertto unicode $utf8] |
| 63 | append utf16 "\x00\x00" |
| 64 | return $utf16 |
| 65 | } |
| 66 | |
| 67 | do_malloc_test mallocG-4 -tclbody { |
| 68 | set rc [sqlite3_complete16 [utf16 "SELECT * FROM t1;"]] |
| 69 | if {$rc==1} {set rc 0} {error "out of memory"} |
| 70 | set rc |
| 71 | } |
| 72 | |
drh | c4dd3fd | 2008-01-22 01:48:05 +0000 | [diff] [blame] | 73 | finish_test |