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