1# 2006 August 23 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 script is automatic extension loading and the 13# sqlite3_auto_extension() API. 14# 15# $Id: loadext2.test,v 1.3 2008/03/19 16:08:54 drh Exp $ 16 17set testdir [file dirname $argv0] 18source $testdir/tester.tcl 19 20# Only run these tests if the approriate APIs are defined 21# in the system under test. 22# 23ifcapable !load_ext { 24 finish_test 25 return 26} 27if {[info command sqlite3_auto_extension_sqr]==""} { 28 finish_test 29 return 30} 31 32 33# None of the extension are loaded by default. 34# 35do_test loadext2-1.1 { 36 catchsql { 37 SELECT sqr(2) 38 } 39} {1 {no such function: sqr}} 40do_test loadext2-1.2 { 41 catchsql { 42 SELECT cube(2) 43 } 44} {1 {no such function: cube}} 45 46# Register auto-loaders. Still functions do not exist. 47# 48do_test loadext2-1.3 { 49 sqlite3_auto_extension_sqr 50 sqlite3_auto_extension_cube 51 catchsql { 52 SELECT sqr(2) 53 } 54} {1 {no such function: sqr}} 55do_test loadext2-1.4 { 56 catchsql { 57 SELECT cube(2) 58 } 59} {1 {no such function: cube}} 60 61 62# Functions do exist in a new database connection 63# 64do_test loadext2-1.5 { 65 sqlite3 db test.db 66 catchsql { 67 SELECT sqr(2) 68 } 69} {0 4.0} 70do_test loadext2-1.6 { 71 catchsql { 72 SELECT cube(2) 73 } 74} {0 8.0} 75 76 77# Reset extension auto loading. Existing extensions still exist. 78# 79do_test loadext2-1.7 { 80 sqlite3_reset_auto_extension 81 catchsql { 82 SELECT sqr(2) 83 } 84} {0 4.0} 85do_test loadext2-1.8 { 86 catchsql { 87 SELECT cube(2) 88 } 89} {0 8.0} 90 91 92# Register only the sqr() function. 93# 94do_test loadext2-1.9 { 95 sqlite3_auto_extension_sqr 96 sqlite3 db test.db 97 catchsql { 98 SELECT sqr(2) 99 } 100} {0 4.0} 101do_test loadext2-1.10 { 102 catchsql { 103 SELECT cube(2) 104 } 105} {1 {no such function: cube}} 106 107# Register only the cube() function. 108# 109do_test loadext2-1.11 { 110 sqlite3_reset_auto_extension 111 sqlite3_auto_extension_cube 112 sqlite3 db test.db 113 catchsql { 114 SELECT sqr(2) 115 } 116} {1 {no such function: sqr}} 117do_test loadext2-1.12 { 118 catchsql { 119 SELECT cube(2) 120 } 121} {0 8.0} 122 123# Register a broken entry point. 124# 125do_test loadext2-1.13 { 126 sqlite3_auto_extension_broken 127 set rc [catch {sqlite3 db test.db} errmsg] 128 lappend rc $errmsg 129} {1 {automatic extension loading failed: broken autoext!}} 130do_test loadext2-1.14 { 131 catchsql { 132 SELECT sqr(2) 133 } 134} {1 {no such function: sqr}} 135do_test loadext2-1.15 { 136 catchsql { 137 SELECT cube(2) 138 } 139} {0 8.0} 140 141 142sqlite3_reset_auto_extension 143autoinstall_test_functions 144finish_test 145