/ Check-in [49d2566c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enable more 'zipfile' tests on Win32.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | testFixes
Files: files | file ages | folders
SHA3-256: 49d2566c8e7d0df37494ee001fc6eae5f47f95e16f6a575f2d8d6777b62e6068
User & Date: mistachkin 2018-03-16 23:54:26
Context
2018-03-16
23:54
Win32 portability fixes to the 'fileio' extension. check-in: 9d2b0f8b user: mistachkin tags: testFixes
23:54
Enable more 'zipfile' tests on Win32. check-in: 49d2566c user: mistachkin tags: testFixes
23:54
Make a couple tests less sensitive to timing. check-in: bc2af8e0 user: mistachkin tags: testFixes
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to test/zipfile.test.

     5      5   #
     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
           12  +
           13  +package require Tcl 8.6
    12     14   
    13     15   set testdir [file dirname $argv0]
    14     16   source $testdir/tester.tcl
    15     17   set testprefix zipfile
    16     18   
    17     19   ifcapable !vtab {
    18     20     finish_test; return
    19     21   }
    20     22   if {[catch {load_static_extension db zipfile} error]} {
    21     23     puts "Skipping zipfile tests, hit load error: $error"
    22     24     finish_test; return
           25  +}
           26  +if {[catch {load_static_extension db fileio} error]} {
           27  +  puts "Skipping zipfile tests, hit load error: $error"
           28  +  finish_test; return
    23     29   }
    24     30   
    25     31   proc readfile {f} {
    26     32     set fd [open $f]
    27     33     fconfigure $fd -translation binary -encoding binary
    28     34     set data [read $fd]
    29     35     close $fd
    30     36     set data
    31     37   }
    32     38   
    33         -if {$::tcl_platform(platform)=="unix" && [catch {exec unzip}]==0} {
    34         -  set ::UNZIP 1
    35         -  load_static_extension db fileio
           39  +unset -nocomplain ::UNZIP
           40  +
           41  +if {[catch {exec unzip} msg]==0 && \
           42  +    [regexp -line {^UnZip \d+\.\d+ .*? Info-ZIP\.} $msg]} {
           43  +  set ::UNZIP unzip
           44  +  proc fix_stat_mode {name mode} {
           45  +    if {$::tcl_platform(platform)=="windows"} {
           46  +      #
           47  +      # NOTE: Set or unset the write bits of the file permissions
           48  +      #       based on the read-only attribute because the Win32
           49  +      #       version of UnZip does this.
           50  +      #
           51  +      set writebits 0x12; # 0o22
           52  +      set result $mode
           53  +      if {[file attributes $name -readonly]} {
           54  +        set result [expr {$result | $writebits}]
           55  +      } else {
           56  +        set result [expr {$result & ~$writebits}]
           57  +      }
           58  +      return $result
           59  +    } else {
           60  +      return $mode
           61  +    }
           62  +  }
    36     63     proc do_unzip {file} {
    37     64       forcedelete test_unzip
    38     65       file mkdir test_unzip
    39         -    exec unzip -d test_unzip $file
    40         -  
    41         -    set res [db eval { 
    42         -      SELECT replace(name,'test_unzip/',''),mode,mtime,data 
           66  +    exec $::UNZIP -d test_unzip $file
           67  +
           68  +    db func modefix fix_stat_mode
           69  +
           70  +    set res [db eval {
           71  +      SELECT replace(name,'test_unzip/',''),modefix(name,mode),mtime,data
    43     72         FROM fsdir('test_unzip') 
    44     73         WHERE name!='test_unzip'
    45     74         ORDER BY name
    46     75       }]
    47     76       set res
    48     77     }
    49     78   }
................................................................................
   104    133   #          ( SELECT zipfile(name,mode,mtime,data,method) FROM zipfile($file) )
   105    134   #      );
   106    135   #
   107    136   #      Then tests that unpacking the new archive using [unzip] produces
   108    137   #      the same results as in (1).
   109    138   #
   110    139   proc do_unzip_test {tn file} {
   111         -  if {[info vars ::UNZIP]==""} { return }
   112    140     db func sss strip_slash
   113    141   
   114    142     db eval {
   115    143       SELECT writefile('test_unzip.zip',
   116    144           ( SELECT zipfile(name,mode,mtime,data,method) FROM zipfile($file) )
   117    145       );
   118    146     }
................................................................................
   242    270     UPDATE zz SET mtime=4 WHERE name='i.txt';
   243    271     SELECT name, mode, mtime, data, method FROM zipfile('test.zip');
   244    272   } {
   245    273     f.txt 33188 1000000000 abcde 0
   246    274     h.txt 33188 1000000004 aaaaaaaaaabbbbbbbbbb 8
   247    275     i.txt 33188 4 zxcvb 0
   248    276   }
          277  +
          278  +if {$::tcl_platform(platform)=="unix"} {
          279  +  set modes -rw-r--r-x
          280  +  set perms 33189
          281  +} else {
          282  +  set modes -rw-r--r--; # no execute bits on Win32
          283  +  set perms 33188
          284  +}
   249    285   
   250    286   do_execsql_test 1.6.3 {
   251         -  UPDATE zz SET mode='-rw-r--r-x' WHERE name='h.txt';
          287  +  UPDATE zz SET mode=$modes WHERE name='h.txt';
   252    288     SELECT name, mode, mtime, data, method FROM zipfile('test.zip');
   253         -} {
          289  +} [string map [list %perms% $perms] {
   254    290     f.txt 33188 1000000000 abcde 0
   255         -  h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8
          291  +  h.txt %perms% 1000000004 aaaaaaaaaabbbbbbbbbb 8
   256    292     i.txt 33188 4 zxcvb 0
   257         -}
          293  +}]
   258    294   do_zip_tests 1.6.3a test.zip
   259    295   
   260    296   do_execsql_test 1.6.4 {
   261    297     UPDATE zz SET name = 'blue.txt' WHERE name='f.txt';
   262    298     SELECT name, mode, mtime, data, method FROM zipfile('test.zip');
   263         -} {
          299  +} [string map [list %perms% $perms] {
   264    300     blue.txt 33188 1000000000 abcde 0
   265         -  h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8
          301  +  h.txt %perms% 1000000004 aaaaaaaaaabbbbbbbbbb 8
   266    302     i.txt 33188 4 zxcvb 0
   267         -}
          303  +}]
   268    304   do_zip_tests 1.6.4a test.zip
   269    305   
   270    306   do_execsql_test 1.6.5 {
   271    307     UPDATE zz SET data = 'edcba' WHERE name='blue.txt';
   272    308     SELECT name, mode, mtime, data, method FROM zipfile('test.zip');
   273         -} {
          309  +} [string map [list %perms% $perms] {
   274    310     blue.txt 33188 1000000000 edcba 0
   275         -  h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8
          311  +  h.txt %perms% 1000000004 aaaaaaaaaabbbbbbbbbb 8
   276    312     i.txt 33188 4 zxcvb 0
   277         -}
          313  +}]
   278    314   
   279    315   do_execsql_test 1.6.6 {
   280    316     UPDATE zz SET mode=NULL, data = NULL WHERE name='blue.txt';
   281    317     SELECT name, mode, mtime, data, method FROM zipfile('test.zip');
   282         -} {
          318  +} [string map [list %perms% $perms] {
   283    319     blue.txt/ 16877 1000000000 {} 0
   284         -  h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8
          320  +  h.txt %perms% 1000000004 aaaaaaaaaabbbbbbbbbb 8
   285    321     i.txt 33188 4 zxcvb 0
   286         -}
          322  +}]
   287    323   
   288    324   do_catchsql_test 1.6.7 {
   289    325     UPDATE zz SET data=NULL WHERE name='i.txt'
   290    326   } {1 {zipfile: mode does not match data}}
   291    327   do_execsql_test 1.6.8 {
   292    328     SELECT name, mode, mtime, data, method FROM zipfile('test.zip');
   293         -} {
          329  +} [string map [list %perms% $perms] {
   294    330     blue.txt/ 16877 1000000000 {} 0
   295         -  h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8
          331  +  h.txt %perms% 1000000004 aaaaaaaaaabbbbbbbbbb 8
   296    332     i.txt 33188 4 zxcvb 0
   297         -}
          333  +}]
   298    334   
   299         -do_execsql_test 1.6.8 {
          335  +do_execsql_test 1.6.9 {
   300    336     UPDATE zz SET data = '' WHERE name='i.txt';
   301    337     SELECT name,mode,mtime,data,method from zipfile('test.zip');
   302         -} {
          338  +} [string map [list %perms% $perms] {
   303    339     blue.txt/ 16877 1000000000 {} 0
   304         -  h.txt 33189 1000000004 aaaaaaaaaabbbbbbbbbb 8
          340  +  h.txt %perms% 1000000004 aaaaaaaaaabbbbbbbbbb 8
   305    341     i.txt 33188 4 {} 0
   306         -}
          342  +}]
   307    343   
   308         -do_execsql_test 1.6.9 {
          344  +do_execsql_test 1.6.10 {
   309    345     SELECT a.name, a.data 
   310    346     FROM zz AS a, zz AS b 
   311    347     WHERE a.name=+b.name AND +a.mode=b.mode
   312    348   } {
   313    349     blue.txt/ {}
   314    350     h.txt aaaaaaaaaabbbbbbbbbb
   315    351     i.txt {}
   316    352   }
   317    353   
   318         -do_execsql_test 1.6.10 {
          354  +do_execsql_test 1.6.11 {
   319    355     SELECT name, data FROM zz WHERE name LIKE '%txt'
   320    356   } {
   321    357     h.txt aaaaaaaaaabbbbbbbbbb
   322    358     i.txt {}
   323    359   }
   324    360   
   325    361   do_execsql_test 1.7 {
................................................................................
   356    392   } {
   357    393     dirname3/ 16877 {}
   358    394     dirname2/ 16877 {}
   359    395     dirname2/file1.txt 33188 abcdefghijklmnop
   360    396   }
   361    397   do_zip_tests 2.4a test.zip
   362    398   
   363         -# If on unix, check that the [unzip] utility can unpack our archive.
          399  +# Check that the [unzip] utility can unpack our archive.
   364    400   #
   365         -if {$::tcl_platform(platform)=="unix"} {
          401  +if {[info exists ::UNZIP]} {
   366    402     do_test 2.5.1 {
   367    403       forcedelete dirname
   368    404       forcedelete dirname2
   369         -    set rc [catch { exec unzip test.zip > /dev/null } msg]
          405  +    if {$::tcl_platform(platform)=="unix"} {
          406  +      set null /dev/null
          407  +    } else {
          408  +      set null NUL
          409  +    }
          410  +    set rc [catch { exec $::UNZIP test.zip > $null } msg]
   370    411       list $rc $msg
   371    412     } {0 {}}
   372    413     do_test 2.5.2 { file isdir dirname3 } 1
   373    414     do_test 2.5.3 { file isdir dirname2 } 1
   374    415     do_test 2.5.4 { file isdir dirname2/file1.txt } 0
   375    416     do_test 2.5.5 { 
   376    417       set fd [open dirname2/file1.txt]
................................................................................
   380    421     } {abcdefghijklmnop}
   381    422   }
   382    423   
   383    424   #-------------------------------------------------------------------------
   384    425   reset_db
   385    426   forcedelete test.zip
   386    427   load_static_extension db zipfile
          428  +load_static_extension db fileio
   387    429   
   388    430   do_execsql_test 3.0 {
   389    431     CREATE VIRTUAL TABLE temp.x1 USING zipfile('test.zip');
   390    432     INSERT INTO x1(name, data) VALUES('dir1/', NULL);
   391    433     INSERT INTO x1(name, data) VALUES('file1', '1234');
   392    434     INSERT INTO x1(name, data) VALUES('dir1/file2', '5678');
   393    435   }
................................................................................
   449    491     WITH c(name,data) AS ( 
   450    492       SELECT 'a.txt', 'abc' UNION ALL
   451    493       SELECT NULL, 'def'
   452    494     )
   453    495     SELECT zipfile(name,data) FROM c
   454    496   } {1 {first argument to zipfile() must be non-NULL}}
   455    497   
   456         -do_catchsql_test 4.7 {
          498  +do_catchsql_test 4.8 {
   457    499     WITH c(name,data,method) AS ( 
   458    500       SELECT 'a.txt', 'abc', 0
   459    501       UNION SELECT 'b.txt', 'def', 8
   460    502       UNION SELECT 'c.txt', 'ghi', 16
   461    503     )
   462    504     SELECT zipfile(name,NULL,NULL,data,method) FROM c
   463    505   } {1 {illegal method value: 16}}
   464    506   
   465         -do_catchsql_test 4.8 {
          507  +do_catchsql_test 4.9 {
   466    508     WITH c(name,data) AS ( 
   467    509       SELECT 'a.txt', 'abc'
   468    510       UNION SELECT 'b.txt', 'def'
   469    511       UNION SELECT 'c.txt/', 'ghi'
   470    512     )
   471    513     SELECT zipfile(name,NULL,NULL,data) FROM c
   472    514   } {1 {non-directory name must not end with /}}
................................................................................
   481    523     SELECT name,mtime,data FROM zipfile(
   482    524       ( SELECT rt( zipfile(name,NULL,mtime,data,NULL) ) FROM c )
   483    525     )
   484    526   } {
   485    527     a.txt 946684800 abc
   486    528   }
   487    529   
   488         -if {[info vars ::UNZIP]!=""} { 
          530  +if {[info exists ::UNZIP]} {
   489    531   ifcapable datetime {
   490         -  load_static_extension db fileio
   491    532     forcedelete test1.zip test2.zip
   492    533     do_test 6.0 {
   493    534       execsql {
   494    535         WITH c(name,mtime,data) AS (
   495    536           SELECT 'a.txt', 946684800, 'abc' UNION ALL
   496    537           SELECT 'b.txt', 1000000000, 'abc' UNION ALL
   497    538           SELECT 'c.txt', 1111111000, 'abc'
................................................................................
   498    539         )
   499    540         SELECT writefile('test1.zip', rt( zipfile(name, NULL, mtime, data) ) ),
   500    541                writefile('test2.zip',   ( zipfile(name, NULL, mtime, data) ) ) 
   501    542         FROM c;
   502    543       }
   503    544       forcedelete test_unzip
   504    545       file mkdir test_unzip
   505         -    exec unzip -d test_unzip test1.zip
          546  +    exec $::UNZIP -d test_unzip test1.zip
   506    547   
   507    548       db eval {
   508    549         SELECT name, strftime('%s', mtime, 'unixepoch', 'localtime') 
   509    550         FROM fsdir('test_unzip') WHERE name!='test_unzip'
   510    551         ORDER BY name
   511    552       }
   512    553     } [list {*}{
................................................................................
   530    571       b.txt 1000000000  abc
   531    572       c.txt 1111111000  abc
   532    573     }
   533    574   
   534    575     do_test 6.2 {
   535    576       forcedelete test_unzip
   536    577       file mkdir test_unzip
   537         -    exec unzip -d test_unzip test2.zip
          578  +    exec $::UNZIP -d test_unzip test2.zip
   538    579   
   539    580       db eval {
   540    581         SELECT name, mtime 
   541    582         FROM fsdir('test_unzip') WHERE name!='test_unzip'
   542    583         ORDER BY name
   543    584       }
   544    585     } [list {*}{
................................................................................
   648    689   #-------------------------------------------------------------------------
   649    690   # INSERT OR REPLACE and INSERT OR IGNORE
   650    691   #
   651    692   catch {db close}
   652    693   forcedelete test.zip test.db
   653    694   sqlite3 db :memory:
   654    695   load_static_extension db zipfile
          696  +load_static_extension db fileio
          697  +
   655    698   do_execsql_test 10.0 {
   656    699     CREATE VIRTUAL TABLE z USING zipfile('test.zip');
   657    700   } {}
   658    701   do_catchsql_test 10.1 {
   659    702     INSERT INTO z(name,data) VALUES('a0','one'),('a0','two');
   660    703   } {1 {duplicate name: "a0"}}
   661    704   do_execsql_test 10.2 {

Changes to test/zipfile2.test.

     5      5   #
     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   #
           12  +
           13  +package require Tcl 8.6
    12     14   
    13     15   set testdir [file dirname $argv0]
    14     16   source $testdir/tester.tcl
    15     17   set testprefix zipfile2
    16     18   
    17     19   ifcapable !vtab {
    18     20     finish_test; return