persistentstorage/sqlite3api/TEST/TclScript/lookaside.test
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 # 2008 August 01
       
     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 #
       
    12 # Tests for the lookaside memory allocator.
       
    13 #
       
    14 # $Id: lookaside.test,v 1.6 2008/09/30 00:31:38 drh Exp $
       
    15 
       
    16 set testdir [file dirname $argv0]
       
    17 source $testdir/tester.tcl
       
    18 
       
    19 catch {db close}
       
    20 sqlite3_shutdown
       
    21 sqlite3_config_pagecache 0 0
       
    22 sqlite3_config_scratch 0 0
       
    23 sqlite3_initialize
       
    24 sqlite3 db test.db
       
    25 
       
    26 # Make sure sqlite3_db_config() and sqlite3_db_status are working.
       
    27 #
       
    28 do_test lookaside-1.1 {
       
    29   catch {sqlite3_config_error db}
       
    30 } {0}
       
    31 do_test lookaside-1.2 {
       
    32   sqlite3_db_config_lookaside db 1 18 18
       
    33 } {0}
       
    34 do_test lookaside-1.3 {
       
    35   sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
       
    36 } {0 0 0}
       
    37 do_test lookaside-1.4 {
       
    38   db eval {CREATE TABLE t1(w,x,y,z);}
       
    39   foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
       
    40   expr {$x==0 && $y<$z && $z==18}
       
    41 } {1}
       
    42 do_test lookaside-1.5 {
       
    43   foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1] break
       
    44   expr {$x==0 && $y<$z && $z==18}
       
    45 } {1}
       
    46 do_test lookaside-1.6 {
       
    47   foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
       
    48   expr {$x==0 && $y==$z && $y<18}
       
    49 } {1}
       
    50 do_test lookaside-1.7 {
       
    51   db cache flush
       
    52   foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
       
    53   expr {$x==0 && $y==0 && $z<18}
       
    54 } {1}
       
    55 do_test lookaside-1.8 {
       
    56   db cache flush
       
    57   foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1] break
       
    58   expr {$x==0 && $y==0 && $z<18}
       
    59 } {1}
       
    60 do_test lookaside-1.9 {
       
    61   db cache flush
       
    62   sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
       
    63 } {0 0 0}
       
    64 
       
    65 do_test lookaside-2.1 {
       
    66   sqlite3_db_config_lookaside db 0 100 1000
       
    67 } {0}
       
    68 do_test lookaside-2.2 {
       
    69   db eval {CREATE TABLE t2(x);}
       
    70   foreach {x y z} [sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0] break
       
    71   expr {$x==0 && $y<$z && $z>10 && $z<100}
       
    72 } {1}
       
    73 do_test lookaside-2.3 {
       
    74   sqlite3_db_config_lookaside db 0 50 50
       
    75 } {5}  ;# SQLITE_BUSY
       
    76 do_test lookaside-2.4 {
       
    77   db cache flush
       
    78   sqlite3_db_config_lookaside db 0 50 50
       
    79 } {0}  ;# SQLITE_OK
       
    80 
       
    81 # sqlite3_db_status() with an invalid verb returns an error.
       
    82 #
       
    83 do_test lookaside-3.1 {
       
    84   sqlite3_db_status db 99999 0
       
    85 } {1 0 0}
       
    86 
       
    87 # Test that an invalid verb on sqlite3_config() is detected and
       
    88 # reported as an error.
       
    89 #
       
    90 do_test lookaside-4.1 {
       
    91   db close
       
    92   sqlite3_shutdown
       
    93   catch sqlite3_config_error
       
    94 } {0}
       
    95 sqlite3_initialize
       
    96 
       
    97 finish_test