persistentstorage/sqlite3api/TEST/TclScript/mutex2.test
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 # 2008 July 7
       
     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 #
       
    12 # Test scripts for deliberate failures of mutex routines.
       
    13 #
       
    14 # $Id: mutex2.test,v 1.8 2008/07/19 13:43:24 danielk1977 Exp $
       
    15 
       
    16 set testdir [file dirname $argv0]
       
    17 source $testdir/tester.tcl
       
    18 
       
    19 # deinitialize
       
    20 #
       
    21 catch {db close}
       
    22 sqlite3_reset_auto_extension
       
    23 sqlite3_shutdown
       
    24 install_mutex_counters 1
       
    25 
       
    26 # Fix the mutex subsystem so that it will not initialize.  In other words,
       
    27 # make it so that sqlite3_initialize() always fails.  
       
    28 #
       
    29 do_test mutex2-1.1 {
       
    30   set ::disable_mutex_init 10
       
    31   sqlite3_initialize
       
    32 } {SQLITE_IOERR}
       
    33 do_test mutex2-1.1 {
       
    34   set ::disable_mutex_init 7
       
    35   sqlite3_initialize
       
    36 } {SQLITE_NOMEM}
       
    37 
       
    38 proc utf16 {str} {
       
    39   set r [encoding convertto unicode $str]
       
    40   append r "\x00\x00"
       
    41   return $r
       
    42 }
       
    43 
       
    44 # Now that sqlite3_initialize() is failing, try to run various APIs that
       
    45 # require that SQLite be initialized.  Verify that they fail.
       
    46 #
       
    47 do_test mutex2-2.1 {
       
    48   set ::disable_mutex_init 7
       
    49   set rc [catch {sqlite db test.db} msg]
       
    50   lappend rc $msg
       
    51 } {1 {}}
       
    52 ifcapable utf16 {
       
    53   do_test mutex2-2.2 {
       
    54     set db2 [sqlite3_open16 [utf16 test.db] {}]
       
    55   } {0}
       
    56   do_test mutex2-2.3 {
       
    57     sqlite3_complete16 [utf16 {SELECT * FROM t1;}]
       
    58   } {7}
       
    59 }
       
    60 do_test mutex2-2.4 {
       
    61   sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3
       
    62 } {}
       
    63 ifcapable load_ext {
       
    64   do_test mutex2-2.5 {
       
    65     sqlite3_auto_extension_sqr
       
    66   } {7}
       
    67 }
       
    68 do_test mutex2-2.6 {
       
    69   sqlite3_reset_auto_extension
       
    70 } {}
       
    71 do_test mutex2-2.7 {
       
    72   sqlite3_malloc 10000
       
    73 } {0}
       
    74 do_test mutex2-2.8 {
       
    75   sqlite3_realloc 0 10000
       
    76 } {0}
       
    77 ifcapable threadsafe {
       
    78   do_test mutex2-2.9 {
       
    79     alloc_dealloc_mutex
       
    80   } {0}
       
    81 }
       
    82 do_test mutex2-2.10 {
       
    83   vfs_initfail_test
       
    84 } {}
       
    85 
       
    86 # Restore the system to a functional state
       
    87 #
       
    88 install_mutex_counters 0
       
    89 set disable_mutex_init 0
       
    90 autoinstall_test_functions
       
    91 
       
    92 # Mutex allocation works now.
       
    93 #
       
    94 
       
    95 do_test mutex2-3.1 {
       
    96   set ptr [alloc_dealloc_mutex]
       
    97   expr {$ptr!=0}
       
    98 } {1}
       
    99 
       
   100 
       
   101 finish_test