AryaWu/sqlite
0
1# 2006 August 232#3# The author disclaims copyright to this source code. In place of4# 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. The12# focus of this script is automatic extension loading and the13# 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.tcl19 20# Only run these tests if the approriate APIs are defined21# in the system under test.22#23ifcapable !load_ext {24 finish_test25 return26}27if {[info command sqlite3_auto_extension_sqr]==""} {28 finish_test29 return30}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# Extensions loaders not currently registered47#48do_test loadext2-1.2.1 {49 sqlite3_cancel_auto_extension_sqr50} {0}51do_test loadext2-1.2.2 {52 sqlite3_cancel_auto_extension_sqr53} {0}54do_test loadext2-1.2.3 {55 sqlite3_cancel_auto_extension_sqr56} {0}57 58 59# Register auto-loaders. Still functions do not exist.60#61do_test loadext2-1.3 {62 sqlite3_auto_extension_sqr63 sqlite3_auto_extension_cube64 catchsql {65 SELECT sqr(2)66 }67} {1 {no such function: sqr}}68do_test loadext2-1.4 {69 catchsql {70 SELECT cube(2)71 }72} {1 {no such function: cube}}73 74 75# Functions do exist in a new database connection76#77do_test loadext2-1.5 {78 sqlite3 db test.db79 catchsql {80 SELECT sqr(2)81 }82} {0 4.0}83do_test loadext2-1.6 {84 catchsql {85 SELECT cube(2)86 }87} {0 8.0}88 89 90# Reset extension auto loading. Existing extensions still exist.91#92do_test loadext2-1.7.1 {93 sqlite3_cancel_auto_extension_sqr94} {1}95do_test loadext2-1.7.2 {96 sqlite3_cancel_auto_extension_sqr97} {0}98do_test loadext2-1.7.3 {99 sqlite3_cancel_auto_extension_cube100} {1}101do_test loadext2-1.7.4 {102 sqlite3_cancel_auto_extension_cube103} {0}104do_test loadext2-1.7.5 {105 catchsql {106 SELECT sqr(2)107 }108} {0 4.0}109do_test loadext2-1.8 {110 catchsql {111 SELECT cube(2)112 }113} {0 8.0}114 115 116# Register only the sqr() function.117#118do_test loadext2-1.9 {119 sqlite3_auto_extension_sqr120 sqlite3 db test.db121 catchsql {122 SELECT sqr(2)123 }124} {0 4.0}125do_test loadext2-1.10 {126 catchsql {127 SELECT cube(2)128 }129} {1 {no such function: cube}}130 131# Register only the cube() function.132#133do_test loadext2-1.11 {134 sqlite3_reset_auto_extension135 sqlite3_auto_extension_cube136 sqlite3 db test.db137 catchsql {138 SELECT sqr(2)139 }140} {1 {no such function: sqr}}141do_test loadext2-1.12 {142 catchsql {143 SELECT cube(2)144 }145} {0 8.0}146 147# Register a broken entry point.148#149do_test loadext2-1.13 {150 sqlite3_auto_extension_broken151 set rc [catch {sqlite3 db test.db} errmsg]152 lappend rc $errmsg153} {1 {automatic extension loading failed: broken autoext!}}154do_test loadext2-1.14 {155 catchsql {156 SELECT sqr(2)157 }158} {1 {no such function: sqr}}159do_test loadext2-1.15 {160 catchsql {161 SELECT cube(2)162 }163} {0 8.0}164 165 166sqlite3_reset_auto_extension167autoinstall_test_functions168finish_test169 