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: boundary1.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(a,x);"
119 set x
[format %08x
%08x
[expr {wide
($r)>>32}] $r]
122 puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');"
124 puts " CREATE INDEX t1i1 ON t1(a);"
125 puts " CREATE INDEX t1i2 ON t1(x);"
129 puts "do_test $tname-1.2 \173"
131 puts " SELECT count(*) FROM t1"
136 lappend nums3
9.22337303685477580800e+18
137 lappend nums3
-9.22337303685477580800e
+18
143 if {abs
($r)<9.22337203685477580800e+18} {
148 puts "do_test $tname-2.$i.1 \173"
150 puts " SELECT * FROM t1 WHERE rowid=$r"
153 puts "do_test $tname-2.$i.2 \173"
155 puts " SELECT rowid, a FROM t1 WHERE x='$x'"
158 puts "do_test $tname-2.$i.3 \173"
160 puts " SELECT rowid, x FROM t1 WHERE a=$a"
165 foreach op
{> >= < <=} subno
{gt ge lt le
} {
167 ################################################################ 2.x.y.1
173 lappend aset
$t1ra($rx)
176 puts "do_test $tname-2.$i.$subno.1 \173"
178 puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a"
180 puts "\175 {[sort $aset]}"
182 ################################################################ 2.x.y.2
183 puts "do_test $tname-2.$i.$subno.2 \173"
185 puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a DESC"
187 puts "\175 {[reverse [sort $aset]]}"
189 ################################################################ 2.x.y.3
191 foreach rx
[sort
$rset] {
192 lappend aset
$t1ra($rx)
194 puts "do_test $tname-2.$i.$subno.3 \173"
196 puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid"
200 ################################################################ 2.x.y.4
202 foreach rx
[reverse
[sort
$rset]] {
203 lappend aset
$t1ra($rx)
205 puts "do_test $tname-2.$i.$subno.4 \173"
207 puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid DESC"
211 ################################################################ 2.x.y.5
215 lappend xset
$t1rx($rx)
217 foreach x
[sort
$xset] {
219 lappend aset
$t1ra($rx)
221 puts "do_test $tname-2.$i.$subno.5 \173"
223 puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY x"
227 ################################################################ 2.x.y.10
228 if {abs
($r)>9223372036854775808 ||
[string length
$r5]>15} continue
236 foreach rx
[sort
$rset] {
237 lappend aset
$t1ra($rx)
239 puts "do_test $tname-2.$i.$subno.10 \173"
241 puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid"
245 ################################################################ 2.x.y.11
247 foreach rx
[reverse
[sort
$rset]] {
248 lappend aset
$t1ra($rx)
250 puts "do_test $tname-2.$i.$subno.11 \173"
252 puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid DESC"
257 ################################################################ 2.x.y.12
265 foreach rx
[sort
$rset] {
266 lappend aset
$t1ra($rx)
268 puts "do_test $tname-2.$i.$subno.12 \173"
270 puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid"
274 ################################################################ 2.x.y.13
276 foreach rx
[reverse
[sort
$rset]] {
277 lappend aset
$t1ra($rx)
279 puts "do_test $tname-2.$i.$subno.13 \173"
281 puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid DESC"