]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Increased test coverage on trigger.c and printf.c. (CVS 2601)
authordrh <drh@noemail.net>
Fri, 19 Aug 2005 02:26:27 +0000 (02:26 +0000)
committerdrh <drh@noemail.net>
Fri, 19 Aug 2005 02:26:27 +0000 (02:26 +0000)
FossilOrigin-Name: 842a80bd8f18d6fd046604f9a057bcd738234f1f

main.mk
manifest
manifest.uuid
src/printf.c
test/printf.test
test/trigger7.test [new file with mode: 0644]

diff --git a/main.mk b/main.mk
index 88bf4471b74f56aec70c48e3b5bfa74c341142d9..d931e281aed438a44c243f788cf44d50b16bd4b2 100644 (file)
--- a/main.mk
+++ b/main.mk
@@ -558,7 +558,7 @@ install:    sqlite3 libsqlite3.a sqlite3.h
        mv sqlite3.h /usr/include
 
 clean: 
-       rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.*
+       rm -f *.o sqlite3 libsqlite3.a sqlite3.h opcodes.* crashtest
        rm -f lemon lempar.c parse.* sqlite*.tar.gz mkkeywordhash keywordhash.h
        rm -f $(PUBLISH)
        rm -f *.da *.bb *.bbg gmon.out
index bc516f3379a10a22477d6dca8826cca06bcae57c..c2fd504720ee7a3a49e4daf0e1d8da75c22d425c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C More\stest\scoverage\senhancements.\s(CVS\s2600)
-D 2005-08-19T01:07:16
+C Increased\stest\scoverage\son\strigger.c\sand\sprintf.c.\s(CVS\s2601)
+D 2005-08-19T02:26:27
 F Makefile.in b109ddb46a5550d0732dcd6caca01c123f6d5cdd
 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -17,7 +17,7 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538
 F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac
 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
 F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826
-F main.mk bf8b4a9dbd9233f2371d0322e33e42bde87212b2
+F main.mk c1cf11f7f14085e5686068fb4f67b6c45b677951
 F mkdll.sh 5ec23622515d5bf8969404e80cfb5e220ddf0512
 F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
 F mkopcodeh.awk 7563ad235670e864ead95cf672be3fe081450ae0
@@ -61,7 +61,7 @@ F src/pager.h 0d9153d6269d60d04af3dd84a0cc0a96253cf4a4
 F src/parse.y d57cdd2adc0923762b40314f08683c836a2e0c90
 F src/pragma.c 69413fbdc0c6aaa493a776ea52c1b3e6cf35dfb2
 F src/prepare.c 86f0d8e744b8d956eff6bc40e29049efee017610
-F src/printf.c 772b15c3395fa60bdbf3aaa03d480ecde38bf192
+F src/printf.c cea584c5888688c650d856563aadc4296b5afac7
 F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
 F src/select.c f441648eb191dcf1e67ae61475ea3b40a0eeb787
 F src/shell.c 86c16f0d534aa51cc82cf9f66903d4eb681580e7
@@ -185,7 +185,7 @@ F test/pager2.test 49c0f57c7da0b060f0486b85fdd074025caa694e
 F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
 F test/pagesize.test cbc6a312b6f6c0f02619b189985df2a14164b690
 F test/pragma.test 95ea907adf68459e1be6f310c9ae94d1d59c465b
-F test/printf.test dc39f7c66db3adfe754b4fc0b97fdd97fa06a9c8
+F test/printf.test 4a91651d4fd5eea999eee82a9bdd0a1b797b9ad9
 F test/progress.test 16496001da445e6534afb94562c286708316d82f x
 F test/quick.test a94d12658a2b590c1a5be580bef09bbb04c1266b
 F test/quote.test c1ca5e18800455f1c882baf5b0274755a3836549
@@ -220,6 +220,7 @@ F test/trigger3.test 9102fd3933db294dc654b5aee9edfe9e94f2b9e2
 F test/trigger4.test 9615207f3746b1f3965113007869e45a895d2497
 F test/trigger5.test 619391a3e9fc194081d22cefd830d811e7badf83
 F test/trigger6.test 0e411654f122552da6590f0b4e6f781048a4a9b9
+F test/trigger7.test 0afa870be2ce1b132cdb85b17a4a4ef45aa8cece
 F test/types.test f0a98d10c5ecc9865d19dc94486f9873afc6bb6b
 F test/types2.test 81dd1897be8ef4b5b73d0006e6076abe40610de3
 F test/types3.test 5c63c9cdbafe8fcb73a70a0beb0ecb65b7fa061d
@@ -294,7 +295,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 2fe0ac4fa4d5911e266979021fa7e413d96c558d
-R 31fa1affa5851be2627a9e42460d8a99
+P 0b6cd5acc0ede3367623f40ccfaa96116e686824
+R e4576da06cab5ef483fe5b761dc368f8
 U drh
