123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- # 2011 December 1
- #
- # 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.
- #
- #***********************************************************************
- #
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- # If SQLITE_CURDIR is not defined, omit this file.
- ifcapable !curdir {
- finish_test
- return
- }
- source $testdir/malloc_common.tcl
- db close
- sqlite3_quota_initialize "" 1
- foreach dir {quota2a/x1 quota2a/x2 quota2a quota2b quota2c} {
- forcedelete $dir
- }
- foreach dir {quota2a quota2a/x1 quota2a/x2 quota2b quota2c} {
- file mkdir $dir
- }
- # The standard_path procedure converts a pathname into a standard format
- # that is the same across platforms.
- #
- unset -nocomplain ::quota_pwd ::quota_mapping
- set ::quota_pwd [string map {\\ /} [get_pwd]]
- set ::quota_mapping [list $::quota_pwd PWD]
- proc standard_path {x} {
- set x [string map {\\ /} $x]
- return [string map $::quota_mapping $x]
- }
- # The quota_check procedure is a callback from the quota handler.
- # It has three arguments which are (1) the full pathname of the file
- # that has gone over quota, (2) the quota limit, (3) the requested
- # new quota size to cover the last write. These three values are
- # appended to the global variable $::quota. The filename is processed
- # to convert every \ character into / and to change the name of the
- # working directory to PWD.
- #
- # The quota is increased to the request if the ::quota_request_ok
- # global variable is true.
- #
- set ::quota {}
- set ::quota_request_ok 0
- proc quota_check {filename limitvar size} {
- upvar $limitvar limit
- lappend ::quota [standard_path $filename] [set limit] $size
- if {$::quota_request_ok} {set limit $size}
- }
- sqlite3_quota_set */quota2a/* 4000 quota_check
- sqlite3_quota_set */quota2b/* 5000 quota_check
- unset -nocomplain bigtext
- for {set i 1} {$i<=1000} {incr i} {
- if {$i%10==0} {
- append bigtext [format "%06d\n" $i]
- } else {
- append bigtext [format "%06d " $i]
- }
- }
- catch { unset h1 }
- catch { unset x }
- do_test quota2-1.1 {
- set ::h1 [sqlite3_quota_fopen quota2a/xyz.txt w+b]
- sqlite3_quota_fwrite $::h1 1 7000 $bigtext
- } {4000}
- do_test quota2-1.2 {
- set ::quota
- } {PWD/quota2a/xyz.txt 4000 7000}
- do_test quota2-1.2.1 {
- sqlite3_quota_file_size $::h1
- } {4000}
- do_test quota2-1.2.2 {
- sqlite3_quota_fflush $::h1 1
- sqlite3_quota_file_truesize $::h1
- } {4000}
- do_test quota2-1.3 {
- sqlite3_quota_rewind $::h1
- set ::x [sqlite3_quota_fread $::h1 1001 7]
- string length $::x
- } {3003}
- do_test quota2-1.4 {
- string match $::x [string range $::bigtext 0 3002]
- } {1}
- do_test quota2-1.5 {
- sqlite3_quota_fseek $::h1 0 SEEK_END
- sqlite3_quota_ftell $::h1
- } {4000}
- do_test quota2-1.6 {
- sqlite3_quota_fseek $::h1 -100 SEEK_END
- sqlite3_quota_ftell $::h1
- } {3900}
- do_test quota2-1.7 {
- sqlite3_quota_fseek $::h1 -100 SEEK_CUR
- sqlite3_quota_ftell $::h1
- } {3800}
- do_test quota2-1.8 {
- sqlite3_quota_fseek $::h1 50 SEEK_CUR
- sqlite3_quota_ftell $::h1
- } {3850}
- do_test quota2-1.9 {
- sqlite3_quota_fseek $::h1 50 SEEK_SET
- sqlite3_quota_ftell $::h1
- } {50}
- do_test quota2-1.10 {
- sqlite3_quota_rewind $::h1
- sqlite3_quota_ftell $::h1
- } {0}
- do_test quota2-1.11 {
- standard_path [sqlite3_quota_dump]
- } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 1 0}}}
- do_test quota2-1.12 {
- sqlite3_quota_ftruncate $::h1 3500
- sqlite3_quota_file_size $::h1
- } {3500}
- do_test quota2-1.13 {
- sqlite3_quota_file_truesize $::h1
- } {3500}
- do_test quota2-1.14 {
- standard_path [sqlite3_quota_dump]
- } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 3500 {PWD/quota2a/xyz.txt 3500 1 0}}}
- do_test quota2-1.15 {
- sqlite3_quota_fseek $::h1 0 SEEK_END
- sqlite3_quota_ftell $::h1
- } {3500}
- do_test quota2-1.16 {
- sqlite3_quota_fwrite $::h1 1 7000 $bigtext
- } {500}
- do_test quota2-1.17 {
- sqlite3_quota_ftell $::h1
- } {4000}
- do_test quota2-1.18 {
- sqlite3_quota_file_size $::h1
- } {4000}
- do_test quota2-1.19 {
- sqlite3_quota_fflush $::h1 1
- sqlite3_quota_file_truesize $::h1
- } {4000}
- do_test quota2-1.20 {
- sqlite3_quota_fclose $::h1
- standard_path [sqlite3_quota_dump]
- } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 0 0}}}
- do_test quota2-1.21 {
- sqlite3_quota_remove quota2a/xyz.txt
- standard_path [sqlite3_quota_dump]
- } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
- set quota {}
- do_test quota2-2.1 {
- set ::h1 [sqlite3_quota_fopen quota2c/xyz.txt w+b]
- sqlite3_quota_fwrite $::h1 1 7000 $bigtext
- } {7000}
- do_test quota2-2.2 {
- set ::quota
- } {}
- do_test quota2-2.3.1 {
- sqlite3_quota_rewind $::h1
- sqlite3_quota_file_available $::h1
- } {7000}
- do_test quota2-2.3.2 {
- set ::x [sqlite3_quota_fread $::h1 1001 7]
- string length $::x
- } {6006}
- do_test quota2-2.3.3 {
- sqlite3_quota_file_available $::h1
- } {0}
- do_test quota2-2.4 {
- string match $::x [string range $::bigtext 0 6005]
- } {1}
- do_test quota2-2.5 {
- sqlite3_quota_fseek $::h1 0 SEEK_END
- sqlite3_quota_ftell $::h1
- } {7000}
- do_test quota2-2.6 {
- sqlite3_quota_fseek $::h1 -100 SEEK_END
- sqlite3_quota_ftell $::h1
- } {6900}
- do_test quota2-2.6.1 {
- sqlite3_quota_file_available $::h1
- } {100}
- do_test quota2-2.7 {
- sqlite3_quota_fseek $::h1 -100 SEEK_CUR
- sqlite3_quota_ftell $::h1
- } {6800}
- do_test quota2-2.7.1 {
- sqlite3_quota_file_available $::h1
- } {200}
- do_test quota2-2.8 {
- sqlite3_quota_fseek $::h1 50 SEEK_CUR
- sqlite3_quota_ftell $::h1
- } {6850}
- do_test quota2-2.8.1 {
- sqlite3_quota_file_available $::h1
- } {150}
- do_test quota2-2.9 {
- sqlite3_quota_fseek $::h1 50 SEEK_SET
- sqlite3_quota_ftell $::h1
- } {50}
- do_test quota2-2.9.1 {
- sqlite3_quota_file_available $::h1
- } {6950}
- do_test quota2-2.10 {
- sqlite3_quota_rewind $::h1
- sqlite3_quota_ftell $::h1
- } {0}
- do_test quota2-2.10.1 {
- sqlite3_quota_file_available $::h1
- } {7000}
- do_test quota2-2.10.2 {
- sqlite3_quota_ferror $::h1
- } {0}
- do_test quota2-2.11 {
- standard_path [sqlite3_quota_dump]
- } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
- do_test quota2-2.12 {
- sqlite3_quota_fclose $::h1
- standard_path [sqlite3_quota_dump]
- } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
- do_test quota2-3.1 {
- sqlite3_quota_set */quota2b/* 0 quota_check
- set ::h1 [sqlite3_quota_fopen quota2a/x1/a.txt a]
- sqlite3_quota_fwrite $::h1 10 10 $bigtext
- } {10}
- do_test quota2-3.2 {
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
- do_test quota2-3.3a {
- sqlite3_quota_fflush $::h1 0
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
- do_test quota2-3.3b {
- sqlite3_quota_fflush $::h1 1
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
- do_test quota2-3.3c {
- sqlite3_quota_fflush $::h1
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
- do_test quota2-3.4 {
- sqlite3_quota_fclose $::h1
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 0 0}}}
- do_test quota2-3.5 {
- set ::h2 [sqlite3_quota_fopen quota2a/x2/b.txt a]
- sqlite3_quota_fwrite $::h2 10 20 $bigtext
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 300 {PWD/quota2a/x2/b.txt 200 1 0} {PWD/quota2a/x1/a.txt 100 0 0}}}
- do_test quota2-3.6 {
- set ::h3 [sqlite3_quota_fopen quota2a/x1/c.txt a]
- sqlite3_quota_fwrite $::h3 10 50 $bigtext
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 800 {PWD/quota2a/x1/c.txt 500 1 0} {PWD/quota2a/x2/b.txt 200 1 0} {PWD/quota2a/x1/a.txt 100 0 0}}}
- do_test quota2-3.7 {
- file exists quota2a/x1/a.txt
- } {1}
- do_test quota2-3.8 {
- file exists quota2a/x2/b.txt
- } {1}
- do_test quota2-3.9 {
- file exists quota2a/x1/c.txt
- } {1}
- do_test quota2-3.10 {
- sqlite3_quota_remove quota2a/x1
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 700 {PWD/quota2a/x1/c.txt 500 1 1} {PWD/quota2a/x2/b.txt 200 1 0}}}
- do_test quota2-3.11 {
- sqlite3_quota_fclose $::h2
- sqlite3_quota_fclose $::h3
- standard_path [sqlite3_quota_dump]
- } {{*/quota2a/* 4000 200 {PWD/quota2a/x2/b.txt 200 0 0}}}
- do_test quota2-3.12 {
- file exists quota2a/x1/a.txt
- } {0}
- do_test quota2-3.13 {
- file exists quota2a/x2/b.txt
- } {1}
- do_test quota2-3.14 {
- file exists quota2a/x1/c.txt
- } {0}
- catch { sqlite3_quota_shutdown }
- catch { unset quota_request_ok }
- finish_test
|