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#*********************************************************************** 11*d3f8f946Sdan# This file implements regression tests for SQLite library. The 12*d3f8f946Sdan# focus of this file is testing the operation of the library in 13*d3f8f946Sdan# "PRAGMA journal_mode=WAL" mode. The tests in this file use 14*d3f8f946Sdan# brute force methods, so may take a while to run. 157c24610eSdan# 167c24610eSdan 177c24610eSdanset testdir [file dirname $argv0] 187c24610eSdansource $testdir/tester.tcl 197c24610eSdan 207c24610eSdanproc reopen_db {} { 217c24610eSdan catch { db close } 227c24610eSdan file delete -force test.db test.db-wal 237c24610eSdan sqlite3 db test.db 247c24610eSdan execsql { PRAGMA journal_mode = wal } 257c24610eSdan} 267c24610eSdan 277c24610eSdandb close 287c24610eSdansave_prng_state 297c24610eSdanfor {set seed 1} {$seed<10} {incr seed} { 307c24610eSdan expr srand($seed) 317c24610eSdan restore_prng_state 327c24610eSdan reopen_db 337c24610eSdan do_test walslow-1.seed=$seed.0 { 347c24610eSdan execsql { CREATE TABLE t1(a, b) } 357c24610eSdan execsql { CREATE INDEX i1 ON t1(a) } 367c24610eSdan execsql { CREATE INDEX i2 ON t1(b) } 377c24610eSdan } {} 387c24610eSdan 397c24610eSdan for {set iTest 1} {$iTest < 100} {incr iTest} { 407c24610eSdan 417c24610eSdan do_test walslow-1.seed=$seed.$iTest.1 { 427c24610eSdan set w [expr int(rand()*2000)] 437c24610eSdan set x [expr int(rand()*2000)] 447c24610eSdan set y [expr int(rand()*9)+1] 457c24610eSdan set z [expr int(rand()*2)] 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 { 517c24610eSdan execsql "PRAGMA checkpoint('$y $y $z')" 527c24610eSdan execsql { PRAGMA integrity_check } 537c24610eSdan } {ok} 547c24610eSdan 557c24610eSdan do_test walslow-1.seed=$seed.$iTest.3 { 567c24610eSdan file delete -force testX.db testX.db-wal 577c24610eSdan file copy test.db testX.db 587c24610eSdan file copy 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