1*c5c4113dSnw141292 2*c5c4113dSnw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*c5c4113dSnw141292 4*c5c4113dSnw141292# 2002 December 03 5*c5c4113dSnw141292# 6*c5c4113dSnw141292# The author disclaims copyright to this source code. In place of 7*c5c4113dSnw141292# a legal notice, here is a blessing: 8*c5c4113dSnw141292# 9*c5c4113dSnw141292# May you do good and not evil. 10*c5c4113dSnw141292# May you find forgiveness for yourself and forgive others. 11*c5c4113dSnw141292# May you share freely, never taking more than you give. 12*c5c4113dSnw141292# 13*c5c4113dSnw141292#*********************************************************************** 14*c5c4113dSnw141292# This file implements regression tests for SQLite library. The 15*c5c4113dSnw141292# focus of this script is btree database backend 16*c5c4113dSnw141292# 17*c5c4113dSnw141292# This file focuses on testing the sqliteBtreeNext() and 18*c5c4113dSnw141292# sqliteBtreePrevious() procedures and making sure they are able 19*c5c4113dSnw141292# to step through an entire table from either direction. 20*c5c4113dSnw141292# 21*c5c4113dSnw141292# $Id: btree4rb.test,v 1.1 2003/04/20 23:45:23 drh Exp $ 22*c5c4113dSnw141292 23*c5c4113dSnw141292 24*c5c4113dSnw141292set testdir [file dirname $argv0] 25*c5c4113dSnw141292source $testdir/tester.tcl 26*c5c4113dSnw141292 27*c5c4113dSnw141292if {[info commands btree_open]!=""} { 28*c5c4113dSnw141292 29*c5c4113dSnw141292# Open a test database. 30*c5c4113dSnw141292# 31*c5c4113dSnw141292set b1 [btree_open :memory:] 32*c5c4113dSnw141292btree_begin_transaction $::b1 33*c5c4113dSnw141292 34*c5c4113dSnw141292set data {abcdefghijklmnopqrstuvwxyz0123456789} 35*c5c4113dSnw141292append data $data 36*c5c4113dSnw141292append data $data 37*c5c4113dSnw141292append data $data 38*c5c4113dSnw141292append data $data 39*c5c4113dSnw141292 40*c5c4113dSnw141292foreach N {10 100 1000} { 41*c5c4113dSnw141292 btree_clear_table $::b1 2 42*c5c4113dSnw141292 set ::c1 [btree_cursor $::b1 2 1] 43*c5c4113dSnw141292 do_test btree4rb-$N.1 { 44*c5c4113dSnw141292 for {set i 1} {$i<=$N} {incr i} { 45*c5c4113dSnw141292 btree_insert $::c1 [format k-%05d $i] $::data-$i 46*c5c4113dSnw141292 } 47*c5c4113dSnw141292 btree_first $::c1 48*c5c4113dSnw141292 btree_key $::c1 49*c5c4113dSnw141292 } {k-00001} 50*c5c4113dSnw141292 do_test btree4rb-$N.2 { 51*c5c4113dSnw141292 btree_data $::c1 52*c5c4113dSnw141292 } $::data-1 53*c5c4113dSnw141292 for {set i 2} {$i<=$N} {incr i} { 54*c5c4113dSnw141292 do_test btree-$N.3.$i.1 { 55*c5c4113dSnw141292 btree_next $::c1 56*c5c4113dSnw141292 } 0 57*c5c4113dSnw141292 do_test btree-$N.3.$i.2 { 58*c5c4113dSnw141292 btree_key $::c1 59*c5c4113dSnw141292 } [format k-%05d $i] 60*c5c4113dSnw141292 do_test btree-$N.3.$i.3 { 61*c5c4113dSnw141292 btree_data $::c1 62*c5c4113dSnw141292 } $::data-$i 63*c5c4113dSnw141292 } 64*c5c4113dSnw141292 do_test btree4rb-$N.4 { 65*c5c4113dSnw141292 btree_next $::c1 66*c5c4113dSnw141292 } 1 67*c5c4113dSnw141292 do_test btree4rb-$N.5 { 68*c5c4113dSnw141292 btree_last $::c1 69*c5c4113dSnw141292 } 0 70*c5c4113dSnw141292 do_test btree4rb-$N.6 { 71*c5c4113dSnw141292 btree_key $::c1 72*c5c4113dSnw141292 } [format k-%05d $N] 73*c5c4113dSnw141292 do_test btree4rb-$N.7 { 74*c5c4113dSnw141292 btree_data $::c1 75*c5c4113dSnw141292 } $::data-$N 76*c5c4113dSnw141292 for {set i [expr {$N-1}]} {$i>=1} {incr i -1} { 77*c5c4113dSnw141292 do_test btree4rb-$N.8.$i.1 { 78*c5c4113dSnw141292 btree_prev $::c1 79*c5c4113dSnw141292 } 0 80*c5c4113dSnw141292 do_test btree4rb-$N.8.$i.2 { 81*c5c4113dSnw141292 btree_key $::c1 82*c5c4113dSnw141292 } [format k-%05d $i] 83*c5c4113dSnw141292 do_test btree4rb-$N.8.$i.3 { 84*c5c4113dSnw141292 btree_data $::c1 85*c5c4113dSnw141292 } $::data-$i 86*c5c4113dSnw141292 } 87*c5c4113dSnw141292 do_test btree4rb-$N.9 { 88*c5c4113dSnw141292 btree_prev $::c1 89*c5c4113dSnw141292 } 1 90*c5c4113dSnw141292 btree_close_cursor $::c1 91*c5c4113dSnw141292} 92*c5c4113dSnw141292 93*c5c4113dSnw141292btree_rollback $::b1 94*c5c4113dSnw141292btree_close $::b1 95*c5c4113dSnw141292 96*c5c4113dSnw141292} ;# end if( not mem: and has pager_open command ); 97*c5c4113dSnw141292 98*c5c4113dSnw141292finish_test 99