]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improved test coverage for util.c. (CVS 2194)
authordrh <drh@noemail.net>
Tue, 11 Jan 2005 15:28:33 +0000 (15:28 +0000)
committerdrh <drh@noemail.net>
Tue, 11 Jan 2005 15:28:33 +0000 (15:28 +0000)
FossilOrigin-Name: ad451a2ddc7993035768f2801d590311807f4397

manifest
manifest.uuid
src/test1.c
src/util.c
test/misc4.test
test/safety.test [new file with mode: 0644]

index e141d28b0a6103c2694969151fa3cb1751f1a41f..788fc10adbb7a7ae59397b1f22bbe3c63ffdcba6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Test\scases\sto\simprove\scoverage\sof\svdbe.c.\s(CVS\s2193)
-D 2005-01-11T13:02:34
+C Improved\stest\scoverage\sfor\sutil.c.\s(CVS\s2194)
+D 2005-01-11T15:28:33
 F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@@ -65,7 +65,7 @@ F src/sqlite.h.in 0d5e48e506845b74a845c9470e01d3f472b59611
 F src/sqliteInt.h a362fd46ba14f67e8e088d30ecbbe228545c43fe
 F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
 F src/tclsqlite.c 354d3e4525c7b29c8f50b1a0125d55c63c916fbc
-F src/test1.c b7d94c54e58f95452387a5cabdf98b2be8059f29
+F src/test1.c ad1b46266b357c283981b2a289cf29bdb35cb26a
 F src/test2.c b11fa244fff02190707dd0879987c37c75e61fc8
 F src/test3.c a72f20066cccd5a7b9f20b7b78fa9b05b47b3020
 F src/test4.c 7c6b9fc33dd1f3f93c7f1ee6e5e6d016afa6c1df
@@ -74,7 +74,7 @@ F src/tokenize.c 2ad3d1ae1a0a70746db0b31a0a74f58050a3c39a
 F src/trigger.c 98f3b07c08ba01b34cff139ef9687883d325ae8e
 F src/update.c 0979397c41ac29c54fe0cc687a356d8629a633af
 F src/utf.c e45ce11be6922408cd381561721f6cca7d3b992a
-F src/util.c 29f43c4a7b9ff29302f7899f793be6836b6cd7f9
+F src/util.c bf42625f35492864faa6fe14aa5a858de25cc2a0
 F src/vacuum.c 1a9db113a027461daaf44724c71dd1ebbd064203
 F src/vdbe.c 8ef389f567e233768a845e7dffacb21308e4f3e8
 F src/vdbe.h 067ca8d6750ba4f69a50284765e5883dee860181
@@ -156,7 +156,7 @@ F test/minmax.test e7048476940df0af11d0f2cf687572f557cd0b29
 F test/misc1.test 744f60d1025fa978708b96cb222a07a1feb1524a
 F test/misc2.test bc852f1622d98b610d1f3e2ceb36ed7271256050
 F test/misc3.test 928a2f1e1189924ed14e1ae074e34f40688bdf94
-F test/misc4.test c683ab8182172474c804b346f8a39ca786322250
+F test/misc4.test 7edc2542eadd98555c2d25c222b88a93124975ae
 F test/misuse.test 2d7c46160f7c214f761fc5d030684a37ae8832a6
 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
 F test/null.test 5a945790ef21b24fd602fe2c7a23847b903f8687
@@ -172,6 +172,7 @@ F test/quote.test 6d75cf635d93ba2484dc9cb378d88cbae9dc2c62
 F test/reindex.test 3552c6b944a3fab28cfd3049c04c65cb79419757
 F test/rollback.test 4097328d44510277244ef4fa51b22b2f11d7ef4c
 F test/rowid.test 1ce3f1520d2082b0363e7d9bdef904cb72b9efe8
+F test/safety.test 907b64fee719554a3622853812af3886fddbbb4f
 F test/select1.test 524d4323f3921db16138f8b1765f1cc44e030bf4
 F test/select2.test 91a2225926039b0d1687840735c284dbbf89f0bc
 F test/select3.test 9de435aa84fc406708cd8dc1b1d60e7f27cea685
@@ -266,7 +267,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
-P ce8e4e885a46cec35b64a81925eb330048ea5cbb
-R 44bedd6ab22a6b83aa2c8db7d5317250
-U danielk1977
-Z edff517034081f5d7cb31d6aed3503e0
+P a6b45722071bde543c4ea28a432339d8708a5cac
+R b0945886e1d424e5155d631ce7e7c70d
+U drh
+Z b50ef0a8c73264bba1e64798ccde8b34
index 642ccde690b36a92baa75704a38c56d87f8bee83..fe78222dc6aa90259afd8eb96e6a27dad69cf83b 100644 (file)
@@ -1 +1 @@
-a6b45722071bde543c4ea28a432339d8708a5cac
\ No newline at end of file
+ad451a2ddc7993035768f2801d590311807f4397
\ No newline at end of file
index b6e8a5b41ef76a912daf986b194892040d40bb8d..adc635a4a338b864d30e67e34e7ea1fd3412d32b 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test1.c,v 1.117 2004/11/22 19:12:21 drh Exp $
+** $Id: test1.c,v 1.118 2005/01/11 15:28:33 drh Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -2474,6 +2474,38 @@ static int test_sqlite3OsTempFileName(
   return TCL_OK;
 }
 
