os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/mutex2.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/mutex2.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,101 @@
     1.4 +# 2008 July 7
     1.5 +#
     1.6 +# The author disclaims copyright to this source code.  In place of
     1.7 +# a legal notice, here is a blessing:
     1.8 +#
     1.9 +#    May you do good and not evil.
    1.10 +#    May you find forgiveness for yourself and forgive others.
    1.11 +#    May you share freely, never taking more than you give.
    1.12 +#
    1.13 +#***********************************************************************
    1.14 +#
    1.15 +# Test scripts for deliberate failures of mutex routines.
    1.16 +#
    1.17 +# $Id: mutex2.test,v 1.8 2008/07/19 13:43:24 danielk1977 Exp $
    1.18 +
    1.19 +set testdir [file dirname $argv0]
    1.20 +source $testdir/tester.tcl
    1.21 +
    1.22 +# deinitialize
    1.23 +#
    1.24 +catch {db close}
    1.25 +sqlite3_reset_auto_extension
    1.26 +sqlite3_shutdown
    1.27 +install_mutex_counters 1
    1.28 +
    1.29 +# Fix the mutex subsystem so that it will not initialize.  In other words,
    1.30 +# make it so that sqlite3_initialize() always fails.  
    1.31 +#
    1.32 +do_test mutex2-1.1 {
    1.33 +  set ::disable_mutex_init 10
    1.34 +  sqlite3_initialize
    1.35 +} {SQLITE_IOERR}
    1.36 +do_test mutex2-1.1 {
    1.37 +  set ::disable_mutex_init 7
    1.38 +  sqlite3_initialize
    1.39 +} {SQLITE_NOMEM}
    1.40 +
    1.41 +proc utf16 {str} {
    1.42 +  set r [encoding convertto unicode $str]
    1.43 +  append r "\x00\x00"
    1.44 +  return $r
    1.45 +}
    1.46 +
    1.47 +# Now that sqlite3_initialize() is failing, try to run various APIs that
    1.48 +# require that SQLite be initialized.  Verify that they fail.
    1.49 +#
    1.50 +do_test mutex2-2.1 {
    1.51 +  set ::disable_mutex_init 7
    1.52 +  set rc [catch {sqlite db test.db} msg]
    1.53 +  lappend rc $msg
    1.54 +} {1 {}}
    1.55 +ifcapable utf16 {
    1.56 +  do_test mutex2-2.2 {
    1.57 +    set db2 [sqlite3_open16 [utf16 test.db] {}]
    1.58 +  } {0}
    1.59 +  do_test mutex2-2.3 {
    1.60 +    sqlite3_complete16 [utf16 {SELECT * FROM t1;}]
    1.61 +  } {7}
    1.62 +}
    1.63 +do_test mutex2-2.4 {
    1.64 +  sqlite3_mprintf_int {This is a test %d,%d,%d} 1 2 3
    1.65 +} {}
    1.66 +ifcapable load_ext {
    1.67 +  do_test mutex2-2.5 {
    1.68 +    sqlite3_auto_extension_sqr
    1.69 +  } {7}
    1.70 +}
    1.71 +do_test mutex2-2.6 {
    1.72 +  sqlite3_reset_auto_extension
    1.73 +} {}
    1.74 +do_test mutex2-2.7 {
    1.75 +  sqlite3_malloc 10000
    1.76 +} {0}
    1.77 +do_test mutex2-2.8 {
    1.78 +  sqlite3_realloc 0 10000
    1.79 +} {0}
    1.80 +ifcapable threadsafe {
    1.81 +  do_test mutex2-2.9 {
    1.82 +    alloc_dealloc_mutex
    1.83 +  } {0}
    1.84 +}
    1.85 +do_test mutex2-2.10 {
    1.86 +  vfs_initfail_test
    1.87 +} {}
    1.88 +
    1.89 +# Restore the system to a functional state
    1.90 +#
    1.91 +install_mutex_counters 0
    1.92 +set disable_mutex_init 0
    1.93 +autoinstall_test_functions
    1.94 +
    1.95 +# Mutex allocation works now.
    1.96 +#
    1.97 +
    1.98 +do_test mutex2-3.1 {
    1.99 +  set ptr [alloc_dealloc_mutex]
   1.100 +  expr {$ptr!=0}
   1.101 +} {1}
   1.102 +
   1.103 +
   1.104 +finish_test