2017-12-29 23:19:03 +03:00
|
|
|
# 2017 December 9
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
set testprefix zipfile
|
|
|
|
|
2018-01-09 21:31:11 +03:00
|
|
|
ifcapable !vtab {
|
|
|
|
finish_test; return
|
|
|
|
}
|
2018-01-05 23:13:33 +03:00
|
|
|
if {[catch {load_static_extension db zipfile} error]} {
|
|
|
|
puts "Skipping zipfile tests, hit load error: $error"
|
|
|
|
finish_test; return
|
|
|
|
}
|
2017-12-29 23:19:03 +03:00
|
|
|
|
|
|
|
forcedelete test.zip
|
|
|
|
do_execsql_test 1.0 {
|
|
|
|
CREATE VIRTUAL TABLE temp.zz USING zipfile('test.zip');
|
|
|
|
PRAGMA table_info(zz);
|
|
|
|
} {
|
|
|
|
0 name {} 0 {} 0
|
|
|
|
1 mode {} 0 {} 0
|
|
|
|
2 mtime {} 0 {} 0
|
|
|
|
3 sz {} 0 {} 0
|
2018-01-08 22:59:59 +03:00
|
|
|
4 rawdata {} 0 {} 0
|
|
|
|
5 data {} 0 {} 0
|
|
|
|
6 method {} 0 {} 0
|
2017-12-29 23:19:03 +03:00
|
|
|
}
|
|
|
|
|
2017-12-30 21:32:27 +03:00
|
|
|
do_execsql_test 1.1.1 {
|
2018-01-08 22:59:59 +03:00
|
|
|
INSERT INTO zz(name, mode, mtime, sz, rawdata, method)
|
|
|
|
VALUES('f.txt', '-rw-r--r--', 1000000000, 5, 'abcde', 0);
|
2017-12-30 21:32:27 +03:00
|
|
|
}
|
|
|
|
do_execsql_test 1.1.2 {
|
2018-01-08 22:59:59 +03:00
|
|
|
INSERT INTO zz(name, mtime, sz, rawdata, method)
|
|
|
|
VALUES('g.txt', 1000000002, 5, '12345', 0);
|
2017-12-29 23:19:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 1.2 {
|
2017-12-30 21:32:27 +03:00
|
|
|
SELECT name, mtime, data FROM zipfile('test.zip')
|
2017-12-29 23:19:03 +03:00
|
|
|
} {
|
|
|
|
f.txt 1000000000 abcde
|
2017-12-30 17:26:29 +03:00
|
|
|
g.txt 1000000002 12345
|
2017-12-29 23:19:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 1.3 {
|
2018-01-08 22:59:59 +03:00
|
|
|
INSERT INTO zz(name, mode, mtime, data) VALUES('h.txt',
|
|
|
|
'-rw-r--r--', 1000000004, 'aaaaaaaaaabbbbbbbbbb'
|
2017-12-29 23:19:03 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 1.4 {
|
2018-01-08 22:59:59 +03:00
|
|
|
SELECT name, mtime, data, method FROM zipfile('test.zip');
|
2017-12-29 23:19:03 +03:00
|
|
|
} {
|
|
|
|
f.txt 1000000000 abcde 0
|
|
|
|
g.txt 1000000002 12345 0
|
2017-12-30 17:26:29 +03:00
|
|
|
h.txt 1000000004 aaaaaaaaaabbbbbbbbbb 8
|
2017-12-29 23:19:03 +03:00
|
|
|
}
|
|
|
|
|
2017-12-30 21:32:27 +03:00
|
|
|
do_execsql_test 1.5.1 {
|
|
|
|
BEGIN;
|
2018-01-08 22:59:59 +03:00
|
|
|
INSERT INTO zz(name, mode, mtime, data, method)
|
|
|
|
VALUES('i.txt', '-rw-r--r--', 1000000006, 'zxcvb', 0);
|
2017-12-30 21:32:27 +03:00
|
|
|
SELECT name FROM zz;
|
|
|
|
COMMIT;
|
|
|
|
} {f.txt g.txt h.txt i.txt}
|
|
|
|
do_execsql_test 1.5.2 {
|
|
|
|
SELECT name FROM zz;
|
|
|
|
} {f.txt g.txt h.txt i.txt}
|
|
|
|
|
|
|
|
do_execsql_test 1.6.0 {
|
|
|
|
DELETE FROM zz WHERE name='g.txt';
|
|
|
|
SELECT name FROM zz;
|
|
|
|
} {f.txt h.txt i.txt}
|
|
|
|
|
2018-01-09 13:29:34 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
db close
|
|
|
|
forcedelete test.zip
|
|
|
|
reset_db
|
|
|
|
load_static_extension db zipfile
|
|
|
|
do_execsql_test 2.1 {
|
|
|
|
CREATE VIRTUAL TABLE zzz USING zipfile('test.zip');
|
|
|
|
INSERT INTO zzz(name, mode) VALUES('dirname', 'drwxr-xr-x');
|
|
|
|
SELECT name, mode, data FROM zzz;
|
2018-01-10 19:30:40 +03:00
|
|
|
} {dirname/ 16877 {}}
|
2018-01-09 13:29:34 +03:00
|
|
|
do_execsql_test 2.2 {
|
|
|
|
INSERT INTO zzz(name, data) VALUES('dirname2', NULL);
|
|
|
|
INSERT INTO zzz(name, data) VALUES('dirname2/file1.txt', 'abcdefghijklmnop');
|
|
|
|
SELECT name, mode, data FROM zzz;
|
|
|
|
} {
|
2018-01-10 19:30:40 +03:00
|
|
|
dirname/ 16877 {}
|
|
|
|
dirname2/ 16877 {}
|
2018-01-09 13:29:34 +03:00
|
|
|
dirname2/file1.txt 33188 abcdefghijklmnop
|
|
|
|
}
|
|
|
|
|
2018-01-09 23:44:04 +03:00
|
|
|
do_catchsql_test 2.3 {
|
2018-01-10 19:30:40 +03:00
|
|
|
UPDATE zzz SET name = 'dirname3' WHERE name = 'dirname/';
|
2018-01-09 23:44:04 +03:00
|
|
|
} {1 {constraint failed}}
|
|
|
|
do_execsql_test 2.4 {
|
|
|
|
SELECT name, mode, data FROM zzz;
|
|
|
|
} {
|
2018-01-10 19:30:40 +03:00
|
|
|
dirname/ 16877 {}
|
|
|
|
dirname2/ 16877 {}
|
2018-01-09 23:44:04 +03:00
|
|
|
dirname2/file1.txt 33188 abcdefghijklmnop
|
|
|
|
}
|
2018-01-09 13:29:34 +03:00
|
|
|
|
2018-01-10 19:30:40 +03:00
|
|
|
# If on unix, check that the [unzip] utility can unpack our archive.
|
|
|
|
#
|
|
|
|
if {$::tcl_platform(platform)=="unix"} {
|
|
|
|
do_test 2.5.1 {
|
|
|
|
forcedelete dirname
|
|
|
|
forcedelete dirname2
|
|
|
|
set rc [catch { exec unzip test.zip > /dev/null } msg]
|
|
|
|
list $rc $msg
|
|
|
|
} {0 {}}
|
|
|
|
do_test 2.5.2 { file isdir dirname } 1
|
|
|
|
do_test 2.5.3 { file isdir dirname2 } 1
|
|
|
|
do_test 2.5.4 { file isdir dirname2/file1.txt } 0
|
|
|
|
do_test 2.5.5 {
|
|
|
|
set fd [open dirname2/file1.txt]
|
|
|
|
set data [read $fd]
|
|
|
|
close $fd
|
|
|
|
set data
|
|
|
|
} {abcdefghijklmnop}
|
|
|
|
}
|
2018-01-09 13:29:34 +03:00
|
|
|
|
2018-01-10 20:37:58 +03:00
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
reset_db
|
|
|
|
forcedelete test.zip
|
|
|
|
load_static_extension db zipfile
|
|
|
|
|
|
|
|
do_execsql_test 3.0 {
|
|
|
|
CREATE VIRTUAL TABLE temp.x1 USING zipfile('test.zip');
|
|
|
|
INSERT INTO x1(name, data) VALUES('dir1/', NULL);
|
|
|
|
INSERT INTO x1(name, data) VALUES('file1', '1234');
|
|
|
|
INSERT INTO x1(name, data) VALUES('dir1/file2', '5678');
|
|
|
|
}
|
|
|
|
foreach {tn fname} {
|
|
|
|
1 dir1
|
|
|
|
2 file1
|
|
|
|
3 dir1/file2
|
|
|
|
} {
|
|
|
|
do_catchsql_test 3.1.$tn.0 {
|
|
|
|
INSERT INTO x1(name, data) VALUES($fname, NULL);
|
|
|
|
} {1 {constraint failed}}
|
|
|
|
do_catchsql_test 3.1.$tn.1 {
|
|
|
|
INSERT INTO x1(name, data) VALUES($fname || '/', NULL);
|
|
|
|
} {1 {constraint failed}}
|
|
|
|
do_catchsql_test 3.1.$tn.2 {
|
|
|
|
INSERT INTO x1(name, data) VALUES($fname, 'abcd');
|
|
|
|
} {1 {constraint failed}}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-29 23:19:03 +03:00
|
|
|
finish_test
|
|
|
|
|