| OLD | NEW |
| 1 /* | 1 /* |
| 2 ** 2001 September 15 | 2 ** 2001 September 15 |
| 3 ** | 3 ** |
| 4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
| 5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
| 6 ** | 6 ** |
| 7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
| 8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
| 9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
| 10 ** | 10 ** |
| 11 ************************************************************************* | 11 ************************************************************************* |
| 12 ** Code for testing the utf.c module in SQLite. This code | 12 ** Code for testing the utf.c module in SQLite. This code |
| 13 ** is not included in the SQLite library. It is used for automated | 13 ** is not included in the SQLite library. It is used for automated |
| 14 ** testing of the SQLite library. Specifically, the code in this file | 14 ** testing of the SQLite library. Specifically, the code in this file |
| 15 ** is used for testing the SQLite routines for converting between | 15 ** is used for testing the SQLite routines for converting between |
| 16 ** the various supported unicode encodings. | 16 ** the various supported unicode encodings. |
| 17 */ | 17 */ |
| 18 #include "sqliteInt.h" | 18 #include "sqliteInt.h" |
| 19 #include "vdbeInt.h" | 19 #include "vdbeInt.h" |
| 20 #include "tcl.h" | 20 #if defined(INCLUDE_SQLITE_TCL_H) |
| 21 # include "sqlite_tcl.h" |
| 22 #else |
| 23 # include "tcl.h" |
| 24 #endif |
| 21 #include <stdlib.h> | 25 #include <stdlib.h> |
| 22 #include <string.h> | 26 #include <string.h> |
| 23 | 27 |
| 24 /* | 28 /* |
| 25 ** The first argument is a TCL UTF-8 string. Return the byte array | 29 ** The first argument is a TCL UTF-8 string. Return the byte array |
| 26 ** object with the encoded representation of the string, including | 30 ** object with the encoded representation of the string, including |
| 27 ** the NULL terminator. | 31 ** the NULL terminator. |
| 28 */ | 32 */ |
| 29 static int binarize( | 33 static int SQLITE_TCLAPI binarize( |
| 30 void * clientData, | 34 void * clientData, |
| 31 Tcl_Interp *interp, | 35 Tcl_Interp *interp, |
| 32 int objc, | 36 int objc, |
| 33 Tcl_Obj *CONST objv[] | 37 Tcl_Obj *CONST objv[] |
| 34 ){ | 38 ){ |
| 35 int len; | 39 int len; |
| 36 char *bytes; | 40 char *bytes; |
| 37 Tcl_Obj *pRet; | 41 Tcl_Obj *pRet; |
| 38 assert(objc==2); | 42 assert(objc==2); |
| 39 | 43 |
| 40 bytes = Tcl_GetStringFromObj(objv[1], &len); | 44 bytes = Tcl_GetStringFromObj(objv[1], &len); |
| 41 pRet = Tcl_NewByteArrayObj((u8*)bytes, len+1); | 45 pRet = Tcl_NewByteArrayObj((u8*)bytes, len+1); |
| 42 Tcl_SetObjResult(interp, pRet); | 46 Tcl_SetObjResult(interp, pRet); |
| 43 return TCL_OK; | 47 return TCL_OK; |
| 44 } | 48 } |
| 45 | 49 |
| 46 /* | 50 /* |
| 47 ** Usage: test_value_overhead <repeat-count> <do-calls>. | 51 ** Usage: test_value_overhead <repeat-count> <do-calls>. |
| 48 ** | 52 ** |
| 49 ** This routine is used to test the overhead of calls to | 53 ** This routine is used to test the overhead of calls to |
| 50 ** sqlite3_value_text(), on a value that contains a UTF-8 string. The idea | 54 ** sqlite3_value_text(), on a value that contains a UTF-8 string. The idea |
| 51 ** is to figure out whether or not it is a problem to use sqlite3_value | 55 ** is to figure out whether or not it is a problem to use sqlite3_value |
| 52 ** structures with collation sequence functions. | 56 ** structures with collation sequence functions. |
| 53 ** | 57 ** |
| 54 ** If <do-calls> is 0, then the calls to sqlite3_value_text() are not | 58 ** If <do-calls> is 0, then the calls to sqlite3_value_text() are not |
| 55 ** actually made. | 59 ** actually made. |
| 56 */ | 60 */ |
| 57 static int test_value_overhead( | 61 static int SQLITE_TCLAPI test_value_overhead( |
| 58 void * clientData, | 62 void * clientData, |
| 59 Tcl_Interp *interp, | 63 Tcl_Interp *interp, |
| 60 int objc, | 64 int objc, |
| 61 Tcl_Obj *CONST objv[] | 65 Tcl_Obj *CONST objv[] |
| 62 ){ | 66 ){ |
| 63 int do_calls; | 67 int do_calls; |
| 64 int repeat_count; | 68 int repeat_count; |
| 65 int i; | 69 int i; |
| 66 Mem val; | 70 Mem val; |
| 67 | 71 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if( pEnc->enc==SQLITE_UTF16 ){ | 115 if( pEnc->enc==SQLITE_UTF16 ){ |
| 112 return SQLITE_UTF16NATIVE; | 116 return SQLITE_UTF16NATIVE; |
| 113 } | 117 } |
| 114 return pEnc->enc; | 118 return pEnc->enc; |
| 115 } | 119 } |
| 116 | 120 |
| 117 /* | 121 /* |
| 118 ** Usage: test_translate <string/blob> <from enc> <to enc> ?<transient>? | 122 ** Usage: test_translate <string/blob> <from enc> <to enc> ?<transient>? |
| 119 ** | 123 ** |
| 120 */ | 124 */ |
| 121 static int test_translate( | 125 static int SQLITE_TCLAPI test_translate( |
| 122 void * clientData, | 126 void * clientData, |
| 123 Tcl_Interp *interp, | 127 Tcl_Interp *interp, |
| 124 int objc, | 128 int objc, |
| 125 Tcl_Obj *CONST objv[] | 129 Tcl_Obj *CONST objv[] |
| 126 ){ | 130 ){ |
| 127 u8 enc_from; | 131 u8 enc_from; |
| 128 u8 enc_to; | 132 u8 enc_to; |
| 129 sqlite3_value *pVal; | 133 sqlite3_value *pVal; |
| 130 | 134 |
| 131 char *z; | 135 char *z; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return TCL_OK; | 179 return TCL_OK; |
| 176 } | 180 } |
| 177 | 181 |
| 178 /* | 182 /* |
| 179 ** Usage: translate_selftest | 183 ** Usage: translate_selftest |
| 180 ** | 184 ** |
| 181 ** Call sqlite3UtfSelfTest() to run the internal tests for unicode | 185 ** Call sqlite3UtfSelfTest() to run the internal tests for unicode |
| 182 ** translation. If there is a problem an assert() will fail. | 186 ** translation. If there is a problem an assert() will fail. |
| 183 **/ | 187 **/ |
| 184 void sqlite3UtfSelfTest(void); | 188 void sqlite3UtfSelfTest(void); |
| 185 static int test_translate_selftest( | 189 static int SQLITE_TCLAPI test_translate_selftest( |
| 186 void * clientData, | 190 void * clientData, |
| 187 Tcl_Interp *interp, | 191 Tcl_Interp *interp, |
| 188 int objc, | 192 int objc, |
| 189 Tcl_Obj *CONST objv[] | 193 Tcl_Obj *CONST objv[] |
| 190 ){ | 194 ){ |
| 191 #ifndef SQLITE_OMIT_UTF16 | 195 #ifndef SQLITE_OMIT_UTF16 |
| 192 sqlite3UtfSelfTest(); | 196 sqlite3UtfSelfTest(); |
| 193 #endif | 197 #endif |
| 194 return SQLITE_OK; | 198 return SQLITE_OK; |
| 195 } | 199 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 207 { "test_value_overhead", (Tcl_ObjCmdProc*)test_value_overhead }, | 211 { "test_value_overhead", (Tcl_ObjCmdProc*)test_value_overhead }, |
| 208 { "test_translate", (Tcl_ObjCmdProc*)test_translate }, | 212 { "test_translate", (Tcl_ObjCmdProc*)test_translate }, |
| 209 { "translate_selftest", (Tcl_ObjCmdProc*)test_translate_selftest}, | 213 { "translate_selftest", (Tcl_ObjCmdProc*)test_translate_selftest}, |
| 210 }; | 214 }; |
| 211 int i; | 215 int i; |
| 212 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ | 216 for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){ |
| 213 Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); | 217 Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0); |
| 214 } | 218 } |
| 215 return SQLITE_OK; | 219 return SQLITE_OK; |
| 216 } | 220 } |
| OLD | NEW |