1# 2011 February 19 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 6# May you do good and not evil. 7# May you find forgiveness for yourself and forgive others. 8# May you share freely, never taking more than you give. 9# 10#*********************************************************************** 11# This file implements regression tests for SQLite library. The 12# focus of this file is testing that error messages are logged via the 13# sqlite3_log() mechanism when certain errors are encountered in the 14# default unix or windows VFS modules. 15# 16 17set testdir [file dirname $argv0] 18source $testdir/tester.tcl 19if {$::tcl_platform(platform)!="unix"} { finish_test ; return } 20set ::testprefix oserror 21 22db close 23sqlite3_shutdown 24test_sqlite3_log xLog 25proc xLog {error_code msg} { 26 if {[string match os_* $msg]} { 27 lappend ::log $msg 28 } 29} 30 31proc do_re_test {tn script expression} { 32 uplevel do_test $tn [list [subst -nocommands { 33 set res [eval { $script }] 34 if {[regexp {$expression} [set res]]} { 35 set {} {$expression} 36 } else { 37 set res 38 } 39 }]] [list $expression] 40 41} 42 43#-------------------------------------------------------------------------- 44# Tests oserror-1.* test failures in the open() system call. 45# 46 47# Test a failure in open() due to too many files. 48# 49do_test 1.1.1 { 50 set ::log [list] 51 list [catch { 52 for {set i 0} {$i < 2000} {incr i} { sqlite3 dbh_$i test.db -readonly 1 } 53 } msg] $msg 54} {1 {unable to open database file}} 55do_test 1.1.2 { 56 catch { for {set i 0} {$i < 2000} {incr i} { dbh_$i close } } 57} {1} 58 59do_re_test 1.1.3 { lindex $::log 0 } {^os_unix.c: open.*test.db$} 60 61 62# Test a failure in open() due to the path being a directory. 63# 64do_test 1.2.1 { 65 file mkdir dir.db 66 set ::log [list] 67 list [catch { sqlite3 dbh dir.db } msg] $msg 68} {1 {unable to open database file}} 69 70do_re_test 1.2.2 { lindex $::log 0 } {^os_unix.c: open.*dir.db$} 71 72# Test a failure in open() due to the path not existing. 73# 74do_test 1.3.1 { 75 set ::log [list] 76 list [catch { sqlite3 dbh /x/y/z/test.db } msg] $msg 77} {1 {unable to open database file}} 78 79do_re_test 1.3.2 { lindex $::log 0 } {^os_unix.c: open.*test.db$} 80 81# Test a failure in open() due to the path not existing. 82# 83do_test 1.4.1 { 84 set ::log [list] 85 list [catch { sqlite3 dbh /root/test.db } msg] $msg 86} {1 {unable to open database file}} 87 88do_re_test 1.4.2 { lindex $::log 0 } {^os_unix.c: open.*test.db$} 89 90#-------------------------------------------------------------------------- 91# Tests oserror-1.* test failures in the unlink() system call. 92# 93do_test 2.1.1 { 94 set ::log [list] 95 file mkdir test.db-wal 96 forcedelete test.db 97 sqlite3 dbh test.db 98 catchsql { SELECT * FROM sqlite_master } dbh 99} {1 {disk I/O error}} 100 101do_re_test 2.1.2 { lindex $::log 0 } {^os_unix.c: unlink.*test.db-wal$} 102do_test 2.1.3 { 103 dbh close 104 forcedelete test.db-wal 105} {} 106 107 108sqlite3_shutdown 109test_sqlite3_log 110sqlite3_initialize 111finish_test 112 113