17c24610eSdan# 2010 March 17 27c24610eSdan# 37c24610eSdan# The author disclaims copyright to this source code. In place of 47c24610eSdan# a legal notice, here is a blessing: 57c24610eSdan# 67c24610eSdan# May you do good and not evil. 77c24610eSdan# May you find forgiveness for yourself and forgive others. 87c24610eSdan# May you share freely, never taking more than you give. 97c24610eSdan# 107c24610eSdan#*********************************************************************** 11d3f8f946Sdan# This file implements regression tests for SQLite library. The 12d3f8f946Sdan# focus of this file is testing the operation of the library in 13d3f8f946Sdan# "PRAGMA journal_mode=WAL" mode. The tests in this file use 14d3f8f946Sdan# brute force methods, so may take a while to run. 157c24610eSdan# 167c24610eSdan 177c24610eSdanset testdir [file dirname $argv0] 187c24610eSdansource $testdir/tester.tcl 197c24610eSdan 205cf53537Sdanifcapable !wal {finish_test ; return } 215cf53537Sdan 227c24610eSdanproc reopen_db {} { 237c24610eSdan catch { db close } 24*fda06befSmistachkin forcedelete test.db test.db-wal 257c24610eSdan sqlite3 db test.db 267c24610eSdan execsql { PRAGMA journal_mode = wal } 277c24610eSdan} 287c24610eSdan 297c24610eSdandb close 307c24610eSdansave_prng_state 317c24610eSdanfor {set seed 1} {$seed<10} {incr seed} { 327c24610eSdan expr srand($seed) 337c24610eSdan restore_prng_state 347c24610eSdan reopen_db 357c24610eSdan do_test walslow-1.seed=$seed.0 { 367c24610eSdan execsql { CREATE TABLE t1(a, b) } 377c24610eSdan execsql { CREATE INDEX i1 ON t1(a) } 387c24610eSdan execsql { CREATE INDEX i2 ON t1(b) } 397c24610eSdan } {} 407c24610eSdan 417c24610eSdan for {set iTest 1} {$iTest < 100} {incr iTest} { 427c24610eSdan 437c24610eSdan do_test walslow-1.seed=$seed.$iTest.1 { 447c24610eSdan set w [expr int(rand()*2000)] 457c24610eSdan set x [expr int(rand()*2000)] 467c24610eSdan execsql { INSERT INTO t1 VALUES(randomblob($w), randomblob($x)) } 477c24610eSdan execsql { PRAGMA integrity_check } 487c24610eSdan } {ok} 497c24610eSdan 507c24610eSdan do_test walslow-1.seed=$seed.$iTest.2 { 515a299f91Sdan execsql "PRAGMA wal_checkpoint;" 527c24610eSdan execsql { PRAGMA integrity_check } 537c24610eSdan } {ok} 547c24610eSdan 557c24610eSdan do_test walslow-1.seed=$seed.$iTest.3 { 56*fda06befSmistachkin forcedelete testX.db testX.db-wal 57*fda06befSmistachkin copy_file test.db testX.db 58*fda06befSmistachkin copy_file test.db-wal testX.db-wal 597c24610eSdan 607c24610eSdan sqlite3 db2 testX.db 617c24610eSdan execsql { PRAGMA journal_mode = WAL } db2 627c24610eSdan execsql { PRAGMA integrity_check } db2 637c24610eSdan } {ok} 647c24610eSdan 657c24610eSdan do_test walslow-1.seed=$seed.$iTest.4 { 667c24610eSdan execsql { SELECT count(*) FROM t1 WHERE a!=b } db2 677c24610eSdan } [execsql { SELECT count(*) FROM t1 WHERE a!=b }] 687c24610eSdan db2 close 697c24610eSdan } 707c24610eSdan} 717c24610eSdan 727c24610eSdan 737c24610eSdanfinish_test 74