interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / zipfilefault.test

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