xref: /sqlite-3.40.0/ext/session/sessionmem.test (revision a2560ce9)
1*a2560ce9Sdan# 2020 December 23
2*a2560ce9Sdan#
3*a2560ce9Sdan# The author disclaims copyright to this source code.  In place of
4*a2560ce9Sdan# a legal notice, here is a blessing:
5*a2560ce9Sdan#
6*a2560ce9Sdan#    May you do good and not evil.
7*a2560ce9Sdan#    May you find forgiveness for yourself and forgive others.
8*a2560ce9Sdan#    May you share freely, never taking more than you give.
9*a2560ce9Sdan#
10*a2560ce9Sdan#***********************************************************************
11*a2560ce9Sdan# This file implements regression tests for the SQLite sessions module
12*a2560ce9Sdan# Specifically, for the sqlite3session_memory_used() API.
13*a2560ce9Sdan#
14*a2560ce9Sdan
15*a2560ce9Sdanif {![info exists testdir]} {
16*a2560ce9Sdan  set testdir [file join [file dirname [info script]] .. .. test]
17*a2560ce9Sdan}
18*a2560ce9Sdansource [file join [file dirname [info script]] session_common.tcl]
19*a2560ce9Sdansource $testdir/tester.tcl
20*a2560ce9Sdanifcapable !session {finish_test; return}
21*a2560ce9Sdan
22*a2560ce9Sdanset testprefix sessionmem
23*a2560ce9Sdan
24*a2560ce9Sdando_execsql_test 1.0 {
25*a2560ce9Sdan  CREATE TABLE t1(i INTEGER PRIMARY KEY, x, y);
26*a2560ce9Sdan  CREATE TABLE t2(i INTEGER, x, y, PRIMARY KEY(x, y));
27*a2560ce9Sdan}
28*a2560ce9Sdan
29*a2560ce9Sdando_test 1.1 {
30*a2560ce9Sdan  sqlite3session S db main
31*a2560ce9Sdan  S attach *
32*a2560ce9Sdan} {}
33*a2560ce9Sdan
34*a2560ce9Sdanforeach {tn sql eRes} {
35*a2560ce9Sdan  1 { INSERT INTO t1 VALUES(1, 2, 3) } 1
36*a2560ce9Sdan  2 { UPDATE t1 SET x=5 }                    0
37*a2560ce9Sdan  3 { UPDATE t1 SET i=5 }                    1
38*a2560ce9Sdan  4 { DELETE FROM t1 }                       0
39*a2560ce9Sdan  5 { INSERT INTO t1 VALUES(1, 2, 3) }       0
40*a2560ce9Sdan  6 { INSERT INTO t1 VALUES(5, 2, 3) }       0
41*a2560ce9Sdan  7 { INSERT INTO t2 VALUES('a', 'b', 'c') } 1
42*a2560ce9Sdan  8 { INSERT INTO t2 VALUES('d', 'e', 'f') } 1
43*a2560ce9Sdan  9 { UPDATE t2 SET i='e' }                  0
44*a2560ce9Sdan} {
45*a2560ce9Sdan  set mem1 [S memory_used]
46*a2560ce9Sdan  do_test 1.2.$tn.(mu=$mem1) {
47*a2560ce9Sdan    execsql $sql
48*a2560ce9Sdan    set mem2 [S memory_used]
49*a2560ce9Sdan    expr {$mem2 > $mem1}
50*a2560ce9Sdan  } $eRes
51*a2560ce9Sdan}
52*a2560ce9Sdan
53*a2560ce9Sdando_test 1.3 {
54*a2560ce9Sdan  S delete
55*a2560ce9Sdan} {}
56*a2560ce9Sdan
57*a2560ce9Sdanfinish_test
58