blob: d5b6ea8d7f809e1ecd4ae8d596de34bdcc2fd334 [file] [log] [blame]
drh1409be62006-08-23 20:07:20 +00001# 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#
drh984bfaa2008-03-19 16:08:53 +000015# $Id: loadext2.test,v 1.3 2008/03/19 16:08:54 drh Exp $
drh1409be62006-08-23 20:07:20 +000016
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#
drh1e9daa62007-04-06 21:42:22 +000023ifcapable !load_ext {
24 finish_test
25 return
26}
drh1409be62006-08-23 20:07:20 +000027if {[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
drh425e27d2013-07-15 17:02:28 +000046# Extensions loaders not currently registered
47#
48do_test loadext2-1.2.1 {
49 sqlite3_cancel_auto_extension_sqr
50} {0}
51do_test loadext2-1.2.2 {
52 sqlite3_cancel_auto_extension_sqr
53} {0}
54do_test loadext2-1.2.3 {
55 sqlite3_cancel_auto_extension_sqr
56} {0}
57
58
drh1409be62006-08-23 20:07:20 +000059# Register auto-loaders. Still functions do not exist.
60#
61do_test loadext2-1.3 {
62 sqlite3_auto_extension_sqr
63 sqlite3_auto_extension_cube
64 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 connection
76#
77do_test loadext2-1.5 {
78 sqlite3 db test.db
79 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#
drh425e27d2013-07-15 17:02:28 +000092do_test loadext2-1.7.1 {
93 sqlite3_cancel_auto_extension_sqr
94} {1}
95do_test loadext2-1.7.2 {
96 sqlite3_cancel_auto_extension_sqr
97} {0}
98do_test loadext2-1.7.3 {
99 sqlite3_cancel_auto_extension_cube
100} {1}
101do_test loadext2-1.7.4 {
102 sqlite3_cancel_auto_extension_cube
103} {0}
104do_test loadext2-1.7.5 {
drh1409be62006-08-23 20:07:20 +0000105 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_sqr
120 sqlite3 db test.db
121 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_extension
135 sqlite3_auto_extension_cube
136 sqlite3 db test.db
137 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_broken
151 set rc [catch {sqlite3 db test.db} errmsg]
152 lappend rc $errmsg
153} {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_extension
drh984bfaa2008-03-19 16:08:53 +0000167autoinstall_test_functions
drh1409be62006-08-23 20:07:20 +0000168finish_test