# This file contains tests for the blockcachevfs system.
#
# Specifically, it uses the SQLite backup API to test the system.
#
source [file join [file dirname [info script]] test_common.tcl]
set testprefix bcv_backup
bcv_create_container cont123
bcv_upload_empty_database cont123 t1.db
bcv_upload_empty_database cont123 t2.db
bcv_mkdir testdir
set cmd [bcvfs_create testdir "bcvfs"]
bcvfs_attach $cmd cont123
sqlite db /cont123/t1.db -vfs bcvfs -uri 1
do_execsql_test 1.0 {
CREATE TABLE t1(a, b, c);
CREATE INDEX t1abc ON t1(a, b, c);
PRAGMA user_version = 201;
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
)
INSERT INTO t1
SELECT randomblob(500),randomblob(500),randomblob(500) FROM s;
PRAGMA bcv_upload;
}
do_test 1.1 {
db backup file:///cont123/t2.db?vfs=bcvfs
} {}
$cmd upload cont123
bcv_mkdir testdir2
set cmd2 [bcvfs_create testdir2 "bcvfs2"]
bcvfs_attach $cmd2 cont123
sqlite db2 / -vfs bcvfs2
sqlite3_bcvfs_register_vtab db2
if {$C(namebytes)>=24} {
# Check that new database test.db2 has a single block that is not
# shared with database test.db1. And that it has 4 or more that are
# shared with said db.
#
do_execsql2_test 1.2 {
SELECT count(*) FROM bcv_block AS o WHERE database='t2.db'
AND NOT EXISTS (
SELECT 1 FROM bcv_block WHERE o.blockid=blockid AND database='t1.db'
);
SELECT count(*)>=4 FROM bcv_block AS o WHERE database='t2.db'
AND EXISTS (
SELECT 1 FROM bcv_block WHERE o.blockid=blockid AND database='t1.db'
);
} {1 1}
}
do_execsql2_test 1.3 {
PRAGMA integrity_check
} {ok}
db2 close
db close
$cmd destroy
$cmd2 destroy
finish_test