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 }
27 # Generate interesting boundary numbers
41 set x
[expr {wide
($x)}]
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
} {
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
} {
61 lappend y
[list [expr {rand
()}] $x]
66 lappend outlist
[lindex $x 1]
71 # A simple selection sort. Not trying to be efficient.
75 set mn
[lindex $inlist 0]
77 if {$x<$mn} {set mn
$x}
84 if {$x>$mx && (!$valid ||
$mn>$x)} {
96 # Reverse the order of a list
98 proc reverse
{inlist
} {
99 set i
[llength $inlist]
101 for {incr i
-1} {$i>=0} {incr i
-1} {
102 lappend outlist
[lindex $inlist $i]
107 set nums1
[scramble
[array names boundarynum
]]
108 set nums2
[scramble
[array names boundarynum
]]
111 puts "do_test $tname-1.1 \173"
113 puts " CREATE TABLE t1(r INTEGER, a INTEGER, x TEXT);"
119 set x
[format %08x
%08x
[expr {wide
($r)>>32}] $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);"
130 puts "do_test $tname-1.2 \173"
132 puts " SELECT count(*) FROM t1"
137 lappend nums3
9.22337303685477580800e+18
138 lappend nums3
-9.22337303685477580800e
+18
144 if {abs
($r)<9.22337203685477580800e+18} {
149 puts "do_test $tname-2.$i.1 \173"
151 puts " SELECT * FROM t1 WHERE r=$r"
153 puts "\175 {$r $a $x}"
154 puts "do_test $tname-2.$i.2 \173"
156 puts " SELECT r, a FROM t1 WHERE x='$x'"
159 puts "do_test $tname-2.$i.3 \173"
161 puts " SELECT r, x FROM t1 WHERE a=$a"
166 foreach op
{> >= < <=} subno
{gt ge lt le
} {
168 ################################################################ 2.x.y.1
174 lappend aset
$t1ra($rx)
177 puts "do_test $tname-2.$i.$subno.1 \173"
179 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a"
181 puts "\175 {[sort $aset]}"
183 ################################################################ 2.x.y.2
184 puts "do_test $tname-2.$i.$subno.2 \173"
186 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a DESC"
188 puts "\175 {[reverse [sort $aset]]}"
190 ################################################################ 2.x.y.3
192 foreach rx
[sort
$rset] {
193 lappend aset
$t1ra($rx)
195 puts "do_test $tname-2.$i.$subno.3 \173"
197 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r"
201 ################################################################ 2.x.y.4
203 foreach rx
[reverse
[sort
$rset]] {
204 lappend aset
$t1ra($rx)
206 puts "do_test $tname-2.$i.$subno.4 \173"
208 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r DESC"
212 ################################################################ 2.x.y.5
216 lappend xset
$t1rx($rx)
218 foreach x
[sort
$xset] {
220 lappend aset
$t1ra($rx)
222 puts "do_test $tname-2.$i.$subno.5 \173"
224 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY x"
228 ################################################################ 2.x.y.10
229 if {abs
($r)>9223372036854775808 ||
[string length
$r5]>15} continue
237 foreach rx
[sort
$rset] {
238 lappend aset
$t1ra($rx)
240 puts "do_test $tname-2.$i.$subno.10 \173"
242 puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r"
246 ################################################################ 2.x.y.11
248 foreach rx
[reverse
[sort
$rset]] {
249 lappend aset
$t1ra($rx)
251 puts "do_test $tname-2.$i.$subno.11 \173"
253 puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r DESC"
258 ################################################################ 2.x.y.12
266 foreach rx
[sort
$rset] {
267 lappend aset
$t1ra($rx)
269 puts "do_test $tname-2.$i.$subno.12 \173"
271 puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r"
275 ################################################################ 2.x.y.13
277 foreach rx
[reverse
[sort
$rset]] {
278 lappend aset
$t1ra($rx)
280 puts "do_test $tname-2.$i.$subno.13 \173"
282 puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r DESC"
288 puts "do_test $tname-3.1 \173"
290 puts " DROP INDEX t1i1;"
291 puts " DROP INDEX t1i2;"
292 puts " DROP INDEX t1i3;"
300 if {abs
($r)<9.22337203685477580800e+18} {
305 puts "do_test $tname-4.$i.1 \173"
307 puts " SELECT * FROM t1 WHERE r=$r"
309 puts "\175 {$r $a $x}"
310 puts "do_test $tname-4.$i.2 \173"
312 puts " SELECT r, a FROM t1 WHERE x='$x'"
315 puts "do_test $tname-4.$i.3 \173"
317 puts " SELECT r, x FROM t1 WHERE a=$a"
322 foreach op
{> >= < <=} subno
{gt ge lt le
} {
324 ################################################################ 2.x.y.1
330 lappend aset
$t1ra($rx)
333 puts "do_test $tname-4.$i.$subno.1 \173"
335 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a"
337 puts "\175 {[sort $aset]}"
339 ################################################################ 2.x.y.2
340 puts "do_test $tname-4.$i.$subno.2 \173"
342 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a DESC"
344 puts "\175 {[reverse [sort $aset]]}"
346 ################################################################ 2.x.y.3
348 foreach rx
[sort
$rset] {
349 lappend aset
$t1ra($rx)
351 puts "do_test $tname-4.$i.$subno.3 \173"
353 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r"
357 ################################################################ 2.x.y.4
359 foreach rx
[reverse
[sort
$rset]] {
360 lappend aset
$t1ra($rx)
362 puts "do_test $tname-4.$i.$subno.4 \173"
364 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r DESC"
368 ################################################################ 2.x.y.5
372 lappend xset
$t1rx($rx)
374 foreach x
[sort
$xset] {
376 lappend aset
$t1ra($rx)
378 puts "do_test $tname-4.$i.$subno.5 \173"
380 puts " SELECT a FROM t1 WHERE r $op $r ORDER BY x"
384 ################################################################ 2.x.y.10
385 if {abs
($r)>9223372036854775808 ||
[string length
$r5]>15} continue
393 foreach rx
[sort
$rset] {
394 lappend aset
$t1ra($rx)
396 puts "do_test $tname-4.$i.$subno.10 \173"
398 puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r"
402 ################################################################ 2.x.y.11
404 foreach rx
[reverse
[sort
$rset]] {
405 lappend aset
$t1ra($rx)
407 puts "do_test $tname-4.$i.$subno.11 \173"
409 puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r DESC"
414 ################################################################ 2.x.y.12
422 foreach rx
[sort
$rset] {
423 lappend aset
$t1ra($rx)
425 puts "do_test $tname-4.$i.$subno.12 \173"
427 puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r"
431 ################################################################ 2.x.y.13
433 foreach rx
[reverse
[sort
$rset]] {
434 lappend aset
$t1ra($rx)
436 puts "do_test $tname-4.$i.$subno.13 \173"
438 puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r DESC"