Update tests in returning1.test to account for [c7896e88].
[sqlite.git] / test / autovacuum2.test
bloba3c409839e3bb3f76800dd37bf0f187bea1acf36
1 # 2021-10-15
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.  The
12 # focus of this file is testing the sqlite3_autovacuum_pages() interface
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
18 # If this build of the library does not support auto-vacuum, omit this
19 # whole file.
20 ifcapable {!autovacuum || !pragma} {
21   finish_test
22   return
25 # Demonstrate basic sqlite3_autovacuum_pages functionality
27 do_execsql_test autovacuum2-1.0 {
28   PRAGMA page_size=1024;
29   PRAGMA auto_vacuum=FULL;
30   CREATE TABLE t1(x);
31   VACUUM;
32   INSERT INTO t1(x) VALUES(zeroblob(10000));
33   PRAGMA page_count;
34 } {12}
35 proc autovac_page_callback {schema filesize freesize pagesize} {
36   global autovac_callback_data
37   lappend autovac_callback_data $schema $filesize $freesize $pagesize
38   return [expr {$freesize/2}]
40 sqlite3_autovacuum_pages db autovac_page_callback
41 set autovac_callback_data {}
42 do_execsql_test autovacuum2-1.1 {
43   BEGIN;
44   DELETE FROM t1;
45   PRAGMA freelist_count;
46   PRAGMA page_count;
47 } {9 12}
48 do_execsql_test autovacuum2-1.2 {
49   COMMIT;
50 } {}
51 do_test autovacuum2-1.3 {
52   set autovac_callback_data
53 } {main 12 9 1024}
54 do_execsql_test autovacuum2-1.4 {
55   PRAGMA freelist_count;
56   PRAGMA page_count;
57 } {5 8}
58 do_execsql_test autovacuum2-1.5 {
59   PRAGMA integrity_check;
60 } {ok}
62 # Disable the autovacuum-pages callback.  Then do any transaction.
63 # The database should shrink to minimal size
65 sqlite3_autovacuum_pages db
66 do_execsql_test autovacuum2-1.10 {
67   CREATE TABLE t2(x);
68   PRAGMA freelist_count;
69 } {0}
71 # Rig the autovacuum-pages callback to always return zero.  No
72 # autovacuum will happen.
74 proc autovac_page_callback_off {schema filesize freesize pagesize} {
75   return 0
77 sqlite3_autovacuum_pages db autovac_page_callback_off
78 do_execsql_test autovacuum2-1.20 {
79   BEGIN;
80   INSERT INTO t1(x) VALUES(zeroblob(10000));
81   DELETE FROM t1;
82   PRAGMA freelist_count;
83   COMMIT;
84   PRAGMA freelist_count;
85 } {9 9}
87 finish_test