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