expand codec error test to include multi-step transaction

This commit is contained in:
Stephen Lombardo 2020-11-11 10:22:13 -05:00
parent 55684b3e94
commit 20c39041fd
1 changed files with 66 additions and 45 deletions

View File

@ -38,7 +38,7 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/sqlcipher.tcl
do_test codec-error-journal-delete {
proc codec-test-setup {} {
sqlite_orig db test.db
execsql {
@ -47,47 +47,6 @@ do_test codec-error-journal-delete {
BEGIN;
}
for {set i 1} {$i<=10000} {incr i} {
execsql "INSERT INTO t1(a,b) VALUES($i,'value $i');"
}
execsql {
COMMIT;
}
db close
sqlite_orig db test.db
catchsql {
PRAGMA key = 'testkey';
PRAGMA cipher_fail_next_encrypt = 1;
UPDATE t1 SET b = 'fail' WHERE a = 5000;
}
db close
sqlite_orig db test.db
execsql {
PRAGMA cipher_fail_next_encrypt = 0;
PRAGMA key = 'testkey';
PRAGMA integrity_check;
PRAGMA cipher_integrity_check;
}
} {ok ok}
db close
file delete -force test.db
do_test codec-error-journal-wal {
sqlite_orig db test.db
execsql {
PRAGMA key = 'testkey';
PRAGMA journal_mode = WAL;
CREATE table t1(a INTEGER PRIMARY KEY,b);
BEGIN;
}
for {set i 1} {$i<=10000} {incr i} {
execsql "INSERT INTO t1(a,b) VALUES($i,'value $i');"
}
@ -97,6 +56,12 @@ do_test codec-error-journal-wal {
}
db close
}
do_test codec-error-journal-delete {
codec-test-setup
sqlite_orig db test.db
catchsql {
@ -111,13 +76,69 @@ do_test codec-error-journal-wal {
execsql {
PRAGMA cipher_fail_next_encrypt = 0;
PRAGMA key = 'testkey';
PRAGMA integrity_check;
PRAGMA cipher_integrity_check;
PRAGMA integrity_check;
SELECT b FROM t1 where a = 5000;
}
} {ok ok}
} {ok ok {value 5000}}
db close
file delete -force test.db
do_test codec-error-journal-wal {
codec-test-setup
sqlite_orig db test.db
catchsql {
PRAGMA key = 'testkey';
PRAGMA cipher_fail_next_encrypt = 1;
UPDATE t1 SET b = 'fail' WHERE a = 5000;
}
db close
sqlite_orig db test.db
execsql {
PRAGMA cipher_fail_next_encrypt = 0;
PRAGMA key = 'testkey';
PRAGMA cipher_integrity_check;
PRAGMA integrity_check;
SELECT b FROM t1 where a = 5000;
}
} {ok ok {value 5000}}
db close
file delete -force test.db
do_test codec-error-journal-wal-transaction {
codec-test-setup
sqlite_orig db test.db
catchsql {
PRAGMA key = 'testkey';
BEGIN;
UPDATE t1 SET b = 'success' WHERE a = 1;
PRAGMA cipher_fail_next_encrypt = 1;
UPDATE t1 SET b = 'fail' WHERE a = 5000;
COMMIT;
}
db close
sqlite_orig db test.db
execsql {
PRAGMA cipher_fail_next_encrypt = 0;
PRAGMA key = 'testkey';
PRAGMA cipher_integrity_check;
PRAGMA integrity_check;
SELECT b FROM t1 where a = 1;
SELECT b FROM t1 where a = 5000;
}
} {ok ok {value 1} {value 5000}}
db close
file delete -force test.db
finish_test