os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/malloc8.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/malloc8.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,95 @@
     1.4 +# 2007 April 25
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +# This file contains additional out-of-memory checks (see malloc.tcl)
    1.15 +# added to expose a bug in out-of-memory handling for sqlite3_value_text()
    1.16 +#
    1.17 +# $Id: malloc8.test,v 1.7 2008/02/18 22:24:58 drh Exp $
    1.18 +
    1.19 +set testdir [file dirname $argv0]
    1.20 +source $testdir/tester.tcl
    1.21 +source $testdir/malloc_common.tcl
    1.22 +
    1.23 +# Only run these tests if memory debugging is turned on.
    1.24 +#
    1.25 +if {!$MEMDEBUG} {
    1.26 +   puts "Skipping malloc8 tests: not compiled with -DSQLITE_MEMDEBUG..."
    1.27 +   finish_test
    1.28 +   return
    1.29 +}
    1.30 +
    1.31 +
    1.32 +# The setup is a database with UTF-16 encoding that contains a single
    1.33 +# large string.  We will be running lots of queries against this 
    1.34 +# database.  Because we will be extracting the string as UTF-8, there
    1.35 +# is a type conversion that occurs and thus an opportunity for malloc()
    1.36 +# to fail and for sqlite3_value_text() to return 0 even though
    1.37 +# sqlite3_value_type() returns SQLITE_TEXT.
    1.38 +#
    1.39 +
    1.40 +do_malloc_test malloc8-1 -sqlprep {
    1.41 +  PRAGMA encoding='UTF-16';
    1.42 +  CREATE TABLE t1(a);
    1.43 +  INSERT INTO t1 
    1.44 +  VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
    1.45 +} -sqlbody {
    1.46 +  SELECT lower(a), upper(a), quote(a), trim(a), trim('x',a) FROM t1;
    1.47 +}
    1.48 +do_malloc_test malloc8-2 -sqlprep {
    1.49 +  PRAGMA encoding='UTF-16';
    1.50 +  CREATE TABLE t1(a);
    1.51 +  INSERT INTO t1 
    1.52 +  VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
    1.53 +} -sqlbody {
    1.54 +  SELECT replace(a,'x','y'), replace('x',a,'y'), replace('x','y',a)
    1.55 +    FROM t1;
    1.56 +}
    1.57 +do_malloc_test malloc8-3 -sqlprep {
    1.58 +  PRAGMA encoding='UTF-16';
    1.59 +  CREATE TABLE t1(a);
    1.60 +  INSERT INTO t1 
    1.61 +  VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
    1.62 +} -sqlbody {
    1.63 +  SELECT length(a), substr(a, 4, 4) FROM t1;
    1.64 +}
    1.65 +ifcapable datetime {
    1.66 +  do_malloc_test malloc8-4 -sqlprep {
    1.67 +    PRAGMA encoding='UTF-16';
    1.68 +    CREATE TABLE t1(a);
    1.69 +    INSERT INTO t1 
    1.70 +    VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
    1.71 +  } -sqlbody {
    1.72 +    SELECT julianday(a,a) FROM t1;
    1.73 +  }
    1.74 +}
    1.75 +do_malloc_test malloc8-5 -sqlprep {
    1.76 +  PRAGMA encoding='UTF-16';
    1.77 +  CREATE TABLE t1(a);
    1.78 +  INSERT INTO t1 
    1.79 +  VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
    1.80 +} -sqlbody {
    1.81 +  SELECT 1 FROM t1 WHERE a LIKE 'hello' ESCAPE NULL;
    1.82 +}
    1.83 +do_malloc_test malloc8-6 -sqlprep {
    1.84 +  PRAGMA encoding='UTF-16';
    1.85 +  CREATE TABLE t1(a);
    1.86 +  INSERT INTO t1 
    1.87 +  VALUES('0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ');
    1.88 +} -sqlbody {
    1.89 +  SELECT hex(randomblob(100));
    1.90 +}
    1.91 +
    1.92 +# Ensure that no file descriptors were leaked.
    1.93 +do_test malloc-99.X {
    1.94 +  catch {db close}
    1.95 +  set sqlite_open_file_count
    1.96 +} {0}
    1.97 +
    1.98 +finish_test