xref: /sqlite-3.40.0/test/gcfault.test (revision 3043b532)
1*3043b532Sdan# 2016 December 30
2*3043b532Sdan#
3*3043b532Sdan# The author disclaims copyright to this source code.  In place of
4*3043b532Sdan# a legal notice, here is a blessing:
5*3043b532Sdan#
6*3043b532Sdan#    May you do good and not evil.
7*3043b532Sdan#    May you find forgiveness for yourself and forgive others.
8*3043b532Sdan#    May you share freely, never taking more than you give.
9*3043b532Sdan#
10*3043b532Sdan#***********************************************************************
11*3043b532Sdan# This file implements regression tests for SQLite library.  The
12*3043b532Sdan# focus of this file is testing OOM error handling within the built-in
13*3043b532Sdan# group_concat() function.
14*3043b532Sdan#
15*3043b532Sdan
16*3043b532Sdanset testdir [file dirname $argv0]
17*3043b532Sdansource $testdir/tester.tcl
18*3043b532Sdanset testprefix gcfault
19*3043b532Sdan
20*3043b532Sdan
21*3043b532Sdanforeach {enc} {
22*3043b532Sdan  utf16
23*3043b532Sdan  utf8
24*3043b532Sdan} {
25*3043b532Sdan  reset_db
26*3043b532Sdan  sqlite3_db_config_lookaside db 0 0 0
27*3043b532Sdan  execsql "PRAGMA encoding = $enc"
28*3043b532Sdan
29*3043b532Sdan  do_execsql_test 1.$enc.1 {
30*3043b532Sdan    CREATE TABLE s(i, s);
31*3043b532Sdan    INSERT INTO s VALUES(1, ',0123456789,');
32*3043b532Sdan    INSERT INTO s VALUES(2, X'2c303132333435363738392c');
33*3043b532Sdan
34*3043b532Sdan    CREATE TABLE e(e);
35*3043b532Sdan    INSERT INTO e VALUES('v1'), ('v2');
36*3043b532Sdan  } {}
37*3043b532Sdan
38*3043b532Sdan  do_faultsim_test 1.$enc.1 -faults oom* -body {
39*3043b532Sdan    execsql { SELECT group_concat(e, (SELECT s FROM s WHERE i=1)) FROM e }
40*3043b532Sdan  }
41*3043b532Sdan
42*3043b532Sdan  do_faultsim_test 1.$enc.2 -faults oom-t* -body {
43*3043b532Sdan    execsql { SELECT group_concat(e, (SELECT s FROM s WHERE i=2)) FROM e }
44*3043b532Sdan  }
45*3043b532Sdan
46*3043b532Sdan  do_faultsim_test 1.$enc.3 -faults oom-t* -prep {
47*3043b532Sdan    set ::STMT [sqlite3_prepare db {SELECT group_concat(e, ?) FROM e} -1 dummy]
48*3043b532Sdan    sqlite3_bind_text $::STMT 1 ",0123456789," 12
49*3043b532Sdan  } -body {
50*3043b532Sdan    while { "SQLITE_ROW"==[sqlite3_step $::STMT] } { }
51*3043b532Sdan  } -test {
52*3043b532Sdan    sqlite3_finalize $::STMT
53*3043b532Sdan  }
54*3043b532Sdan}
55*3043b532Sdan
56*3043b532Sdanfinish_test
57