1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# 2018 January 30
#
# 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
source $testdir/malloc_common.tcl
set testprefix zipfilefault
ifcapable !vtab {
finish_test; return
}
if {[catch {load_static_extension db zipfile} error]} {
puts "Skipping zipfile2 tests, hit load error: $error"
finish_test; return
}
faultsim_save_and_close
do_faultsim_test 1 -prep {
faultsim_restore_and_reopen
load_static_extension db zipfile
execsql { DROP TABLE IF EXISTS aaa }
} -body {
execsql { CREATE VIRTUAL TABLE aaa USING zipfile('test.zip') }
} -test {
faultsim_test_result {0 {}}
}
forcedelete test.zip
sqlite3 db test.db
load_static_extension db zipfile
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE setup USING zipfile('test.zip');
INSERT INTO setup(name, data) VALUES('a.txt', '1234567890');
}
do_faultsim_test 2.1 -faults oom* -body {
execsql { SELECT name,data FROM zipfile('test.zip') }
} -test {
faultsim_test_result {0 {a.txt 1234567890}}
}
ifcapable json1 {
do_faultsim_test 2.2 -faults oom* -body {
execsql {
SELECT json_extract( zipfile_cds(z), '$.version-made-by' )
FROM zipfile('test.zip')
}
} -test {
faultsim_test_result {0 798}
}
}
forcedelete test.zip
reset_db
load_static_extension db zipfile
do_execsql_test 3.0 {
CREATE VIRTUAL TABLE setup USING zipfile('test.zip');
INSERT INTO setup(name, data) VALUES('a.txt', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
}
do_faultsim_test 3 -faults oom* -body {
execsql { SELECT name,data FROM zipfile('test.zip') }
} -test {
faultsim_test_result {0 {a.txt aaaaaaaaaaaaaaaaaaaaaaaaaaaa}}
}
do_faultsim_test 4 -faults oom* -body {
execsql {
WITH c(n, d) AS (
SELECT 1, 'aaaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbb'
)
SELECT name, data FROM zipfile(
(SELECT zipfile(n, d) FROM c)
);
}
} -test {
faultsim_test_result {0 {1 aaaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbb}}
}
reset_db
sqlite3_db_config_lookaside db 0 0 0
load_static_extension db zipfile
do_execsql_test 5.0 {
CREATE VIRTUAL TABLE setup USING zipfile('test.zip')
}
do_faultsim_test 5.1 -faults oom* -prep {
forcedelete test.zip
} -body {
execsql {
INSERT INTO setup(name, data)
VALUES('a.txt', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa');
}
} -test {
faultsim_test_result {0 {}}
}
do_faultsim_test 5.2 -faults oom* -prep {
forcedelete test.zip
} -body {
execsql {
INSERT INTO setup(name, data) VALUES('dir', NULL)
}
} -test {
faultsim_test_result {0 {}}
}
do_faultsim_test 5.3 -faults oom* -prep {
forcedelete test.zip
execsql {
DROP TABLE IF EXISTS setup;
BEGIN;
CREATE VIRTUAL TABLE setup USING zipfile('test.zip')
}
} -body {
execsql {
INSERT INTO setup(name, data) VALUES('dir', NULL)
}
} -test {
catchsql { COMMIT }
faultsim_test_result {0 {}}
}
do_faultsim_test 6.1 -faults oom* -body {
execsql {
WITH c(n, d) AS (
VALUES('a.txt', '1234567890') UNION ALL
VALUES('dir', NULL)
)
SELECT zipfile(n, d) IS NULL FROM c;
}
} -test {
faultsim_test_result {0 0}
}
set big [string repeat 0123456789 1000]
do_faultsim_test 6.2 -faults oom* -body {
execsql {
WITH c(n, d) AS (
VALUES('a.txt', $big)
)
SELECT zipfile(n, NULL, NULL, d, 0) IS NULL FROM c;
}
} -test {
faultsim_test_result {0 0}
}
do_faultsim_test 7.0 -faults oom* -prep {
catch { db close }
sqlite3 db ""
} -body {
load_static_extension db zipfile
} -test {
}
finish_test
|