sl@0: # 2006 August 23 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 script is automatic extension loading and the sl@0: # sqlite3_auto_extension() API. sl@0: # sl@0: # $Id: loadext2.test,v 1.3 2008/03/19 16:08:54 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # Only run these tests if the approriate APIs are defined sl@0: # in the system under test. sl@0: # sl@0: ifcapable !load_ext { sl@0: finish_test sl@0: return sl@0: } sl@0: if {[info command sqlite3_auto_extension_sqr]==""} { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: sl@0: # None of the extension are loaded by default. sl@0: # sl@0: do_test loadext2-1.1 { sl@0: catchsql { sl@0: SELECT sqr(2) sl@0: } sl@0: } {1 {no such function: sqr}} sl@0: do_test loadext2-1.2 { sl@0: catchsql { sl@0: SELECT cube(2) sl@0: } sl@0: } {1 {no such function: cube}} sl@0: sl@0: # Register auto-loaders. Still functions do not exist. sl@0: # sl@0: do_test loadext2-1.3 { sl@0: sqlite3_auto_extension_sqr sl@0: sqlite3_auto_extension_cube sl@0: catchsql { sl@0: SELECT sqr(2) sl@0: } sl@0: } {1 {no such function: sqr}} sl@0: do_test loadext2-1.4 { sl@0: catchsql { sl@0: SELECT cube(2) sl@0: } sl@0: } {1 {no such function: cube}} sl@0: sl@0: sl@0: # Functions do exist in a new database connection sl@0: # sl@0: do_test loadext2-1.5 { sl@0: sqlite3 db test.db sl@0: catchsql { sl@0: SELECT sqr(2) sl@0: } sl@0: } {0 4.0} sl@0: do_test loadext2-1.6 { sl@0: catchsql { sl@0: SELECT cube(2) sl@0: } sl@0: } {0 8.0} sl@0: sl@0: sl@0: # Reset extension auto loading. Existing extensions still exist. sl@0: # sl@0: do_test loadext2-1.7 { sl@0: sqlite3_reset_auto_extension sl@0: catchsql { sl@0: SELECT sqr(2) sl@0: } sl@0: } {0 4.0} sl@0: do_test loadext2-1.8 { sl@0: catchsql { sl@0: SELECT cube(2) sl@0: } sl@0: } {0 8.0} sl@0: sl@0: sl@0: # Register only the sqr() function. sl@0: # sl@0: do_test loadext2-1.9 { sl@0: sqlite3_auto_extension_sqr sl@0: sqlite3 db test.db sl@0: catchsql { sl@0: SELECT sqr(2) sl@0: } sl@0: } {0 4.0} sl@0: do_test loadext2-1.10 { sl@0: catchsql { sl@0: SELECT cube(2) sl@0: } sl@0: } {1 {no such function: cube}} sl@0: sl@0: # Register only the cube() function. sl@0: # sl@0: do_test loadext2-1.11 { sl@0: sqlite3_reset_auto_extension sl@0: sqlite3_auto_extension_cube sl@0: sqlite3 db test.db sl@0: catchsql { sl@0: SELECT sqr(2) sl@0: } sl@0: } {1 {no such function: sqr}} sl@0: do_test loadext2-1.12 { sl@0: catchsql { sl@0: SELECT cube(2) sl@0: } sl@0: } {0 8.0} sl@0: sl@0: # Register a broken entry point. sl@0: # sl@0: do_test loadext2-1.13 { sl@0: sqlite3_auto_extension_broken sl@0: set rc [catch {sqlite3 db test.db} errmsg] sl@0: lappend rc $errmsg sl@0: } {1 {automatic extension loading failed: broken autoext!}} sl@0: do_test loadext2-1.14 { sl@0: catchsql { sl@0: SELECT sqr(2) sl@0: } sl@0: } {1 {no such function: sqr}} sl@0: do_test loadext2-1.15 { sl@0: catchsql { sl@0: SELECT cube(2) sl@0: } sl@0: } {0 8.0} sl@0: sl@0: sl@0: sqlite3_reset_auto_extension sl@0: autoinstall_test_functions sl@0: finish_test