-Z 767cac511bcfeb21d48a46ba088681f1
+Z f0280623a4012ade3b1bce2760205da0
index a0dc753b02b5d3a52d931a078eb013c1201c31bc..aa2b3481461bda6d3e269f0f8e84bbfe56fd2142 100644 (file)
@@ -1 +1 @@
-0b6cd5acc0ede3367623f40ccfaa96116e686824
\ No newline at end of file
+842a80bd8f18d6fd046604f9a057bcd738234f1f
\ No newline at end of file
index 18810e4b7c03e4d4f166b5b97b5370dbdfdec7ae..d4cb66499fb57ccd827c446ac579a1d95dab04da 100644 (file)
@@ -419,7 +419,7 @@ static int vxprintf(
         realvalue = va_arg(ap,double);
 #ifndef etNOFLOATINGPOINT
         if( precision<0 ) precision = 6;         /* Set default precision */
-        if( precision>etBUFSIZE-10 ) precision = etBUFSIZE-10;
+        if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
         if( realvalue<0.0 ){
           realvalue = -realvalue;
           prefix = '-';
@@ -472,12 +472,6 @@ static int vxprintf(
         }else{
           flag_rtz = 0;
         }
-        /* If exp+precision causes the output to be too big for etFLOAT, then
-        ** do etEXP instead
-        */
-        if( xtype==etFLOAT && exp+precision>=etBUFSIZE-30 ){
-          xtype = etEXP;
-        }
         if( xtype==etEXP ){
           e2 = 0;
         }else{
@@ -591,36 +585,35 @@ static int vxprintf(
         if( precision>=0 && precision<length ) length = precision;
         break;
       case etSQLESCAPE:
-      case etSQLESCAPE2:
-        {
-          int i, j, n, c, isnull;
-          int needQuote;
-          char *arg = va_arg(ap,char*);
-          isnull = arg==0;
-          if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
-          for(i=n=0; (c=arg[i])!=0; i++){
-            if( c=='\'' )  n++;
-          }
-          needQuote = !isnull && xtype==etSQLESCAPE2;
-          n += i + 1 + needQuote*2;
-          if( n>etBUFSIZE ){
-            bufpt = zExtra = sqliteMalloc( n );
-            if( bufpt==0 ) return -1;
-          }else{
-            bufpt = buf;
-          }
-          j = 0;
-          if( needQuote ) bufpt[j++] = '\'';
-          for(i=0; (c=arg[i])!=0; i++){
-            bufpt[j++] = c;
-            if( c=='\'' ) bufpt[j++] = c;
-          }
-          if( needQuote ) bufpt[j++] = '\'';
-          bufpt[j] = 0;
-          length = j;
-          if( precision>=0 && precision<length ) length = precision;
+      case etSQLESCAPE2: {
+        int i, j, n, c, isnull;
+        int needQuote;
+        char *arg = va_arg(ap,char*);
+        isnull = arg==0;
+        if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
+        for(i=n=0; (c=arg[i])!=0; i++){
+          if( c=='\'' )  n++;
+        }
+        needQuote = !isnull && xtype==etSQLESCAPE2;
+        n += i + 1 + needQuote*2;
+        if( n>etBUFSIZE ){
+          bufpt = zExtra = sqliteMalloc( n );
+          if( bufpt==0 ) return -1;
+        }else{
+          bufpt = buf;
         }
+        j = 0;
+        if( needQuote ) bufpt[j++] = '\'';
+        for(i=0; (c=arg[i])!=0; i++){
+          bufpt[j++] = c;
+          if( c=='\'' ) bufpt[j++] = c;
+        }
+        if( needQuote ) bufpt[j++] = '\'';
+        bufpt[j] = 0;
+        length = j;
+        if( precision>=0 && precision<length ) length = precision;
         break;
+      }
       case etTOKEN: {
         Token *pToken = va_arg(ap, Token*);
         if( pToken && pToken->z ){
index bd57751d9d9d6d50c62a64ad98da8bbcf02a505b..5a8b14ba6dc3d7c34e87fa7745925b7a9fa0c765 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the sqlite_*_printf() interface.
 #
-# $Id: printf.test,v 1.16 2005/08/13 12:59:16 drh Exp $
+# $Id: printf.test,v 1.17 2005/08/19 02:26:27 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -159,6 +159,14 @@ do_test printf-9.3 {
   sqlite3_mprintf_int {%*.*c} 4 1 67
 } {   C}
 do_test printf-9.4 {
+  sqlite3_mprintf_int {%d %d %c} 4 1 67
+} {4 1 C}
+set ten {          }
+set fifty $ten$ten$ten$ten$ten
+do_test printf-9.5 {
+  sqlite3_mprintf_int {%d %*c} 1 -201 67
+} "1 C$fifty$fifty$fifty$fifty"
+do_test printf-9.6 {
   sqlite3_mprintf_int {%yhello} 0 0 0
 } {%}
 
@@ -205,5 +213,10 @@ do_test printf-11.7 {
   sqlite3_mprintf_double {%d %d %!.15g} 1 1 1e300
 } {1 1 1.0e+300}
 
+# Additional tests for coverage
+#
+do_test printf-12.1 {
+  sqlite3_mprintf_double {%d %d %.2000g} 1 1 1.0
+} {1 1 1}
 
 finish_test
diff --git a/test/trigger7.test b/test/trigger7.test
new file mode 100644 (file)
index 0000000..dfaf18f
--- /dev/null
@@ -0,0 +1,121 @@
+# 2005 August 18
+#
+# 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.
+#
+# This file implements tests to increase coverage of trigger.c.
+#
+# $Id: trigger7.test,v 1.1 2005/08/19 02:26:27 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+ifcapable {!trigger} {
+  finish_test
+  return
+}
+
+
+# Error messages resulting from qualified trigger names.
+#
+do_test trigger7-1.1 {
+  execsql {
+    CREATE TABLE t1(x, y);
+  }
+  catchsql {
+    CREATE TEMP TRIGGER main.r1 AFTER INSERT ON t1 BEGIN
+      SELECT 'no nothing';
+    END
+  }
+} {1 {temporary trigger may not have qualified name}}
+do_test trigger7-1.2 {
+  catchsql {
+    CREATE TRIGGER not_a_db.r1 AFTER INSERT ON t1 BEGIN
+      SELECT 'no nothing';
+    END
+  }
+} {1 {unknown database not_a_db}}
+
+
+# When the UPDATE OF syntax is used, no code is generated for triggers
+# that do not match the update columns.
+#
+ifcapable explain {
+  do_test trigger7-2.1 {
+    execsql {
+      CREATE TRIGGER r1 AFTER UPDATE OF x ON t1 BEGIN
+        SELECT '___update_t1.x___';
+      END;
+      CREATE TRIGGER r2 AFTER UPDATE OF y ON t1 BEGIN
+        SELECT '___update_t1.y___';
+      END;
+    }
+    set txt [db eval {EXPLAIN UPDATE t1 SET x=5}]
+    string match *___update_t1.x___* $txt
+  } 1
+  do_test trigger7-2.2 {
+    set txt [db eval {EXPLAIN UPDATE t1 SET x=5}]
+    string match *___update_t1.y___* $txt
+  } 0
+  do_test trigger7-2.3 {
+    set txt [db eval {EXPLAIN UPDATE t1 SET y=5}]
+    string match *___update_t1.x___* $txt
+  } 0
+  do_test trigger7-2.4 {
+    set txt [db eval {EXPLAIN UPDATE t1 SET y=5}]
+    string match *___update_t1.y___* $txt
+  } 1
+  do_test trigger7-2.5 {
+    set txt [db eval {EXPLAIN UPDATE t1 SET rowid=5}]
+    string match *___update_t1.x___* $txt
+  } 0
+  do_test trigger7-2.6 {
+    set txt [db eval {EXPLAIN UPDATE t1 SET rowid=5}]
+    string match *___update_t1.x___* $txt
+  } 0
+}
+
+# Test the ability to create many triggers on the same table, then
+# selectively drop those triggers.
+#
+do_test trigger7-3.1 {
+  execsql {
+    CREATE TABLE t2(x,y,z);
+    CREATE TRIGGER t2r1 AFTER INSERT ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r2 BEFORE INSERT ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r3 AFTER UPDATE ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r4 BEFORE UPDATE ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r5 AFTER DELETE ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r6 BEFORE DELETE ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r7 AFTER INSERT ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r8 BEFORE INSERT ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r9 AFTER UPDATE ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r10 BEFORE UPDATE ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r11 AFTER DELETE ON t2 BEGIN SELECT 1; END;
+    CREATE TRIGGER t2r12 BEFORE DELETE ON t2 BEGIN SELECT 1; END;
+    DROP TRIGGER t2r6;
+  }
+} {}
+
+# This test corrupts the database file so it must be the last test
+# in the series.
+#
+do_test trigger7-99.1 {
+  execsql {
+    PRAGMA writable_schema=on;
+    UPDATE sqlite_master SET sql='nonsense';
+  }
+  db close
+  sqlite3 db test.db
+  catchsql {
+    DROP TRIGGER t2r5
+  }
+} {1 {malformed database schema - near "nonsense": syntax error}}
+
+finish_test