os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/manydb.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/manydb.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,91 @@
     1.4 +# 2005 October 3
     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 +# This file implements regression tests for SQLite library.
    1.15 +#
    1.16 +# This file implements tests the ability of the library to open
    1.17 +# many different databases at the same time without leaking memory.
    1.18 +#
    1.19 +# $Id: manydb.test,v 1.3 2006/01/11 01:08:34 drh Exp $
    1.20 +
    1.21 +set testdir [file dirname $argv0]
    1.22 +source $testdir/tester.tcl
    1.23 +
    1.24 +set N 300
    1.25 +
    1.26 +# First test how many file descriptors are available for use. To open a
    1.27 +# database for writing SQLite requires 3 file descriptors (the database, the
    1.28 +# journal and the directory).
    1.29 +set filehandles {}
    1.30 +catch {
    1.31 +  for {set i 0} {$i<($N * 3)} {incr i} {
    1.32 +    lappend filehandles [open testfile.1 w]
    1.33 +  }
    1.34 +}
    1.35 +foreach fd $filehandles {
    1.36 +  close $fd
    1.37 +}
    1.38 +catch {
    1.39 +  file delete -force testfile.1
    1.40 +}
    1.41 +set N [expr $i / 3]
    1.42 +
    1.43 +# Create a bunch of random database names
    1.44 +#
    1.45 +unset -nocomplain dbname
    1.46 +unset -nocomplain used
    1.47 +for {set i 0} {$i<$N} {incr i} {
    1.48 +  while 1 {
    1.49 +    set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db
    1.50 +    if {[info exists used($name)]} continue
    1.51 +    set dbname($i) $name
    1.52 +    set used($name) $i
    1.53 +    break
    1.54 +  }
    1.55 +}
    1.56 +
    1.57 +# Create a bunch of databases
    1.58 +#
    1.59 +for {set i 0} {$i<$N} {incr i} {
    1.60 +  do_test manydb-1.$i {
    1.61 +    sqlite3 db$i $dbname($i)
    1.62 +    execsql {
    1.63 +       CREATE TABLE t1(a,b);
    1.64 +       BEGIN;
    1.65 +       INSERT INTO t1 VALUES(1,2);
    1.66 +    } db$i
    1.67 +  } {}
    1.68 +}
    1.69 +
    1.70 +# Finish the transactions
    1.71 +#
    1.72 +for {set i 0} {$i<$N} {incr i} {
    1.73 +  do_test manydb-2.$i {
    1.74 +    execsql {
    1.75 +       COMMIT;
    1.76 +       SELECT * FROM t1;
    1.77 +    } db$i
    1.78 +  } {1 2}
    1.79 +}
    1.80 +
    1.81 +
    1.82 +# Close the databases and erase the files.
    1.83 +#
    1.84 +for {set i 0} {$i<$N} {incr i} {
    1.85 +  do_test manydb-3.$i {
    1.86 +    db$i close
    1.87 +    file delete -force $dbname($i)
    1.88 +  } {}
    1.89 +}
    1.90 +
    1.91 +
    1.92 +
    1.93 +
    1.94 +finish_test