Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: third_party/sqlite/src/test/quota.test

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2010 September 1 1 # 2010 September 1
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
11 # 11 #
12 12
13 set testdir [file dirname $argv0] 13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl 14 source $testdir/tester.tcl
15
16 # If SQLITE_CURDIR is not defined, omit this file.
17 ifcapable !curdir {
18 finish_test
19 return
20 }
21
15 source $testdir/malloc_common.tcl 22 source $testdir/malloc_common.tcl
16 23
24 unset -nocomplain defaultVfs
25 set defaultVfs [file_control_vfsname db]
17 db close 26 db close
18 27
19 do_test quota-1.1 { sqlite3_quota_initialize nosuchvfs 1 } {SQLITE_ERROR} 28 do_test quota-1.1 { sqlite3_quota_initialize nosuchvfs 1 } {SQLITE_ERROR}
20 do_test quota-1.2 { sqlite3_quota_initialize "" 1 } {SQLITE_OK} 29 do_test quota-1.2 { sqlite3_quota_initialize "" 1 } {SQLITE_OK}
21 do_test quota-1.3 { sqlite3_quota_initialize "" 1 } {SQLITE_MISUSE} 30 do_test quota-1.3 { sqlite3_quota_initialize "" 1 } {SQLITE_MISUSE}
22 do_test quota-1.4 { sqlite3_quota_shutdown } {SQLITE_OK} 31 do_test quota-1.4 { sqlite3_quota_shutdown } {SQLITE_OK}
23 32
24 do_test quota-1.5 { sqlite3_quota_initialize "" 0 } {SQLITE_OK} 33 do_test quota-1.5 { sqlite3_quota_initialize "" 0 } {SQLITE_OK}
25 do_test quota-1.6 { sqlite3_quota_shutdown } {SQLITE_OK} 34 do_test quota-1.6 { sqlite3_quota_shutdown } {SQLITE_OK}
26 do_test quota-1.7 { sqlite3_quota_initialize "" 1 } {SQLITE_OK} 35 do_test quota-1.7 { sqlite3_quota_initialize "" 1 } {SQLITE_OK}
(...skipping 14 matching lines...) Expand all
41 # quota-2.3.*: Open and close a db that is not part of any quota group. At 50 # quota-2.3.*: Open and close a db that is not part of any quota group. At
42 # one point this was causing mutex refs to be leaked. 51 # one point this was causing mutex refs to be leaked.
43 # 52 #
44 # quota-2.4.*: Try to shutdown the quota system before closing the db 53 # quota-2.4.*: Try to shutdown the quota system before closing the db
45 # file. Check that this fails and the quota system still works 54 # file. Check that this fails and the quota system still works
46 # afterwards. Then close the database and successfully shut 55 # afterwards. Then close the database and successfully shut
47 # down the quota system. 56 # down the quota system.
48 # 57 #
49 sqlite3_quota_initialize "" 1 58 sqlite3_quota_initialize "" 1
50 59
60 unset -nocomplain quota_request_ok
51 proc quota_check {filename limitvar size} { 61 proc quota_check {filename limitvar size} {
52 upvar $limitvar limit 62 upvar $limitvar limit
53 63
54 lappend ::quota [set limit] $size 64 lappend ::quota [set limit] $size
55 if {[info exists ::quota_request_ok]} { set limit $size } 65 if {[info exists ::quota_request_ok]} { set limit $size }
56 } 66 }
57 67
58 do_test quota-2.1.1 { 68 do_test quota-2.1.1 {
59 sqlite3_quota_set *test.db 4096 quota_check 69 sqlite3_quota_set *test.db 4096 quota_check
60 } {SQLITE_OK} 70 } {SQLITE_OK}
61 do_test quota-2.1.2 { 71 do_test quota-2.1.2 {
62 sqlite3 db test.db 72 sqlite3 db test.db
63 execsql { 73 execsql {
64 PRAGMA page_size=1024; 74 PRAGMA page_size=1024;
65 PRAGMA auto_vacuum=OFF; 75 PRAGMA auto_vacuum=OFF;
66 PRAGMA journal_mode=DELETE; 76 PRAGMA journal_mode=DELETE;
67 } 77 }
68 set ::quota [list] 78 set ::quota [list]
69 execsql { 79 execsql {
70 CREATE TABLE t1(a, b); 80 CREATE TABLE t1(a, b);
71 INSERT INTO t1 VALUES(1, randomblob(1100)); 81 INSERT INTO t1 VALUES(1, randomblob(1100));
72 INSERT INTO t1 VALUES(2, randomblob(1100)); 82 INSERT INTO t1 VALUES(2, randomblob(1100));
73 } 83 }
74 set ::quota 84 set ::quota
75 } {} 85 } {}
86 do_test quota-2.1.2.1 {
87 file_control_vfsname db
88 } quota/$defaultVfs
76 do_test quota-2.1.3 { file size test.db } {4096} 89 do_test quota-2.1.3 { file size test.db } {4096}
77 do_test quota-2.1.4 { 90 do_test quota-2.1.4 {
78 catchsql { INSERT INTO t1 VALUES(3, randomblob(1100)) } 91 catchsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
79 } {1 {database or disk is full}} 92 } {1 {database or disk is full}}
80 do_test quota-2.1.5 { set ::quota } {4096 5120} 93 do_test quota-2.1.5 { set ::quota } {4096 5120}
81 94
82 set ::quota_request_ok 1 95 set ::quota_request_ok 1
83 set ::quota [list] 96 set ::quota [list]
84 do_test quota-2.2.1 { 97 do_test quota-2.2.1 {
85 execsql { INSERT INTO t1 VALUES(3, randomblob(1100)) } 98 execsql { INSERT INTO t1 VALUES(3, randomblob(1100)) }
(...skipping 30 matching lines...) Expand all
116 # quota-3.2.*: Two connections to each of several database files (that 129 # quota-3.2.*: Two connections to each of several database files (that
117 # are in the same quota group). 130 # are in the same quota group).
118 # 131 #
119 proc quota_check {filename limitvar size} { 132 proc quota_check {filename limitvar size} {
120 upvar $limitvar limit 133 upvar $limitvar limit
121 lappend ::quota [set limit] $size 134 lappend ::quota [set limit] $size
122 if {[info exists ::quota_request_ok]} { set limit $size } 135 if {[info exists ::quota_request_ok]} { set limit $size }
123 } 136 }
124 137
125 do_test quota-3.1.1 { 138 do_test quota-3.1.1 {
126 file delete -force test.db 139 forcedelete test.db
127 sqlite3_quota_initialize "" 1 140 sqlite3_quota_initialize "" 1
128 sqlite3_quota_set *test.db 4096 quota_check 141 sqlite3_quota_set *test.db 4096 quota_check
129 } {SQLITE_OK} 142 } {SQLITE_OK}
130 do_test quota-3.1.2 { 143 do_test quota-3.1.2 {
131 sqlite3 db test.db 144 sqlite3 db test.db
132 execsql { 145 execsql {
133 PRAGMA page_size = 1024; 146 PRAGMA page_size = 1024;
134 PRAGMA journal_mode = delete; 147 PRAGMA journal_mode = delete;
135 PRAGMA auto_vacuum = off; 148 PRAGMA auto_vacuum = off;
136 CREATE TABLE t1(a PRIMARY KEY, b); 149 CREATE TABLE t1(a PRIMARY KEY, b);
(...skipping 14 matching lines...) Expand all
151 set ::quota_request_ok 1 164 set ::quota_request_ok 1
152 execsql { CREATE TABLE t3(a, b) } 165 execsql { CREATE TABLE t3(a, b) }
153 } {} 166 } {}
154 do_test quota-3.1.6 { 167 do_test quota-3.1.6 {
155 db close 168 db close
156 db2 close 169 db2 close
157 sqlite3_quota_set *test.db 0 {} 170 sqlite3_quota_set *test.db 0 {}
158 } {SQLITE_OK} 171 } {SQLITE_OK}
159 172
160 do_test quota-3.2.1 { 173 do_test quota-3.2.1 {
161 file delete force test.db test2.db 174 delete_file force test.db test2.db
162 175
163 sqlite3_quota_set * 4096 {} 176 sqlite3_quota_set * 4096 {}
164 sqlite3 db1a test.db 177 sqlite3 db1a test.db
165 sqlite3 db2a test2.db 178 sqlite3 db2a test2.db
166 179
167 foreach db {db1a db2a} { 180 foreach db {db1a db2a} {
168 execsql { 181 execsql {
169 PRAGMA page_size = 1024; 182 PRAGMA page_size = 1024;
170 PRAGMA journal_mode = delete; 183 PRAGMA journal_mode = delete;
171 PRAGMA auto_vacuum = off; 184 PRAGMA auto_vacuum = off;
(...skipping 23 matching lines...) Expand all
195 do_test quota-3.2.8 { 208 do_test quota-3.2.8 {
196 catchsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a 209 catchsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a
197 } {1 {database or disk is full}} 210 } {1 {database or disk is full}}
198 do_test quota-3.2.9 { 211 do_test quota-3.2.9 {
199 catchsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b 212 catchsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b
200 } {1 {database or disk is full}} 213 } {1 {database or disk is full}}
201 214
202 set ::quota [list] 215 set ::quota [list]
203 proc quota_callback {file limitvar size} { 216 proc quota_callback {file limitvar size} {
204 upvar $limitvar limit 217 upvar $limitvar limit
218 if {$::tcl_platform(platform)=="windows"} {
219 set file [ lindex [string map {\\ \/} $file] 0 ]
220 }
205 lappend ::quota $file $size 221 lappend ::quota $file $size
206 set limit 0 222 set limit 0
207 } 223 }
208 sqlite3_quota_set * 4096 quota_callback 224 sqlite3_quota_set * 4096 quota_callback
209 do_test quota-3.3.1 { 225 do_test quota-3.3.1 {
210 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1a 226 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1a
211 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1b 227 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db1b
212 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a 228 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2a
213 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b 229 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } db2b
214 set ::quota 230 set ::quota
215 } [list [file join [pwd] test.db] 5120] 231 } [list [file join [get_pwd] test.db] 5120]
216 232
217 do_test quota-3.2.X { 233 do_test quota-3.2.X {
218 foreach db {db1a db2a db2b db1b} { catch { $db close } } 234 foreach db {db1a db2a db2b db1b} { catch { $db close } }
219 sqlite3_quota_set * 0 {} 235 sqlite3_quota_set * 0 {}
220 } {SQLITE_OK} 236 } {SQLITE_OK}
221 237
222 #------------------------------------------------------------------------- 238 #-------------------------------------------------------------------------
223 # Quotas are deleted when unused and when there limit is set to zero 239 # Quotas are deleted when unused and when their limit is set to zero
224 # 240 #
225 241
226 # Return a list of all currently defined quotas. Each quota is identified 242 # Return a list of all currently defined quotas. Each quota is identified
227 # by its pattern. 243 # by its pattern.
228 proc quota_list {} { 244 proc quota_list {} {
229 set allq {} 245 set allq {}
230 foreach q [sqlite3_quota_dump] { 246 foreach q [sqlite3_quota_dump] {
231 lappend allq [lindex $q 0] 247 lappend allq [lindex $q 0]
232 } 248 }
233 return [lsort $allq] 249 return [lsort $allq]
234 } 250 }
251 proc quota_size {name} {
252 set allq {}
253 foreach q [sqlite3_quota_dump] {
254 if {[lindex $q 0]==$name} {return [lindex $q 2]}
255 }
256 return 0
257 }
235 258
236 do_test quota-4.1.1 { 259 do_test quota-4.1.1 {
237 sqlite3_quota_set *test.db 0 {} 260 sqlite3_quota_set *test.db 0 {}
238 quota_list 261 quota_list
239 } {} 262 } {}
240 do_test quota-4.1.2 { 263 do_test quota-4.1.2 {
241 sqlite3_quota_set *test.db 4096 {} 264 sqlite3_quota_set *test.db 4096 {}
242 quota_list 265 quota_list
243 } {*test.db} 266 } {*test.db}
244 do_test quota-4.1.3 { 267 do_test quota-4.1.3 {
245 sqlite3_quota_set *test2.db 0 {} 268 sqlite3_quota_set *test2.db 0 {}
246 quota_list 269 quota_list
247 } {*test.db} 270 } {*test.db}
248 do_test quota-4.1.4 { 271 do_test quota-4.1.4 {
249 sqlite3_quota_set *test2.db 100000 {} 272 sqlite3_quota_set *test2.db 100000 {}
250 quota_list 273 quota_list
251 } {*test.db *test2.db} 274 } {*test.db *test2.db}
252 do_test quota-4.1.5 { 275 do_test quota-4.1.5 {
253 sqlite3_quota_set *test.db 0 {} 276 sqlite3_quota_set *test.db 0 {}
254 quota_list 277 quota_list
255 } {*test2.db} 278 } {*test2.db}
256 do_test quota-4.1.6 { 279 do_test quota-4.1.6 {
257 file delete -force test2.db test2.db-journal test2.db-wal 280 forcedelete test2.db test2.db-journal test2.db-wal
258 sqlite3 db test2.db 281 sqlite3 db test2.db
259 db eval {CREATE TABLE t2(x); INSERT INTO t2 VALUES('tab-t2');} 282 db eval {CREATE TABLE t2(x); INSERT INTO t2 VALUES('tab-t2');}
260 quota_list 283 quota_list
261 } {*test2.db} 284 } {*test2.db}
262 do_test quota-4.1.7 { 285 do_test quota-4.1.7 {
263 catchsql {INSERT INTO t2 VALUES(zeroblob(200000))} 286 catchsql {INSERT INTO t2 VALUES(zeroblob(200000))}
264 } {1 {database or disk is full}} 287 } {1 {database or disk is full}}
265 do_test quota-4.1.8 { 288 do_test quota-4.1.8 {
266 sqlite3 db2 test2.db 289 sqlite3 db2 test2.db
267 db2 eval {SELECT * FROM t2} 290 db2 eval {SELECT * FROM t2}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } {} 342 } {}
320 343
321 do_test quota-4.3.1 { 344 do_test quota-4.3.1 {
322 sqlite3_quota_set A 1000 quota_callback 345 sqlite3_quota_set A 1000 quota_callback
323 sqlite3 db A 346 sqlite3 db A
324 sqlite3_quota_set A 0 quota_callback 347 sqlite3_quota_set A 0 quota_callback
325 db close 348 db close
326 quota_list 349 quota_list
327 } {} 350 } {}
328 351
352 unset -nocomplain quotagroup
353 if {$tcl_platform(platform)=="windows"} {
354 set quotagroup *\\quota-test-A?.db
355 } else {
356 set quotagroup */quota-test-A?.db
357 }
358 foreach file [glob -nocomplain quota-test-A*] {
359 forcedelete $file
360 }
329 do_test quota-4.4.1 { 361 do_test quota-4.4.1 {
362 set ::quota {}
363 sqlite3_quota_set $::quotagroup 10000 quota_callback
364 forcedelete ./quota-test-A1.db ./quota-test-A2.db
365 sqlite3 db ./quota-test-A1.db
366 db eval {
367 CREATE TABLE t1(x);
368 INSERT INTO t1 VALUES(randomblob(5000));
369 }
370 quota_list
371 } [list $quotagroup]
372 do_test quota-4.4.2 {
373 expr {$::quota==""}
374 } {1}
375 do_test quota-4.4.3 {
376 db close
377 sqlite3 db ./quota-test-A2.db
378 db eval {
379 CREATE TABLE t1(x);
380 INSERT INTO t1 VALUES(randomblob(5000));
381 }
382 quota_list
383 } [list $quotagroup]
384 do_test quota-4.4.4 {
385 expr {$::quota!=""}
386 } {1}
387 do_test quota-4.4.5 {
388 db close
389 sqlite3_quota_set $::quotagroup 0 {}
390 sqlite3_quota_dump
391 } {}
392 do_test quota-4.4.6 {
393 sqlite3_quota_set $quotagroup 10000 quota_callback
394 sqlite3 db quota-test-A1.db
395 db eval {SELECT count(*) FROM sqlite_master}
396 quota_size $quotagroup
397 } [file size quota-test-A1.db]
398 do_test quota-4.4.7 {
399 sqlite3_quota_file quota-test-A2.db
400 quota_size $::quotagroup
401 } [expr {[file size quota-test-A1.db]+[file size quota-test-A2.db]}]
402
403 unset -nocomplain quotagroup
404 if {$tcl_platform(platform)=="windows"} {
405 set quotagroup *\\quota-test-B*
406 } else {
407 set quotagroup */quota-test-B*
408 }
409 foreach file [glob -nocomplain quota-test-B*] {
410 forcedelete $file
411 }
412 do_test quota-4.5.1 {
413 sqlite3_quota_set $::quotagroup 100000 quota_callback
414 quota_size $::quotagroup
415 } {0}
416 do_test quota-4.5.2 {
417 sqlite3_quota_file quota-test-B1.txt
418 quota_size $::quotagroup
419 } {0}
420 proc add_to_file {name n} {
421 set out [open $name a]
422 fconfigure $out -translation binary
423 puts -nonewline $out [string repeat x $n]
424 close $out
425 }
426 do_test quota-4.5.3 {
427 add_to_file quota-test-B1.txt 123
428 sqlite3_quota_file quota-test-B1.txt
429 quota_size $::quotagroup
430 } {123}
431 do_test quota-4.5.4 {
432 add_to_file quota-test-B2.txt 234
433 sqlite3_quota_file quota-test-B2.txt
434 quota_size $::quotagroup
435 } {357}
436 do_test quota-4.5.5 {
437 add_to_file quota-test-B1.txt 2000
438 sqlite3_quota_file quota-test-B1.txt
439 quota_size $::quotagroup
440 } {2357}
441 do_test quota-4.5.6 {
442 forcedelete quota-test-B1.txt
443 sqlite3_quota_file quota-test-B1.txt
444 quota_size $::quotagroup
445 } {234}
446 do_test quota-4.5.7 {
447 forcedelete quota-test-B2.txt
448 sqlite3_quota_file quota-test-B2.txt
449 quota_size $::quotagroup
450 } {0}
451 do_test quota-4.5.8 {
452 add_to_file quota-test-B3.txt 1234
453 sqlite3_quota_file quota-test-B3.txt
454 quota_size $::quotagroup
455 } {1234}
456 do_test quota-4.5.9 {
457 sqlite3_quota_set $quotagroup 0 {}
458 quota_size $::quotagroup
459 } {0}
460
461 do_test quota-4.9.1 {
462 db close
330 sqlite3_quota_set A 1000 quota_callback 463 sqlite3_quota_set A 1000 quota_callback
331 sqlite3_quota_shutdown 464 sqlite3_quota_shutdown
332 } {SQLITE_OK} 465 } {SQLITE_OK}
333 do_test quota-4.4.2 { 466 do_test quota-4.9.2 {
334 quota_list 467 quota_list
335 } {} 468 } {}
336 469
337 #------------------------------------------------------------------------- 470 #-------------------------------------------------------------------------
338 # The following tests test that the quota VFS handles malloc and IO 471 # The following tests test that the quota VFS handles malloc and IO
339 # errors. 472 # errors.
340 # 473 #
341 474
342 sqlite3_quota_initialize "" 1 475 sqlite3_quota_initialize "" 1
343 sqlite3_quota_set *test.db 4096 {} 476 sqlite3_quota_set *test.db 4096 {}
344 477
345 do_faultsim_test quota-5.1 -prep { 478 do_faultsim_test quota-5.1 -prep {
346 catch {db close} 479 catch {db close}
347 } -body { 480 } -body {
348 sqlite3 db test2.db 481 sqlite3 db test2.db
349 } 482 }
350 do_faultsim_test quota-5.2 -prep { 483 do_faultsim_test quota-5.2 -prep {
351 catch {db close} 484 catch {db close}
352 } -body { 485 } -body {
353 sqlite3 db test.db 486 sqlite3 db test.db
354 } 487 }
355 488
356 catch { db close } 489 catch { db close }
357 file delete -force test.db 490 forcedelete test.db
358 491
359 do_test quota-5.3.prep { 492 do_test quota-5.3.prep {
360 sqlite3 db test.db 493 sqlite3 db test.db
361 execsql { 494 execsql {
362 PRAGMA auto_vacuum = 1; 495 PRAGMA auto_vacuum = 1;
363 PRAGMA page_size = 1024; 496 PRAGMA page_size = 1024;
364 CREATE TABLE t1(a, b); 497 CREATE TABLE t1(a, b);
365 INSERT INTO t1 VALUES(10, zeroblob(1200)); 498 INSERT INTO t1 VALUES(10, zeroblob(1200));
366 } 499 }
367 faultsim_save_and_close 500 faultsim_save_and_close
368 } {} 501 } {}
369 do_faultsim_test quota-5.3 -prep { 502 do_faultsim_test quota-5.3 -prep {
370 faultsim_restore_and_reopen 503 faultsim_restore_and_reopen
371 } -body { 504 } -body {
372 execsql { DELETE FROM t1 } 505 execsql { DELETE FROM t1 }
373 } 506 }
374 507
375 do_test quota-5.4.1 { 508 do_test quota-5.4.1 {
376 catch { db close } 509 catch { db close }
377 file delete -force test.db 510 forcedelete test.db
378 file mkdir test.db 511 file mkdir test.db
379 list [catch { sqlite3 db test.db } msg] $msg 512 list [catch { sqlite3 db test.db } msg] $msg
380 } {1 {unable to open database file}} 513 } {1 {unable to open database file}}
381 514
382 do_faultsim_test quota-5.5 -prep { 515 do_faultsim_test quota-5.5 -prep {
383 catch { sqlite3_quota_shutdown } 516 catch { sqlite3_quota_shutdown }
384 } -body { 517 } -body {
385 sqlite3_quota_initialize "" 1 518 sqlite3_quota_initialize "" 1
386 } 519 }
387 520
388 do_faultsim_test quota-5.6 -prep { 521 do_faultsim_test quota-5.6 -prep {
389 catch { sqlite3_quota_shutdown } 522 catch { sqlite3_quota_shutdown }
390 sqlite3_quota_initialize "" 1 523 sqlite3_quota_initialize "" 1
391 } -body { 524 } -body {
392 sqlite3_quota_set * 4096 {} 525 sqlite3_quota_set * 4096 {}
393 } 526 }
394 527
395 catch { sqlite3_quota_shutdown } 528 catch { sqlite3_quota_shutdown }
396 finish_test 529 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698