AryaWu/sqlite
0
1# 2008 July 72#3# The author disclaims copyright to this source code. In place of4# 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#12# Test scripts for deliberate failures of mutex routines.13#14# $Id: mutex2.test,v 1.9 2008/10/07 15:25:49 drh Exp $15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18ifcapable !mutex {19 finish_test20 return21}22 23# deinitialize24#25catch {db close}26sqlite3_reset_auto_extension27sqlite3_shutdown28install_mutex_counters 129 30# Fix the mutex subsystem so that it will not initialize. In other words,31# make it so that sqlite3_initialize() always fails. 32#33do_test mutex2-1.1 {34 set ::disable_mutex_init 1035 sqlite3_initialize36} {SQLITE_IOERR}37do_test mutex2-1.1 {38 set ::disable_mutex_init 739 sqlite3_initialize40} {SQLITE_NOMEM}41 42proc utf16 {str} {43 set r [encoding convertto unicode $str]44 append r "\x00\x00"45 return $r46}47 48# Now that sqlite3_initialize() is failing, try to run various APIs that49# require that SQLite be initialized. Verify that they fail.50#51do_test mutex2-2.1 {52 set ::disable_mutex_init 753 set rc [catch {sqlite db test.db} msg]54 lappend rc $msg55} {1 {}}56ifcapable utf16 {57 do_test mutex2-2.2 {58 set db2 [sqlite3_open16 [utf16 test.db] {}]59 } {0}60 do_test mutex2-2.3 {61 sqlite3_complete16 [utf16 {SELECT * FROM t1;}]62 } {7}63}64do_test mutex2-2.4 {65 sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 366} {}67ifcapable load_ext {68 do_test mutex2-2.5 {69 sqlite3_auto_extension_sqr70 } {7}71}72do_test mutex2-2.6 {73 sqlite3_reset_auto_extension74} {}75do_test mutex2-2.7 {76 sqlite3_malloc 1000077} {0}78do_test mutex2-2.8 {79 sqlite3_realloc 0 1000080} {0}81ifcapable threadsafe {82 do_test mutex2-2.9 {83 alloc_dealloc_mutex84 } {0}85}86do_test mutex2-2.10 {87 vfs_initfail_test88} {}89 90# Restore the system to a functional state91#92install_mutex_counters 093set disable_mutex_init 094autoinstall_test_functions95 96# Mutex allocation works now.97#98 99do_test mutex2-3.1 {100 set ptr [alloc_dealloc_mutex]101 expr {$ptr!=0}102} {1}103 104 105finish_test106 