diff options
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/safety.test')
-rw-r--r-- | libraries/sqlite/unix/sqlite-3.5.1/test/safety.test | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/safety.test b/libraries/sqlite/unix/sqlite-3.5.1/test/safety.test new file mode 100644 index 0000000..fb8c56c --- /dev/null +++ b/libraries/sqlite/unix/sqlite-3.5.1/test/safety.test | |||
@@ -0,0 +1,68 @@ | |||
1 | # 2005 January 11 | ||
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 SQLite library. The | ||
12 | # focus of this file is testing the sqlite3SafetyOn and sqlite3SafetyOff | ||
13 | # functions. Those routines are not strictly necessary - they are | ||
14 | # designed to detect misuse of the library. | ||
15 | # | ||
16 | # $Id: safety.test,v 1.2 2006/01/03 00:33:50 drh Exp $ | ||
17 | |||
18 | set testdir [file dirname $argv0] | ||
19 | source $testdir/tester.tcl | ||
20 | |||
21 | do_test safety-1.1 { | ||
22 | set DB [sqlite3_connection_pointer db] | ||
23 | db eval {CREATE TABLE t1(a)} | ||
24 | sqlite_set_magic $DB SQLITE_MAGIC_BUSY | ||
25 | catchsql { | ||
26 | SELECT name FROM sqlite_master; | ||
27 | } | ||
28 | } {1 {library routine called out of sequence}} | ||
29 | do_test safety-1.2 { | ||
30 | sqlite_set_magic $DB SQLITE_MAGIC_OPEN | ||
31 | catchsql { | ||
32 | SELECT name FROM sqlite_master | ||
33 | } | ||
34 | } {0 t1} | ||
35 | |||
36 | do_test safety-2.1 { | ||
37 | proc safety_on {} "sqlite_set_magic $DB SQLITE_MAGIC_BUSY" | ||
38 | db function safety_on safety_on | ||
39 | catchsql { | ||
40 | SELECT safety_on(), name FROM sqlite_master | ||
41 | } | ||
42 | } {1 {library routine called out of sequence}} | ||
43 | do_test safety-2.2 { | ||
44 | catchsql { | ||
45 | SELECT 'hello' | ||
46 | } | ||
47 | } {1 {library routine called out of sequence}} | ||
48 | do_test safety-2.3 { | ||
49 | sqlite3_close $DB | ||
50 | } {SQLITE_MISUSE} | ||
51 | do_test safety-2.4 { | ||
52 | sqlite_set_magic $DB SQLITE_MAGIC_OPEN | ||
53 | execsql { | ||
54 | SELECT name FROM sqlite_master | ||
55 | } | ||
56 | } {t1} | ||
57 | |||
58 | do_test safety-3.1 { | ||
59 | set rc [catch { | ||
60 | db eval {SELECT name FROM sqlite_master} { | ||
61 | sqlite_set_magic $DB SQLITE_MAGIC_BUSY | ||
62 | } | ||
63 | } msg] | ||
64 | lappend rc $msg | ||
65 | } {1 {library routine called out of sequence}} | ||
66 | sqlite_set_magic $DB SQLITE_MAGIC_OPEN | ||
67 | |||
68 | finish_test | ||