os/persistentdata/persistentstorage/sqlite3api/TEST/SRC/test9.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/SRC/test9.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,193 @@
     1.4 +/*
     1.5 +** 2007 March 29
     1.6 +**
     1.7 +** The author disclaims copyright to this source code.  In place of
     1.8 +** a legal notice, here is a blessing:
     1.9 +**
    1.10 +**    May you do good and not evil.
    1.11 +**    May you find forgiveness for yourself and forgive others.
    1.12 +**    May you share freely, never taking more than you give.
    1.13 +**
    1.14 +*************************************************************************
    1.15 +**
    1.16 +** This file contains obscure tests of the C-interface required
    1.17 +** for completeness. Test code is written in C for these cases
    1.18 +** as there is not much point in binding to Tcl.
    1.19 +**
    1.20 +** $Id: test9.c,v 1.6 2008/07/11 13:53:55 drh Exp $
    1.21 +*/
    1.22 +#include "sqliteInt.h"
    1.23 +#include "tcl.h"
    1.24 +#include <stdlib.h>
    1.25 +#include <string.h>
    1.26 +
    1.27 +/*
    1.28 +** c_collation_test
    1.29 +*/
    1.30 +static int c_collation_test(
    1.31 +  ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
    1.32 +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
    1.33 +  int objc,              /* Number of arguments */
    1.34 +  Tcl_Obj *CONST objv[]  /* Command arguments */
    1.35 +){
    1.36 +  const char *zErrFunction = "N/A";
    1.37 +  sqlite3 *db;
    1.38 +
    1.39 +  int rc;
    1.40 +  if( objc!=1 ){
    1.41 +    Tcl_WrongNumArgs(interp, 1, objv, "");
    1.42 +    return TCL_ERROR;
    1.43 +  }
    1.44 +
    1.45 +  /* Open a database. */
    1.46 +  rc = sqlite3_open(":memory:", &db);
    1.47 +  if( rc!=SQLITE_OK ){
    1.48 +    zErrFunction = "sqlite3_open";
    1.49 +    goto error_out;
    1.50 +  }
    1.51 +
    1.52 +  rc = sqlite3_create_collation(db, "collate", 456, 0, 0);
    1.53 +  if( rc!=SQLITE_MISUSE ){
    1.54 +    sqlite3_close(db);
    1.55 +    zErrFunction = "sqlite3_create_collation";
    1.56 +    goto error_out;
    1.57 +  }
    1.58 +
    1.59 +  sqlite3_close(db);
    1.60 +  return TCL_OK;
    1.61 +
    1.62 +error_out:
    1.63 +  Tcl_ResetResult(interp);
    1.64 +  Tcl_AppendResult(interp, "Error testing function: ", zErrFunction, 0);
    1.65 +  return TCL_ERROR;
    1.66 +}
    1.67 +
    1.68 +/*
    1.69 +** c_realloc_test
    1.70 +*/
    1.71 +static int c_realloc_test(
    1.72 +  ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
    1.73 +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
    1.74 +  int objc,              /* Number of arguments */
    1.75 +  Tcl_Obj *CONST objv[]  /* Command arguments */
    1.76 +){
    1.77 +  void *p;
    1.78 +  const char *zErrFunction = "N/A";
    1.79 +
    1.80 +  if( objc!=1 ){
    1.81 +    Tcl_WrongNumArgs(interp, 1, objv, "");
    1.82 +    return TCL_ERROR;
    1.83 +  }
    1.84 +
    1.85 +  p = sqlite3_malloc(5);
    1.86 +  if( !p ){
    1.87 +    zErrFunction = "sqlite3_malloc";
    1.88 +    goto error_out;
    1.89 +  }
    1.90 +
    1.91 +  /* Test that realloc()ing a block of memory to a negative size is
    1.92 +  ** the same as free()ing that memory.
    1.93 +  */
    1.94 +  p = sqlite3_realloc(p, -1);
    1.95 +  if( p ){
    1.96 +    zErrFunction = "sqlite3_realloc";
    1.97 +    goto error_out;
    1.98 +  }
    1.99 +
   1.100 +  return TCL_OK;
   1.101 +
   1.102 +error_out:
   1.103 +  Tcl_ResetResult(interp);
   1.104 +  Tcl_AppendResult(interp, "Error testing function: ", zErrFunction, 0);
   1.105 +  return TCL_ERROR;
   1.106 +}
   1.107 +
   1.108 +
   1.109 +/*
   1.110 +** c_misuse_test
   1.111 +*/
   1.112 +static int c_misuse_test(
   1.113 +  ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
   1.114 +  Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
   1.115 +  int objc,              /* Number of arguments */
   1.116 +  Tcl_Obj *CONST objv[]  /* Command arguments */
   1.117 +){
   1.118 +  const char *zErrFunction = "N/A";
   1.119 +  sqlite3 *db = 0;
   1.120 +  int rc;
   1.121 +
   1.122 +  if( objc!=1 ){
   1.123 +    Tcl_WrongNumArgs(interp, 1, objv, "");
   1.124 +    return TCL_ERROR;
   1.125 +  }
   1.126 +
   1.127 +  /* Open a database. Then close it again. We need to do this so that
   1.128 +  ** we have a "closed database handle" to pass to various API functions.
   1.129 +  */
   1.130 +  rc = sqlite3_open(":memory:", &db);
   1.131 +  if( rc!=SQLITE_OK ){
   1.132 +    zErrFunction = "sqlite3_open";
   1.133 +    goto error_out;
   1.134 +  }
   1.135 +  sqlite3_close(db);
   1.136 +
   1.137 +
   1.138 +  rc = sqlite3_errcode(db);
   1.139 +  if( rc!=SQLITE_MISUSE ){
   1.140 +    zErrFunction = "sqlite3_errcode";
   1.141 +    goto error_out;
   1.142 +  }
   1.143 +
   1.144 +  rc = sqlite3_prepare(db, 0, 0, 0, 0);
   1.145 +  if( rc!=SQLITE_MISUSE ){
   1.146 +    zErrFunction = "sqlite3_prepare";
   1.147 +    goto error_out;
   1.148 +  }
   1.149 +
   1.150 +  rc = sqlite3_prepare_v2(db, 0, 0, 0, 0);
   1.151 +  if( rc!=SQLITE_MISUSE ){
   1.152 +    zErrFunction = "sqlite3_prepare_v2";
   1.153 +    goto error_out;
   1.154 +  }
   1.155 +
   1.156 +#ifndef SQLITE_OMIT_UTF16
   1.157 +  rc = sqlite3_prepare16(db, 0, 0, 0, 0);
   1.158 +  if( rc!=SQLITE_MISUSE ){
   1.159 +    zErrFunction = "sqlite3_prepare16";
   1.160 +    goto error_out;
   1.161 +  }
   1.162 +  rc = sqlite3_prepare16_v2(db, 0, 0, 0, 0);
   1.163 +  if( rc!=SQLITE_MISUSE ){
   1.164 +    zErrFunction = "sqlite3_prepare16_v2";
   1.165 +    goto error_out;
   1.166 +  }
   1.167 +#endif
   1.168 +
   1.169 +  return TCL_OK;
   1.170 +
   1.171 +error_out:
   1.172 +  Tcl_ResetResult(interp);
   1.173 +  Tcl_AppendResult(interp, "Error testing function: ", zErrFunction, 0);
   1.174 +  return TCL_ERROR;
   1.175 +}
   1.176 +
   1.177 +/*
   1.178 +** Register commands with the TCL interpreter.
   1.179 +*/
   1.180 +int Sqlitetest9_Init(Tcl_Interp *interp){
   1.181 +  static struct {
   1.182 +     char *zName;
   1.183 +     Tcl_ObjCmdProc *xProc;
   1.184 +     void *clientData;
   1.185 +  } aObjCmd[] = {
   1.186 +     { "c_misuse_test",    c_misuse_test, 0 },
   1.187 +     { "c_realloc_test",   c_realloc_test, 0 },
   1.188 +     { "c_collation_test", c_collation_test, 0 },
   1.189 +  };
   1.190 +  int i;
   1.191 +  for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
   1.192 +    Tcl_CreateObjCommand(interp, aObjCmd[i].zName, 
   1.193 +        aObjCmd[i].xProc, aObjCmd[i].clientData, 0);
   1.194 +  }
   1.195 +  return TCL_OK;
   1.196 +}