1# 2019 Jan 3
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# This file contains tests for the RBU module. More specifically, it
13# contains tests to ensure that the sqlite3rbu_vacuum() API works as
14# expected.
15#
16
17source [file join [file dirname [info script]] rbu_common.tcl]
18set testprefix rbuvacuum3
19
20do_execsql_test 1.0 {
21  CREATE TABLE t1(a PRIMARY KEY, b, c);
22  CREATE INDEX i1b ON t1(b);
23  CREATE INDEX i1c ON t1(c);
24
25  WITH s(i) AS (
26    VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100
27  )
28  INSERT INTO t1 SELECT i, randomblob(100), randomblob(100) FROM s;
29}
30
31forcedelete state.db
32do_test 1.1 {
33  sqlite3rbu_vacuum rbu test.db state.db
34  while {1} {
35    set rc [rbu step]
36    if {$rc!="SQLITE_OK"} break
37    rbu savestate
38  }
39  rbu close
40} {SQLITE_DONE}
41
42do_test 1.2 {
43  sqlite3rbu_vacuum rbu test.db state.db
44  while {1} {
45    set rc [rbu step]
46    if {$rc!="SQLITE_OK"} break
47    rbu savestate
48  }
49  rbu close
50} {SQLITE_DONE}
51
52do_test 1.3 {
53  while {1} {
54    sqlite3rbu_vacuum rbu test.db state.db
55    set rc [rbu step]
56    if {$rc!="SQLITE_OK"} break
57    rbu savestate
58    rbu close
59  }
60  rbu close
61} {SQLITE_DONE}
62
63finish_test
64