aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/btree6.test
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/btree6.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/btree6.test128
1 files changed, 128 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/btree6.test b/libraries/sqlite/unix/sqlite-3.5.1/test/btree6.test
new file mode 100644
index 0000000..2d31157
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/btree6.test
@@ -0,0 +1,128 @@
1# 2004 May 10
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this script is btree database backend - specifically
13# the B+tree tables. B+trees store all data on the leaves rather
14# that storing data with keys on interior nodes.
15#
16# $Id: btree6.test,v 1.4 2004/05/20 22:16:31 drh Exp $
17
18
19set testdir [file dirname $argv0]
20source $testdir/tester.tcl
21
22
23# Insert many entries into the table that cursor $cur points to.
24# The table should be an INTKEY table.
25#
26# Stagger the inserts. After the inserts complete, go back and do
27# deletes. Stagger the deletes too. Repeat this several times.
28#
29
30# Do N inserts into table $tab using random keys between 0 and 1000000
31#
32proc random_inserts {cur N} {
33 global inscnt
34 while {$N>0} {
35 set k [expr {int(rand()*1000000)}]
36 if {[btree_move_to $cur $k]==0} {
37 continue; # entry already exists
38 }
39 incr inscnt
40 btree_insert $cur $k data-for-$k
41 incr N -1
42 }
43}
44set inscnt 0
45
46# Do N delete from the table that $cur points to.
47#
48proc random_deletes {cur N} {
49 while {$N>0} {
50 set k [expr {int(rand()*1000000)}]
51 btree_move_to $cur $k
52 btree_delete $cur
53 incr N -1
54 }
55}
56
57# Make sure the table that $cur points to has exactly N entries.
58# Make sure the data for each entry agrees with its key.
59#
60proc check_table {cur N} {
61 btree_first $cur
62 set cnt 0
63 while {![btree_eof $cur]} {
64 if {[set data [btree_data $cur]] ne "data-for-[btree_key $cur]"} {
65 return "wrong data for entry $cnt"
66 }
67 set n [string length $data]
68 set fdata1 [btree_fetch_data $cur $n]
69 set fdata2 [btree_fetch_data $cur -1]
70 if {$fdata1 ne "" && $fdata1 ne $data} {
71 return "DataFetch returned the wrong value with amt=$n"
72 }
73 if {$fdata1 ne $fdata2} {
74 return "DataFetch returned the wrong value when amt=-1"
75 }
76 if {$n>10} {
77 set fdata3 [btree_fetch_data $cur 10]
78 if {$fdata3 ne [string range $data 0 9]} {
79 return "DataFetch returned the wrong value when amt=10"
80 }
81 }
82 incr cnt
83 btree_next $cur
84 }
85 if {$cnt!=$N} {
86 return "wrong number of entries. Got $cnt. Looking for $N"
87 }
88 return {}
89}
90
91# Initialize the database
92#
93file delete -force test1.bt
94file delete -force test1.bt-journal
95set b1 [btree_open test1.bt 2000 0]
96btree_begin_transaction $b1
97set tab [btree_create_table $b1 5]
98set cur [btree_cursor $b1 $tab 1]
99set btree_trace 0
100expr srand(1)
101
102# Do the tests.
103#
104set cnt 0
105for {set i 1} {$i<=40} {incr i} {
106 do_test btree6-1.$i.1 {
107 random_inserts $cur 200
108 incr cnt 200
109 check_table $cur $cnt
110 } {}
111 do_test btree6-1.$i.2 {
112 btree_integrity_check $b1 1 $tab
113 } {}
114 do_test btree6-1.$i.3 {
115 random_deletes $cur 90
116 incr cnt -90
117 check_table $cur $cnt
118 } {}
119 do_test btree6-1.$i.4 {
120 btree_integrity_check $b1 1 $tab
121 } {}
122}
123
124btree_close_cursor $cur
125btree_commit $b1
126btree_close $b1
127
128finish_test