]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add tests to quota.test.
authordan <dan@noemail.net>
Wed, 1 Sep 2010 18:00:09 +0000 (18:00 +0000)
committerdan <dan@noemail.net>
Wed, 1 Sep 2010 18:00:09 +0000 (18:00 +0000)
FossilOrigin-Name: ec9af6ebd49505c4e5f90fb6450c71946cdc7291

manifest
manifest.uuid
src/test_quota.c
test/quota.test

index 52c90fb96932d27d9d9053a87e59bf68e58456a9..6239ab950e084afeb87e9a136534cdc87e072aa5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Call\squota\scallback\sdestructors\sfrom\swithin\ssqlite3_quota_shutdown().
-D 2010-09-01T16:19:57
+C Add\stests\sto\squota.test.
+D 2010-09-01T18:00:10
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -208,7 +208,7 @@ F src/test_mutex.c ce06b59aca168cd8c520b77159a24352a7469bd3
 F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec
 F src/test_osinst.c f408c6a181f2fb04c56273afd5c3e1e82f60392c
 F src/test_pcache.c 7bf828972ac0d2403f5cfa4cd14da41f8ebe73d8
-F src/test_quota.c 6afa78d864509f490ffffd997761ebb2890478d0
+F src/test_quota.c 6d32dd5885777f432db91e3a6c9e39008dd67d86
 F src/test_rtree.c e957a603a98871dcf005c1e96ae791cfe74eb7f6
 F src/test_schema.c 8c06ef9ddb240c7a0fcd31bc221a6a2aade58bf0
 F src/test_server.c bbba05c144b5fc4b52ff650a4328027b3fa5fcc6
@@ -562,7 +562,7 @@ F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea
 F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301
 F test/ptrchng.test ef1aa72d6cf35a2bbd0869a649b744e9d84977fc
 F test/quick.test 1681febc928d686362d50057c642f77a02c62e57
-F test/quota.test f4028117363a4a42d5b45fc8f6f5ba34556062d4
+F test/quota.test ddafe133653093eb9a99ccd6264884ae43f9c9b8
 F test/quote.test 215897dbe8de1a6f701265836d6601cc6ed103e6
 F test/randexpr1.tcl 40dec52119ed3a2b8b2a773bce24b63a3a746459
 F test/randexpr1.test 1084050991e9ba22c1c10edd8d84673b501cc25a
@@ -853,7 +853,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 7f6072f0827e3aafd17f5f2bac9e3a3f8482e5f6
-R 683c19de50a702003d36bb4bcbf13d6b
+P fb80c6f3de73ed832faaeb8c4d83e1354f132b39
+R c08f0a6930588c34007d44f357699c43
 U dan