+/*
+** Usage:  sqlite_set_magic  DB  MAGIC-NUMBER
+**
+** Set the db->magic value.  This is used to test error recovery logic.
+*/
+static int sqlite_set_magic(
+  void * clientData,
+  Tcl_Interp *interp,
+  int argc,
+  char **argv
+){
+  sqlite3 *db;
+  if( argc!=3 ){
+    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
+         " DB MAGIC", 0);
+    return TCL_ERROR;
+  }
+  if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
+  if( strcmp(argv[2], "SQLITE_MAGIC_OPEN")==0 ){
+    db->magic = SQLITE_MAGIC_OPEN;
+  }else if( strcmp(argv[2], "SQLITE_MAGIC_CLOSED")==0 ){
+    db->magic = SQLITE_MAGIC_CLOSED;
+  }else if( strcmp(argv[2], "SQLITE_MAGIC_BUSY")==0 ){
+    db->magic = SQLITE_MAGIC_BUSY;
+  }else if( strcmp(argv[2], "SQLITE_MAGIC_ERROR")==0 ){
+    db->magic = SQLITE_MAGIC_ERROR;
+  }else if( Tcl_GetInt(interp, argv[2], &db->magic) ){
+    return TCL_ERROR;
+  }
+  return TCL_OK;
+}
+
 /*
 ** Usage:  tcl_variable_type VARIABLENAME
 **
@@ -2704,6 +2736,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
      { "breakpoint",                    (Tcl_CmdProc*)test_breakpoint       },
      { "sqlite3_key",                   (Tcl_CmdProc*)test_key              },
      { "sqlite3_rekey",                 (Tcl_CmdProc*)test_rekey            },
+     { "sqlite_set_magic",              (Tcl_CmdProc*)sqlite_set_magic      },
   };
   static struct {
      char *zName;
index 55d792485f16e84c4435006ebd12a659bf2f5aca..988372ce1a659a3f3661367345f04991dc376525 100644 (file)
@@ -14,7 +14,7 @@
 ** This file contains functions for allocating memory, comparing
 ** strings, and stuff like that.
 **
-** $Id: util.c,v 1.123 2004/12/25 01:03:14 drh Exp $
+** $Id: util.c,v 1.124 2005/01/11 15:28:33 drh Exp $
 */
 #include "sqliteInt.h"
 #include <stdarg.h>
@@ -926,10 +926,9 @@ static int hexToInt(int h){
     return h - '0';
   }else if( h>='a' && h<='f' ){
     return h - 'a' + 10;
-  }else if( h>='A' && h<='F' ){
-    return h - 'A' + 10;
   }else{
-    return 0;
+    assert( h>='A' && h<='F' );
+    return h - 'A' + 10;
   }
 }
 #endif /* (!SQLITE_OMIT_BLOB_LITERAL && !SQLITE_HAS_CODEC) || SQLITE_TEST */
index 5e0a16ad163430e2aec9ad28be64aa00096e3505..26983415509ccca34e698b9d2feb76f59d756298 100644 (file)
@@ -13,7 +13,7 @@
 # This file implements tests for miscellanous features that were
 # left out of other test files.
 #
-# $Id: misc4.test,v 1.8 2004/11/22 13:35:42 danielk1977 Exp $
+# $Id: misc4.test,v 1.9 2005/01/11 15:28:33 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -99,5 +99,4 @@ do_test misc4-3.1 {
 } {{} {} 1 x 1 z}
 } ;# ifcapable compound
 
-
 finish_test
diff --git a/test/safety.test b/test/safety.test
new file mode 100644 (file)
index 0000000..a12cd84
--- /dev/null
@@ -0,0 +1,69 @@
+# 2005 January 11
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.  The
+# focus of this file is testing the sqlite3SafetyOn and sqlite3SafetyOff
+# functions.  Those routines are not strictly necessary - they are
+# designed to detect misuse of the library.
+#
+# $Id: safety.test,v 1.1 2005/01/11 15:28:33 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+do_test safety-1.1 {
+  db close
+  set DB [sqlite3 db test.db]
+  db eval {CREATE TABLE t1(a)}
+  sqlite_set_magic $DB SQLITE_MAGIC_BUSY
+  catchsql {
+    SELECT name FROM sqlite_master;
+  }
+} {1 {library routine called out of sequence}}
+do_test safety-1.2 {
+  sqlite_set_magic $DB SQLITE_MAGIC_OPEN
+  catchsql {
+    SELECT name FROM sqlite_master
+  }
+} {0 t1}
+
+do_test safety-2.1 {
+  proc safety_on {} "sqlite_set_magic $DB SQLITE_MAGIC_BUSY"
+  db function safety_on safety_on
+  catchsql {
+    SELECT safety_on(), name FROM sqlite_master
+  }
+} {1 {library routine called out of sequence}}
+do_test safety-2.2 {
+  catchsql {
+    SELECT 'hello'
+  }
+} {1 {library routine called out of sequence}}
+do_test safety-2.3 {
+  sqlite3_close $DB
+} {SQLITE_MISUSE}
+do_test safety-2.4 {
+  sqlite_set_magic $DB SQLITE_MAGIC_OPEN
+  execsql {
+    SELECT name FROM sqlite_master
+  }
+} {t1}
+
+do_test safety-3.1 {
+  set rc [catch {
+    db eval {SELECT name FROM sqlite_master} {
+      sqlite_set_magic $DB SQLITE_MAGIC_BUSY
+    }
+  } msg]
+  lappend rc $msg
+} {1 {library routine called out of sequence}}
+sqlite_set_magic $DB SQLITE_MAGIC_OPEN
+
+finish_test