diff options
author | dan miller | 2007-10-20 02:49:29 +0000 |
---|---|---|
committer | dan miller | 2007-10-20 02:49:29 +0000 |
commit | e36d23a85ebff914d74bb541558c2b6082b78edb (patch) | |
tree | 54b58fdf162e78af64055282a6035c8d2443389d /libraries/sqlite/unix/sqlite-3.5.1/test/btree6.test | |
parent | * Fixed an issue whereby avatar chat distances were being calculated against ... (diff) | |
download | opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.zip opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.gz opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.bz2 opensim-SC-e36d23a85ebff914d74bb541558c2b6082b78edb.tar.xz |
sqlite source (unix build) added to libraries
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.test | 128 |
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 | |||
19 | set testdir [file dirname $argv0] | ||
20 | source $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 | # | ||
32 | proc 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 | } | ||
44 | set inscnt 0 | ||
45 | |||
46 | # Do N delete from the table that $cur points to. | ||
47 | # | ||
48 | proc 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 | # | ||
60 | proc 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 | # | ||
93 | file delete -force test1.bt | ||
94 | file delete -force test1.bt-journal | ||
95 | set b1 [btree_open test1.bt 2000 0] | ||
96 | btree_begin_transaction $b1 | ||
97 | set tab [btree_create_table $b1 5] | ||
98 | set cur [btree_cursor $b1 $tab 1] | ||
99 | set btree_trace 0 | ||
100 | expr srand(1) | ||
101 | |||
102 | # Do the tests. | ||
103 | # | ||
104 | set cnt 0 | ||
105 | for {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 | |||
124 | btree_close_cursor $cur | ||
125 | btree_commit $b1 | ||
126 | btree_close $b1 | ||
127 | |||
128 | finish_test | ||