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"
25 static int c_collation_test(
26 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
27 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
28 int objc
, /* Number of arguments */
29 Tcl_Obj
*CONST objv
[] /* Command arguments */
31 const char *zErrFunction
= "N/A";
36 Tcl_WrongNumArgs(interp
, 1, objv
, "");
40 /* Open a database. */
41 rc
= sqlite3_open(":memory:", &db
);
43 zErrFunction
= "sqlite3_open";
47 rc
= sqlite3_create_collation(db
, "collate", 456, 0, 0);
48 if( rc
!=SQLITE_MISUSE
){
50 zErrFunction
= "sqlite3_create_collation";
58 Tcl_ResetResult(interp
);
59 Tcl_AppendResult(interp
, "Error testing function: ", zErrFunction
, 0);
66 static int c_realloc_test(
67 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
68 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
69 int objc
, /* Number of arguments */
70 Tcl_Obj
*CONST objv
[] /* Command arguments */
73 const char *zErrFunction
= "N/A";
76 Tcl_WrongNumArgs(interp
, 1, objv
, "");
80 p
= sqlite3_malloc(5);
82 zErrFunction
= "sqlite3_malloc";
86 /* Test that realloc()ing a block of memory to a negative size is
87 ** the same as free()ing that memory.
89 p
= sqlite3_realloc(p
, -1);
91 zErrFunction
= "sqlite3_realloc";
98 Tcl_ResetResult(interp
);
99 Tcl_AppendResult(interp
, "Error testing function: ", zErrFunction
, 0);
107 static int c_misuse_test(
108 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
109 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
110 int objc
, /* Number of arguments */
111 Tcl_Obj
*CONST objv
[] /* Command arguments */
113 const char *zErrFunction
= "N/A";
119 Tcl_WrongNumArgs(interp
, 1, objv
, "");
123 /* Open a database. Then close it again. We need to do this so that
124 ** we have a "closed database handle" to pass to various API functions.
126 rc
= sqlite3_open(":memory:", &db
);
128 zErrFunction
= "sqlite3_open";
134 rc
= sqlite3_errcode(db
);
135 if( rc
!=SQLITE_MISUSE
){
136 zErrFunction
= "sqlite3_errcode";
140 pStmt
= (sqlite3_stmt
*)1234;
141 rc
= sqlite3_prepare(db
, 0, 0, &pStmt
, 0);
142 if( rc
!=SQLITE_MISUSE
){
143 zErrFunction
= "sqlite3_prepare";
146 assert( pStmt
==0 ); /* Verify that pStmt is zeroed even on a MISUSE error */
148 pStmt
= (sqlite3_stmt
*)1234;
149 rc
= sqlite3_prepare_v2(db
, 0, 0, &pStmt
, 0);
150 if( rc
!=SQLITE_MISUSE
){
151 zErrFunction
= "sqlite3_prepare_v2";
156 #ifndef SQLITE_OMIT_UTF16
157 pStmt
= (sqlite3_stmt
*)1234;
158 rc
= sqlite3_prepare16(db
, 0, 0, &pStmt
, 0);
159 if( rc
!=SQLITE_MISUSE
){
160 zErrFunction
= "sqlite3_prepare16";
164 pStmt
= (sqlite3_stmt
*)1234;
165 rc
= sqlite3_prepare16_v2(db
, 0, 0, &pStmt
, 0);
166 if( rc
!=SQLITE_MISUSE
){
167 zErrFunction
= "sqlite3_prepare16_v2";
176 Tcl_ResetResult(interp
);
177 Tcl_AppendResult(interp
, "Error testing function: ", zErrFunction
, 0);
182 ** Register commands with the TCL interpreter.
184 int Sqlitetest9_Init(Tcl_Interp
*interp
){
187 Tcl_ObjCmdProc
*xProc
;
190 { "c_misuse_test", c_misuse_test
, 0 },
191 { "c_realloc_test", c_realloc_test
, 0 },
192 { "c_collation_test", c_collation_test
, 0 },
195 for(i
=0; i
<sizeof(aObjCmd
)/sizeof(aObjCmd
[0]); i
++){
196 Tcl_CreateObjCommand(interp
, aObjCmd
[i
].zName
,
197 aObjCmd
[i
].xProc
, aObjCmd
[i
].clientData
, 0);