sl@0: # 2007 April 25 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file contains additional out-of-memory checks (see malloc.tcl) sl@0: # added to expose a bug in out-of-memory handling for sqlite3_value_text() sl@0: # sl@0: # $Id: malloc8.test,v 1.7 2008/02/18 22:24:58 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: source $testdir/malloc_common.tcl sl@0: sl@0: # Only run these tests if memory debugging is turned on. sl@0: # sl@0: if {!$MEMDEBUG} { sl@0: puts "Skipping malloc8 tests: not compiled with -DSQLITE_MEMDEBUG..." sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: sl@0: # The setup is a database with UTF-16 encoding that contains a single sl@0: # large string. We will be running lots of queries against this sl@0: # database. Because we will be extracting the string as UTF-8, there sl@0: # is a type conversion that occurs and thus an opportunity for malloc() sl@0: # to fail and for sqlite3_value_text() to return 0 even though sl@0: # sqlite3_value_type() returns SQLITE_TEXT. sl@0: # sl@0: sl@0: do_malloc_test malloc8-1 -sqlprep { sl@0: PRAGMA encoding='UTF-16'; sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 sl@0: VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'); sl@0: } -sqlbody { sl@0: SELECT lower(a), upper(a), quote(a), trim(a), trim('x',a) FROM t1; sl@0: } sl@0: do_malloc_test malloc8-2 -sqlprep { sl@0: PRAGMA encoding='UTF-16'; sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 sl@0: VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'); sl@0: } -sqlbody { sl@0: SELECT replace(a,'x','y'), replace('x',a,'y'), replace('x','y',a) sl@0: FROM t1; sl@0: } sl@0: do_malloc_test malloc8-3 -sqlprep { sl@0: PRAGMA encoding='UTF-16'; sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 sl@0: VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'); sl@0: } -sqlbody { sl@0: SELECT length(a), substr(a, 4, 4) FROM t1; sl@0: } sl@0: ifcapable datetime { sl@0: do_malloc_test malloc8-4 -sqlprep { sl@0: PRAGMA encoding='UTF-16'; sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 sl@0: VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'); sl@0: } -sqlbody { sl@0: SELECT julianday(a,a) FROM t1; sl@0: } sl@0: } sl@0: do_malloc_test malloc8-5 -sqlprep { sl@0: PRAGMA encoding='UTF-16'; sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 sl@0: VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'); sl@0: } -sqlbody { sl@0: SELECT 1 FROM t1 WHERE a LIKE 'hello' ESCAPE NULL; sl@0: } sl@0: do_malloc_test malloc8-6 -sqlprep { sl@0: PRAGMA encoding='UTF-16'; sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 sl@0: VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'); sl@0: } -sqlbody { sl@0: SELECT hex(randomblob(100)); sl@0: } sl@0: sl@0: # Ensure that no file descriptors were leaked. sl@0: do_test malloc-99.X { sl@0: catch {db close} sl@0: set sqlite_open_file_count sl@0: } {0} sl@0: sl@0: finish_test