]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Test cases to improve coverage of vdbe.c. (CVS 2193)
authordanielk1977 <danielk1977@noemail.net>
Tue, 11 Jan 2005 13:02:33 +0000 (13:02 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Tue, 11 Jan 2005 13:02:33 +0000 (13:02 +0000)
FossilOrigin-Name: a6b45722071bde543c4ea28a432339d8708a5cac

manifest
manifest.uuid
src/func.c
src/vdbe.c
test/func.test
test/ioerr.test
test/malloc.test

index 9ba9626e3025a08cc3bc85a0dc14527b0c4e6b6c..e141d28b0a6103c2694969151fa3cb1751f1a41f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sa\sC++\sstyle\scomment\sthat\swent\sin\swith\sthe\sprevious\scommit.\s(CVS\s2192)
-D 2005-01-11T11:08:23
+C Test\scases\sto\simprove\scoverage\sof\svdbe.c.\s(CVS\s2193)
+D 2005-01-11T13:02:34
 F Makefile.in ecf441ac5ca1ccfc8748a8a9537706e69893dfa4
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@@ -36,7 +36,7 @@ F src/cursor.c f883813759742068890b1f699335872bfa8fdf41
 F src/date.c 65536e7ea04fdde6e0551264fca15966966e171f
 F src/delete.c 32277d2834e36c7538c047f14d643751c256c73b
 F src/expr.c d718509e56f58b06bc5f9b46afb295675334d544
-F src/func.c b668e5ad043176049454c95a6a780367a0e8f6bb
+F src/func.c dc188d862d7276ea897655b248e2cb17022686e3
 F src/hash.c a97721a55440b7bea31ffe471bb2f6b4123cddd5
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
 F src/insert.c f6b69e40e8938f63a2368cbcb5087a56098cf632
@@ -76,7 +76,7 @@ F src/update.c 0979397c41ac29c54fe0cc687a356d8629a633af
 F src/utf.c e45ce11be6922408cd381561721f6cca7d3b992a
 F src/util.c 29f43c4a7b9ff29302f7899f793be6836b6cd7f9
 F src/vacuum.c 1a9db113a027461daaf44724c71dd1ebbd064203
-F src/vdbe.c f20455da51615ba185ac3c41416e8714ca84509d
+F src/vdbe.c 8ef389f567e233768a845e7dffacb21308e4f3e8
 F src/vdbe.h 067ca8d6750ba4f69a50284765e5883dee860181
 F src/vdbeInt.h 0f74561e629af86172de7cdf0ecaea014c51696c
 F src/vdbeapi.c 0cf3bdc1072616bedc8eec7fc22e3f5a169d33fd
@@ -129,7 +129,7 @@ F test/enc2.test 6d1a2650e9da43eab499d18ca694a0cb6ec69dee
 F test/enc3.test f6a5f0b7b7f3a88f030d3143729b87cd5c86d837
 F test/expr.test bf826516ea0ba159eb9680fbcea955148bfe9bc3
 F test/fkey1.test 81bb13caaa78f58d7d191d7f535529f7c91d821a
-F test/func.test 830d352574c7f5cd15149a9be58a6dcc2b995c05
+F test/func.test 810a1a2984ed83d55cc20746b049c7d099bd0408
 F test/hook.test f8605cde4c77b2c6a4a73723bf6c507796a64dda
 F test/in.test b92a2df9162e1cbd33c6449a29a05e6955b1741a
 F test/index.test 1294997b4743007af57f8148c63ba14f07ad31ab
@@ -137,7 +137,7 @@ F test/insert.test 56f9c20c9adc8d707490c4ffa5d4daa94826ea03
 F test/insert2.test 0bb50ff999e35a21549d8ee5dc44db8ac24d31a7
 F test/interrupt.test 0aa230f8aedec0ad7caaf5edaced337e4cfb3820
 F test/intpkey.test b57cf5236fde1bd8cbc1388fa0c91908f6fd9194
-F test/ioerr.test b37837850294c6cbafb0fd5211a4df40b10d46af
+F test/ioerr.test 01ac547c4a6fc53fcd9fe7ecc9698ab5d827093a
 F test/join.test ea8c77b9fbc377fe553cdb5ce5f1bd72021dca5d
 F test/join2.test c97e4c5aa65dea462145529e58212a709b4722b8
 F test/join3.test 67dc0d7c8dab3fff25796d0f3c3fd9c999aeded3
@@ -149,7 +149,7 @@ F test/lock.test 32fe28e5030f25f23bcf6beef440675b0d848413
 F test/lock2.test 59c3dd7d9b24d1bf7ec91b2d1541c37e97939d5f
 F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
 F test/main.test 5f9deae11b93336da1ccc5f91cf8be075c91ddf1
-F test/malloc.test c20b7208d8d123e1185b3cbe54c6fdde3c060c55
+F test/malloc.test 74b9d6b8e6b388102e2c5dbcda7da4341e00e6b5
 F test/memdb.test 532aac7128a3da494cddc4461d76c6e3988f771b
 F test/memleak.test f1fa233f8295dd1d955a00d5e5ee857850f27f29
 F test/minmax.test e7048476940df0af11d0f2cf687572f557cd0b29
@@ -266,7 +266,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
 F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
 F www/whentouse.tcl c3b50d3ac31c54be2a1af9b488a89d22f1e6e746
-P a37e0108dea4896d8aaf84cc590b5cecbdefee6c
-R a66eec2a6cf2cb95c24e2e822d8c8a29
+P ce8e4e885a46cec35b64a81925eb330048ea5cbb
+R 44bedd6ab22a6b83aa2c8db7d5317250
 U danielk1977
-Z b88d13fd6460a9f412a6a1a64f3b0e8a
+Z edff517034081f5d7cb31d6aed3503e0
index c81d666d463fe02fa5483a395d54e27116767dea..642ccde690b36a92baa75704a38c56d87f8bee83 100644 (file)
@@ -1 +1 @@
-ce8e4e885a46cec35b64a81925eb330048ea5cbb
\ No newline at end of file
+a6b45722071bde543c4ea28a432339d8708a5cac
\ No newline at end of file
index e0b85cad648786f44d2f12bd929ef3ec42dc15d8..c4412035a030b5c8f089d01a599f3a91d986eec5 100644 (file)
@@ -16,7 +16,7 @@
 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: func.c,v 1.91 2004/11/19 05:14:55 danielk1977 Exp $
+** $Id: func.c,v 1.92 2005/01/11 13:02:34 danielk1977 Exp $
 */
 #include <ctype.h>
 #include <math.h>
@@ -915,6 +915,21 @@ static void test_auxdata(
 }
 #endif /* SQLITE_TEST */
 
+#ifdef SQLITE_TEST
+/*
+** A function to test error reporting from user functions. This function
+** returns a copy of it's first argument as an error.
+*/
+static void test_error(
+  sqlite3_context *pCtx, 
+  int nArg,
+  sqlite3_value **argv
+){
+  // sqlite3_result_error(pCtx, sqlite3_value_text(argv[0]), 0);
+  sqlite3_result_error(pCtx, 0, 0);
+}
+#endif /* SQLITE_TEST */
+
 /*
 ** An instance of the following structure holds the context of a
 ** sum() or avg() aggregate computation.
@@ -1122,6 +1137,7 @@ void sqlite3RegisterBuiltinFunctions(sqlite3 *db){
     { "test_destructor",       1, 1, SQLITE_UTF8, 0, test_destructor},
     { "test_destructor_count", 0, 0, SQLITE_UTF8, 0, test_destructor_count},
     { "test_auxdata",         -1, 0, SQLITE_UTF8, 0, test_auxdata},
+    { "test_error",            1, 0, SQLITE_UTF8, 0, test_error},
 #endif
   };
   static const struct {
index 212ff121815b36f921cdf7288eeafcaa0d9ffdf7..edc3e732e35f97440a826426f08eeae3b8c1efd0 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.439 2005/01/11 11:08:23 danielk1977 Exp $
+** $Id: vdbe.c,v 1.440 2005/01/11 13:02:34 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -627,11 +627,10 @@ case OP_Halt: {
     sqlite3SetString(&p->zErrMsg, pOp->p3, (char*)0);
   }
   rc = sqlite3VdbeHalt(p);
+  assert( rc==SQLITE_BUSY || rc==SQLITE_OK );
   if( rc==SQLITE_BUSY ){
     p->rc = SQLITE_BUSY;
     return SQLITE_BUSY;
-  }else if( rc!=SQLITE_OK ){
-    p->rc = rc;
   }
   return p->rc ? SQLITE_ERROR : SQLITE_DONE;
 }
@@ -1872,9 +1871,7 @@ case OP_Column: {
 
   /* Get the column information.
   */
-  if( rc!=SQLITE_OK ){
-    goto abort_due_to_error;
-  }
+  assert( rc==SQLITE_OK );
   if( zRec ){
     zData = &zRec[aOffset[p2]];
   }else{
@@ -2048,15 +2045,7 @@ case OP_MakeRecord: {
   if( addRowid ){
     zCsr += sqlite3VdbeSerialPut(zCsr, pRowid);
   }
-
-  /* If zCsr has not been advanced exactly nByte bytes, then one
-  ** of the sqlite3PutVarint() or sqlite3VdbeSerialPut() calls above
-  ** failed. This indicates a corrupted memory cell or code bug.
-  */
-  if( zCsr!=(zNewRecord+nByte) ){
-    rc = SQLITE_INTERNAL;
-    goto abort_due_to_error;
-  }
+  assert( zCsr==(zNewRecord+nByte) );
 
   /* Pop entries off the stack if required. Push the new record on. */
   if( !leaveOnStack ){
@@ -2586,9 +2575,7 @@ case OP_MoveGt: {
     if( oc==OP_MoveGe || oc==OP_MoveGt ){
       if( res<0 ){
         rc = sqlite3BtreeNext(pC->pCursor, &res);
-        if( rc!=SQLITE_OK ){
-          goto abort_due_to_error;
-        }
+        if( rc!=SQLITE_OK ) goto abort_due_to_error;
         pC->recnoIsValid = 0;
       }else{
         res = 0;
@@ -2596,7 +2583,8 @@ case OP_MoveGt: {
     }else{
       assert( oc==OP_MoveLt || oc==OP_MoveLe );
       if( res>=0 ){
-        sqlite3BtreePrevious(pC->pCursor, &res);
+        rc = sqlite3BtreePrevious(pC->pCursor, &res);
+        if( rc!=SQLITE_OK ) goto abort_due_to_error;
         pC->recnoIsValid = 0;
       }else{
         /* res might be negative because the table is empty.  Check to
index cb53360c7ab14d49027c9f6c1d99328dacbab7ac..a84a019dcb9571c7085dd8f9db64899eb00ec790 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing built-in functions.
 #
-# $Id: func.test,v 1.29 2004/08/20 18:34:20 drh Exp $
+# $Id: func.test,v 1.30 2005/01/11 13:02:34 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -452,4 +452,10 @@ do_test func-14.2 {
   }
 } {1}
 
+do_test func-15.1 {
+  catchsql {
+    select test_error(NULL);
+  }
+} {1 {user function error}}
+
 finish_test
index 06a32da33e8a869caadd1c8924ccd68fb84c6e7d..75f6806eb0b5fdb20518af2abdd7ac83c6b5137f 100644 (file)
@@ -15,7 +15,7 @@
 # The tests in this file use special facilities that are only
 # available in the SQLite test fixture.
 #
-# $Id: ioerr.test,v 1.9 2005/01/11 10:25:07 danielk1977 Exp $
+# $Id: ioerr.test,v 1.10 2005/01/11 13:02:34 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -174,4 +174,33 @@ for {set n 1} {$go} {incr n} {
 }
 set ::sqlite_io_error_pending 0
 
+set ::go 1
+for {set n 1} {$go} {incr n} {
+  do_test ioerr-4.$n.1 {
+    set ::sqlite_io_error_pending 0
+    db close
+    catch {file delete -force test.db}
+    catch {file delete -force test.db-journal}
+    sqlite3 db test.db
+    set sql "CREATE TABLE abc(a1"
+    for {set i 2} {$i<1300} {incr i} {
+      append sql ", a$i"
+    }
+    append sql ");"
+    execsql $sql
+    execsql {INSERT INTO abc (a1) VALUES(NULL)}
+  } {}
+  do_test ioerr-4.$n.2 [subst {
+    set ::sqlite_io_error_pending $n
+  }] $n
+  do_test ioerr-4.$n.3 {
+    set r [catch {db eval {
+      SELECT * FROM abc;
+    }} msg]
+    set ::go [expr {$::sqlite_io_error_pending<=0}]
+    expr {$::sqlite_io_error_pending>0 || $r!=0}
+  } {1}
+}
+set ::sqlite_io_error_pending 0
+
 finish_test
index 8ac403a522d609536accee22d3ac45b1c611a2c8..57c6336ab85c16435dab6e8ac746d08f241ee0c3 100644 (file)
@@ -14,7 +14,7 @@
 # special feature is used to see what happens in the library if a malloc
 # were to really fail due to an out-of-memory situation.
 #
-# $Id: malloc.test,v 1.12 2005/01/03 01:33:00 drh Exp $
+# $Id: malloc.test,v 1.13 2005/01/11 13:02:34 danielk1977 Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -304,6 +304,36 @@ for {set go 1; set i 1} {$go} {incr i} {
   } {1 1}
 }
 
+for {set go 1; set i 1} {$go} {incr i} {
+  do_test malloc-7.$i {
+     sqlite_malloc_fail 0
+     catch {db close}
+     catch {file delete -force test.db}
+     catch {file delete -force test.db-journal}
+     sqlite3 db test.db
+     execsql {
+       CREATE TABLE t1(a, b);
+       INSERT INTO t1 VALUES(1, 2);
+       INSERT INTO t1 VALUES(3, 4);
+       INSERT INTO t1 VALUES(5, 6);
+     }
+     sqlite_malloc_fail $i
+     set v [catch {execsql {
+       SELECT min(a) FROM t1 GROUP BY b;
+     }} msg]
+     set leftover [lindex [sqlite_malloc_stat] 2]
+     if {$leftover>0} {
+       if {$leftover>1} {puts "\nLeftover: $leftover\nReturn=$v  Message=$msg"}
+       set ::go 0
+       set v {1 1}
+     } else {
+       set v2 [expr {$msg=="" || $msg=="out of memory"}]
+       if {!$v2} {puts "\nError message returned: $msg"}
+       lappend v $v2
+     }
+  } {1 1}
+}
+
 # Ensure that no file descriptors were leaked.
 do_test malloc-6.X {
   catch {db close}