1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/altermalloc.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,70 @@
1.4 +# 2005 September 19
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 implements regression tests for SQLite library. The
1.15 +# focus of this script is testing the ALTER TABLE statement and
1.16 +# specifically out-of-memory conditions within that command.
1.17 +#
1.18 +# $Id: altermalloc.test,v 1.9 2008/08/04 20:13:27 drh Exp $
1.19 +#
1.20 +
1.21 +set testdir [file dirname $argv0]
1.22 +source $testdir/tester.tcl
1.23 +
1.24 +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
1.25 +ifcapable !altertable||!memdebug {
1.26 + finish_test
1.27 + return
1.28 +}
1.29 +
1.30 +source $testdir/malloc_common.tcl
1.31 +
1.32 +do_malloc_test altermalloc-1 -tclprep {
1.33 + db close
1.34 +} -tclbody {
1.35 + if {[catch {sqlite3 db test.db}]} {
1.36 + error "out of memory"
1.37 + }
1.38 + sqlite3_db_config_lookaside db 0 0 0
1.39 + sqlite3_extended_result_codes db 1
1.40 +} -sqlbody {
1.41 + CREATE TABLE t1(a int);
1.42 + ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL;
1.43 + ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text';
1.44 + ALTER TABLE t1 RENAME TO t2;
1.45 +}
1.46 +
1.47 +# Test malloc() failure on an ALTER TABLE on a virtual table.
1.48 +#
1.49 +ifcapable vtab {
1.50 + do_malloc_test altermalloc-vtab -tclprep {
1.51 + sqlite3 db2 test.db
1.52 + sqlite3_db_config_lookaside db2 0 0 0
1.53 + sqlite3_extended_result_codes db2 1
1.54 + register_echo_module [sqlite3_connection_pointer db2]
1.55 + db2 eval {
1.56 + CREATE TABLE t1(a, b VARCHAR, c INTEGER);
1.57 + CREATE VIRTUAL TABLE t1echo USING echo(t1);
1.58 + }
1.59 + db2 close
1.60 +
1.61 + register_echo_module [sqlite3_connection_pointer db]
1.62 + } -tclbody {
1.63 + set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg]
1.64 + if {$msg eq "vtable constructor failed: t1echo"} {
1.65 + set msg "out of memory"
1.66 + }
1.67 + if {$rc} {
1.68 + error $msg
1.69 + }
1.70 + }
1.71 +}
1.72 +
1.73 +finish_test