aboutsummaryrefslogtreecommitdiff
path: root/test/malloc4.test
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2007-08-22 22:04:37 +0000
committerdrh <drh@noemail.net>2007-08-22 22:04:37 +0000
commited138fb3bc8e55a6ae93669899dce79e5e26c65a (patch)
treeb47d13ffd4af69fc5372d4a2a845404079c7cc8b /test/malloc4.test
parentf3a65f7e443865f00b6799ba9637604b0ae55dc5 (diff)
downloadsqlite-ed138fb3bc8e55a6ae93669899dce79e5e26c65a.tar.gz
sqlite-ed138fb3bc8e55a6ae93669899dce79e5e26c65a.zip
All of the malloc test cases run. Still seeing failures in malloc4.test. (CVS 4272)
FossilOrigin-Name: 205d0b881d541db65837ce6cf44d58d607635bc2
Diffstat (limited to 'test/malloc4.test')
-rw-r--r--test/malloc4.test61
1 files changed, 30 insertions, 31 deletions
diff --git a/test/malloc4.test b/test/malloc4.test
index af48f234f..1ce95b924 100644
--- a/test/malloc4.test
+++ b/test/malloc4.test
@@ -12,7 +12,7 @@
# This file contains tests to ensure that the library handles malloc() failures
# correctly. The emphasis in this file is on sqlite3_column_XXX() APIs.
#
-# $Id: malloc4.test,v 1.3 2006/01/23 07:52:41 danielk1977 Exp $
+# $Id: malloc4.test,v 1.4 2007/08/22 22:04:37 drh Exp $
#---------------------------------------------------------------------------
# NOTES ON EXPECTED BEHAVIOUR
@@ -27,7 +27,7 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Only run these tests if memory debugging is turned on.
-if {[info command sqlite_malloc_stat]==""} {
+if {[info command sqlite3_memdebug_pending]==""} {
puts "Skipping malloc tests: not compiled with -DSQLITE_MEMDEBUG..."
finish_test
return
@@ -42,7 +42,7 @@ proc do_stmt_test {id sql} {
set ::sql $sql
set go 1
for {set n 1} {$go} {incr n} {
- set testid "malloc4-$id.(iFail $n)"
+ set testid "malloc4-$id.$n"
# Prepare the statement
do_test ${testid}.1 {
@@ -51,7 +51,7 @@ proc do_stmt_test {id sql} {
} {1}
# Set the Nth malloc() to fail.
- sqlite_malloc_fail $n
+ sqlite3_memdebug_fail $n 1
# Test malloc failure in the _name(), _name16(), decltype() and
# decltype16() APIs. Calls that occur after the malloc() failure should
@@ -69,26 +69,26 @@ proc do_stmt_test {id sql} {
# about explicitly testing them.
#
do_test ${testid}.2.1 {
- set mf1 [expr [lindex [sqlite_malloc_stat] 2] <= 0]
+ set mf1 [expr [sqlite3_memdebug_pending] <= 0]
set ::name8 [sqlite3_column_name $::STMT 0]
- set mf2 [expr [lindex [sqlite_malloc_stat] 2] <= 0]
+ set mf2 [expr [sqlite3_memdebug_pending] <= 0]
expr {$mf1 == $mf2 || $::name8 == ""}
} {1}
do_test ${testid}.2.2 {
- set mf1 [expr [lindex [sqlite_malloc_stat] 2] <= 0]
+ set mf1 [expr [sqlite3_memdebug_pending] <= 0]
set ::name16 [sqlite3_column_name16 $::STMT 0]
set ::name16 [encoding convertfrom unicode $::name16]
set ::name16 [string range $::name16 0 end-1]
- set mf2 [expr [lindex [sqlite_malloc_stat] 2] <= 0]
+ set mf2 [expr [sqlite3_memdebug_pending] <= 0]
expr {$mf1 == $mf2 || $::name16 == ""}
} {1}
do_test ${testid}.2.3 {
- set mf1 [expr [lindex [sqlite_malloc_stat] 2] <= 0]
+ set mf1 [expr [sqlite3_memdebug_pending] <= 0]
set ::name8_2 [sqlite3_column_name $::STMT 0]
- set mf2 [expr [lindex [sqlite_malloc_stat] 2] <= 0]
+ set mf2 [expr [sqlite3_memdebug_pending] <= 0]
expr {$mf1 == $mf2 || $::name8_2 == ""}
} {1}
- set ::mallocFailed [expr [lindex [sqlite_malloc_stat] 2] <= 0]
+ set ::mallocFailed [expr [sqlite3_memdebug_pending] <= 0]
do_test ${testid}.2.4 {
expr {
$::name8 == $::name8_2 && $::name16 == $::name8 && !$::mallocFailed ||
@@ -102,30 +102,30 @@ proc do_stmt_test {id sql} {
# running sqlite3_step(), make sure that malloc() is not about to fail.
# Memory allocation failures that occur within sqlite3_step() are tested
# elsewhere.
- set mf [lindex [sqlite_malloc_stat] 2]
- sqlite_malloc_fail 0
+ set mf [sqlite3_memdebug_pending]
+ sqlite3_memdebug_fail -1
do_test ${testid}.3 {
sqlite3_step $::STMT
} {SQLITE_ROW}
- sqlite_malloc_fail $mf
+ sqlite3_memdebug_fail $mf
# Test for malloc() failures within _text() and _text16().
#
do_test ${testid}.4.1 {
set ::text8 [sqlite3_column_text $::STMT 0]
- set mf [expr [lindex [sqlite_malloc_stat] 2] <= 0 && !$::mallocFailed]
+ set mf [expr [sqlite3_memdebug_pending] <= 0 && !$::mallocFailed]
expr {$mf==0 || $::text8 == ""}
} {1}
do_test ${testid}.4.2 {
set ::text16 [sqlite3_column_text16 $::STMT 0]
set ::text16 [encoding convertfrom unicode $::text16]
set ::text16 [string range $::text16 0 end-1]
- set mf [expr [lindex [sqlite_malloc_stat] 2] <= 0 && !$::mallocFailed]
+ set mf [expr [sqlite3_memdebug_pending] <= 0 && !$::mallocFailed]
expr {$mf==0 || $::text16 == ""}
} {1}
do_test ${testid}.4.3 {
set ::text8_2 [sqlite3_column_text $::STMT 0]
- set mf [expr [lindex [sqlite_malloc_stat] 2] <= 0 && !$::mallocFailed]
+ set mf [expr [sqlite3_memdebug_pending] <= 0 && !$::mallocFailed]
expr {$mf==0 || $::text8_2 == "" || ($::text16 == "" && $::text8 != "")}
} {1}
@@ -133,33 +133,33 @@ proc do_stmt_test {id sql} {
# way this can occur is if the string has to be translated from UTF-16 to
# UTF-8 before being converted to a numeric value.
do_test ${testid}.4.4.1 {
- set mf [lindex [sqlite_malloc_stat] 2]
- sqlite_malloc_fail 0
+ set mf [sqlite3_memdebug_pending]
+ sqlite3_memdebug_fail -1
sqlite3_column_text16 $::STMT 0
- sqlite_malloc_fail $mf
+ sqlite3_memdebug_fail $mf
sqlite3_column_int $::STMT 0
} {0}
do_test ${testid}.4.5 {
- set mf [lindex [sqlite_malloc_stat] 2]
- sqlite_malloc_fail 0
+ set mf [sqlite3_memdebug_pending]
+ sqlite3_memdebug_fail -1
sqlite3_column_text16 $::STMT 0
- sqlite_malloc_fail $mf
+ sqlite3_memdebug_fail $mf
sqlite3_column_int64 $::STMT 0
} {0}
do_test ${testid}.4.6 {
- set mf [lindex [sqlite_malloc_stat] 2]
- sqlite_malloc_fail 0
+ set mf [sqlite3_memdebug_pending]
+ sqlite3_memdebug_fail -1
sqlite3_column_text16 $::STMT 0
- sqlite_malloc_fail $mf
+ sqlite3_memdebug_fail $mf
sqlite3_column_double $::STMT 0
} {0.0}
set mallocFailedAfterStep [expr \
- [lindex [sqlite_malloc_stat] 2] <= 0 && !$::mallocFailed
+ [sqlite3_memdebug_pending] <= 0 && !$::mallocFailed
]
- sqlite_malloc_fail 0
+ sqlite3_memdebug_fail -1
# Test that if a malloc() failed the next call to sqlite3_step() returns
# SQLITE_ERROR. If malloc() did not fail, it should return SQLITE_DONE.
#
@@ -172,7 +172,7 @@ proc do_stmt_test {id sql} {
} [expr {$mallocFailedAfterStep ? "SQLITE_NOMEM" : "SQLITE_OK"}]
if {$::mallocFailed == 0 && $mallocFailedAfterStep == 0} {
- sqlite_malloc_fail 0
+ sqlite3_memdebug_fail -1
set go 0
}
}
@@ -189,6 +189,5 @@ execsql {
do_stmt_test 1 "SELECT * FROM tbl"
-sqlite_malloc_fail 0
+sqlite3_memdebug_fail -1
finish_test
-