mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Improvements to the SQLITE_MISUSE detection logic. Also added test cases
for this logic, including the new test file "misuse.test". (CVS 559) FossilOrigin-Name: f42907ce457e012592f8c043dc6c915e87258b35
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: all.test,v 1.13 2002/03/06 22:01:36 drh Exp $
|
||||
# $Id: all.test,v 1.14 2002/05/10 13:14:08 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -33,6 +33,7 @@ set EXCLUDE {
|
||||
all.test
|
||||
quick.test
|
||||
malloc.test
|
||||
misuse.test
|
||||
btree2.test
|
||||
}
|
||||
|
||||
@ -71,9 +72,10 @@ if {$LeakList!=""} {
|
||||
puts " Ok"
|
||||
}
|
||||
|
||||
# Run the malloc tests after memory leak detection. We do leak
|
||||
# some if malloc fails.
|
||||
# Run the malloc tests and the misuse test after memory leak detection.
|
||||
# Both tests leak memory.
|
||||
#
|
||||
catch {source $testdir/misuse.test}
|
||||
catch {source $testdir/malloc.test}
|
||||
|
||||
really_finish_test
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is database locks.
|
||||
#
|
||||
# $Id: lock.test,v 1.13 2001/10/09 04:19:47 drh Exp $
|
||||
# $Id: lock.test,v 1.14 2002/05/10 13:14:08 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@ -21,6 +21,7 @@ source $testdir/tester.tcl
|
||||
#
|
||||
do_test lock-1.0 {
|
||||
sqlite db2 ./test.db
|
||||
set dummy {}
|
||||
} {}
|
||||
do_test lock-1.1 {
|
||||
execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name}
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is exercising the code in main.c.
|
||||
#
|
||||
# $Id: main.test,v 1.9 2001/10/13 02:59:09 drh Exp $
|
||||
# $Id: main.test,v 1.10 2002/05/10 13:14:08 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -80,7 +80,7 @@ do_test main-2.0 {
|
||||
puts $fd hi!
|
||||
close $fd
|
||||
set v [catch {sqlite db test.db} msg]
|
||||
lappend v $msg
|
||||
if {$v} {lappend v $msg} {lappend v {}}
|
||||
} {0 {}}
|
||||
|
||||
# Here are some tests for tokenize.c.
|
||||
|
161
test/misuse.test
Normal file
161
test/misuse.test
Normal file
@ -0,0 +1,161 @@
|
||||
# 2002 May 10
|
||||
#
|
||||
# The author disclaims copyright to this source code. In place of
|
||||
# a legal notice, here is a blessing:
|
||||
#
|
||||
# May you do good and not evil.
|
||||
# May you find forgiveness for yourself and forgive others.
|
||||
# May you share freely, never taking more than you give.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
# This file implements tests for the SQLITE_MISUSE detection logic.
|
||||
# This test file leaks memory and file descriptors.
|
||||
#
|
||||
# $Id: misuse.test,v 1.1 2002/05/10 13:14:08 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Make sure the test logic works
|
||||
#
|
||||
do_test misuse-1.1 {
|
||||
db close
|
||||
set ::DB [sqlite db test.db]
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
INSERT INTO t1 VALUES(1,2);
|
||||
}
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {0 {a b 1 2}}
|
||||
do_test misuse-1.2 {
|
||||
sqlite_exec_printf $::DB {SELECT x_coalesce(NULL,a) AS 'xyz' FROM t1} {}
|
||||
} {1 {no such function: x_coalesce}}
|
||||
do_test misuse-1.3 {
|
||||
sqlite_create_function $::DB
|
||||
sqlite_exec_printf $::DB {SELECT x_coalesce(NULL,a) AS 'xyz' FROM t1} {}
|
||||
} {0 {xyz 1}}
|
||||
|
||||
# Use the x_sqlite_exec() SQL function to simulate the effect of two
|
||||
# threads trying to use the same database at the same time.
|
||||
#
|
||||
do_test misuse-1.4 {
|
||||
sqlite_exec_printf $::DB {
|
||||
SELECT x_sqlite_exec('SELECT * FROM t1');
|
||||
} {}
|
||||
} {21 {library routine called out of sequence}}
|
||||
do_test misuse-1.5 {
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {21 {library routine called out of sequence}}
|
||||
do_test misuse-1.6 {
|
||||
catchsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 {library routine called out of sequence}}
|
||||
|
||||
# Attempt to register a new SQL function while an sqlite_exec() is active.
|
||||
#
|
||||
do_test misuse-2.1 {
|
||||
db close
|
||||
set ::DB [sqlite db test.db]
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2}
|
||||
do_test misuse-2.2 {
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {0 {a b 1 2}}
|
||||
do_test misuse-2.3 {
|
||||
set v [catch {
|
||||
db eval {SELECT * FROM t1} {} {
|
||||
sqlite_create_function $::DB
|
||||
}
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {1 {library routine called out of sequence}}
|
||||
do_test misuse-2.4 {
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {21 {library routine called out of sequence}}
|
||||
do_test misuse-2.5 {
|
||||
catchsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 {library routine called out of sequence}}
|
||||
|
||||
# Attempt to register a new SQL aggregate while an sqlite_exec() is active.
|
||||
#
|
||||
do_test misuse-3.1 {
|
||||
db close
|
||||
set ::DB [sqlite db test.db]
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2}
|
||||
do_test misuse-3.2 {
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {0 {a b 1 2}}
|
||||
do_test misuse-3.3 {
|
||||
set v [catch {
|
||||
db eval {SELECT * FROM t1} {} {
|
||||
sqlite_create_aggregate $::DB
|
||||
}
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {1 {library routine called out of sequence}}
|
||||
do_test misuse-3.4 {
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {21 {library routine called out of sequence}}
|
||||
do_test misuse-3.5 {
|
||||
catchsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 {library routine called out of sequence}}
|
||||
|
||||
# Attempt to close the database from an sqlite_exec callback.
|
||||
#
|
||||
do_test misuse-4.1 {
|
||||
db close
|
||||
set ::DB [sqlite db test.db]
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2}
|
||||
do_test misuse-4.2 {
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {0 {a b 1 2}}
|
||||
do_test misuse-4.3 {
|
||||
set v [catch {
|
||||
db eval {SELECT * FROM t1} {} {
|
||||
sqlite_close $::DB
|
||||
}
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {1 {library routine called out of sequence}}
|
||||
do_test misuse-4.4 {
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {21 {library routine called out of sequence}}
|
||||
do_test misuse-4.5 {
|
||||
catchsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 {library routine called out of sequence}}
|
||||
|
||||
# Attempt to use a database after it has been closed.
|
||||
#
|
||||
do_test misuse-5.1 {
|
||||
db close
|
||||
set ::DB [sqlite db test.db]
|
||||
execsql {
|
||||
SELECT * FROM t1
|
||||
}
|
||||
} {1 2}
|
||||
do_test misuse-5.2 {
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {0 {a b 1 2}}
|
||||
do_test misuse-5.3 {
|
||||
db close
|
||||
sqlite_exec_printf $::DB {SELECT * FROM t1} {}
|
||||
} {21 {library routine called out of sequence}}
|
||||
|
||||
finish_test
|
@ -12,7 +12,7 @@
|
||||
#
|
||||
# This file implements tests for temporary tables and indices.
|
||||
#
|
||||
# $Id: temptable.test,v 1.4 2002/01/10 14:31:49 drh Exp $
|
||||
# $Id: temptable.test,v 1.5 2002/05/10 13:14:08 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -21,6 +21,7 @@ source $testdir/tester.tcl
|
||||
#
|
||||
do_test temptable-1.0 {
|
||||
sqlite db2 ./test.db
|
||||
set dummy {}
|
||||
} {}
|
||||
|
||||
# Create a permanent table.
|
||||
|
Reference in New Issue
Block a user