| OLD | NEW |
| 1 # 2006 July 14 | 1 # 2006 July 14 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #*********************************************************************** | 10 #*********************************************************************** |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 # Make sure the test extension actually exists. If it does not | 75 # Make sure the test extension actually exists. If it does not |
| 76 # exist, try to create it. If unable to create it, then skip this | 76 # exist, try to create it. If unable to create it, then skip this |
| 77 # test file. | 77 # test file. |
| 78 # | 78 # |
| 79 if {![file exists $testextension]} { | 79 if {![file exists $testextension]} { |
| 80 set srcdir [file dir $testdir]/src | 80 set srcdir [file dir $testdir]/src |
| 81 set testextsrc $srcdir/test_loadext.c | 81 set testextsrc $srcdir/test_loadext.c |
| 82 | 82 |
| 83 set cmdline [concat exec gcc $gcc_shared] | 83 set cmdline [concat exec gcc $gcc_shared] |
| 84 lappend cmdline -Wall -I$srcdir -I. -g $testextsrc -o $testextension | 84 lappend cmdline -Wall -I$srcdir -I. -I.. -g $testextsrc -o $testextension |
| 85 | 85 |
| 86 if {[catch $cmdline msg]} { | 86 if {[catch $cmdline msg]} { |
| 87 puts "Skipping loadext tests: Test extension not built..." | 87 puts "Skipping loadext tests: Test extension not built..." |
| 88 puts $msg | 88 puts $msg |
| 89 finish_test | 89 finish_test |
| 90 return | 90 return |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 # Test that loading the extension produces the expected results - adding | 94 # Test that loading the extension produces the expected results - adding |
| 95 # the half() function to the specified database handle. | 95 # the half() function to the specified database handle. |
| 96 # | 96 # |
| 97 do_test loadext-1.1 { | 97 do_test loadext-1.1 { |
| 98 catchsql { | 98 catchsql { |
| 99 SELECT half(1.0); | 99 SELECT half(1.0); |
| 100 } | 100 } |
| 101 } {1 {no such function: half}} | 101 } {1 {no such function: half}} |
| 102 do_test loadext-1.2 { | 102 do_test loadext-1.2 { |
| 103 db enable_load_extension 1 | 103 db enable_load_extension 1 |
| 104 sqlite3_load_extension db $testextension testloadext_init | 104 sqlite3_load_extension db $testextension testloadext_init |
| 105 catchsql { | 105 catchsql { |
| 106 SELECT half(1.0); | 106 SELECT half(1.0); |
| 107 } | 107 } |
| 108 } {0 0.5} | 108 } {0 0.5} |
| 109 | 109 |
| 110 # Test that a second database connection (db2) can load the extension also. | 110 # Test that a second database connection (db2) can load the extension also. |
| 111 # | 111 # |
| 112 do_test loadext-1.3 { | 112 do_test loadext-1.3 { |
| 113 sqlite3 db2 test.db | 113 sqlite3 db2 test.db |
| 114 sqlite3_enable_load_extension db2 1 | 114 sqlite3_db_config db2 SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1 |
| 115 catchsql { | 115 catchsql { |
| 116 SELECT half(1.0); | 116 SELECT half(1.0); |
| 117 } db2 | 117 } db2 |
| 118 } {1 {no such function: half}} | 118 } {1 {no such function: half}} |
| 119 do_test loadext-1.4 { | 119 do_test loadext-1.4 { |
| 120 sqlite3_load_extension db2 $testextension testloadext_init | 120 sqlite3_load_extension db2 $testextension testloadext_init |
| 121 catchsql { | 121 catchsql { |
| 122 SELECT half(1.0); | 122 SELECT half(1.0); |
| 123 } db2 | 123 } db2 |
| 124 } {0 0.5} | 124 } {0 0.5} |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 SELECT load_extension($::testextension,'testloadext_init') | 249 SELECT load_extension($::testextension,'testloadext_init') |
| 250 } | 250 } |
| 251 } {1 {not authorized}} | 251 } {1 {not authorized}} |
| 252 do_test loadext-4.2 { | 252 do_test loadext-4.2 { |
| 253 sqlite3_enable_load_extension db 1 | 253 sqlite3_enable_load_extension db 1 |
| 254 catchsql { | 254 catchsql { |
| 255 SELECT load_extension($::testextension,'testloadext_init') | 255 SELECT load_extension($::testextension,'testloadext_init') |
| 256 } | 256 } |
| 257 } {0 {{}}} | 257 } {0 {{}}} |
| 258 | 258 |
| 259 # disable all extension loading |
| 259 do_test loadext-4.3 { | 260 do_test loadext-4.3 { |
| 260 sqlite3_enable_load_extension db 0 | 261 sqlite3_enable_load_extension db 0 |
| 261 catchsql { | 262 catchsql { |
| 262 SELECT load_extension($::testextension,'testloadext_init') | 263 SELECT load_extension($::testextension,'testloadext_init') |
| 263 } | 264 } |
| 264 } {1 {not authorized}} | 265 } {1 {not authorized}} |
| 265 | 266 |
| 267 # enable C-api extension loading only. Show that the SQL function |
| 268 # still does not work. |
| 269 do_test loadext-4.4 { |
| 270 sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1 |
| 271 catchsql { |
| 272 SELECT load_extension($::testextension,'testloadext_init') |
| 273 } |
| 274 } {1 {not authorized}} |
| 275 |
| 266 source $testdir/malloc_common.tcl | 276 source $testdir/malloc_common.tcl |
| 267 | 277 |
| 268 | 278 |
| 269 # Malloc failure in sqlite3_auto_extension and sqlite3_load_extension | 279 # Malloc failure in sqlite3_auto_extension and sqlite3_load_extension |
| 270 # | 280 # |
| 271 do_malloc_test loadext-5 -tclprep { | 281 do_malloc_test loadext-5 -tclprep { |
| 272 sqlite3_reset_auto_extension | 282 sqlite3_reset_auto_extension |
| 273 } -tclbody { | 283 } -tclbody { |
| 274 if {[autoinstall_test_functions]==7} {error "out of memory"} | 284 if {[autoinstall_test_functions]==7} {error "out of memory"} |
| 275 } | 285 } |
| 276 | 286 |
| 277 # On Windows, this malloc test must be skipped because the winDlOpen | 287 # On Windows, this malloc test must be skipped because the winDlOpen |
| 278 # function itself can fail due to "out of memory" conditions. | 288 # function itself can fail due to "out of memory" conditions. |
| 279 # | 289 # |
| 280 if {$::tcl_platform(platform) ne "windows"} { | 290 if {$::tcl_platform(platform) ne "windows"} { |
| 281 do_malloc_test loadext-6 -tclbody { | 291 do_malloc_test loadext-6 -tclbody { |
| 282 db enable_load_extension 1 | 292 db enable_load_extension 1 |
| 283 sqlite3_load_extension db $::testextension testloadext_init | 293 sqlite3_load_extension db $::testextension testloadext_init |
| 284 } | 294 } |
| 285 } | 295 } |
| 286 | 296 |
| 287 autoinstall_test_functions | 297 autoinstall_test_functions |
| 288 | 298 |
| 289 finish_test | 299 finish_test |
| OLD | NEW |