os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/capi3d.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.
     1 # 2008 June 18
     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 # This file implements regression tests for SQLite library.  
    12 #
    13 # This file is devoted to testing the sqlite3_next_stmt interface.
    14 #
    15 # $Id: capi3d.test,v 1.2 2008/07/14 15:11:20 drh Exp $
    16 #
    17 
    18 set testdir [file dirname $argv0]
    19 source $testdir/tester.tcl
    20 
    21 # Create N prepared statements against database connection db
    22 # and return a list of all the generated prepared statements.
    23 #
    24 proc make_prepared_statements {N} {
    25   set plist {}
    26   for {set i 0} {$i<$N} {incr i} {
    27     set sql "SELECT $i FROM sqlite_master WHERE name LIKE '%$i%'"
    28     if {rand()<0.33} {    
    29       set s [sqlite3_prepare_v2 db $sql -1 notused]
    30     } else {
    31       ifcapable utf16 {
    32         if {rand()<0.5} {
    33           set sql [encoding convertto unicode $sql]\x00\x00
    34           set s [sqlite3_prepare16 db $sql -1 notused]
    35         } else {
    36           set s [sqlite3_prepare db $sql -1 notused]
    37         }
    38       }
    39       ifcapable !utf16 {
    40         set s [sqlite3_prepare db $sql -1 notused]
    41       }
    42     }
    43     lappend plist $s
    44   }
    45   return $plist
    46 }
    47 
    48 
    49 # Scramble the $inlist into a random order.
    50 #
    51 proc scramble {inlist} {
    52   set y {}
    53   foreach x $inlist {
    54     lappend y [list [expr {rand()}] $x]
    55   }
    56   set y [lsort $y]
    57   set outlist {}
    58   foreach x $y {
    59     lappend outlist [lindex $x 1]
    60   }
    61   return $outlist
    62 }
    63 
    64 # Database initially has no prepared statements.
    65 #
    66 do_test capi3d-1.1 {
    67   db cache flush
    68   sqlite3_next_stmt db 0
    69 } {}
    70 
    71 # Run the following tests for between 1 and 100 prepared statements.
    72 #
    73 for {set i 1} {$i<=100} {incr i} {
    74   set stmtlist [make_prepared_statements $i]
    75   do_test capi3d-1.2.$i.1 {
    76     set p [sqlite3_next_stmt db 0]
    77     set x {}
    78     while {$p!=""} {
    79       lappend x $p
    80       set p [sqlite3_next_stmt db $p]
    81     }
    82     lsort $x
    83   } [lsort $stmtlist]
    84   do_test capi3-1.2.$i.2 {
    85     foreach p [scramble $::stmtlist] {
    86       sqlite3_finalize $p
    87     }
    88     sqlite3_next_stmt db 0
    89   } {}
    90 }
    91       
    92 
    93 finish_test