sl@0: # 2005 January 11 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this file is testing the sqlite3SafetyOn and sqlite3SafetyOff sl@0: # functions. Those routines are not strictly necessary - they are sl@0: # designed to detect misuse of the library. sl@0: # sl@0: # $Id: safety.test,v 1.4 2008/03/18 13:46:53 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !debug { sl@0: puts "Skipping safety tests since SQLITE_DEBUG is off" sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Return the UTF-8 representation of the supplied UTF-16 string $str. sl@0: proc utf8 {str} { sl@0: # If $str ends in two 0x00 0x00 bytes, knock these off before sl@0: # converting to UTF-8 using TCL. sl@0: binary scan $str \c* vals sl@0: if {[lindex $vals end]==0 && [lindex $vals end-1]==0} { sl@0: set str [binary format \c* [lrange $vals 0 end-2]] sl@0: } sl@0: sl@0: set r [encoding convertfrom unicode $str] sl@0: return $r sl@0: } sl@0: sl@0: sl@0: do_test safety-1.1 { sl@0: set DB [sqlite3_connection_pointer db] sl@0: db eval {CREATE TABLE t1(a)} sl@0: sqlite_set_magic $DB SQLITE_MAGIC_BUSY sl@0: catchsql { sl@0: SELECT name FROM sqlite_master; sl@0: } sl@0: } {1 {library routine called out of sequence}} sl@0: do_test safety-1.2 { sl@0: sqlite_set_magic $DB SQLITE_MAGIC_OPEN sl@0: catchsql { sl@0: SELECT name FROM sqlite_master sl@0: } sl@0: } {0 t1} sl@0: sl@0: do_test safety-2.1 { sl@0: proc safety_on {} "sqlite_set_magic $DB SQLITE_MAGIC_BUSY" sl@0: db function safety_on safety_on sl@0: catchsql { sl@0: SELECT safety_on(), name FROM sqlite_master sl@0: } sl@0: } {1 {library routine called out of sequence}} sl@0: ifcapable {utf16} { sl@0: do_test safety-2.1.1 { sl@0: utf8 [sqlite3_errmsg16 db] sl@0: } {library routine called out of sequence} sl@0: } sl@0: do_test safety-2.2 { sl@0: catchsql { sl@0: SELECT 'hello' sl@0: } sl@0: } {1 {library routine called out of sequence}} sl@0: do_test safety-2.3 { sl@0: sqlite3_close $DB sl@0: } {SQLITE_MISUSE} sl@0: do_test safety-2.4 { sl@0: sqlite_set_magic $DB SQLITE_MAGIC_OPEN sl@0: execsql { sl@0: SELECT name FROM sqlite_master sl@0: } sl@0: } {t1} sl@0: sl@0: do_test safety-3.1 { sl@0: set rc [catch { sl@0: db eval {SELECT name FROM sqlite_master} { sl@0: sqlite_set_magic $DB SQLITE_MAGIC_BUSY sl@0: } sl@0: } msg] sl@0: lappend rc $msg sl@0: } {1 {library routine called out of sequence}} sl@0: sqlite_set_magic $DB SQLITE_MAGIC_OPEN sl@0: sl@0: finish_test