sl@0
|
1 |
# 2008 August 01
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# This test script checks malloc failures in various obscure operations.
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# $Id: mallocH.test,v 1.2 2008/08/01 20:10:09 drh Exp $
|
sl@0
|
15 |
|
sl@0
|
16 |
set testdir [file dirname $argv0]
|
sl@0
|
17 |
source $testdir/tester.tcl
|
sl@0
|
18 |
source $testdir/malloc_common.tcl
|
sl@0
|
19 |
|
sl@0
|
20 |
# Malloc failures in journaling of in-memory databases.
|
sl@0
|
21 |
#
|
sl@0
|
22 |
do_malloc_test mallocH-1 -tclprep {
|
sl@0
|
23 |
db close
|
sl@0
|
24 |
sqlite3 db :memory:
|
sl@0
|
25 |
db eval {
|
sl@0
|
26 |
CREATE TABLE t1(x UNIQUE, y);
|
sl@0
|
27 |
INSERT INTO t1 VALUES(1,2);
|
sl@0
|
28 |
}
|
sl@0
|
29 |
} -sqlbody {
|
sl@0
|
30 |
INSERT INTO t1 SELECT x+1, y+100 FROM t1;
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
# Malloc failures while parsing a CASE expression.
|
sl@0
|
34 |
#
|
sl@0
|
35 |
do_malloc_test mallocH-2 -sqlbody {
|
sl@0
|
36 |
SELECT CASE WHEN 1 THEN 1 END;
|
sl@0
|
37 |
}
|
sl@0
|
38 |
|
sl@0
|
39 |
# Malloc failures while parsing a EXISTS(SELECT ...)
|
sl@0
|
40 |
#
|
sl@0
|
41 |
do_malloc_test mallocH-3 -sqlbody {
|
sl@0
|
42 |
SELECT 3+EXISTS(SELECT * FROM sqlite_master);
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
# Malloc failures within the replace() function.
|
sl@0
|
46 |
#
|
sl@0
|
47 |
do_malloc_test mallocH-3 -sqlbody {
|
sl@0
|
48 |
SELECT replace('ababa','a','xyzzy');
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
# Malloc failures during EXPLAIN.
|
sl@0
|
52 |
#
|
sl@0
|
53 |
ifcapable explain {
|
sl@0
|
54 |
do_malloc_test mallocH-4 -sqlprep {
|
sl@0
|
55 |
CREATE TABLE abc(a PRIMARY KEY, b, c);
|
sl@0
|
56 |
} -sqlbody {
|
sl@0
|
57 |
EXPLAIN SELECT * FROM abc AS t2 WHERE rowid=1;
|
sl@0
|
58 |
EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE rowid=1;
|
sl@0
|
59 |
}
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
# Malloc failure during integrity_check pragma.
|
sl@0
|
63 |
#
|
sl@0
|
64 |
do_malloc_test mallocH-5 -sqlprep {
|
sl@0
|
65 |
CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
|
sl@0
|
66 |
CREATE TABLE t2(x,y);
|
sl@0
|
67 |
INSERT INTO t1 VALUES(1,2);
|
sl@0
|
68 |
INSERT INTO t2 SELECT * FROM t1;
|
sl@0
|
69 |
} -sqlbody {
|
sl@0
|
70 |
PRAGMA integrity_check;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
finish_test
|