os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/async2.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#
sl@0
     2
#    May you do good and not evil.
sl@0
     3
#    May you find forgiveness for yourself and forgive others.
sl@0
     4
#    May you share freely, never taking more than you give.
sl@0
     5
#
sl@0
     6
#***********************************************************************
sl@0
     7
#
sl@0
     8
# $Id: async2.test,v 1.9 2007/11/05 17:01:08 danielk1977 Exp $
sl@0
     9
sl@0
    10
sl@0
    11
set testdir [file dirname $argv0]
sl@0
    12
source $testdir/tester.tcl
sl@0
    13
sl@0
    14
if {
sl@0
    15
  [info commands sqlite3async_enable]=="" ||
sl@0
    16
  [info command sqlite3_memdebug_fail]==""
sl@0
    17
} {
sl@0
    18
  # The async logic is not built into this system
sl@0
    19
  puts "Skipping async2 tests: not compiled with required features"
sl@0
    20
  finish_test
sl@0
    21
  return
sl@0
    22
}
sl@0
    23
sl@0
    24
# Enable asynchronous IO.
sl@0
    25
sl@0
    26
set setup_script {
sl@0
    27
  CREATE TABLE counter(c);
sl@0
    28
  INSERT INTO counter(c) VALUES (1);
sl@0
    29
} 
sl@0
    30
sl@0
    31
set sql_script {
sl@0
    32
  BEGIN;
sl@0
    33
    UPDATE counter SET c = 2;
sl@0
    34
    CREATE TABLE t1(a PRIMARY KEY, b, c);
sl@0
    35
    CREATE TABLE t2(a PRIMARY KEY, b, c);
sl@0
    36
  COMMIT;
sl@0
    37
sl@0
    38
  BEGIN;
sl@0
    39
    UPDATE counter SET c = 3;
sl@0
    40
    INSERT INTO t1 VALUES('abcdefghij', 'four', 'score');
sl@0
    41
    INSERT INTO t2 VALUES('klmnopqrst', 'and', 'seven');
sl@0
    42
  COMMIT;
sl@0
    43
sl@0
    44
  UPDATE counter SET c = 'FIN';
sl@0
    45
}
sl@0
    46
sl@0
    47
db close
sl@0
    48
sl@0
    49
foreach err [list ioerr malloc-transient malloc-persistent] {
sl@0
    50
  set ::go 1
sl@0
    51
  for {set n 1} {$::go} {incr n} {
sl@0
    52
    set ::sqlite_io_error_pending 0
sl@0
    53
    sqlite3_memdebug_fail -1
sl@0
    54
    file delete -force test.db test.db-journal
sl@0
    55
    sqlite3 db test.db
sl@0
    56
    execsql $::setup_script
sl@0
    57
    db close
sl@0
    58
  
sl@0
    59
    sqlite3async_enable 1
sl@0
    60
    sqlite3 db test.db
sl@0
    61
  
sl@0
    62
    switch -- $err {
sl@0
    63
      ioerr             { set ::sqlite_io_error_pending $n }
sl@0
    64
      malloc-persistent { sqlite3_memdebug_fail $n -repeat 1 }
sl@0
    65
      malloc-transient  { sqlite3_memdebug_fail $n -repeat 0 }
sl@0
    66
    }
sl@0
    67
sl@0
    68
    catchsql $::sql_script
sl@0
    69
    db close
sl@0
    70
sl@0
    71
    sqlite3async_halt idle
sl@0
    72
    sqlite3async_start
sl@0
    73
    sqlite3async_wait
sl@0
    74
    sqlite3async_halt never
sl@0
    75
    sqlite3async_enable 0
sl@0
    76
sl@0
    77
    set ::sqlite_io_error_pending 0
sl@0
    78
    sqlite3_memdebug_fail -1
sl@0
    79
sl@0
    80
    sqlite3 db test.db
sl@0
    81
    set c [db eval {SELECT c FROM counter LIMIT 1}]
sl@0
    82
    switch -- $c {
sl@0
    83
      1 {
sl@0
    84
        do_test async-$err-1.1.$n {
sl@0
    85
          execsql {
sl@0
    86
            SELECT name FROM sqlite_master;
sl@0
    87
          }
sl@0
    88
        } {counter}
sl@0
    89
      }
sl@0
    90
      2 {
sl@0
    91
        do_test async-$err-1.2.$n.1 {
sl@0
    92
          execsql {
sl@0
    93
            SELECT * FROM t1;
sl@0
    94
          }
sl@0
    95
        } {}
sl@0
    96
        do_test async-$err-1.2.$n.2 {
sl@0
    97
          execsql {
sl@0
    98
            SELECT * FROM t2;
sl@0
    99
          }
sl@0
   100
        } {}
sl@0
   101
      }
sl@0
   102
      3 {
sl@0
   103
        do_test async-$err-1.3.$n.1 {
sl@0
   104
          execsql {
sl@0
   105
            SELECT * FROM t1;
sl@0
   106
          }
sl@0
   107
        } {abcdefghij four score}
sl@0
   108
        do_test async-$err-1.3.$n.2 {
sl@0
   109
          execsql {
sl@0
   110
            SELECT * FROM t2;
sl@0
   111
          }
sl@0
   112
        } {klmnopqrst and seven}
sl@0
   113
      }
sl@0
   114
      FIN {
sl@0
   115
        set ::go 0
sl@0
   116
      }
sl@0
   117
    }
sl@0
   118
  
sl@0
   119
    db close
sl@0
   120
  }
sl@0
   121
}
sl@0
   122
sl@0
   123
catch {db close}
sl@0
   124
sqlite3async_halt idle
sl@0
   125
sqlite3async_start
sl@0
   126
sqlite3async_wait
sl@0
   127
sqlite3async_halt never
sl@0
   128
sl@0
   129
finish_test