sqlite/test/trace3.test
mistachkin b52dcd8989 More work on the Tcl interface and tests for the sqlite3_trace_v2() API.
FossilOrigin-Name: f3c4aa97d8c10fdb69efc6405b5fa45781f45a61
2016-07-14 23:17:03 +00:00

125 lines
3.2 KiB
Plaintext

# 2016 July 14
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The focus
# of this test file is the "sqlite3_trace_v2()" API.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !trace { finish_test ; return }
set ::testprefix trace3
proc trace_v2_error { args } {
lappend ::stmtlist(error) [string trim $args]
error "trace error"; # this will be ignored.
}
proc trace_v2_record { args } {
lappend ::stmtlist(record) [string trim $args]
}
proc trace_v2_nop { args } {}; # do nothing.
do_test trace3-1.0 {
execsql {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,NULL);
INSERT INTO t1 VALUES(2,-1);
INSERT INTO t1 VALUES(3,0);
INSERT INTO t1 VALUES(4,1);
INSERT INTO t1 VALUES(5,-2147483648);
INSERT INTO t1 VALUES(6,2147483647);
INSERT INTO t1 VALUES(7,-9223372036854775808);
INSERT INTO t1 VALUES(8,9223372036854775807);
INSERT INTO t1 VALUES(9,-1.0);
INSERT INTO t1 VALUES(10,0.0);
INSERT INTO t1 VALUES(11,1.0);
INSERT INTO t1 VALUES(12,'');
INSERT INTO t1 VALUES(13,'1');
INSERT INTO t1 VALUES(14,'one');
INSERT INTO t1 VALUES(15,x'abcd0123');
INSERT INTO t1 VALUES(16,x'4567cdef');
}
} {}
do_test trace3-1.1 {
set rc [catch {db trace_v2 1 2 3} msg]
lappend rc $msg
} {1 {wrong # args: should be "db trace_v2 ?CALLBACK? ?MASK?"}}
do_test trace3-1.2 {
set rc [catch {db trace_v2 1 bad} msg]
lappend rc $msg
} {1 {bad trace type "bad": must be statement, profile, row, or close}}
do_test trace3-2.1 {
db trace_v2 trace_v2_nop
db trace_v2
} {trace_v2_nop}
do_test trace3-3.1 {
unset -nocomplain ::stmtlist
db trace_v2 trace_v2_nop
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
array get ::stmtlist
} {}
do_test trace3-3.2 {
set ::stmtlist(error) {}
db trace_v2 trace_v2_error
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(error)
} {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
do_test trace3-3.3 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} {/^\{-?\d+ \{SELECT a, b FROM t1 ORDER BY a;\}\}$/}
do_test trace3-4.1 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record profile
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} {/^\{-?\d+ -?\d+\}$/}
do_test trace3-5.1 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record row
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} "/^[string trim [string repeat {\d+ } 16]]\$/"
do_test trace3-6.1 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record {profile row}
execsql {
SELECT a, b FROM t1 ORDER BY a;
}
set ::stmtlist(record)
} "/^[string trim [string repeat {-?\d+ } 16]] \\\{-?\\d+ -?\\d+\\\}\$/"
do_test trace3-7.1 {
set ::stmtlist(record) {}
db trace_v2 trace_v2_record close
db close
set ::stmtlist(record)
} {/^-?\d+$/}
finish_test