CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
quota2.test303 linesDownload Raw Back to test
1# 2011 December 12#3# The author disclaims copyright to this source code.  In place of4# 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 13set testdir [file dirname $argv0]14source $testdir/tester.tcl15 16# If SQLITE_CURDIR is not defined, omit this file.17ifcapable !curdir {18  finish_test19  return20}21 22source $testdir/malloc_common.tcl23 24db close25sqlite3_quota_initialize "" 126 27foreach dir {quota2a/x1 quota2a/x2 quota2a quota2b quota2c} {28  forcedelete $dir29}30foreach dir {quota2a quota2a/x1 quota2a/x2 quota2b quota2c} {31  file mkdir $dir32}33 34# The standard_path procedure converts a pathname into a standard format35# that is the same across platforms.36#37unset -nocomplain ::quota_pwd ::quota_mapping38set ::quota_pwd [string map {\\ /} [get_pwd]]39set ::quota_mapping [list $::quota_pwd PWD]40proc standard_path {x} {41  set x [string map {\\ /} $x]42  return [string map $::quota_mapping $x]43}44 45# The quota_check procedure is a callback from the quota handler.46# It has three arguments which are (1) the full pathname of the file47# that has gone over quota, (2) the quota limit, (3) the requested48# new quota size to cover the last write.  These three values are49# appended to the global variable $::quota.  The filename is processed50# to convert every \ character into / and to change the name of the51# working directory to PWD.  52#53# The quota is increased to the request if the ::quota_request_ok 54# global variable is true.55#56set ::quota {}57set ::quota_request_ok 058 59proc quota_check {filename limitvar size} {60  upvar $limitvar limit61  lappend ::quota [standard_path $filename] [set limit] $size62  if {$::quota_request_ok} {set limit $size}63}64 65sqlite3_quota_set */quota2a/* 4000 quota_check66sqlite3_quota_set */quota2b/* 5000 quota_check67 68unset -nocomplain bigtext69for {set i 1} {$i<=1000} {incr i} {70  if {$i%10==0} {71    append bigtext [format "%06d\n" $i]72  } else {73    append bigtext [format "%06d " $i]74  }75}76 77catch { unset h1 }78catch { unset x }79do_test quota2-1.1 {80  set ::h1 [sqlite3_quota_fopen quota2a/xyz.txt w+b]81  sqlite3_quota_fwrite $::h1 1 7000 $bigtext82} {4000}83do_test quota2-1.2 {84  set ::quota85} {PWD/quota2a/xyz.txt 4000 7000}86do_test quota2-1.2.1 {87  sqlite3_quota_file_size $::h188} {4000}89do_test quota2-1.2.2 {90  sqlite3_quota_fflush $::h1 191  sqlite3_quota_file_truesize $::h192} {4000}93do_test quota2-1.3 {94  sqlite3_quota_rewind $::h195  set ::x [sqlite3_quota_fread $::h1 1001 7]96  string length $::x97} {3003}98do_test quota2-1.4 {99  string match $::x [string range $::bigtext 0 3002]100} {1}101do_test quota2-1.5 {102  sqlite3_quota_fseek $::h1 0 SEEK_END103  sqlite3_quota_ftell $::h1104} {4000}105do_test quota2-1.6 {106  sqlite3_quota_fseek $::h1 -100 SEEK_END107  sqlite3_quota_ftell $::h1108} {3900}109do_test quota2-1.7 {110  sqlite3_quota_fseek $::h1 -100 SEEK_CUR111  sqlite3_quota_ftell $::h1112} {3800}113do_test quota2-1.8 {114  sqlite3_quota_fseek $::h1 50 SEEK_CUR115  sqlite3_quota_ftell $::h1116} {3850}117do_test quota2-1.9 {118  sqlite3_quota_fseek $::h1 50 SEEK_SET119  sqlite3_quota_ftell $::h1120} {50}121do_test quota2-1.10 {122  sqlite3_quota_rewind $::h1123  sqlite3_quota_ftell $::h1124} {0}125do_test quota2-1.11 {126  standard_path [sqlite3_quota_dump]127} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 1 0}}}128do_test quota2-1.12 {129  sqlite3_quota_ftruncate $::h1 3500130  sqlite3_quota_file_size $::h1131} {3500}132do_test quota2-1.13 {133  sqlite3_quota_file_truesize $::h1134} {3500}135do_test quota2-1.14 {136  standard_path [sqlite3_quota_dump]137} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 3500 {PWD/quota2a/xyz.txt 3500 1 0}}}138do_test quota2-1.15 {139  sqlite3_quota_fseek $::h1 0 SEEK_END140  sqlite3_quota_ftell $::h1141} {3500}142do_test quota2-1.16 {143  sqlite3_quota_fwrite $::h1 1 7000 $bigtext144} {500}145do_test quota2-1.17 {146  sqlite3_quota_ftell $::h1147} {4000}148do_test quota2-1.18 {149  sqlite3_quota_file_size $::h1150} {4000}151do_test quota2-1.19 {152  sqlite3_quota_fflush $::h1 1153  sqlite3_quota_file_truesize $::h1154} {4000}155do_test quota2-1.20 {156  sqlite3_quota_fclose $::h1157  standard_path [sqlite3_quota_dump]158} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 4000 {PWD/quota2a/xyz.txt 4000 0 0}}}159do_test quota2-1.21 {160  sqlite3_quota_remove quota2a/xyz.txt161  standard_path [sqlite3_quota_dump]162} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}163 164 165 166set quota {}167do_test quota2-2.1 {168  set ::h1 [sqlite3_quota_fopen quota2c/xyz.txt w+b]169  sqlite3_quota_fwrite $::h1 1 7000 $bigtext170} {7000}171do_test quota2-2.2 {172  set ::quota173} {}174do_test quota2-2.3.1 {175  sqlite3_quota_rewind $::h1176  sqlite3_quota_file_available $::h1177} {7000}178do_test quota2-2.3.2 {179  set ::x [sqlite3_quota_fread $::h1 1001 7]180  string length $::x181} {6006}182do_test quota2-2.3.3 {183  sqlite3_quota_file_available $::h1184} {0}185do_test quota2-2.4 {186  string match $::x [string range $::bigtext 0 6005]187} {1}188do_test quota2-2.5 {189  sqlite3_quota_fseek $::h1 0 SEEK_END190  sqlite3_quota_ftell $::h1191} {7000}192do_test quota2-2.6 {193  sqlite3_quota_fseek $::h1 -100 SEEK_END194  sqlite3_quota_ftell $::h1195} {6900}196do_test quota2-2.6.1 {197  sqlite3_quota_file_available $::h1198} {100}199do_test quota2-2.7 {200  sqlite3_quota_fseek $::h1 -100 SEEK_CUR201  sqlite3_quota_ftell $::h1202} {6800}203do_test quota2-2.7.1 {204  sqlite3_quota_file_available $::h1205} {200}206do_test quota2-2.8 {207  sqlite3_quota_fseek $::h1 50 SEEK_CUR208  sqlite3_quota_ftell $::h1209} {6850}210do_test quota2-2.8.1 {211  sqlite3_quota_file_available $::h1212} {150}213do_test quota2-2.9 {214  sqlite3_quota_fseek $::h1 50 SEEK_SET215  sqlite3_quota_ftell $::h1216} {50}217do_test quota2-2.9.1 {218  sqlite3_quota_file_available $::h1219} {6950}220do_test quota2-2.10 {221  sqlite3_quota_rewind $::h1222  sqlite3_quota_ftell $::h1223} {0}224do_test quota2-2.10.1 {225  sqlite3_quota_file_available $::h1226} {7000}227do_test quota2-2.10.2 {228  sqlite3_quota_ferror $::h1229} {0}230do_test quota2-2.11 {231  standard_path [sqlite3_quota_dump]232} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}233do_test quota2-2.12 {234  sqlite3_quota_fclose $::h1235  standard_path [sqlite3_quota_dump]236} {{*/quota2b/* 5000 0} {*/quota2a/* 4000 0}}237 238do_test quota2-3.1 {239  sqlite3_quota_set */quota2b/* 0 quota_check240  set ::h1 [sqlite3_quota_fopen quota2a/x1/a.txt a]241  sqlite3_quota_fwrite $::h1 10 10 $bigtext242} {10}243do_test quota2-3.2 {244  standard_path [sqlite3_quota_dump]245} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}246do_test quota2-3.3a {247  sqlite3_quota_fflush $::h1 0248  standard_path [sqlite3_quota_dump]249} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}250do_test quota2-3.3b {251  sqlite3_quota_fflush $::h1 1252  standard_path [sqlite3_quota_dump]253} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}254do_test quota2-3.3c {255  sqlite3_quota_fflush $::h1256  standard_path [sqlite3_quota_dump]257} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 1 0}}}258do_test quota2-3.4 {259  sqlite3_quota_fclose $::h1260  standard_path [sqlite3_quota_dump]261} {{*/quota2a/* 4000 100 {PWD/quota2a/x1/a.txt 100 0 0}}}262do_test quota2-3.5 {263  set ::h2 [sqlite3_quota_fopen quota2a/x2/b.txt a]264  sqlite3_quota_fwrite $::h2 10 20 $bigtext265  standard_path [sqlite3_quota_dump]266} {{*/quota2a/* 4000 300 {PWD/quota2a/x2/b.txt 200 1 0} {PWD/quota2a/x1/a.txt 100 0 0}}}267do_test quota2-3.6 {268  set ::h3 [sqlite3_quota_fopen quota2a/x1/c.txt a]269  sqlite3_quota_fwrite $::h3 10 50 $bigtext270  standard_path [sqlite3_quota_dump]271} {{*/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}}}272do_test quota2-3.7 {273  file exists quota2a/x1/a.txt274} {1}275do_test quota2-3.8 {276  file exists quota2a/x2/b.txt277} {1}278do_test quota2-3.9 {279  file exists quota2a/x1/c.txt280} {1}281do_test quota2-3.10 {282  sqlite3_quota_remove quota2a/x1283  standard_path [sqlite3_quota_dump]284} {{*/quota2a/* 4000 700 {PWD/quota2a/x1/c.txt 500 1 1} {PWD/quota2a/x2/b.txt 200 1 0}}}285do_test quota2-3.11 {286  sqlite3_quota_fclose $::h2287  sqlite3_quota_fclose $::h3288  standard_path [sqlite3_quota_dump]289} {{*/quota2a/* 4000 200 {PWD/quota2a/x2/b.txt 200 0 0}}}290do_test quota2-3.12 {291  file exists quota2a/x1/a.txt292} {0}293do_test quota2-3.13 {294  file exists quota2a/x2/b.txt295} {1}296do_test quota2-3.14 {297  file exists quota2a/x1/c.txt298} {0}299 300catch { sqlite3_quota_shutdown }301catch { unset quota_request_ok }302finish_test303