Annotation of embedaddon/sqlite3/test/quota2.test, revision 1.1

1.1     ! misho       1: # 2011 December 1
        !             2: #
        !             3: # The author disclaims copyright to this source code.  In place of
        !             4: # a legal notice, here is a blessing:
        !             5: #
        !             6: #    May you do good and not evil.
        !             7: #    May you find forgiveness for yourself and forgive others.
        !             8: #    May you share freely, never taking more than you give.
        !             9: #
        !            10: #***********************************************************************
        !            11: #
        !            12: 
        !            13: set testdir [file dirname $argv0]
        !            14: source $testdir/tester.tcl
        !            15: source $testdir/malloc_common.tcl
        !            16: 
        !            17: db close
        !            18: sqlite3_quota_initialize "" 1
        !            19: 
        !            20: foreach dir {quota2a/x1 quota2a/x2 quota2a quota2b quota2c} {
        !            21:   file delete -force $dir
        !            22: }
        !            23: foreach dir {quota2a quota2a/x1 quota2a/x2 quota2b quota2c} {
        !            24:   file mkdir $dir
        !            25: }
        !            26: 
        !            27: # The standard_path procedure converts a pathname into a standard format
        !            28: # that is the same across platforms.
        !            29: #
        !            30: unset -nocomplain ::quota_pwd ::quota_mapping
        !            31: set ::quota_pwd [string map {\\ /} [pwd]]
        !            32: set ::quota_mapping [list $::quota_pwd PWD]
        !            33: proc standard_path {x} {
        !            34:   set x [string map {\\ /} $x]
        !            35:   return [string map $::quota_mapping $x]
        !            36: }
        !            37: 
        !            38: # The quota_check procedure is a callback from the quota handler.
        !            39: # It has three arguments which are (1) the full pathname of the file
        !            40: # that has gone over quota, (2) the quota limit, (3) the requested
        !            41: # new quota size to cover the last write.  These three values are
        !            42: # appended to the global variable $::quota.  The filename is processed
        !            43: # to convert every \ character into / and to change the name of the
        !            44: # working directory to PWD.  
        !            45: #
        !            46: # The quota is increased to the request if the ::quota_request_ok 
        !            47: # global variable is true.
        !            48: #
        !            49: set ::quota {}
        !            50: set ::quota_request_ok 0
        !            51: 
        !            52: proc quota_check {filename limitvar size} {
        !            53:   upvar $limitvar limit
        !            54:   lappend ::quota [standard_path $filename] [set limit] $size
        !            55:   if {$::quota_request_ok} {set limit $size}
        !            56: }
        !            57: 
        !            58: sqlite3_quota_set */quota2a/* 4000 quota_check
        !            59: sqlite3_quota_set */quota2b/* 5000 quota_check
        !            60: 
        !            61: unset -nocomplain bigtext
        !            62: for {set i 1} {$i<=1000} {incr i} {
        !            63:   if {$i%10==0} {
        !            64:     append bigtext [format "%06d\n" $i]
        !            65:   } else {
        !            66:     append bigtext [format "%06d " $i]
        !            67:   }
        !            68: }
        !            69: 
        !            70: catch { unset h1 }
        !            71: catch { unset x }
        !            72: do_test quota2-1.1 {
        !            73:   set ::h1 [sqlite3_quota_fopen quota2a/xyz.txt w+b]
        !            74:   sqlite3_quota_fwrite $::h1 1 7000 $bigtext
        !            75: } {4000}
        !            76: do_test quota2-1.2 {
        !            77:   set ::quota
        !            78: } {PWD/quota2a/xyz.txt 4000 7000}
        !            79: do_test quota2-1.3 {
        !            80:   sqlite3_quota_rewind $::h1
        !            81:   set ::x [sqlite3_quota_fread $::h1 1001 7]
        !            82:   string length $::x
        !            83: } {3003}
        !            84: do_test quota2-1.4 {
        !            85:   string match $::x [string range $::bigtext 0 3002]
        !            86: } {1}
        !            87: do_test quota2-1.5 {
        !            88:   sqlite3_quota_fseek $::h1 0 SEEK_END
        !            89:   sqlite3_quota_ftell $::h1
        !            90: } {4000}
        !            91: do_test quota2-1.6 {
        !            92:   sqlite3_quota_fseek $::h1 -100 SEEK_END
        !            93:   sqlite3_quota_ftell $::h1
        !            94: } {3900}
        !            95: do_test quota2-1.7 {
        !            96:   sqlite3_quota_fseek $::h1 -100 SEEK_CUR
        !            97:   sqlite3_quota_ftell $::h1
        !            98: } {3800}
        !            99: do_test quota2-1.8 {
        !           100:   sqlite3_quota_fseek $::h1 50 SEEK_CUR
        !           101:   sqlite3_quota_ftell $::h1
        !           102: } {3850}
        !           103: do_test quota2-1.9 {
        !           104:   sqlite3_quota_fseek $::h1 50 SEEK_SET
        !           105:   sqlite3_quota_ftell $::h1
        !           106: } {50}
        !           107: do_test quota2-1.10 {
        !           108:   sqlite3_quota_rewind $::h1
        !           109:   sqlite3_quota_ftell $::h1
        !           110: } {0}
        !           111: do_test quota2-1.11 {
        !           112:   standard_path [sqlite3_quota_dump]
        !           113: } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 1 0}}}
        !           114: do_test quota2-1.12 {
        !           115:   sqlite3_quota_fclose $::h1
        !           116:   standard_path [sqlite3_quota_dump]
        !           117: } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 0 0}}}
        !           118: do_test quota2-1.13 {
        !           119:   sqlite3_quota_remove quota2a/xyz.txt
        !           120:   standard_path [sqlite3_quota_dump]
        !           121: } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
        !           122: 
        !           123: 
        !           124: set quota {}
        !           125: do_test quota2-2.1 {
        !           126:   set ::h1 [sqlite3_quota_fopen quota2c/xyz.txt w+b]
        !           127:   sqlite3_quota_fwrite $::h1 1 7000 $bigtext
        !           128: } {7000}
        !           129: do_test quota2-2.2 {
        !           130:   set ::quota
        !           131: } {}
        !           132: do_test quota2-2.3 {
        !           133:   sqlite3_quota_rewind $::h1
        !           134:   set ::x [sqlite3_quota_fread $::h1 1001 7]
        !           135:   string length $::x
        !           136: } {6006}
        !           137: do_test quota2-2.4 {
        !           138:   string match $::x [string range $::bigtext 0 6005]
        !           139: } {1}
        !           140: do_test quota2-2.5 {
        !           141:   sqlite3_quota_fseek $::h1 0 SEEK_END
        !           142:   sqlite3_quota_ftell $::h1
        !           143: } {7000}
        !           144: do_test quota2-2.6 {
        !           145:   sqlite3_quota_fseek $::h1 -100 SEEK_END
        !           146:   sqlite3_quota_ftell $::h1
        !           147: } {6900}
        !           148: do_test quota2-2.7 {
        !           149:   sqlite3_quota_fseek $::h1 -100 SEEK_CUR
        !           150:   sqlite3_quota_ftell $::h1
        !           151: } {6800}
        !           152: do_test quota2-2.8 {
        !           153:   sqlite3_quota_fseek $::h1 50 SEEK_CUR
        !           154:   sqlite3_quota_ftell $::h1
        !           155: } {6850}
        !           156: do_test quota2-2.9 {
        !           157:   sqlite3_quota_fseek $::h1 50 SEEK_SET
        !           158:   sqlite3_quota_ftell $::h1
        !           159: } {50}
        !           160: do_test quota2-2.10 {
        !           161:   sqlite3_quota_rewind $::h1
        !           162:   sqlite3_quota_ftell $::h1
        !           163: } {0}
        !           164: do_test quota2-2.11 {
        !           165:   standard_path [sqlite3_quota_dump]
        !           166: } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
        !           167: do_test quota2-2.12 {
        !           168:   sqlite3_quota_fclose $::h1
        !           169:   standard_path [sqlite3_quota_dump]
        !           170: } {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}
        !           171: 
        !           172: do_test quota2-3.1 {
        !           173:   sqlite3_quota_set */quota2b/* 0 quota_check
        !           174:   set ::h1 [sqlite3_quota_fopen quota2a/x1/a.txt a]
        !           175:   sqlite3_quota_fwrite $::h1 10 10 $bigtext
        !           176: } {10}
        !           177: do_test quota2-3.2 {
        !           178:   standard_path [sqlite3_quota_dump]
        !           179: } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
        !           180: do_test quota2-3.3a {
        !           181:   sqlite3_quota_fflush $::h1 0
        !           182:   standard_path [sqlite3_quota_dump]
        !           183: } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
        !           184: do_test quota2-3.3b {
        !           185:   sqlite3_quota_fflush $::h1 1
        !           186:   standard_path [sqlite3_quota_dump]
        !           187: } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
        !           188: do_test quota2-3.3c {
        !           189:   sqlite3_quota_fflush $::h1
        !           190:   standard_path [sqlite3_quota_dump]
        !           191: } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}
        !           192: do_test quota2-3.4 {
        !           193:   sqlite3_quota_fclose $::h1
        !           194:   standard_path [sqlite3_quota_dump]
        !           195: } {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 0 0}}}
        !           196: do_test quota2-3.5 {
        !           197:   set ::h2 [sqlite3_quota_fopen quota2a/x2/b.txt a]
        !           198:   sqlite3_quota_fwrite $::h2 10 20 $bigtext
        !           199:   standard_path [sqlite3_quota_dump]
        !           200: } {{*/quota2a/* 4000 300 {PWD/quota2a/x2/b.txt 200 1 0} {PWD/quota2a/x1/a.txt 100 0 0}}}
        !           201: do_test quota2-3.6 {
        !           202:   set ::h3 [sqlite3_quota_fopen quota2a/x1/c.txt a]
        !           203:   sqlite3_quota_fwrite $::h3 10 50 $bigtext
        !           204:   standard_path [sqlite3_quota_dump]
        !           205: } {{*/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}}}
        !           206: do_test quota2-3.7 {
        !           207:   file exists quota2a/x1/a.txt
        !           208: } {1}
        !           209: do_test quota2-3.8 {
        !           210:   file exists quota2a/x2/b.txt
        !           211: } {1}
        !           212: do_test quota2-3.9 {
        !           213:   file exists quota2a/x1/c.txt
        !           214: } {1}
        !           215: do_test quota2-3.10 {
        !           216:   sqlite3_quota_remove quota2a/x1
        !           217:   standard_path [sqlite3_quota_dump]
        !           218: } {{*/quota2a/* 4000 700 {PWD/quota2a/x1/c.txt 500 1 1} {PWD/quota2a/x2/b.txt 200 1 0}}}
        !           219: do_test quota2-3.11 {
        !           220:   sqlite3_quota_fclose $::h2
        !           221:   sqlite3_quota_fclose $::h3
        !           222:   standard_path [sqlite3_quota_dump]
        !           223: } {{*/quota2a/* 4000 200 {PWD/quota2a/x2/b.txt 200 0 0}}}
        !           224: do_test quota2-3.12 {
        !           225:   file exists quota2a/x1/a.txt
        !           226: } {0}
        !           227: do_test quota2-3.13 {
        !           228:   file exists quota2a/x2/b.txt
        !           229: } {1}
        !           230: do_test quota2-3.14 {
        !           231:   file exists quota2a/x1/c.txt
        !           232: } {0}
        !           233: 
        !           234: catch { sqlite3_quota_shutdown }
        !           235: catch { unset quota_request_ok }
        !           236: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>