1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/incrvacuum2.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,146 @@
1.4 +# 2007 May 04
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. The
1.15 +# focus of this file is testing the incremental vacuum feature.
1.16 +#
1.17 +# $Id: incrvacuum2.test,v 1.5 2008/05/07 07:13:16 danielk1977 Exp $
1.18 +
1.19 +set testdir [file dirname $argv0]
1.20 +source $testdir/tester.tcl
1.21 +
1.22 +# If this build of the library does not support auto-vacuum, omit this
1.23 +# whole file.
1.24 +ifcapable {!autovacuum || !pragma} {
1.25 + finish_test
1.26 + return
1.27 +}
1.28 +
1.29 +# If the OMIT_INCRBLOB symbol was defined at compile time, there
1.30 +# is no zeroblob() function available. So create a similar
1.31 +# function here using Tcl. It doesn't return a blob, but it returns
1.32 +# data of the required length, which is good enough for this
1.33 +# test file.
1.34 +ifcapable !incrblob {
1.35 + proc zeroblob {n} { string repeat 0 $n }
1.36 + db function zeroblob zeroblob
1.37 +}
1.38 +
1.39 +
1.40 +# Create a database in incremental vacuum mode that has many
1.41 +# pages on the freelist.
1.42 +#
1.43 +do_test incrvacuum2-1.1 {
1.44 + execsql {
1.45 + PRAGMA page_size=1024;
1.46 + PRAGMA auto_vacuum=incremental;
1.47 + CREATE TABLE t1(x);
1.48 + INSERT INTO t1 VALUES(zeroblob(30000));
1.49 + DELETE FROM t1;
1.50 + }
1.51 + file size test.db
1.52 +} {32768}
1.53 +
1.54 +# Vacuum off a single page.
1.55 +#
1.56 +do_test incrvacuum2-1.2 {
1.57 + execsql {
1.58 + PRAGMA incremental_vacuum(1);
1.59 + }
1.60 + file size test.db
1.61 +} {31744}
1.62 +
1.63 +# Vacuum off five pages
1.64 +#
1.65 +do_test incrvacuum2-1.3 {
1.66 + execsql {
1.67 + PRAGMA incremental_vacuum(5);
1.68 + }
1.69 + file size test.db
1.70 +} {26624}
1.71 +
1.72 +# Vacuum off all the rest
1.73 +#
1.74 +do_test incrvacuum2-1.4 {
1.75 + execsql {
1.76 + PRAGMA incremental_vacuum(1000);
1.77 + }
1.78 + file size test.db
1.79 +} {3072}
1.80 +
1.81 +# Make sure incremental vacuum works on attached databases.
1.82 +#
1.83 +ifcapable attach {
1.84 + do_test incrvacuum2-2.1 {
1.85 + file delete -force test2.db test2.db-journal
1.86 + execsql {
1.87 + ATTACH DATABASE 'test2.db' AS aux;
1.88 + PRAGMA aux.auto_vacuum=incremental;
1.89 + CREATE TABLE aux.t2(x);
1.90 + INSERT INTO t2 VALUES(zeroblob(30000));
1.91 + INSERT INTO t1 SELECT * FROM t2;
1.92 + DELETE FROM t2;
1.93 + DELETE FROM t1;
1.94 + }
1.95 + list [file size test.db] [file size test2.db]
1.96 + } {32768 32768}
1.97 + do_test incrvacuum2-2.2 {
1.98 + execsql {
1.99 + PRAGMA aux.incremental_vacuum(1)
1.100 + }
1.101 + list [file size test.db] [file size test2.db]
1.102 + } {32768 31744}
1.103 + do_test incrvacuum2-2.3 {
1.104 + execsql {
1.105 + PRAGMA aux.incremental_vacuum(5)
1.106 + }
1.107 + list [file size test.db] [file size test2.db]
1.108 + } {32768 26624}
1.109 + do_test incrvacuum2-2.4 {
1.110 + execsql {
1.111 + PRAGMA main.incremental_vacuum(5)
1.112 + }
1.113 + list [file size test.db] [file size test2.db]
1.114 + } {27648 26624}
1.115 + do_test incrvacuum2-2.5 {
1.116 + execsql {
1.117 + PRAGMA aux.incremental_vacuum
1.118 + }
1.119 + list [file size test.db] [file size test2.db]
1.120 + } {27648 3072}
1.121 + do_test incrvacuum2-2.6 {
1.122 + execsql {
1.123 + PRAGMA incremental_vacuum(1)
1.124 + }
1.125 + list [file size test.db] [file size test2.db]
1.126 + } {26624 3072}
1.127 +}
1.128 +
1.129 +do_test incrvacuum2-3.1 {
1.130 + execsql {
1.131 + PRAGMA auto_vacuum = 'full';
1.132 + BEGIN;
1.133 + CREATE TABLE abc(a);
1.134 + INSERT INTO abc VALUES(randstr(1500,1500));
1.135 + COMMIT;
1.136 + }
1.137 +} {}
1.138 +do_test incrvacuum2-3.2 {
1.139 + execsql {
1.140 + BEGIN;
1.141 + DELETE FROM abc;
1.142 + PRAGMA incremental_vacuum;
1.143 + COMMIT;
1.144 + }
1.145 +} {}
1.146 +
1.147 +integrity_check incremental2-3.3
1.148 +
1.149 +finish_test