replace use of sqlite3StrICmp with public sqlite3_stricmp API
[sqlcipher.git] / ext / rbu / rbutemplimit.test
blob958b2bfcbc6c63878d9454bc03e2800957fafc6d
1 # 2014 August 30
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 #***********************************************************************
13 source [file join [file dirname [info script]] rbu_common.tcl]
14 set ::testprefix rbutemplimit
16 db close
17 sqlite3_shutdown
18 sqlite3_config_uri 1
20 proc setup_databases {} {
21   forcedelete test.db2
22   forcedelete test.db
23   sqlite3 db test.db
24   execsql {
25     -- Create target database schema.
26     --
27     CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB(100), c BLOB(100));
28     CREATE TABLE t2(a INTEGER PRIMARY KEY, b BLOB(100), c BLOB(100));
29     CREATE INDEX i1b ON t1(b);
30     CREATE INDEX i1c ON t1(c);
31     CREATE INDEX i2b ON t2(b);
32     CREATE INDEX i2c ON t2(c);
33   
34     -- Create a large RBU database.
35     --
36     ATTACH 'test.db2' AS rbu;
37     CREATE TABLE rbu.data_t1(a, b, c, rbu_control);
38     WITH s(i) AS (
39       VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<10000
40     )
41     INSERT INTO data_t1 SELECT i, randomblob(100), randomblob(100), 0 FROM s;
42     CREATE TABLE rbu.data_t2(a, b, c, rbu_control);
43     WITH s(i) AS (
44       VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<15000
45     )
46     INSERT INTO data_t2 SELECT i, randomblob(100), randomblob(100), 0 FROM s;
47   }
48   db close
51 proc run_rbu_cachesize {target rbu cachesize temp_limit} {
52   sqlite3rbu rbu $target $rbu
53   rbu temp_size_limit $temp_limit
54   sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize"
55   while 1 {
56     set rc [rbu step]
57     set ::A([rbu temp_size]) 1
58     if {$rc!="SQLITE_OK"} break
59   }
60   list [catch {rbu close} msg] $msg
63 proc step_rbu_cachesize {target rbu stepsize cachesize temp_limit} {
64   set res ""
65   while 1 {
66     sqlite3rbu rbu $target $rbu
67     rbu temp_size_limit $temp_limit
68     if { [rbu temp_size_limit -1]!=$temp_limit } { error "round trip problem!" }
69     sqlite3_exec_nr [rbu db 1] "PRAGMA cache_size = $cachesize"
70     for {set i 0} {$i < $stepsize} {incr i} {
71       set rc [rbu step]
72       set ::A([rbu temp_size]) 1
73       if {$rc!="SQLITE_OK"} break
74     }
75     set res [list [catch {rbu close} msg] $msg]
76     if {$res != "0 SQLITE_OK"} break
77   }
78   set res
81 do_test 1.1.0 { setup_databases } {}
83 do_test 1.1.1 {
84   unset -nocomplain ::A
85   run_rbu_cachesize test.db test.db2 10 0
86 } {0 SQLITE_DONE}
88 do_test 1.1.2 { llength [array names ::A] } 3
90 do_test 1.1.3 { 
91   foreach {a0 a1 a2} [lsort -integer [array names ::A]] {}
92   list [expr $a0==0]                         \
93        [expr $a1>1048576] [expr $a1<1200000] \
94        [expr $a2>1500000] [expr $a2<1700000]
95 } {1 1 1 1 1}
97 do_test 1.2.1 {
98   setup_databases
99   run_rbu_cachesize test.db test.db2 10 1000000
100 } {1 SQLITE_FULL}
101 do_test 1.2.2 { info commands rbu } {}
103 do_test 1.3.1 {
104   setup_databases
105   run_rbu_cachesize test.db test.db2 10 1300000
106 } {1 SQLITE_FULL}
107 do_test 1.3.2 { info commands rbu } {}
109 do_test 1.4.1 {
110   setup_databases
111   run_rbu_cachesize test.db test.db2 10 1800000
112 } {0 SQLITE_DONE}
113 do_test 1.4.2 { info commands rbu } {}
115 do_test 1.5.1 {
116   setup_databases
117   unset -nocomplain ::A
118   step_rbu_cachesize test.db test.db2 1000 10 2400000
119 } {0 SQLITE_DONE}
120 do_test 1.5.2 { info commands rbu } {}
122 do_test 1.6.1 {
123   setup_databases
124   unset -nocomplain ::A
125   step_rbu_cachesize test.db test.db2 1000 10 1400000
126 } {1 SQLITE_FULL}
127 do_test 1.6.2 { info commands rbu } {}
129 finish_test