mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Tests for text encoding conversion functions. Also new sqlite3_bindXX APIs. (CVS 1400)
FossilOrigin-Name: 4e602bb473e22cc45de2f5788c035d18586cb836
This commit is contained in:
56
src/test5.c
56
src/test5.c
@@ -11,9 +11,11 @@
|
||||
*************************************************************************
|
||||
** Code for testing the utf.c module in SQLite. This code
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
** testing of the SQLite library. Specifically, the code in this file
|
||||
** is used for testing the SQLite routines for converting between
|
||||
** the various supported unicode encodings.
|
||||
**
|
||||
** $Id:
|
||||
** $Id: test5.c,v 1.4 2004/05/19 10:34:53 danielk1977 Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "tcl.h"
|
||||
@@ -21,8 +23,8 @@
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** Return the number of bytes up to and including the first \u0000
|
||||
** character in *pStr.
|
||||
** Return the number of bytes up to and including the first pair of
|
||||
** 0x00 bytes in *pStr.
|
||||
*/
|
||||
static int utf16_length(const unsigned char *pZ){
|
||||
const unsigned char *pC1 = pZ;
|
||||
@@ -50,10 +52,10 @@ static int sqlite_utf8to16le(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
in = Tcl_GetByteArrayFromObj(objv[1], 0);
|
||||
in = Tcl_GetString(objv[1]);
|
||||
out = (unsigned char *)sqlite3utf8to16le(in, -1);
|
||||
res = Tcl_NewByteArrayObj(out, utf16_length(out));
|
||||
sqliteFree(out);
|
||||
sqliteFree(out);
|
||||
|
||||
Tcl_SetObjResult(interp, res);
|
||||
|
||||
@@ -77,6 +79,7 @@ static int sqlite_utf8to16be(
|
||||
}
|
||||
|
||||
in = Tcl_GetByteArrayFromObj(objv[1], 0);
|
||||
in = Tcl_GetString(objv[1]);
|
||||
out = (unsigned char *)sqlite3utf8to16be(in, -1);
|
||||
res = Tcl_NewByteArrayObj(out, utf16_length(out));
|
||||
sqliteFree(out);
|
||||
@@ -158,13 +161,13 @@ static int sqlite_utf16to8(
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), "<utf-16 encoded-string>", 0);
|
||||
Tcl_GetStringFromObj(objv[0], 0), " <utf-16 encoded-string>", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
in = Tcl_GetByteArrayFromObj(objv[1], 0);
|
||||
out = sqlite3utf16to8(in, -1);
|
||||
res = Tcl_NewByteArrayObj(out, strlen(out));
|
||||
res = Tcl_NewByteArrayObj(out, strlen(out)+1);
|
||||
sqliteFree(out);
|
||||
|
||||
Tcl_SetObjResult(interp, res);
|
||||
@@ -172,6 +175,28 @@ static int sqlite_utf16to8(
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** The first argument is a TCL UTF-8 string. Return the byte array
|
||||
** object with the encoded representation of the string, including
|
||||
** the NULL terminator.
|
||||
*/
|
||||
static int binarize(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int len;
|
||||
char *bytes;
|
||||
Tcl_Obj *pRet;
|
||||
assert(objc==2);
|
||||
|
||||
bytes = Tcl_GetStringFromObj(objv[1], &len);
|
||||
pRet = Tcl_NewByteArrayObj(bytes, len+1);
|
||||
Tcl_SetObjResult(interp, pRet);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
@@ -179,17 +204,18 @@ static int sqlite_utf16to8(
|
||||
int Sqlitetest5_Init(Tcl_Interp *interp){
|
||||
static struct {
|
||||
char *zName;
|
||||
Tcl_CmdProc *xProc;
|
||||
Tcl_ObjCmdProc *xProc;
|
||||
} aCmd[] = {
|
||||
{ "sqlite_utf16to8", (Tcl_CmdProc*)sqlite_utf16to8 },
|
||||
{ "sqlite_utf8to16le", (Tcl_CmdProc*)sqlite_utf8to16le },
|
||||
{ "sqlite_utf8to16be", (Tcl_CmdProc*)sqlite_utf8to16be },
|
||||
{ "sqlite_utf16to16le", (Tcl_CmdProc*)sqlite_utf16to16le },
|
||||
{ "sqlite_utf16to16be", (Tcl_CmdProc*)sqlite_utf16to16be }
|
||||
{ "sqlite_utf16to8", (Tcl_ObjCmdProc*)sqlite_utf16to8 },
|
||||
{ "sqlite_utf8to16le", (Tcl_ObjCmdProc*)sqlite_utf8to16le },
|
||||
{ "sqlite_utf8to16be", (Tcl_ObjCmdProc*)sqlite_utf8to16be },
|
||||
{ "sqlite_utf16to16le", (Tcl_ObjCmdProc*)sqlite_utf16to16le },
|
||||
{ "sqlite_utf16to16be", (Tcl_ObjCmdProc*)sqlite_utf16to16be },
|
||||
{ "binarize", (Tcl_ObjCmdProc*)binarize }
|
||||
};
|
||||
int i;
|
||||
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
||||
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
||||
}
|
||||
|
||||
return TCL_OK;
|
||||
|
Reference in New Issue
Block a user