/ Check-in [ad451a2d]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved test coverage for util.c. (CVS 2194)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ad451a2ddc7993035768f2801d590311807f4397
User & Date: drh 2005-01-11 15:28:33
Context
2005-01-11
16:54
Improved test coverage for vdbeaux.c. (CVS 2195) check-in: 3f46cd77 user: drh tags: trunk
15:28
Improved test coverage for util.c. (CVS 2194) check-in: ad451a2d user: drh tags: trunk
13:02
Test cases to improve coverage of vdbe.c. (CVS 2193) check-in: a6b45722 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/test1.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the printf() interface to SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test1.c,v 1.117 2004/11/22 19:12:21 drh Exp $
           16  +** $Id: test1.c,v 1.118 2005/01/11 15:28:33 drh Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include "os.h"
    21     21   #include <stdlib.h>
    22     22   #include <string.h>
    23     23   
................................................................................
  2469   2469     if( rc!=SQLITE_OK ){
  2470   2470       Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
  2471   2471       return TCL_ERROR;
  2472   2472     }
  2473   2473     Tcl_AppendResult(interp, zFile, 0);
  2474   2474     return TCL_OK;
  2475   2475   }
         2476  +
         2477  +/*
         2478  +** Usage:  sqlite_set_magic  DB  MAGIC-NUMBER
         2479  +**
         2480  +** Set the db->magic value.  This is used to test error recovery logic.
         2481  +*/
         2482  +static int sqlite_set_magic(
         2483  +  void * clientData,
         2484  +  Tcl_Interp *interp,
         2485  +  int argc,
         2486  +  char **argv
         2487  +){
         2488  +  sqlite3 *db;
         2489  +  if( argc!=3 ){
         2490  +    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
         2491  +         " DB MAGIC", 0);
         2492  +    return TCL_ERROR;
         2493  +  }
         2494  +  if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
         2495  +  if( strcmp(argv[2], "SQLITE_MAGIC_OPEN")==0 ){
         2496  +    db->magic = SQLITE_MAGIC_OPEN;
         2497  +  }else if( strcmp(argv[2], "SQLITE_MAGIC_CLOSED")==0 ){
         2498  +    db->magic = SQLITE_MAGIC_CLOSED;
         2499  +  }else if( strcmp(argv[2], "SQLITE_MAGIC_BUSY")==0 ){
         2500  +    db->magic = SQLITE_MAGIC_BUSY;
         2501  +  }else if( strcmp(argv[2], "SQLITE_MAGIC_ERROR")==0 ){
         2502  +    db->magic = SQLITE_MAGIC_ERROR;
         2503  +  }else if( Tcl_GetInt(interp, argv[2], &db->magic) ){
         2504  +    return TCL_ERROR;
         2505  +  }
         2506  +  return TCL_OK;
         2507  +}
  2476   2508   
  2477   2509   /*
  2478   2510   ** Usage:  tcl_variable_type VARIABLENAME
  2479   2511   **
  2480   2512   ** Return the name of the internal representation for the
  2481   2513   ** value of the given variable.
  2482   2514   */
