xref: /titanic_52/usr/src/lib/libsqlite/test/btree4rb.test (revision 4a5d661a82b942b6538acd26209d959ce98b593a)
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: btree4rb.test,v 1.1 2003/04/20 23:45:23 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#
31set b1 [btree_open :memory:]
32btree_begin_transaction $::b1
33
34set data {abcdefghijklmnopqrstuvwxyz0123456789}
35append data $data
36append data $data
37append data $data
38append data $data
39
40foreach N {10 100 1000} {
41  btree_clear_table $::b1 2
42  set ::c1 [btree_cursor $::b1 2 1]
43  do_test btree4rb-$N.1 {
44    for {set i 1} {$i<=$N} {incr i} {
45      btree_insert $::c1 [format k-%05d $i] $::data-$i
46    }
47    btree_first $::c1
48    btree_key $::c1
49  } {k-00001}
50  do_test btree4rb-$N.2 {
51    btree_data $::c1
52  } $::data-1
53  for {set i 2} {$i<=$N} {incr i} {
54    do_test btree-$N.3.$i.1 {
55      btree_next $::c1
56    } 0
57    do_test btree-$N.3.$i.2 {
58      btree_key $::c1
59    } [format k-%05d $i]
60    do_test btree-$N.3.$i.3 {
61      btree_data $::c1
62    } $::data-$i
63  }
64  do_test btree4rb-$N.4 {
65    btree_next $::c1
66  } 1
67  do_test btree4rb-$N.5 {
68    btree_last $::c1
69  } 0
70  do_test btree4rb-$N.6 {
71    btree_key $::c1
72  } [format k-%05d $N]
73  do_test btree4rb-$N.7 {
74    btree_data $::c1
75  } $::data-$N
76  for {set i [expr {$N-1}]} {$i>=1} {incr i -1} {
77    do_test btree4rb-$N.8.$i.1 {
78      btree_prev $::c1
79    } 0
80    do_test btree4rb-$N.8.$i.2 {
81      btree_key $::c1
82    } [format k-%05d $i]
83    do_test btree4rb-$N.8.$i.3 {
84      btree_data $::c1
85    } $::data-$i
86  }
87  do_test btree4rb-$N.9 {
88    btree_prev $::c1
89  } 1
90  btree_close_cursor $::c1
91}
92
93btree_rollback $::b1
94btree_close $::b1
95
96} ;# end if( not mem: and has pager_open command );
97
98finish_test
99