/ Check-in [bb721865]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Create the test_destructor16() test SQL function to enhance test coverage. Prior to check-in (4883), the test_destructor() function was sufficient, but we now need separate functions since the implementation is restricted to using the published API. (CVS 4884)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: bb7218657f3b06d810ad710fe64e5c9984aa518c
User & Date: drh 2008-03-19 16:35:24
Context
2008-03-19
19:01
Initialize the MD5 SQL functions from test_func.c instead of using conditional compilation in tclsqlite.c. (CVS 4885) check-in: 801a0e3c user: drh tags: trunk
16:35
Create the test_destructor16() test SQL function to enhance test coverage. Prior to check-in (4883), the test_destructor() function was sufficient, but we now need separate functions since the implementation is restricted to using the published API. (CVS 4884) check-in: bb721865 user: drh tags: trunk
16:08
Move SQL functions used for testing only out of func.c and into a new test file named test_func.c. Use sqlite3_auto_extension() to make sure the test functions appear in every database connection. (CVS 4883) check-in: e90c4cc8 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test_func.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing all sorts of SQLite interfaces.  This code
    13     13   ** implements new SQL functions used by the test scripts.
    14     14   **
    15         -** $Id: test_func.c,v 1.1 2008/03/19 16:08:54 drh Exp $
           15  +** $Id: test_func.c,v 1.2 2008/03/19 16:35:24 drh Exp $
    16     16   */
    17     17   #include "sqlite3.h"
    18     18   #include "tcl.h"
    19     19   #include <stdlib.h>
    20     20   #include <string.h>
    21     21   #include <assert.h>
    22     22   
................................................................................
   110    110     }
   111    111     zVal[len+1] = 0;
   112    112     zVal[len+2] = 0;
   113    113     zVal++;
   114    114     memcpy(zVal, sqlite3_value_text(argv[0]), len);
   115    115     sqlite3_result_text(pCtx, zVal, -1, destructor);
   116    116   }
          117  +static void test_destructor16(
          118  +  sqlite3_context *pCtx, 
          119  +  int nArg,
          120  +  sqlite3_value **argv
          121  +){
          122  +  char *zVal;
          123  +  int len;
          124  +  
          125  +  test_destructor_count_var++;
          126  +  assert( nArg==1 );
          127  +  if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
          128  +  len = sqlite3_value_bytes16(argv[0]); 
          129  +  zVal = testContextMalloc(pCtx, len+3);
          130  +  if( !zVal ){
          131  +    return;
          132  +  }
          133  +  zVal[len+1] = 0;
          134  +  zVal[len+2] = 0;
          135  +  zVal++;
          136  +  memcpy(zVal, sqlite3_value_text16(argv[0]), len);
          137  +  sqlite3_result_text16(pCtx, zVal, -1, destructor);
          138  +}
   117    139   static void test_destructor_count(
   118    140     sqlite3_context *pCtx, 
   119    141     int nArg,
   120    142     sqlite3_value **argv
   121    143   ){
   122    144     sqlite3_result_int(pCtx, test_destructor_count_var);
   123    145   }
................................................................................
   183    205        char *zName;
   184    206        signed char nArg;
   185    207        unsigned char eTextRep; /* 1: UTF-16.  0: UTF-8 */
   186    208        void (*xFunc)(sqlite3_context*,int,sqlite3_value **);
   187    209     } aFuncs[] = {
   188    210       { "randstr",               2, SQLITE_UTF8, randStr    },
   189    211       { "test_destructor",       1, SQLITE_UTF8, test_destructor},
          212  +    { "test_destructor16",     1, SQLITE_UTF8, test_destructor16},
   190    213       { "test_destructor_count", 0, SQLITE_UTF8, test_destructor_count},
   191    214       { "test_auxdata",         -1, SQLITE_UTF8, test_auxdata},
   192    215       { "test_error",            1, SQLITE_UTF8, test_error},
   193    216     };
   194    217     int i;
   195    218   
   196    219     for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){

Changes to test/func.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing built-in functions.
    13     13   #
    14         -# $Id: func.test,v 1.72 2008/01/12 19:03:49 drh Exp $
           14  +# $Id: func.test,v 1.73 2008/03/19 16:35:24 drh Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Create a table to work with.
    20     20   #
    21     21   do_test func-0.0 {
................................................................................
   422    422   # (implemented in func.c) only available in test builds. 
   423    423   #
   424    424   # Function test_destructor() takes one argument and returns a copy of the
   425    425   # text form of that argument. A destructor is associated with the return
   426    426   # value. Function test_destructor_count() returns the number of outstanding
   427    427   # destructor calls for values returned by test_destructor().
   428    428   #
   429         -do_test func-12.1 {
   430         -  execsql {
   431         -    SELECT test_destructor('hello world'), test_destructor_count();
   432         -  }
   433         -} {{hello world} 1}
          429  +if {[db eval {PRAGMA encoding}]=="UTF-8"} {
          430  +  do_test func-12.1-utf8 {
          431  +    execsql {
          432  +      SELECT test_destructor('hello world'), test_destructor_count();
          433  +    }
          434  +  } {{hello world} 1}
          435  +} else {
          436  +  do_test func-12.1-utf16 {
          437  +    execsql {
          438  +      SELECT test_destructor16('hello world'), test_destructor_count();
          439  +    }
          440  +  } {{hello world} 1}
          441  +}
   434    442   do_test func-12.2 {
   435    443     execsql {
   436    444       SELECT test_destructor_count();
   437    445     }
   438    446   } {0}
   439    447   do_test func-12.3 {
   440    448     execsql {