-Z a5272a839c843ec4c6d420e66112a9e4
+Z efb044ac8547d8d2011ff96cf1ab3840
index 59d5e2a67086e0b1c61a832e0f3a6b8b33d34f9d..1eed96a1ea658bd53d62887db335fb107ab0e33f 100644 (file)
@@ -1 +1 @@
-fb80c6f3de73ed832faaeb8c4d83e1354f132b39
\ No newline at end of file
+ec9af6ebd49505c4e5f90fb6450c71946cdc7291
\ No newline at end of file
index 4d576f160ea5ce4dd2a80feb5dfe6a2c4c03f456..352f289d3e6624c1fa69e9f556d7db4146db787e 100644 (file)
@@ -832,6 +832,7 @@ static int test_quota_set(
   TclQuotaCallback *p;            /* Callback object */
   int nScript;                    /* Length of callback script */
   void (*xDestroy)(void*);        /* Optional destructor for pArg */
+  void (*xCallback)(const char *, sqlite3_int64 *, sqlite3_int64, void *);
 
   /* Process arguments */
   if( objc!=4 ){
@@ -855,13 +856,15 @@ static int test_quota_set(
     Tcl_IncrRefCount(pScript);
     p->pScript = pScript;
     xDestroy = tclCallbackDestructor;
+    xCallback = tclQuotaCallback;
   }else{
     p = 0;
     xDestroy = 0;
+    xCallback = 0;
   }
 
   /* Invoke sqlite3_quota_set() */
-  rc = sqlite3_quota_set(zPattern, iLimit, tclQuotaCallback, (void*)p,xDestroy);
+  rc = sqlite3_quota_set(zPattern, iLimit, xCallback, (void*)p, xDestroy);
 
   Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_STATIC);
   return TCL_OK;
index 9c138e6c864809dfeb4be3058a3e23151f34275f..2cf7628004a941bc5984770ae971c7c5b6d18ad0 100644 (file)
@@ -12,6 +12,7 @@
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
+source $testdir/malloc_common.tcl
 
 db close
 
@@ -110,6 +111,11 @@ do_test quota-2.4.99 {
 # Try some tests with more than one connection to a database file. Still
 # in rollback mode.
 #
+#   quota-3.1.*: Two connections to a single database file.
+#
+#   quota-3.2.*: Two connections to each of several database files (that
+#                are in the same quota group).
+#
 proc quota_check {filename limitvar size} {
   upvar $limitvar limit
   lappend ::quota [set limit] $size
@@ -145,11 +151,73 @@ do_test quota-3.1.5 {
   set ::quota_request_ok 1
   execsql { CREATE TABLE t3(a, b) }
 } {}
+do_test quota-3.1.6 {
+  db close
+  db2 close
+  sqlite3_quota_set *test.db 0 {}
+} {SQLITE_OK}
 
-do_test quota-3.X {
-  catch { db close }
-  catch { db2 close }
-} {0}
+do_test quota-3.2.1 {
+  file delete force test.db test2.db 
+
+  sqlite3_quota_set * 4096 {}
+  sqlite3 db1a test.db
+  sqlite3 db2a test2.db
+
+  foreach db {db1a db2a} {
+    execsql {
+      PRAGMA page_size = 1024;
+      PRAGMA journal_mode = delete;
+      PRAGMA auto_vacuum = off;
+      CREATE TABLE t1(a, b);
+    } $db
+  }
+
+  sqlite3 db1b test.db
+  sqlite3 db2b test2.db
+
+  list [file size test.db] [file size test2.db]
+} {2048 2048}
+
+catch { unset ::quota_request_ok }
+
+do_test quota-3.2.2 { execsql { INSERT INTO t1 VALUES('x', 'y') } db1a } {}
+do_test quota-3.2.3 { execsql { INSERT INTO t1 VALUES('v', 'w') } db1b } {}
+do_test quota-3.2.4 { execsql { INSERT INTO t1 VALUES('t', 'u') } db2a } {}
+do_test quota-3.2.5 { execsql { INSERT INTO t1 VALUES('r', 's') } db2b } {}
+
+do_test quota-3.2.6 { 
+  catchsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1a
+} {1 {database or disk is full}}
+do_test quota-3.2.7 { 
+  catchsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1b
+} {1 {database or disk is full}}
+do_test quota-3.2.8 { 
+  catchsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a
+} {1 {database or disk is full}}
+do_test quota-3.2.9 { 
+  catchsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b
+} {1 {database or disk is full}}
+
+set ::quota [list]
+proc quota_callback {file limitvar size} {
+  upvar $limitvar limit
+  lappend ::quota $file $size
+  set limit 0
+}
+sqlite3_quota_set * 4096 quota_callback
+do_test quota-3.3.1 { 
+  execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1a
+  execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1b
+  execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a
+  execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b
+  set ::quota
+} [list [file join [pwd] test.db] 5120]
+
+do_test quota-3.2.X {
+  foreach db {db1a db2a db2b db1b} { catch { $db close } }
+  sqlite3_quota_set * 0 {}
+} {SQLITE_OK}
 
 #-------------------------------------------------------------------------
 # Quotas are deleted when unused and when there limit is set to zero
@@ -266,7 +334,63 @@ do_test quota-4.4.2 {
   quota_list
 } {}
 
+#-------------------------------------------------------------------------
+# The following tests test that the quota VFS handles malloc and IO 
+# errors.
+#
+
+sqlite3_quota_initialize "" 1
+sqlite3_quota_set *test.db 4096 {}
+
+do_faultsim_test quota-5.1 -prep {
+  catch {db close}
+} -body {
+  sqlite3 db test2.db
+}
+do_faultsim_test quota-5.2 -prep {
+  catch {db close}
+} -body {
+  sqlite3 db test.db
+}
+
+catch { db close }
+file delete -force test.db
+
+do_test quota-5.3.prep {
+  sqlite3 db test.db
+  execsql {
+    PRAGMA auto_vacuum = 1;
+    PRAGMA page_size = 1024;
+    CREATE TABLE t1(a, b);
+    INSERT INTO t1 VALUES(10, zeroblob(1200));
+  }
+  faultsim_save_and_close
+} {}
+do_faultsim_test quota-5.3 -prep {
+  faultsim_restore_and_reopen
+} -body {
+  execsql { DELETE FROM t1 }
+}
 
+do_test quota-5.4.1 {
+  catch { db close }
+  file delete -force test.db
+  file mkdir test.db
+  list [catch { sqlite3 db test.db } msg] $msg
+} {1 {unable to open database file}}
+
+do_faultsim_test quota-5.5 -prep {
+  catch { sqlite3_quota_shutdown }
+} -body {
+  sqlite3_quota_initialize "" 1
+}
+
+do_faultsim_test quota-5.6 -prep {
+  catch { sqlite3_quota_shutdown }
+  sqlite3_quota_initialize "" 1
+} -body {
+  sqlite3_quota_set * 4096 {}
+}
 
 catch { sqlite3_quota_shutdown }
 finish_test