1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/loadext2.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,144 @@
1.4 +# 2006 August 23
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this script is automatic extension loading and the
1.16 +# sqlite3_auto_extension() API.
1.17 +#
1.18 +# $Id: loadext2.test,v 1.3 2008/03/19 16:08:54 drh Exp $
1.19 +
1.20 +set testdir [file dirname $argv0]
1.21 +source $testdir/tester.tcl
1.22 +
1.23 +# Only run these tests if the approriate APIs are defined
1.24 +# in the system under test.
1.25 +#
1.26 +ifcapable !load_ext {
1.27 + finish_test
1.28 + return
1.29 +}
1.30 +if {[info command sqlite3_auto_extension_sqr]==""} {
1.31 + finish_test
1.32 + return
1.33 +}
1.34 +
1.35 +
1.36 +# None of the extension are loaded by default.
1.37 +#
1.38 +do_test loadext2-1.1 {
1.39 + catchsql {
1.40 + SELECT sqr(2)
1.41 + }
1.42 +} {1 {no such function: sqr}}
1.43 +do_test loadext2-1.2 {
1.44 + catchsql {
1.45 + SELECT cube(2)
1.46 + }
1.47 +} {1 {no such function: cube}}
1.48 +
1.49 +# Register auto-loaders. Still functions do not exist.
1.50 +#
1.51 +do_test loadext2-1.3 {
1.52 + sqlite3_auto_extension_sqr
1.53 + sqlite3_auto_extension_cube
1.54 + catchsql {
1.55 + SELECT sqr(2)
1.56 + }
1.57 +} {1 {no such function: sqr}}
1.58 +do_test loadext2-1.4 {
1.59 + catchsql {
1.60 + SELECT cube(2)
1.61 + }
1.62 +} {1 {no such function: cube}}
1.63 +
1.64 +
1.65 +# Functions do exist in a new database connection
1.66 +#
1.67 +do_test loadext2-1.5 {
1.68 + sqlite3 db test.db
1.69 + catchsql {
1.70 + SELECT sqr(2)
1.71 + }
1.72 +} {0 4.0}
1.73 +do_test loadext2-1.6 {
1.74 + catchsql {
1.75 + SELECT cube(2)
1.76 + }
1.77 +} {0 8.0}
1.78 +
1.79 +
1.80 +# Reset extension auto loading. Existing extensions still exist.
1.81 +#
1.82 +do_test loadext2-1.7 {
1.83 + sqlite3_reset_auto_extension
1.84 + catchsql {
1.85 + SELECT sqr(2)
1.86 + }
1.87 +} {0 4.0}
1.88 +do_test loadext2-1.8 {
1.89 + catchsql {
1.90 + SELECT cube(2)
1.91 + }
1.92 +} {0 8.0}
1.93 +
1.94 +
1.95 +# Register only the sqr() function.
1.96 +#
1.97 +do_test loadext2-1.9 {
1.98 + sqlite3_auto_extension_sqr
1.99 + sqlite3 db test.db
1.100 + catchsql {
1.101 + SELECT sqr(2)
1.102 + }
1.103 +} {0 4.0}
1.104 +do_test loadext2-1.10 {
1.105 + catchsql {
1.106 + SELECT cube(2)
1.107 + }
1.108 +} {1 {no such function: cube}}
1.109 +
1.110 +# Register only the cube() function.
1.111 +#
1.112 +do_test loadext2-1.11 {
1.113 + sqlite3_reset_auto_extension
1.114 + sqlite3_auto_extension_cube
1.115 + sqlite3 db test.db
1.116 + catchsql {
1.117 + SELECT sqr(2)
1.118 + }
1.119 +} {1 {no such function: sqr}}
1.120 +do_test loadext2-1.12 {
1.121 + catchsql {
1.122 + SELECT cube(2)
1.123 + }
1.124 +} {0 8.0}
1.125 +
1.126 +# Register a broken entry point.
1.127 +#
1.128 +do_test loadext2-1.13 {
1.129 + sqlite3_auto_extension_broken
1.130 + set rc [catch {sqlite3 db test.db} errmsg]
1.131 + lappend rc $errmsg
1.132 +} {1 {automatic extension loading failed: broken autoext!}}
1.133 +do_test loadext2-1.14 {
1.134 + catchsql {
1.135 + SELECT sqr(2)
1.136 + }
1.137 +} {1 {no such function: sqr}}
1.138 +do_test loadext2-1.15 {
1.139 + catchsql {
1.140 + SELECT cube(2)
1.141 + }
1.142 +} {0 8.0}
1.143 +
1.144 +
1.145 +sqlite3_reset_auto_extension
1.146 +autoinstall_test_functions
1.147 +finish_test