xref: /illumos-gate/usr/src/lib/libsqlite/test/btree3rb.test (revision d48be21240dfd051b689384ce2b23479d757f2d8)
1#
2# 2001 November 22
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# In particular, this file tests a small part of the Delete logic
16# for the BTree backend.  When a row is deleted from a table, the
17# cursor is suppose to be left pointing at either the previous or
18# next entry in that table.  If the cursor is left pointing at the
19# next entry, then the next Next operation is ignored.  So the
20# sequence of operations (Delete, Next) should always leave the
21# cursor pointing at the first entry past the one that was deleted.
22# This test is designed to verify that behavior.
23#
24# $Id: btree3rb.test,v 1.1 2003/04/20 23:45:23 drh Exp $
25
26
27set testdir [file dirname $argv0]
28source $testdir/tester.tcl
29
30if {[info commands btree_open]!=""} {
31
32# Open a test database.
33#
34set b1 [btree_open :memory:]
35btree_begin_transaction $::b1
36
37# Insert a few one records
38#
39set data {abcdefghijklmnopqrstuvwxyz0123456789}
40append data $data
41append data $data
42append data $data
43append data $data
44for {set k 2} {$k<=20} {incr k} {
45  for {set j 1} {$j<=$k} {incr j} {
46    set jkey [format %02d $j]
47    btree_clear_table $::b1 2
48    set ::c1 [btree_cursor $::b1 2 1]
49    for {set i 1} {$i<=$k} {incr i} {
50      set key [format %02d $i]
51      do_test btree3rb-$k.$j.1.$i {
52        btree_insert $::c1 $::key $::data
53      } {}
54      # btree_tree_dump $::b1 2
55    }
56    do_test btree3rb-$k.$j.2 {
57      btree_move_to $::c1 $::jkey
58      btree_key $::c1
59    } $::jkey
60    do_test btree3rb-$k.$j.3 {
61      btree_delete $::c1
62    } {}
63    if {$j<$k} {
64      do_test btree3rb-$k.$j.4 {
65        btree_next $::c1
66        btree_key $::c1
67      } [format %02d [expr $j+1]]
68    }
69    if {$j>1} {
70      do_test btree3rb-$k.$j.5 {
71        btree_prev $::c1
72        btree_key $::c1
73      } [format %02d [expr $j-1]]
74    }
75    btree_close_cursor $::c1
76  }
77}
78
79btree_rollback $::b1
80#btree_pager_ref_dump $::b1
81btree_close $::b1
82
83} ;# end if( not mem: and has pager_open command );
84
85finish_test
86