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