4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
13 ** This file contains obscure tests of the C-interface required
14 ** for completeness. Test code is written in C for these cases
15 ** as there is not much point in binding to Tcl.
17 #include "sqliteInt.h"
18 #if defined(INCLUDE_SQLITE_TCL_H)
19 # include "sqlite_tcl.h"
29 static int SQLITE_TCLAPI
c_collation_test(
30 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
31 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
32 int objc
, /* Number of arguments */
33 Tcl_Obj
*CONST objv
[] /* Command arguments */
35 const char *zErrFunction
= "N/A";
40 Tcl_WrongNumArgs(interp
, 1, objv
, "");
44 /* Open a database. */
45 rc
= sqlite3_open(":memory:", &db
);
47 zErrFunction
= "sqlite3_open";
51 rc
= sqlite3_create_collation(db
, "collate", 456, 0, 0);
52 if( rc
!=SQLITE_MISUSE
){
54 zErrFunction
= "sqlite3_create_collation";
62 Tcl_ResetResult(interp
);
63 Tcl_AppendResult(interp
, "Error testing function: ", zErrFunction
, 0);
70 static int SQLITE_TCLAPI
c_realloc_test(
71 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
72 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
73 int objc
, /* Number of arguments */
74 Tcl_Obj
*CONST objv
[] /* Command arguments */
77 const char *zErrFunction
= "N/A";
80 Tcl_WrongNumArgs(interp
, 1, objv
, "");
84 p
= sqlite3_malloc(5);
86 zErrFunction
= "sqlite3_malloc";
90 /* Test that realloc()ing a block of memory to a negative size is
91 ** the same as free()ing that memory.
93 p
= sqlite3_realloc(p
, -1);
95 zErrFunction
= "sqlite3_realloc";
102 Tcl_ResetResult(interp
);
103 Tcl_AppendResult(interp
, "Error testing function: ", zErrFunction
, 0);
111 static int SQLITE_TCLAPI
c_misuse_test(
112 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
113 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
114 int objc
, /* Number of arguments */
115 Tcl_Obj
*CONST objv
[] /* Command arguments */
117 const char *zErrFunction
= "N/A";
123 Tcl_WrongNumArgs(interp
, 1, objv
, "");
127 /* Open a database. Then close it again. We need to do this so that
128 ** we have a "closed database handle" to pass to various API functions.
130 rc
= sqlite3_open(":memory:", &db
);
132 zErrFunction
= "sqlite3_open";
138 rc
= sqlite3_errcode(db
);
139 if( rc
!=SQLITE_MISUSE
){
140 zErrFunction
= "sqlite3_errcode";
144 pStmt
= (sqlite3_stmt
*)1234;
145 rc
= sqlite3_prepare(db
, 0, 0, &pStmt
, 0);
146 if( rc
!=SQLITE_MISUSE
){
147 zErrFunction
= "sqlite3_prepare";
150 assert( pStmt
==0 ); /* Verify that pStmt is zeroed even on a MISUSE error */
152 pStmt
= (sqlite3_stmt
*)1234;
153 rc
= sqlite3_prepare_v2(db
, 0, 0, &pStmt
, 0);
154 if( rc
!=SQLITE_MISUSE
){
155 zErrFunction
= "sqlite3_prepare_v2";
160 #ifndef SQLITE_OMIT_UTF16
161 pStmt
= (sqlite3_stmt
*)1234;
162 rc
= sqlite3_prepare16(db
, 0, 0, &pStmt
, 0);
163 if( rc
!=SQLITE_MISUSE
){
164 zErrFunction
= "sqlite3_prepare16";
168 pStmt
= (sqlite3_stmt
*)1234;
169 rc
= sqlite3_prepare16_v2(db
, 0, 0, &pStmt
, 0);
170 if( rc
!=SQLITE_MISUSE
){
171 zErrFunction
= "sqlite3_prepare16_v2";
180 Tcl_ResetResult(interp
);
181 Tcl_AppendResult(interp
, "Error testing function: ", zErrFunction
, 0);
186 ** Register commands with the TCL interpreter.
188 int Sqlitetest9_Init(Tcl_Interp
*interp
){
191 Tcl_ObjCmdProc
*xProc
;
194 { "c_misuse_test", c_misuse_test
, 0 },
195 { "c_realloc_test", c_realloc_test
, 0 },
196 { "c_collation_test", c_collation_test
, 0 },
199 for(i
=0; i
<sizeof(aObjCmd
)/sizeof(aObjCmd
[0]); i
++){
200 Tcl_CreateObjCommand(interp
, aObjCmd
[i
].zName
,
201 aObjCmd
[i
].xProc
, aObjCmd
[i
].clientData
, 0);