os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/async2.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/async2.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,129 @@
     1.4 +#
     1.5 +#    May you do good and not evil.
     1.6 +#    May you find forgiveness for yourself and forgive others.
     1.7 +#    May you share freely, never taking more than you give.
     1.8 +#
     1.9 +#***********************************************************************
    1.10 +#
    1.11 +# $Id: async2.test,v 1.9 2007/11/05 17:01:08 danielk1977 Exp $
    1.12 +
    1.13 +
    1.14 +set testdir [file dirname $argv0]
    1.15 +source $testdir/tester.tcl
    1.16 +
    1.17 +if {
    1.18 +  [info commands sqlite3async_enable]=="" ||
    1.19 +  [info command sqlite3_memdebug_fail]==""
    1.20 +} {
    1.21 +  # The async logic is not built into this system
    1.22 +  puts "Skipping async2 tests: not compiled with required features"
    1.23 +  finish_test
    1.24 +  return
    1.25 +}
    1.26 +
    1.27 +# Enable asynchronous IO.
    1.28 +
    1.29 +set setup_script {
    1.30 +  CREATE TABLE counter(c);
    1.31 +  INSERT INTO counter(c) VALUES (1);
    1.32 +} 
    1.33 +
    1.34 +set sql_script {
    1.35 +  BEGIN;
    1.36 +    UPDATE counter SET c = 2;
    1.37 +    CREATE TABLE t1(a PRIMARY KEY, b, c);
    1.38 +    CREATE TABLE t2(a PRIMARY KEY, b, c);
    1.39 +  COMMIT;
    1.40 +
    1.41 +  BEGIN;
    1.42 +    UPDATE counter SET c = 3;
    1.43 +    INSERT INTO t1 VALUES('abcdefghij', 'four', 'score');
    1.44 +    INSERT INTO t2 VALUES('klmnopqrst', 'and', 'seven');
    1.45 +  COMMIT;
    1.46 +
    1.47 +  UPDATE counter SET c = 'FIN';
    1.48 +}
    1.49 +
    1.50 +db close
    1.51 +
    1.52 +foreach err [list ioerr malloc-transient malloc-persistent] {
    1.53 +  set ::go 1
    1.54 +  for {set n 1} {$::go} {incr n} {
    1.55 +    set ::sqlite_io_error_pending 0
    1.56 +    sqlite3_memdebug_fail -1
    1.57 +    file delete -force test.db test.db-journal
    1.58 +    sqlite3 db test.db
    1.59 +    execsql $::setup_script
    1.60 +    db close
    1.61 +  
    1.62 +    sqlite3async_enable 1
    1.63 +    sqlite3 db test.db
    1.64 +  
    1.65 +    switch -- $err {
    1.66 +      ioerr             { set ::sqlite_io_error_pending $n }
    1.67 +      malloc-persistent { sqlite3_memdebug_fail $n -repeat 1 }
    1.68 +      malloc-transient  { sqlite3_memdebug_fail $n -repeat 0 }
    1.69 +    }
    1.70 +
    1.71 +    catchsql $::sql_script
    1.72 +    db close
    1.73 +
    1.74 +    sqlite3async_halt idle
    1.75 +    sqlite3async_start
    1.76 +    sqlite3async_wait
    1.77 +    sqlite3async_halt never
    1.78 +    sqlite3async_enable 0
    1.79 +
    1.80 +    set ::sqlite_io_error_pending 0
    1.81 +    sqlite3_memdebug_fail -1
    1.82 +
    1.83 +    sqlite3 db test.db
    1.84 +    set c [db eval {SELECT c FROM counter LIMIT 1}]
    1.85 +    switch -- $c {
    1.86 +      1 {
    1.87 +        do_test async-$err-1.1.$n {
    1.88 +          execsql {
    1.89 +            SELECT name FROM sqlite_master;
    1.90 +          }
    1.91 +        } {counter}
    1.92 +      }
    1.93 +      2 {
    1.94 +        do_test async-$err-1.2.$n.1 {
    1.95 +          execsql {
    1.96 +            SELECT * FROM t1;
    1.97 +          }
    1.98 +        } {}
    1.99 +        do_test async-$err-1.2.$n.2 {
   1.100 +          execsql {
   1.101 +            SELECT * FROM t2;
   1.102 +          }
   1.103 +        } {}
   1.104 +      }
   1.105 +      3 {
   1.106 +        do_test async-$err-1.3.$n.1 {
   1.107 +          execsql {
   1.108 +            SELECT * FROM t1;
   1.109 +          }
   1.110 +        } {abcdefghij four score}
   1.111 +        do_test async-$err-1.3.$n.2 {
   1.112 +          execsql {
   1.113 +            SELECT * FROM t2;
   1.114 +          }
   1.115 +        } {klmnopqrst and seven}
   1.116 +      }
   1.117 +      FIN {
   1.118 +        set ::go 0
   1.119 +      }
   1.120 +    }
   1.121 +  
   1.122 +    db close
   1.123 +  }
   1.124 +}
   1.125 +
   1.126 +catch {db close}
   1.127 +sqlite3async_halt idle
   1.128 +sqlite3async_start
   1.129 +sqlite3async_wait
   1.130 +sqlite3async_halt never
   1.131 +
   1.132 +finish_test