/ Artifact Content
Login

Artifact 7480f4eb87c9883e0db47b97b57e23ee565f4248:


# 2008 August 01
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Tests for the lookaside memory allocator.
#
# $Id: lookaside.test,v 1.1 2008/08/01 16:31:14 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Make sure sqlite3_db_config() and sqlite3_db_status are working.
#
do_test lookaside-1.1 {
  catch {sqlite3_config_error db}
} {0}
do_test lookaside-1.2 {
  sqlite3_db_config_lookaside db 20 20
} {0}
do_test lookaside-1.3 {
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 0 0}
do_test lookaside-1.4 {
  db eval {CREATE TABLE t1(x);}
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 7 20}
do_test lookaside-1.5 {
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1
} {0 7 20}
do_test lookaside-1.6 {
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 7 7}
do_test lookaside-1.7 {
  db cache flush
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 0 7}
do_test lookaside-1.8 {
  db cache flush
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 1
} {0 0 7}
do_test lookaside-1.9 {
  db cache flush
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 0 0}

do_test lookaside-2.1 {
  sqlite3_db_config_lookaside db 100 1000
} {0}
do_test lookaside-2.2 {
  db eval {CREATE TABLE t2(x);}
  sqlite3_db_status db SQLITE_DBSTATUS_LOOKASIDE_USED 0
} {0 10 48}
do_test lookaside-2.3 {
  sqlite3_db_config_lookaside db 50 50
} {5}  ;# SQLITE_BUSY
do_test lookaside-2.4 {
  db cache flush
  sqlite3_db_config_lookaside db 50 50
} {0}  ;# SQLITE_OK

# sqlite3_db_status() with an invalid verb returns an error.
#
do_test lookaside-3.1 {
  sqlite3_db_status db 99999 0
} {1 0 0}

# Test that an invalid verb on sqlite3_config() is detected and
# reported as an error.
#
do_test lookaside-4.1 {
  db close
  sqlite3_shutdown
  catch sqlite3_config_error
} {0}
sqlite3_initialize