sqlite/test/zipfilefault.test
dan c3ef23a1c9 Fix a memory leak that could follow an IO error in the zipfile extension. And
add other tests.

FossilOrigin-Name: e6bb750697c3c7ceb5ce41d216e8ef6a1d556822a3b55e0a007b4a03e194a7d9
2018-02-01 15:19:54 +00:00

81 lines
2.0 KiB
Plaintext

# 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 -faults oom* -body {
execsql { SELECT name,data FROM zipfile('test.zip') }
} -test {
faultsim_test_result {0 {a.txt 1234567890}}
}
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}}
}
finish_test