................................................................................
  2700   2732        { "sqlite_malloc_fail",            (Tcl_CmdProc*)sqlite_malloc_fail    },
  2701   2733        { "sqlite_malloc_stat",            (Tcl_CmdProc*)sqlite_malloc_stat    },
  2702   2734   #endif
  2703   2735        { "sqlite_bind",                   (Tcl_CmdProc*)test_bind             },
  2704   2736        { "breakpoint",                    (Tcl_CmdProc*)test_breakpoint       },
  2705   2737        { "sqlite3_key",                   (Tcl_CmdProc*)test_key              },
  2706   2738        { "sqlite3_rekey",                 (Tcl_CmdProc*)test_rekey            },
         2739  +     { "sqlite_set_magic",              (Tcl_CmdProc*)sqlite_set_magic      },
  2707   2740     };
  2708   2741     static struct {
  2709   2742        char *zName;
  2710   2743        Tcl_ObjCmdProc *xProc;
  2711   2744        void *clientData;
  2712   2745     } aObjCmd[] = {
  2713   2746        { "sqlite3_bind_int",              test_bind_int,      0 },

Changes to src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.123 2004/12/25 01:03:14 drh Exp $
           17  +** $Id: util.c,v 1.124 2005/01/11 15:28:33 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <stdarg.h>
    21     21   #include <ctype.h>
    22     22   
    23     23   #if SQLITE_DEBUG>2 && defined(__GLIBC__)
    24     24   #include <execinfo.h>
................................................................................
   922    922   ** Translate a single byte of Hex into an integer.
   923    923   */
   924    924   static int hexToInt(int h){
   925    925     if( h>='0' && h<='9' ){
   926    926       return h - '0';
   927    927     }else if( h>='a' && h<='f' ){
   928    928       return h - 'a' + 10;
   929         -  }else if( h>='A' && h<='F' ){
   930         -    return h - 'A' + 10;
   931    929     }else{
   932         -    return 0;
          930  +    assert( h>='A' && h<='F' );
          931  +    return h - 'A' + 10;
   933    932     }
   934    933   }
   935    934   #endif /* (!SQLITE_OMIT_BLOB_LITERAL && !SQLITE_HAS_CODEC) || SQLITE_TEST */
   936    935   
   937    936   #if !defined(SQLITE_OMIT_BLOB_LITERAL) || defined(SQLITE_HAS_CODEC)
   938    937   /*
   939    938   ** Convert a BLOB literal of the form "x'hhhhhh'" into its binary

Changes to test/misc4.test.

     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.
    12     12   #
    13     13   # This file implements tests for miscellanous features that were
    14     14   # left out of other test files.
    15     15   #
    16         -# $Id: misc4.test,v 1.8 2004/11/22 13:35:42 danielk1977 Exp $
           16  +# $Id: misc4.test,v 1.9 2005/01/11 15:28:33 drh Exp $
    17     17   
    18     18   set testdir [file dirname $argv0]
    19     19   source $testdir/tester.tcl
    20     20   
    21     21   # Prepare a statement that will create a temporary table.  Then do
    22     22   # a rollback.  Then try to execute the prepared statement.
    23     23   #
................................................................................
    94     94       INSERT INTO Table2 VALUES (1, 'a');
    95     95       SELECT ID, Value FROM Table1
    96     96          UNION SELECT ID, max(Value) FROM Table2 GROUP BY 1,2
    97     97       ORDER BY 1, 2;
    98     98     }
    99     99   } {{} {} 1 x 1 z}
   100    100   } ;# ifcapable compound
   101         -
   102    101   
   103    102   finish_test

Added test/safety.test.

            1  +# 2005 January 11
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library.  The
           12  +# focus of this file is testing the sqlite3SafetyOn and sqlite3SafetyOff
           13  +# functions.  Those routines are not strictly necessary - they are
           14  +# designed to detect misuse of the library.
           15  +#
           16  +# $Id: safety.test,v 1.1 2005/01/11 15:28:33 drh Exp $
           17  +
           18  +set testdir [file dirname $argv0]
           19  +source $testdir/tester.tcl
           20  +
           21  +do_test safety-1.1 {
           22  +  db close
           23  +  set DB [sqlite3 db test.db]
           24  +  db eval {CREATE TABLE t1(a)}
           25  +  sqlite_set_magic $DB SQLITE_MAGIC_BUSY
           26  +  catchsql {
           27  +    SELECT name FROM sqlite_master;
           28  +  }
           29  +} {1 {library routine called out of sequence}}
           30  +do_test safety-1.2 {
           31  +  sqlite_set_magic $DB SQLITE_MAGIC_OPEN
           32  +  catchsql {
           33  +    SELECT name FROM sqlite_master
           34  +  }
           35  +} {0 t1}
           36  +
           37  +do_test safety-2.1 {
           38  +  proc safety_on {} "sqlite_set_magic $DB SQLITE_MAGIC_BUSY"
           39  +  db function safety_on safety_on
           40  +  catchsql {
           41  +    SELECT safety_on(), name FROM sqlite_master
           42  +  }
           43  +} {1 {library routine called out of sequence}}
           44  +do_test safety-2.2 {
           45  +  catchsql {
           46  +    SELECT 'hello'
           47  +  }
           48  +} {1 {library routine called out of sequence}}
           49  +do_test safety-2.3 {
           50  +  sqlite3_close $DB
           51  +} {SQLITE_MISUSE}
           52  +do_test safety-2.4 {
           53  +  sqlite_set_magic $DB SQLITE_MAGIC_OPEN
           54  +  execsql {
           55  +    SELECT name FROM sqlite_master
           56  +  }
           57  +} {t1}
           58  +
           59  +do_test safety-3.1 {
           60  +  set rc [catch {
           61  +    db eval {SELECT name FROM sqlite_master} {
           62  +      sqlite_set_magic $DB SQLITE_MAGIC_BUSY
           63  +    }
           64  +  } msg]
           65  +  lappend rc $msg
           66  +} {1 {library routine called out of sequence}}
           67  +sqlite_set_magic $DB SQLITE_MAGIC_OPEN
           68  +
           69  +finish_test