mirror of https://github.com/sqlite/sqlite
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) FossilOrigin-Name: e90c4cc8a89838161f218739bc821126e247498c
This commit is contained in:
parent
2fa1868fb6
commit
984bfaa4c7
|
@ -318,6 +318,7 @@ TESTSRC = \
|
|||
$(TOP)/src/test_btree.c \
|
||||
$(TOP)/src/test_config.c \
|
||||
$(TOP)/src/test_devsym.c \
|
||||
$(TOP)/src/test_func.c \
|
||||
$(TOP)/src/test_hexio.c \
|
||||
$(TOP)/src/test_malloc.c \
|
||||
$(TOP)/src/test_md5.c \
|
||||
|
|
1
main.mk
1
main.mk
|
@ -217,6 +217,7 @@ TESTSRC = \
|
|||
$(TOP)/src/test_btree.c \
|
||||
$(TOP)/src/test_config.c \
|
||||
$(TOP)/src/test_devsym.c \
|
||||
$(TOP)/src/test_func.c \
|
||||
$(TOP)/src/test_hexio.c \
|
||||
$(TOP)/src/test_malloc.c \
|
||||
$(TOP)/src/test_md5.c \
|
||||
|
|
29
manifest
29
manifest
|
@ -1,7 +1,7 @@
|
|||
C Add\sa\snew\sapi\ssqlite3_randomness()\sfor\sproviding\saccess\sto\sSQLite's\ninternal\sPRNG.\s\sAdd\ssqlite3_test_control()\sverbs\sfor\scontrolling\sthe\sPRNG.\s(CVS\s4882)
|
||||
D 2008-03-19T14:15:34
|
||||
C Move\sSQL\sfunctions\sused\sfor\stesting\sonly\sout\sof\sfunc.c\sand\sinto\sa\snew\ntest\sfile\snamed\stest_func.c.\s\sUse\ssqlite3_auto_extension()\sto\smake\ssure\nthe\stest\sfunctions\sappear\sin\severy\sdatabase\sconnection.\s(CVS\s4883)
|
||||
D 2008-03-19T16:08:54
|
||||
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
|
||||
F Makefile.in 5be94fea84f1599672e5041de03b97990baca593
|
||||
F Makefile.in 31182aff7a39a0a0fc41e2e68562d20d57a8b16e
|
||||
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
|
||||
F README b974cdc3f9f12b87e851b04e75996d720ebf81ac
|
||||
F VERSION 7a41970464b74225915bcaf9d76efd01f26e08f9
|
||||
|
@ -64,7 +64,7 @@ F ext/icu/README.txt 3b130aa66e7a681136f6add198b076a2f90d1e33
|
|||
F ext/icu/icu.c 12e763d288d23b5a49de37caa30737b971a2f1e2
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
|
||||
F ltmain.sh 56abb507100ed2d4261f6dd1653dec3cf4066387
|
||||
F main.mk c9f2b9c47ed145008976f5fcfd74ff3e34f31678
|
||||
F main.mk e6715c0ad8d7350d7ec9e1d8693c665b52fa1c5c
|
||||
F mkdll.sh 712e74f3efe08a6ba12b2945d018a29a89d7fe3b
|
||||
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
|
||||
F mkextw.sh 1a866b53637dab137191341cc875575a5ca110fb
|
||||
|
@ -97,15 +97,15 @@ F src/delete.c fa13c296262e89c32d28949f15be275e52d7f524
|
|||
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
|
||||
F src/expr.c 242f2f57a32f6909270e4a22ce1c810a150f5a17
|
||||
F src/fault.c 039abb45c9dbcbdf575ec2a23ae38db01bc2f7b2
|
||||
F src/func.c 1832b2fd1742f6a3adc0ff3c73e75274a7b52435
|
||||
F src/func.c 00a4f0a75faaf5f85c90710d099be2fc3aaf7914
|
||||
F src/hash.c 53655c312280211444bfe23af6490a460aec2980
|
||||
F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
|
||||
F src/insert.c 3eb3d0b739eb318c7435b9da35330e2e893e3b78
|
||||
F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2
|
||||
F src/legacy.c cb1939fdeb91ea88fb44fbd2768a10e14bc44650
|
||||
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
|
||||
F src/loadext.c 41bb393d74362f84d4ca751a761667187d4cff51
|
||||
F src/main.c b0c3b5f0728ccfe8ca8809baf629ad354ed6be6d
|
||||
F src/loadext.c 6f1105d8e156983f6986534e55d2e60394544e76
|
||||
F src/main.c bb31f65f7b1870825a4c9a31f19354d566b7633c
|
||||
F src/malloc.c 60e392a4c12c839517f9b0db7b995f825444fb35
|
||||
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
|
||||
F src/mem1.c fc716ff521b6dd3e43eaa211967383308800e70a
|
||||
|
@ -144,7 +144,7 @@ F src/sqlite3ext.h 0d07b81ce98fb4d7d331961feeedfdb274266908
|
|||
F src/sqliteInt.h e7596d5491f65aafe00c0f63f41aedf2a8e007a3
|
||||
F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e
|
||||
F src/table.c 2c48c575dd59b3a6c5c306bc55f51a9402cf429a
|
||||
F src/tclsqlite.c d95e0e74c7167b2807f9f4f73bf45f7c58096297
|
||||
F src/tclsqlite.c dcaedb102d53b151f31c69b6bb0f2920ffc5eeff
|
||||
F src/test1.c 935f327fe989694a3aa07ab78ae5c00705651b34
|
||||
F src/test2.c 443ccc1bd5717b1001e5558b6f6b33bd34f8b81b
|
||||
F src/test3.c 5c7452038ab27aa698070799b10132f26cdd2a80
|
||||
|
@ -155,10 +155,11 @@ F src/test7.c acec2256c7c2d279db5a8b5fa1a2a68fcc942c67
|
|||
F src/test8.c 7933b27f8d300512546ef6bdd25f2fe64c3c13f3
|
||||
F src/test9.c 4615ef08750245a2d96aaa7cbe2fb4aff2b57acc
|
||||
F src/test_async.c 3147c64c34721f088d5ab20f85dabd5d7732c007
|
||||
F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
|
||||
F src/test_autoext.c 1d128825bdf413330f66f4cf3a4d03e8a15b8231
|
||||
F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c
|
||||
F src/test_config.c 4c1fe5184b1e9db8a4bb130889f3a2e91f07508b
|
||||
F src/test_devsym.c cee1aecaa90c895030399ca4ae38f84a08038f8a
|
||||
F src/test_func.c 4e791ce3569792de9123343e077f5aadcef4a2d4
|
||||
F src/test_hexio.c 1a1cd8324d57585ea86b922f609fa1fbaaf9662d
|
||||
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
|
||||
F src/test_malloc.c bba50714c0aa75552bc535473afb8213f18c2fe6
|
||||
|
@ -366,7 +367,7 @@ F test/laststmtchanges.test 18ead86c8a87ade949a1d5658f6dc4bb111d1b02
|
|||
F test/like.test 2a3ddbd5d91503f914eabae67a47c4196fe33a58
|
||||
F test/limit.test ca61a9fc520f54470edb3a771167fe4b68abc247
|
||||
F test/loadext.test 1911e7365a6d31d77ba00dd3a8a31b7f2111a670
|
||||
F test/loadext2.test 95ca7e2cb03fd3e068de97c3a2fe58dbdfd769e1
|
||||
F test/loadext2.test 0bcaeb4d81cd5b6e883fdfea3c1bdbe1f173cbca
|
||||
F test/lock.test 6825aea0b5885578b1b63a3b178803842c4ee9f1
|
||||
F test/lock2.test 018b846f6f3b3b695fad07e317b7988442b556f4
|
||||
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
|
||||
|
@ -458,7 +459,7 @@ F test/table.test 13b1c2e2fb4727b35ee1fb7641fc469214fd2455
|
|||
F test/tableapi.test 791f7e3891d9b70bdb43b311694bf5e9befcbc34
|
||||
F test/tclsqlite.test 3fac87cb1059c46b8fa8a60b553f4f1adb0fb6d9
|
||||
F test/temptable.test 19b851b9e3e64d91e9867619b2a3f5fffee6e125
|
||||
F test/tester.tcl 8f1df98df42667d05ee56ac4ba1ee58f9bb1e885
|
||||
F test/tester.tcl c32f6dfadf9148482d533236c4efee972791d424
|
||||
F test/thread001.test 8fbd9559da0bbdc273e00318c7fd66c162020af7
|
||||
F test/thread002.test 2c4ad2c386f60f6fe268cd91c769ee35b3c1fd0b
|
||||
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
|
||||
|
@ -623,7 +624,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
|
|||
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
|
||||
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
|
||||
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
|
||||
P 57805b588f6b6d070918102a0ff096ade674279a
|
||||
R 643303f05474f1b897ac49030799d91c
|
||||
P 15110ea02768bfe977a57eccd6b941a36ebd6b32
|
||||
R af21ad725b424534724b574d9d688864
|
||||
U drh
|
||||
Z a32ad7ac0402c464aaeb1823ba25215a
|
||||
Z f919f779e5c636162ff7df98711c7fdb
|
||||
|
|
|
@ -1 +1 @@
|
|||
15110ea02768bfe977a57eccd6b941a36ebd6b32
|
||||
e90c4cc8a89838161f218739bc821126e247498c
|
169
src/func.c
169
src/func.c
|
@ -16,7 +16,7 @@
|
|||
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
|
||||
** All other code has file scope.
|
||||
**
|
||||
** $Id: func.c,v 1.187 2008/03/19 14:15:34 drh Exp $
|
||||
** $Id: func.c,v 1.188 2008/03/19 16:08:54 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
|
@ -1020,166 +1020,6 @@ static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** This function generates a string of random characters. Used for
|
||||
** generating test data.
|
||||
*/
|
||||
static void randStr(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
static const unsigned char zSrc[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"0123456789"
|
||||
".-!,:*^+=_|?/<> ";
|
||||
int iMin, iMax, n, r, i;
|
||||
unsigned char zBuf[1000];
|
||||
|
||||
/* It used to be possible to call randstr() with any number of arguments,
|
||||
** but now it is registered with SQLite as requiring exactly 2.
|
||||
*/
|
||||
assert(argc==2);
|
||||
|
||||
iMin = sqlite3_value_int(argv[0]);
|
||||
if( iMin<0 ) iMin = 0;
|
||||
if( iMin>=sizeof(zBuf) ) iMin = sizeof(zBuf)-1;
|
||||
iMax = sqlite3_value_int(argv[1]);
|
||||
if( iMax<iMin ) iMax = iMin;
|
||||
if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf)-1;
|
||||
n = iMin;
|
||||
if( iMax>iMin ){
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
r &= 0x7fffffff;
|
||||
n += r%(iMax + 1 - iMin);
|
||||
}
|
||||
assert( n<sizeof(zBuf) );
|
||||
sqlite3_randomness(n, zBuf);
|
||||
for(i=0; i<n; i++){
|
||||
zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
|
||||
}
|
||||
zBuf[n] = 0;
|
||||
sqlite3_result_text(context, (char*)zBuf, n, SQLITE_TRANSIENT);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** The following two SQL functions are used to test returning a text
|
||||
** result with a destructor. Function 'test_destructor' takes one argument
|
||||
** and returns the same argument interpreted as TEXT. A destructor is
|
||||
** passed with the sqlite3_result_text() call.
|
||||
**
|
||||
** SQL function 'test_destructor_count' returns the number of outstanding
|
||||
** allocations made by 'test_destructor';
|
||||
**
|
||||
** WARNING: Not threadsafe.
|
||||
*/
|
||||
static int test_destructor_count_var = 0;
|
||||
static void destructor(void *p){
|
||||
char *zVal = (char *)p;
|
||||
assert(zVal);
|
||||
zVal--;
|
||||
sqlite3_free(zVal);
|
||||
test_destructor_count_var--;
|
||||
}
|
||||
static void test_destructor(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
char *zVal;
|
||||
int len;
|
||||
sqlite3 *db = sqlite3_user_data(pCtx);
|
||||
|
||||
test_destructor_count_var++;
|
||||
assert( nArg==1 );
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
len = sqlite3ValueBytes(argv[0], ENC(db));
|
||||
zVal = contextMalloc(pCtx, len+3);
|
||||
if( !zVal ){
|
||||
return;
|
||||
}
|
||||
zVal[len+1] = 0;
|
||||
zVal[len+2] = 0;
|
||||
zVal++;
|
||||
memcpy(zVal, sqlite3ValueText(argv[0], ENC(db)), len);
|
||||
if( ENC(db)==SQLITE_UTF8 ){
|
||||
sqlite3_result_text(pCtx, zVal, -1, destructor);
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
}else if( ENC(db)==SQLITE_UTF16LE ){
|
||||
sqlite3_result_text16le(pCtx, zVal, -1, destructor);
|
||||
}else{
|
||||
sqlite3_result_text16be(pCtx, zVal, -1, destructor);
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
}
|
||||
}
|
||||
static void test_destructor_count(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_result_int(pCtx, test_destructor_count_var);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** Routines for testing the sqlite3_get_auxdata() and sqlite3_set_auxdata()
|
||||
** interface.
|
||||
**
|
||||
** The test_auxdata() SQL function attempts to register each of its arguments
|
||||
** as auxiliary data. If there are no prior registrations of aux data for
|
||||
** that argument (meaning the argument is not a constant or this is its first
|
||||
** call) then the result for that argument is 0. If there is a prior
|
||||
** registration, the result for that argument is 1. The overall result
|
||||
** is the individual argument results separated by spaces.
|
||||
*/
|
||||
static void free_test_auxdata(void *p) {sqlite3_free(p);}
|
||||
static void test_auxdata(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int i;
|
||||
char *zRet = contextMalloc(pCtx, nArg*2);
|
||||
if( !zRet ) return;
|
||||
memset(zRet, 0, nArg*2);
|
||||
for(i=0; i<nArg; i++){
|
||||
char const *z = (char*)sqlite3_value_text(argv[i]);
|
||||
if( z ){
|
||||
int n;
|
||||
char *zAux = sqlite3_get_auxdata(pCtx, i);
|
||||
if( zAux ){
|
||||
zRet[i*2] = '1';
|
||||
assert( strcmp(zAux,z)==0 );
|
||||
}else {
|
||||
zRet[i*2] = '0';
|
||||
}
|
||||
n = strlen(z) + 1;
|
||||
zAux = contextMalloc(pCtx, n);
|
||||
if( zAux ){
|
||||
memcpy(zAux, z, n);
|
||||
sqlite3_set_auxdata(pCtx, i, zAux, free_test_auxdata);
|
||||
}
|
||||
zRet[i*2+1] = ' ';
|
||||
}
|
||||
}
|
||||
sqlite3_result_text(pCtx, zRet, 2*nArg-1, free_test_auxdata);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
/*
|
||||
** A function to test error reporting from user functions. This function
|
||||
** returns a copy of its first argument as an error.
|
||||
*/
|
||||
static void test_error(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), 0);
|
||||
}
|
||||
#endif /* SQLITE_TEST */
|
||||
|
||||
/*
|
||||
** An instance of the following structure holds the context of a
|
||||
|
@ -1424,13 +1264,6 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
|
|||
#ifndef SQLITE_OMIT_LOAD_EXTENSION
|
||||
{ "load_extension", 1, 0xff, SQLITE_UTF8, 0, loadExt },
|
||||
{ "load_extension", 2, 0xff, SQLITE_UTF8, 0, loadExt },
|
||||
#endif
|
||||
#ifdef SQLITE_TEST
|
||||
{ "randstr", 2, 0, SQLITE_UTF8, 0, randStr },
|
||||
{ "test_destructor", 1, 0xff, SQLITE_UTF8, 0, test_destructor},
|
||||
{ "test_destructor_count", 0, 0, SQLITE_UTF8, 0, test_destructor_count},
|
||||
{ "test_auxdata", -1, 0, SQLITE_UTF8, 0, test_auxdata},
|
||||
{ "test_error", 1, 0, SQLITE_UTF8, 0, test_error},
|
||||
#endif
|
||||
};
|
||||
static const struct {
|
||||
|
|
|
@ -430,6 +430,17 @@ int sqlite3_enable_load_extension(sqlite3 *db, int onoff){
|
|||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_LOADEXTENSION */
|
||||
|
||||
/*
|
||||
** The following code is added regardless of whether or not extension
|
||||
** loading is supported.
|
||||
*/
|
||||
#ifdef SQLITE_OMIT_LOAD_EXTENSTION
|
||||
const sqlite3_api_routines sqlite3Apis = { 0 };
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
** The following object holds the list of automatically loaded
|
||||
** extensions.
|
||||
|
@ -519,5 +530,3 @@ int sqlite3AutoLoadExtensions(sqlite3 *db){
|
|||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
|
||||
|
|
49
src/main.c
49
src/main.c
|
@ -14,7 +14,7 @@
|
|||
** other files are for internal use by SQLite and should not be
|
||||
** accessed by users of the library.
|
||||
**
|
||||
** $Id: main.c,v 1.423 2008/03/19 14:15:34 drh Exp $
|
||||
** $Id: main.c,v 1.424 2008/03/19 16:08:54 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include <ctype.h>
|
||||
|
@ -541,7 +541,6 @@ int sqlite3_create_function(
|
|||
){
|
||||
int rc;
|
||||
sqlite3_mutex_enter(db->mutex);
|
||||
assert( !db->mallocFailed );
|
||||
rc = sqlite3CreateFunc(db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal);
|
||||
rc = sqlite3ApiExit(db, rc);
|
||||
sqlite3_mutex_leave(db->mutex);
|
||||
|
@ -1495,6 +1494,14 @@ int sqlite3_test_control(int op, ...){
|
|||
va_list ap;
|
||||
va_start(ap, op);
|
||||
switch( op ){
|
||||
/*
|
||||
** sqlite3_test_control(FAULT_CONFIG, fault_id, nDelay, nRepeat)
|
||||
**
|
||||
** Configure a fault injector. The specific fault injector is
|
||||
** identified by the fault_id argument. (ex: SQLITE_FAULTINJECTOR_MALLOC)
|
||||
** The fault will occur after a delay of nDelay calls. The fault
|
||||
** will repeat nRepeat times.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_FAULT_CONFIG: {
|
||||
int id = va_arg(ap, int);
|
||||
int nDelay = va_arg(ap, int);
|
||||
|
@ -1502,29 +1509,67 @@ int sqlite3_test_control(int op, ...){
|
|||
sqlite3FaultConfig(id, nDelay, nRepeat);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite3_test_control(FAULT_FAILURES, fault_id)
|
||||
**
|
||||
** Return the number of faults (both hard and benign faults) that have
|
||||
** occurred since the injector identified by fault_id) was last configured.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_FAULT_FAILURES: {
|
||||
int id = va_arg(ap, int);
|
||||
rc = sqlite3FaultFailures(id);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite3_test_control(FAULT_BENIGN_FAILURES, fault_id)
|
||||
**
|
||||
** Return the number of benign faults that have occurred since the
|
||||
** injector identified by fault_id was last configured.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_FAULT_BENIGN_FAILURES: {
|
||||
int id = va_arg(ap, int);
|
||||
rc = sqlite3FaultBenignFailures(id);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** sqlite3_test_control(FAULT_PENDING, fault_id)
|
||||
**
|
||||
** Return the number of successes that will occur before the next
|
||||
** scheduled failure on fault injector fault_id.
|
||||
** If no failures are scheduled, return -1.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_FAULT_PENDING: {
|
||||
int id = va_arg(ap, int);
|
||||
rc = sqlite3FaultPending(id);
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** Save the current state of the PRNG.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_PRNG_SAVE: {
|
||||
sqlite3PrngSaveState();
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** Restore the state of the PRNG to the last state saved using
|
||||
** PRNG_SAVE. If PRNG_SAVE has never before been called, then
|
||||
** this verb acts like PRNG_RESET.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_PRNG_RESTORE: {
|
||||
sqlite3PrngRestoreState();
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
** Reset the PRNG back to its uninitialized state. The next call
|
||||
** to sqlite3_randomness() will reseed the PRNG using a single call
|
||||
** to the xRandomness method of the default VFS.
|
||||
*/
|
||||
case SQLITE_TESTCTRL_PRNG_RESET: {
|
||||
sqlite3PrngResetState();
|
||||
break;
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
** A TCL Interface to SQLite. Append this file to sqlite3.c and
|
||||
** compile the whole thing to build a TCL-enabled version of SQLite.
|
||||
**
|
||||
** $Id: tclsqlite.c,v 1.209 2008/02/18 22:24:58 drh Exp $
|
||||
** $Id: tclsqlite.c,v 1.210 2008/03/19 16:08:54 drh Exp $
|
||||
*/
|
||||
#include "tcl.h"
|
||||
#include <errno.h>
|
||||
|
@ -2534,6 +2534,7 @@ int TCLSH_MAIN(int argc, char **argv){
|
|||
extern int Sqlitetest9_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestasync_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest_autoext_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest_func_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest_hexio_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest_malloc_Init(Tcl_Interp*);
|
||||
extern int Sqlitetestschema_Init(Tcl_Interp*);
|
||||
|
@ -2555,6 +2556,7 @@ int TCLSH_MAIN(int argc, char **argv){
|
|||
Sqlitetest9_Init(interp);
|
||||
Sqlitetestasync_Init(interp);
|
||||
Sqlitetest_autoext_Init(interp);
|
||||
Sqlitetest_func_Init(interp);
|
||||
Sqlitetest_hexio_Init(interp);
|
||||
Sqlitetest_malloc_Init(interp);
|
||||
Sqlitetestschema_Init(interp);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*************************************************************************
|
||||
** Test extension for testing the sqlite3_auto_extension() function.
|
||||
**
|
||||
** $Id: test_autoext.c,v 1.2 2006/12/19 18:57:11 drh Exp $
|
||||
** $Id: test_autoext.c,v 1.3 2008/03/19 16:08:54 drh Exp $
|
||||
*/
|
||||
#include "tcl.h"
|
||||
#ifndef SQLITE_OMIT_LOAD_EXTENSION
|
||||
|
@ -157,8 +157,8 @@ int Sqlitetest_autoext_Init(Tcl_Interp *interp){
|
|||
autoExtCubeObjCmd, 0, 0);
|
||||
Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_broken",
|
||||
autoExtBrokenObjCmd, 0, 0);
|
||||
#endif
|
||||
Tcl_CreateObjCommand(interp, "sqlite3_reset_auto_extension",
|
||||
resetAutoExtObjCmd, 0, 0);
|
||||
#endif
|
||||
return TCL_OK;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
** 2008 March 19
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** Code for testing all sorts of SQLite interfaces. This code
|
||||
** implements new SQL functions used by the test scripts.
|
||||
**
|
||||
** $Id: test_func.c,v 1.1 2008/03/19 16:08:54 drh Exp $
|
||||
*/
|
||||
#include "sqlite3.h"
|
||||
#include "tcl.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
/*
|
||||
** Allocate nByte bytes of space using sqlite3_malloc(). If the
|
||||
** allocation fails, call sqlite3_result_error_nomem() to notify
|
||||
** the database handle that malloc() has failed.
|
||||
*/
|
||||
static void *testContextMalloc(sqlite3_context *context, int nByte){
|
||||
char *z = sqlite3_malloc(nByte);
|
||||
if( !z && nByte>0 ){
|
||||
sqlite3_result_error_nomem(context);
|
||||
}
|
||||
return z;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function generates a string of random characters. Used for
|
||||
** generating test data.
|
||||
*/
|
||||
static void randStr(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
static const unsigned char zSrc[] =
|
||||
"abcdefghijklmnopqrstuvwxyz"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"0123456789"
|
||||
".-!,:*^+=_|?/<> ";
|
||||
int iMin, iMax, n, r, i;
|
||||
unsigned char zBuf[1000];
|
||||
|
||||
/* It used to be possible to call randstr() with any number of arguments,
|
||||
** but now it is registered with SQLite as requiring exactly 2.
|
||||
*/
|
||||
assert(argc==2);
|
||||
|
||||
iMin = sqlite3_value_int(argv[0]);
|
||||
if( iMin<0 ) iMin = 0;
|
||||
if( iMin>=sizeof(zBuf) ) iMin = sizeof(zBuf)-1;
|
||||
iMax = sqlite3_value_int(argv[1]);
|
||||
if( iMax<iMin ) iMax = iMin;
|
||||
if( iMax>=sizeof(zBuf) ) iMax = sizeof(zBuf)-1;
|
||||
n = iMin;
|
||||
if( iMax>iMin ){
|
||||
sqlite3_randomness(sizeof(r), &r);
|
||||
r &= 0x7fffffff;
|
||||
n += r%(iMax + 1 - iMin);
|
||||
}
|
||||
assert( n<sizeof(zBuf) );
|
||||
sqlite3_randomness(n, zBuf);
|
||||
for(i=0; i<n; i++){
|
||||
zBuf[i] = zSrc[zBuf[i]%(sizeof(zSrc)-1)];
|
||||
}
|
||||
zBuf[n] = 0;
|
||||
sqlite3_result_text(context, (char*)zBuf, n, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
/*
|
||||
** The following two SQL functions are used to test returning a text
|
||||
** result with a destructor. Function 'test_destructor' takes one argument
|
||||
** and returns the same argument interpreted as TEXT. A destructor is
|
||||
** passed with the sqlite3_result_text() call.
|
||||
**
|
||||
** SQL function 'test_destructor_count' returns the number of outstanding
|
||||
** allocations made by 'test_destructor';
|
||||
**
|
||||
** WARNING: Not threadsafe.
|
||||
*/
|
||||
static int test_destructor_count_var = 0;
|
||||
static void destructor(void *p){
|
||||
char *zVal = (char *)p;
|
||||
assert(zVal);
|
||||
zVal--;
|
||||
sqlite3_free(zVal);
|
||||
test_destructor_count_var--;
|
||||
}
|
||||
static void test_destructor(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
char *zVal;
|
||||
int len;
|
||||
|
||||
test_destructor_count_var++;
|
||||
assert( nArg==1 );
|
||||
if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return;
|
||||
len = sqlite3_value_bytes(argv[0]);
|
||||
zVal = testContextMalloc(pCtx, len+3);
|
||||
if( !zVal ){
|
||||
return;
|
||||
}
|
||||
zVal[len+1] = 0;
|
||||
zVal[len+2] = 0;
|
||||
zVal++;
|
||||
memcpy(zVal, sqlite3_value_text(argv[0]), len);
|
||||
sqlite3_result_text(pCtx, zVal, -1, destructor);
|
||||
}
|
||||
static void test_destructor_count(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_result_int(pCtx, test_destructor_count_var);
|
||||
}
|
||||
|
||||
/*
|
||||
** Routines for testing the sqlite3_get_auxdata() and sqlite3_set_auxdata()
|
||||
** interface.
|
||||
**
|
||||
** The test_auxdata() SQL function attempts to register each of its arguments
|
||||
** as auxiliary data. If there are no prior registrations of aux data for
|
||||
** that argument (meaning the argument is not a constant or this is its first
|
||||
** call) then the result for that argument is 0. If there is a prior
|
||||
** registration, the result for that argument is 1. The overall result
|
||||
** is the individual argument results separated by spaces.
|
||||
*/
|
||||
static void free_test_auxdata(void *p) {sqlite3_free(p);}
|
||||
static void test_auxdata(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
int i;
|
||||
char *zRet = testContextMalloc(pCtx, nArg*2);
|
||||
if( !zRet ) return;
|
||||
memset(zRet, 0, nArg*2);
|
||||
for(i=0; i<nArg; i++){
|
||||
char const *z = (char*)sqlite3_value_text(argv[i]);
|
||||
if( z ){
|
||||
int n;
|
||||
char *zAux = sqlite3_get_auxdata(pCtx, i);
|
||||
if( zAux ){
|
||||
zRet[i*2] = '1';
|
||||
assert( strcmp(zAux,z)==0 );
|
||||
}else {
|
||||
zRet[i*2] = '0';
|
||||
}
|
||||
n = strlen(z) + 1;
|
||||
zAux = testContextMalloc(pCtx, n);
|
||||
if( zAux ){
|
||||
memcpy(zAux, z, n);
|
||||
sqlite3_set_auxdata(pCtx, i, zAux, free_test_auxdata);
|
||||
}
|
||||
zRet[i*2+1] = ' ';
|
||||
}
|
||||
}
|
||||
sqlite3_result_text(pCtx, zRet, 2*nArg-1, free_test_auxdata);
|
||||
}
|
||||
|
||||
/*
|
||||
** A function to test error reporting from user functions. This function
|
||||
** returns a copy of its first argument as an error.
|
||||
*/
|
||||
static void test_error(
|
||||
sqlite3_context *pCtx,
|
||||
int nArg,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
sqlite3_result_error(pCtx, (char*)sqlite3_value_text(argv[0]), 0);
|
||||
}
|
||||
|
||||
static int registerTestFunctions(sqlite3 *db){
|
||||
static const struct {
|
||||
char *zName;
|
||||
signed char nArg;
|
||||
unsigned char eTextRep; /* 1: UTF-16. 0: UTF-8 */
|
||||
void (*xFunc)(sqlite3_context*,int,sqlite3_value **);
|
||||
} aFuncs[] = {
|
||||
{ "randstr", 2, SQLITE_UTF8, randStr },
|
||||
{ "test_destructor", 1, SQLITE_UTF8, test_destructor},
|
||||
{ "test_destructor_count", 0, SQLITE_UTF8, test_destructor_count},
|
||||
{ "test_auxdata", -1, SQLITE_UTF8, test_auxdata},
|
||||
{ "test_error", 1, SQLITE_UTF8, test_error},
|
||||
};
|
||||
int i;
|
||||
|
||||
for(i=0; i<sizeof(aFuncs)/sizeof(aFuncs[0]); i++){
|
||||
sqlite3_create_function(db, aFuncs[i].zName, aFuncs[i].nArg,
|
||||
aFuncs[i].eTextRep, 0, aFuncs[i].xFunc, 0, 0);
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** TCLCMD: autoinstall_test_functions
|
||||
**
|
||||
** Invoke this TCL command to use sqlite3_auto_extension() to cause
|
||||
** the standard set of test functions to be loaded into each new
|
||||
** database connection.
|
||||
*/
|
||||
static int autoinstall_test_funcs(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3_auto_extension((void*)registerTestFunctions);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest_func_Init(Tcl_Interp *interp){
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_ObjCmdProc *xProc;
|
||||
} aObjCmd[] = {
|
||||
{ "autoinstall_test_functions", autoinstall_test_funcs },
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
|
||||
Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, 0, 0);
|
||||
}
|
||||
sqlite3_auto_extension((void*)registerTestFunctions);
|
||||
return TCL_OK;
|
||||
}
|
|
@ -12,7 +12,7 @@
|
|||
# focus of this script is automatic extension loading and the
|
||||
# sqlite3_auto_extension() API.
|
||||
#
|
||||
# $Id: loadext2.test,v 1.2 2007/04/06 21:42:22 drh Exp $
|
||||
# $Id: loadext2.test,v 1.3 2008/03/19 16:08:54 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
@ -140,4 +140,5 @@ do_test loadext2-1.15 {
|
|||
|
||||
|
||||
sqlite3_reset_auto_extension
|
||||
autoinstall_test_functions
|
||||
finish_test
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# This file implements some common TCL routines used for regression
|
||||
# testing the SQLite library
|
||||
#
|
||||
# $Id: tester.tcl,v 1.106 2008/03/07 19:51:15 drh Exp $
|
||||
# $Id: tester.tcl,v 1.107 2008/03/19 16:08:54 drh Exp $
|
||||
|
||||
|
||||
set tcl_precision 15
|
||||
|
@ -187,6 +187,7 @@ proc finalize_testing {} {
|
|||
sqlite3 db {}
|
||||
# sqlite3_clear_tsd_memdebug
|
||||
db close
|
||||
sqlite3_reset_auto_extension
|
||||
set heaplimit [sqlite3_soft_heap_limit]
|
||||
if {$heaplimit!=$::soft_limit} {
|
||||
puts "soft-heap-limit changed by this script\
|
||||
|
|
Loading…
Reference in New Issue