1c4dd3fd2Sdrh# 2007 Aug 29 2c4dd3fd2Sdrh# 3c4dd3fd2Sdrh# The author disclaims copyright to this source code. In place of 4c4dd3fd2Sdrh# a legal notice, here is a blessing: 5c4dd3fd2Sdrh# 6c4dd3fd2Sdrh# May you do good and not evil. 7c4dd3fd2Sdrh# May you find forgiveness for yourself and forgive others. 8c4dd3fd2Sdrh# May you share freely, never taking more than you give. 9c4dd3fd2Sdrh# 10c4dd3fd2Sdrh#*********************************************************************** 11c4dd3fd2Sdrh# 12c4dd3fd2Sdrh# This test script checks malloc failures in various obscure operations. 13c4dd3fd2Sdrh# 144cfb22f7Sdrh# $Id: mallocG.test,v 1.5 2008/08/01 18:47:02 drh Exp $ 15c4dd3fd2Sdrh 16c4dd3fd2Sdrhset testdir [file dirname $argv0] 17c4dd3fd2Sdrhsource $testdir/tester.tcl 18eee4c8caSdrhsource $testdir/malloc_common.tcl 19c4dd3fd2Sdrh 20c4dd3fd2Sdrh# Only run these tests if memory debugging is turned on. 21c4dd3fd2Sdrh# 22eee4c8caSdrhif {!$MEMDEBUG} { 23c4dd3fd2Sdrh puts "Skipping mallocG tests: not compiled with -DSQLITE_MEMDEBUG..." 24c4dd3fd2Sdrh finish_test 25c4dd3fd2Sdrh return 26c4dd3fd2Sdrh} 27c4dd3fd2Sdrh 28c4dd3fd2Sdrh# Malloc failures while opening a database connection. 29c4dd3fd2Sdrh# 304cfb22f7Sdrhdo_malloc_test mallocG-1 -tclbody { 31c4dd3fd2Sdrh db close 32c4dd3fd2Sdrh sqlite3 db test.db 33c4dd3fd2Sdrh} 34c4dd3fd2Sdrh 35c4dd3fd2Sdrhdo_malloc_test mallocG-2 -sqlprep { 36c4dd3fd2Sdrh CREATE TABLE t1(x, y); 37c4dd3fd2Sdrh CREATE TABLE t2(x INTEGER PRIMARY KEY); 38c4dd3fd2Sdrh} -sqlbody { 39c4dd3fd2Sdrh SELECT y FROM t1 WHERE x IN t2; 40c4dd3fd2Sdrh} 41c4dd3fd2Sdrh 4201495b99Sdrhdo_malloc_test mallocG-3 -sqlprep { 4301495b99Sdrh CREATE TABLE t1(x UNIQUE); 4401495b99Sdrh INSERT INTO t1 VALUES ('hello'); 4501495b99Sdrh INSERT INTO t1 VALUES ('out there'); 4601495b99Sdrh} -sqlbody { 4701495b99Sdrh SELECT * FROM t1 4801495b99Sdrh WHERE x BETWEEN 'a' AND 'z' 4901495b99Sdrh AND x BETWEEN 'c' AND 'w' 5001495b99Sdrh AND x BETWEEN 'e' AND 'u' 5101495b99Sdrh AND x BETWEEN 'g' AND 'r' 5201495b99Sdrh AND x BETWEEN 'i' AND 'q' 5301495b99Sdrh AND x BETWEEN 'i' AND 'm' 5401495b99Sdrh} 5501495b99Sdrh 56*5acefe7dSmistachkinifcapable !utf16 { 57*5acefe7dSmistachkin finish_test 58*5acefe7dSmistachkin return 59*5acefe7dSmistachkin} 60*5acefe7dSmistachkin 61bd0b1b50Sdrhproc utf16 {utf8} { 62bd0b1b50Sdrh set utf16 [encoding convertto unicode $utf8] 63bd0b1b50Sdrh append utf16 "\x00\x00" 64bd0b1b50Sdrh return $utf16 65bd0b1b50Sdrh} 66bd0b1b50Sdrh 67bd0b1b50Sdrhdo_malloc_test mallocG-4 -tclbody { 68bd0b1b50Sdrh set rc [sqlite3_complete16 [utf16 "SELECT * FROM t1;"]] 69bd0b1b50Sdrh if {$rc==1} {set rc 0} {error "out of memory"} 70bd0b1b50Sdrh set rc 71bd0b1b50Sdrh} 72bd0b1b50Sdrh 73c4dd3fd2Sdrhfinish_test 74