File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / sqlite3 / test / loadext2.test
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 17:04:16 2012 UTC (12 years, 10 months ago) by misho
Branches: sqlite3, MAIN
CVS tags: v3_7_10, HEAD
sqlite3

    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.1.1.1 2012/02/21 17:04:16 misho Exp $
   16: 
   17: set testdir [file dirname $argv0]
   18: source $testdir/tester.tcl
   19: 
   20: # Only run these tests if the approriate APIs are defined
   21: # in the system under test.
   22: #
   23: ifcapable !load_ext {
   24:   finish_test
   25:   return
   26: }
   27: if {[info command sqlite3_auto_extension_sqr]==""} {
   28:   finish_test
   29:   return
   30: }
   31: 
   32: 
   33: # None of the extension are loaded by default.
   34: #
   35: do_test loadext2-1.1 {
   36:   catchsql {
   37:     SELECT sqr(2)
   38:   }
   39: } {1 {no such function: sqr}}
   40: do_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: #
   48: do_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}}
   55: do_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: #
   64: do_test loadext2-1.5 {
   65:   sqlite3 db test.db
   66:   catchsql {
   67:     SELECT sqr(2)
   68:   }
   69: } {0 4.0}
   70: do_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: #
   79: do_test loadext2-1.7 {
   80:   sqlite3_reset_auto_extension
   81:   catchsql {
   82:     SELECT sqr(2)
   83:   }
   84: } {0 4.0}
   85: do_test loadext2-1.8 {
   86:   catchsql {
   87:     SELECT cube(2)
   88:   }
   89: } {0 8.0}
   90: 
   91: 
   92: # Register only the sqr() function.
   93: #
   94: do_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}
  101: do_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: #
  109: do_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}}
  117: do_test loadext2-1.12 {
  118:   catchsql {
  119:     SELECT cube(2)
  120:   }
  121: } {0 8.0}
  122: 
  123: # Register a broken entry point.
  124: #
  125: do_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!}}
  130: do_test loadext2-1.14 {
  131:   catchsql {
  132:     SELECT sqr(2)
  133:   }
  134: } {1 {no such function: sqr}}
  135: do_test loadext2-1.15 {
  136:   catchsql {
  137:     SELECT cube(2)
  138:   }
  139: } {0 8.0}
  140: 
  141: 
  142: sqlite3_reset_auto_extension
  143: autoinstall_test_functions
  144: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>