downgrade memory unlock failures to info level and fix function name in log output
[sqlcipher.git] / test / boundary2.tcl
blobb141166072d9174f9cc05232724ecc5253c1e64c
1 puts {# 2008 December 11
3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file is automatically generated from a separate TCL script.
14 # This file seeks to exercise integer boundary values.
16 # $Id: boundary2.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # Many of the boundary tests depend on a working 64-bit implementation.
22 if {![working_64bit_int]} { finish_test; return }
25 expr srand(0)
27 # Generate interesting boundary numbers
29 foreach x {
32 0x7f
33 0x7fff
34 0x7fffff
35 0x7fffffff
36 0x7fffffffff
37 0x7fffffffffff
38 0x7fffffffffffff
39 0x7fffffffffffffff
40 } {
41 set x [expr {wide($x)}]
42 set boundarynum($x) 1
43 set boundarynum([expr {$x+1}]) 1
44 set boundarynum([expr {-($x+1)}]) 1
45 set boundarynum([expr {-($x+2)}]) 1
46 set boundarynum([expr {$x+$x+1}]) 1
47 set boundarynum([expr {$x+$x+2}]) 1
49 set x [expr {wide(127)}]
50 for {set i 1} {$i<=9} {incr i} {
51 set boundarynum($x) 1
52 set boundarynum([expr {$x+1}]) 1
53 set x [expr {wide($x*128 + 127)}]
56 # Scramble the $inlist into a random order.
58 proc scramble {inlist} {
59 set y {}
60 foreach x $inlist {
61 lappend y [list [expr {rand()}] $x]
63 set y [lsort $y]
64 set outlist {}
65 foreach x $y {
66 lappend outlist [lindex $x 1]
68 return $outlist
71 # A simple selection sort. Not trying to be efficient.
73 proc sort {inlist} {
74 set outlist {}
75 set mn [lindex $inlist 0]
76 foreach x $inlist {
77 if {$x<$mn} {set mn $x}
79 set outlist $mn
80 set mx $mn
81 while {1} {
82 set valid 0
83 foreach x $inlist {
84 if {$x>$mx && (!$valid || $mn>$x)} {
85 set mn $x
86 set valid 1
89 if {!$valid} break
90 lappend outlist $mn
91 set mx $mn
93 return $outlist
96 # Reverse the order of a list
98 proc reverse {inlist} {
99 set i [llength $inlist]
100 set outlist {}
101 for {incr i -1} {$i>=0} {incr i -1} {
102 lappend outlist [lindex $inlist $i]
104 return $outlist
107 set nums1 [scramble [array names boundarynum]]
108 set nums2 [scramble [array names boundarynum]]
110 set tname boundary2
111 puts "do_test $tname-1.1 \173"
112 puts " db eval \173"
113 puts " CREATE TABLE t1(r INTEGER, a INTEGER, x TEXT);"
114 set a 0
115 foreach r $nums1 {
116 incr a
117 set t1ra($r) $a
118 set t1ar($a) $r
119 set x [format %08x%08x [expr {wide($r)>>32}] $r]
120 set t1rx($r) $x
121 set t1xr($x) $r
122 puts " INSERT INTO t1 VALUES($r,$a,'$x');"
124 puts " CREATE INDEX t1i1 ON t1(r);"
125 puts " CREATE INDEX t1i2 ON t1(a);"
126 puts " CREATE INDEX t1i3 ON t1(x);"
127 puts " \175"
128 puts "\175 {}"
130 puts "do_test $tname-1.2 \173"
131 puts " db eval \173"
132 puts " SELECT count(*) FROM t1"
133 puts " \175"
134 puts "\175 {64}"
136 set nums3 $nums2
137 lappend nums3 9.22337303685477580800e+18
138 lappend nums3 -9.22337303685477580800e+18
140 set i 0
141 foreach r $nums3 {
142 incr i
144 if {abs($r)<9.22337203685477580800e+18} {
145 set x $t1rx($r)
146 set a $t1ra($r)
147 set r5 $r.5
148 set r0 $r.0
149 puts "do_test $tname-2.$i.1 \173"
150 puts " db eval \173"
151 puts " SELECT * FROM t1 WHERE r=$r"
152 puts " \175"
153 puts "\175 {$r $a $x}"
154 puts "do_test $tname-2.$i.2 \173"
155 puts " db eval \173"
156 puts " SELECT r, a FROM t1 WHERE x='$x'"
157 puts " \175"
158 puts "\175 {$r $a}"
159 puts "do_test $tname-2.$i.3 \173"
160 puts " db eval \173"
161 puts " SELECT r, x FROM t1 WHERE a=$a"
162 puts " \175"
163 puts "\175 {$r $x}"
166 foreach op {> >= < <=} subno {gt ge lt le} {
168 ################################################################ 2.x.y.1
169 set rset {}
170 set aset {}
171 foreach rx $nums2 {
172 if "\$rx $op \$r" {
173 lappend rset $rx
174 lappend aset $t1ra($rx)
177 puts "do_test $tname-2.$i.$subno.1 \173"
178 puts " db eval \173"
179 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a"
180 puts " \175"
181 puts "\175 {[sort $aset]}"
183 ################################################################ 2.x.y.2
184 puts "do_test $tname-2.$i.$subno.2 \173"
185 puts " db eval \173"
186 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a DESC"
187 puts " \175"
188 puts "\175 {[reverse [sort $aset]]}"
190 ################################################################ 2.x.y.3
191 set aset {}
192 foreach rx [sort $rset] {
193 lappend aset $t1ra($rx)
195 puts "do_test $tname-2.$i.$subno.3 \173"
196 puts " db eval \173"
197 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r"
198 puts " \175"
199 puts "\175 {$aset}"
201 ################################################################ 2.x.y.4
202 set aset {}
203 foreach rx [reverse [sort $rset]] {
204 lappend aset $t1ra($rx)
206 puts "do_test $tname-2.$i.$subno.4 \173"
207 puts " db eval \173"
208 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r DESC"
209 puts " \175"
210 puts "\175 {$aset}"
212 ################################################################ 2.x.y.5
213 set aset {}
214 set xset {}
215 foreach rx $rset {
216 lappend xset $t1rx($rx)
218 foreach x [sort $xset] {
219 set rx $t1xr($x)
220 lappend aset $t1ra($rx)
222 puts "do_test $tname-2.$i.$subno.5 \173"
223 puts " db eval \173"
224 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY x"
225 puts " \175"
226 puts "\175 {$aset}"
228 ################################################################ 2.x.y.10
229 if {abs($r)>9223372036854775808 || [string length $r5]>15} continue
230 set rset {}
231 set aset {}
232 foreach rx $nums2 {
233 if "\$rx $op \$r0" {
234 lappend rset $rx
237 foreach rx [sort $rset] {
238 lappend aset $t1ra($rx)
240 puts "do_test $tname-2.$i.$subno.10 \173"
241 puts " db eval \173"
242 puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r"
243 puts " \175"
244 puts "\175 {$aset}"
246 ################################################################ 2.x.y.11
247 set aset {}
248 foreach rx [reverse [sort $rset]] {
249 lappend aset $t1ra($rx)
251 puts "do_test $tname-2.$i.$subno.11 \173"
252 puts " db eval \173"
253 puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r DESC"
254 puts " \175"
255 puts "\175 {$aset}"
258 ################################################################ 2.x.y.12
259 set rset {}
260 set aset {}
261 foreach rx $nums2 {
262 if "\$rx $op \$r5" {
263 lappend rset $rx
266 foreach rx [sort $rset] {
267 lappend aset $t1ra($rx)
269 puts "do_test $tname-2.$i.$subno.12 \173"
270 puts " db eval \173"
271 puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r"
272 puts " \175"
273 puts "\175 {$aset}"
275 ################################################################ 2.x.y.13
276 set aset {}
277 foreach rx [reverse [sort $rset]] {
278 lappend aset $t1ra($rx)
280 puts "do_test $tname-2.$i.$subno.13 \173"
281 puts " db eval \173"
282 puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r DESC"
283 puts " \175"
284 puts "\175 {$aset}"
288 puts "do_test $tname-3.1 \173"
289 puts " db eval \173"
290 puts " DROP INDEX t1i1;"
291 puts " DROP INDEX t1i2;"
292 puts " DROP INDEX t1i3;"
293 puts " \175"
294 puts "\175 {}"
296 set i 0
297 foreach r $nums3 {
298 incr i
300 if {abs($r)<9.22337203685477580800e+18} {
301 set x $t1rx($r)
302 set a $t1ra($r)
303 set r5 $r.5
304 set r0 $r.0
305 puts "do_test $tname-4.$i.1 \173"
306 puts " db eval \173"
307 puts " SELECT * FROM t1 WHERE r=$r"
308 puts " \175"
309 puts "\175 {$r $a $x}"
310 puts "do_test $tname-4.$i.2 \173"
311 puts " db eval \173"
312 puts " SELECT r, a FROM t1 WHERE x='$x'"
313 puts " \175"
314 puts "\175 {$r $a}"
315 puts "do_test $tname-4.$i.3 \173"
316 puts " db eval \173"
317 puts " SELECT r, x FROM t1 WHERE a=$a"
318 puts " \175"
319 puts "\175 {$r $x}"
322 foreach op {> >= < <=} subno {gt ge lt le} {
324 ################################################################ 2.x.y.1
325 set rset {}
326 set aset {}
327 foreach rx $nums2 {
328 if "\$rx $op \$r" {
329 lappend rset $rx
330 lappend aset $t1ra($rx)
333 puts "do_test $tname-4.$i.$subno.1 \173"
334 puts " db eval \173"
335 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a"
336 puts " \175"
337 puts "\175 {[sort $aset]}"
339 ################################################################ 2.x.y.2
340 puts "do_test $tname-4.$i.$subno.2 \173"
341 puts " db eval \173"
342 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a DESC"
343 puts " \175"
344 puts "\175 {[reverse [sort $aset]]}"
346 ################################################################ 2.x.y.3
347 set aset {}
348 foreach rx [sort $rset] {
349 lappend aset $t1ra($rx)
351 puts "do_test $tname-4.$i.$subno.3 \173"
352 puts " db eval \173"
353 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r"
354 puts " \175"
355 puts "\175 {$aset}"
357 ################################################################ 2.x.y.4
358 set aset {}
359 foreach rx [reverse [sort $rset]] {
360 lappend aset $t1ra($rx)
362 puts "do_test $tname-4.$i.$subno.4 \173"
363 puts " db eval \173"
364 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r DESC"
365 puts " \175"
366 puts "\175 {$aset}"
368 ################################################################ 2.x.y.5
369 set aset {}
370 set xset {}
371 foreach rx $rset {
372 lappend xset $t1rx($rx)
374 foreach x [sort $xset] {
375 set rx $t1xr($x)
376 lappend aset $t1ra($rx)
378 puts "do_test $tname-4.$i.$subno.5 \173"
379 puts " db eval \173"
380 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY x"
381 puts " \175"
382 puts "\175 {$aset}"
384 ################################################################ 2.x.y.10
385 if {abs($r)>9223372036854775808 || [string length $r5]>15} continue
386 set rset {}
387 set aset {}
388 foreach rx $nums2 {
389 if "\$rx $op \$r0" {
390 lappend rset $rx
393 foreach rx [sort $rset] {
394 lappend aset $t1ra($rx)
396 puts "do_test $tname-4.$i.$subno.10 \173"
397 puts " db eval \173"
398 puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r"
399 puts " \175"
400 puts "\175 {$aset}"
402 ################################################################ 2.x.y.11
403 set aset {}
404 foreach rx [reverse [sort $rset]] {
405 lappend aset $t1ra($rx)
407 puts "do_test $tname-4.$i.$subno.11 \173"
408 puts " db eval \173"
409 puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r DESC"
410 puts " \175"
411 puts "\175 {$aset}"
414 ################################################################ 2.x.y.12
415 set rset {}
416 set aset {}
417 foreach rx $nums2 {
418 if "\$rx $op \$r5" {
419 lappend rset $rx
422 foreach rx [sort $rset] {
423 lappend aset $t1ra($rx)
425 puts "do_test $tname-4.$i.$subno.12 \173"
426 puts " db eval \173"
427 puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r"
428 puts " \175"
429 puts "\175 {$aset}"
431 ################################################################ 2.x.y.13
432 set aset {}
433 foreach rx [reverse [sort $rset]] {
434 lappend aset $t1ra($rx)
436 puts "do_test $tname-4.$i.$subno.13 \173"
437 puts " db eval \173"
438 puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r DESC"
439 puts " \175"
440 puts "\175 {$aset}"
445 puts {finish_test}