Debian Codegraph @

ext/session/sessionmem.test

raw
1 # 2020 December 23
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 # This file implements regression tests for the SQLite sessions module
12 # Specifically, for the sqlite3session_memory_used() API.
13 #
14
15 if {![info exists testdir]} {
16 set testdir [file join [file dirname [info script]] .. .. test]
17 }
18 source [file join [file dirname [info script]] session_common.tcl]
19 source $testdir/tester.tcl
20 ifcapable !session {finish_test; return}
21
22 set testprefix sessionmem
23
24 do_execsql_test 1.0 {
25 CREATE TABLE t1(i INTEGER PRIMARY KEY, x, y);
26 CREATE TABLE t2(i INTEGER, x, y, PRIMARY KEY(x, y));
27 }
28
29 do_test 1.1 {
30 sqlite3session S db main
31 S attach *
32 } {}
33
34 foreach {tn sql eRes} {
35 1 { INSERT INTO t1 VALUES(1, 2, 3) } 1
36 2 { UPDATE t1 SET x=5 } 0
37 3 { UPDATE t1 SET i=5 } 1
38 4 { DELETE FROM t1 } 0
39 5 { INSERT INTO t1 VALUES(1, 2, 3) } 0
40 6 { INSERT INTO t1 VALUES(5, 2, 3) } 0
41 7 { INSERT INTO t2 VALUES('a', 'b', 'c') } 1
42 8 { INSERT INTO t2 VALUES('d', 'e', 'f') } 1
43 9 { UPDATE t2 SET i='e' } 0
44 } {
45 set mem1 [S memory_used]
46 do_test 1.2.$tn.(mu=$mem1) {
47 execsql $sql
48 set mem2 [S memory_used]
49 expr {$mem2 > $mem1}
50 } $eRes
51 }
52
53 do_test 1.3 {
54 S delete
55 } {}
56
57 finish_test