aboutsummaryrefslogtreecommitdiff
path: root/src/test1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test1.c')
-rw-r--r--src/test1.c164
1 files changed, 164 insertions, 0 deletions
diff --git a/src/test1.c b/src/test1.c
index 8d2249cbb..5ea0e38b9 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -2718,6 +2718,46 @@ bad_args:
}
/*
+** Usage: add_test_utf16bin_collate <db ptr>
+**
+** Add a utf-16 collation sequence named "utf16bin" to the database
+** handle. This collation sequence compares arguments in the same way as the
+** built-in collation "binary".
+*/
+static int test_utf16bin_collate_func(
+ void *pCtx,
+ int nA, const void *zA,
+ int nB, const void *zB
+){
+ int nCmp = (nA>nB ? nB : nA);
+ int res = memcmp(zA, zB, nCmp);
+ if( res==0 ) res = nA - nB;
+ return res;
+}
+static int test_utf16bin_collate(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ sqlite3 *db;
+ int rc;
+
+ if( objc!=2 ) goto bad_args;
+ if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
+
+ rc = sqlite3_create_collation(db, "utf16bin", SQLITE_UTF16, 0,
+ test_utf16bin_collate_func
+ );
+ if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
+ return TCL_OK;
+
+bad_args:
+ Tcl_WrongNumArgs(interp, 1, objv, "DB");
+ return TCL_ERROR;
+}
+
+/*
** When the collation needed callback is invoked, record the name of
** the requested collating function here. The recorded name is linked
** to a TCL variable and used to make sure that the requested collation
@@ -5895,6 +5935,7 @@ static int test_test_control(
int i;
} aVerb[] = {
{ "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT },
+ { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP },
};
int iVerb;
int iFlag;
@@ -5922,6 +5963,19 @@ static int test_test_control(
sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, val);
break;
}
+
+ case SQLITE_TESTCTRL_SORTER_MMAP: {
+ int val;
+ sqlite3 *db;
+ if( objc!=4 ){
+ Tcl_WrongNumArgs(interp, 2, objv, "DB LIMIT");
+ return TCL_ERROR;
+ }
+ if( getDbPointer(interp, Tcl_GetString(objv[2]), &db) ) return TCL_ERROR;
+ if( Tcl_GetIntFromObj(interp, objv[3], &val) ) return TCL_ERROR;
+ sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP, db, val);
+ break;
+ }
}
Tcl_ResetResult(interp);
@@ -6335,6 +6389,113 @@ static int tclLoadStaticExtensionCmd(
return TCL_OK;
}
+/*
+** sorter_test_fakeheap BOOL
+**
+*/
+static int sorter_test_fakeheap(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ int bArg;
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "BOOL");
+ return TCL_ERROR;
+ }
+
+ if( Tcl_GetBooleanFromObj(interp, objv[1], &bArg) ){
+ return TCL_ERROR;
+ }
+
+ if( bArg ){
+ if( sqlite3GlobalConfig.pHeap==0 ){
+ sqlite3GlobalConfig.pHeap = SQLITE_INT_TO_PTR(-1);
+ }
+ }else{
+ if( sqlite3GlobalConfig.pHeap==SQLITE_INT_TO_PTR(-1) ){
+ sqlite3GlobalConfig.pHeap = 0;
+ }
+ }
+
+ Tcl_ResetResult(interp);
+ return TCL_OK;
+}
+
+/*
+** sorter_test_sort4_helper DB SQL1 NSTEP SQL2
+**
+** Compile SQL statement $SQL1 and step it $NSTEP times. For each row,
+** check that the leftmost and rightmost columns returned are both integers,
+** and that both contain the same value.
+**
+** Then execute statement $SQL2. Check that the statement returns the same
+** set of integers in the same order as in the previous step (using $SQL1).
+*/
+static int sorter_test_sort4_helper(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ const char *zSql1;
+ const char *zSql2;
+ int nStep;
+ int iStep;
+ int iCksum1 = 0;
+ int iCksum2 = 0;
+ int rc;
+ int iB;
+ sqlite3 *db;
+ sqlite3_stmt *pStmt;
+
+ if( objc!=5 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "DB SQL1 NSTEP SQL2");
+ return TCL_ERROR;
+ }
+
+ if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
+ zSql1 = Tcl_GetString(objv[2]);
+ if( Tcl_GetIntFromObj(interp, objv[3], &nStep) ) return TCL_ERROR;
+ zSql2 = Tcl_GetString(objv[4]);
+
+ rc = sqlite3_prepare_v2(db, zSql1, -1, &pStmt, 0);
+ if( rc!=SQLITE_OK ) goto sql_error;
+
+ iB = sqlite3_column_count(pStmt)-1;
+ for(iStep=0; iStep<nStep && SQLITE_ROW==sqlite3_step(pStmt); iStep++){
+ int a = sqlite3_column_int(pStmt, 0);
+ if( a!=sqlite3_column_int(pStmt, iB) ){
+ Tcl_AppendResult(interp, "data error: (a!=b)", 0);
+ return TCL_ERROR;
+ }
+
+ iCksum1 += (iCksum1 << 3) + a;
+ }
+ rc = sqlite3_finalize(pStmt);
+ if( rc!=SQLITE_OK ) goto sql_error;
+
+ rc = sqlite3_prepare_v2(db, zSql2, -1, &pStmt, 0);
+ if( rc!=SQLITE_OK ) goto sql_error;
+ for(iStep=0; SQLITE_ROW==sqlite3_step(pStmt); iStep++){
+ int a = sqlite3_column_int(pStmt, 0);
+ iCksum2 += (iCksum2 << 3) + a;
+ }
+ rc = sqlite3_finalize(pStmt);
+ if( rc!=SQLITE_OK ) goto sql_error;
+
+ if( iCksum1!=iCksum2 ){
+ Tcl_AppendResult(interp, "checksum mismatch", 0);
+ return TCL_ERROR;
+ }
+
+ return TCL_OK;
+ sql_error:
+ Tcl_AppendResult(interp, "sql error: ", sqlite3_errmsg(db), 0);
+ return TCL_ERROR;
+}
+
/*
** Register commands with the TCL interpreter.
@@ -6537,6 +6698,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "add_test_collate", test_collate, 0 },
{ "add_test_collate_needed", test_collate_needed, 0 },
{ "add_test_function", test_function, 0 },
+ { "add_test_utf16bin_collate", test_utf16bin_collate, 0 },
#endif
{ "sqlite3_test_errstr", test_errstr, 0 },
{ "tcl_variable_type", tcl_variable_type, 0 },
@@ -6570,6 +6732,8 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "getrusage", test_getrusage },
#endif
{ "load_static_extension", tclLoadStaticExtensionCmd },
+ { "sorter_test_fakeheap", sorter_test_fakeheap },
+ { "sorter_test_sort4_helper", sorter_test_sort4_helper },
};
static int bitmask_size = sizeof(Bitmask)*8;
int i;