000001  # 2011 November 16
000002  #
000003  # The author disclaims copyright to this source code.  In place of
000004  # a legal notice, here is a blessing:
000005  #
000006  #    May you do good and not evil.
000007  #    May you find forgiveness for yourself and forgive others.
000008  #    May you share freely, never taking more than you give.
000009  #
000010  #***********************************************************************
000011  #
000012  # This file contains test cases for sqlite3_db_release_memory and
000013  # the PRAGMA shrink_memory statement.
000014  #
000015  
000016  set testdir [file dirname $argv0]
000017  source $testdir/tester.tcl
000018  test_set_config_pagecache 0 0
000019  
000020  unset -nocomplain baseline
000021  do_test shrink-1.1 {
000022    db eval {
000023      PRAGMA cache_size = 2000;
000024      CREATE TABLE t1(x,y);
000025      INSERT INTO t1 VALUES(randomblob(1000000),1);
000026    }
000027    set ::baseline sqlite3_memory_used
000028    # EVIDENCE-OF: R-58814-63508 The sqlite3_db_release_memory(D) interface
000029    # attempts to free as much heap memory as possible from database
000030    # connection D.
000031    sqlite3_db_release_memory db
000032    expr {$::baseline > [sqlite3_memory_used]+500000}
000033  } {1}
000034  do_test shrink-1.2 {
000035    set baseline [sqlite3_memory_used]
000036    db eval {
000037      UPDATE t1 SET y=y+1;
000038    }
000039    expr {$::baseline+500000 < [sqlite3_memory_used]}
000040  } {1}
000041  do_test shrink-1.3 {
000042    set baseline [sqlite3_memory_used]
000043    db eval {PRAGMA shrink_memory}
000044    expr {$::baseline > [sqlite3_memory_used]+500000}
000045  } {1}
000046  
000047  test_restore_config_pagecache
000048  finish_test