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: boundary3.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"
135 puts "do_test $tname-1.3 \173"
137 puts " CREATE TABLE t2(r,a);"
138 puts " INSERT INTO t2 SELECT rowid, a FROM t1;"
139 puts " CREATE INDEX t2i1 ON t2(r);"
140 puts " CREATE INDEX t2i2 ON t2(a);"
141 puts " INSERT INTO t2 VALUES(9.22337303685477580800e+18,65);"
142 set t1ra
(9.22337303685477580800e+18) 65
143 set t1ar
(65) 9.22337303685477580800e+18)
144 puts " INSERT INTO t2 VALUES(-9.22337303685477580800e+18,66);"
145 set t1ra
(-9.22337303685477580800e
+18
) 66
146 set t1ar
(66) -9.22337303685477580800e
+18
)
147 puts " SELECT count(*) FROM t2;"
152 lappend nums3
9.22337303685477580800e+18
153 lappend nums3
-9.22337303685477580800e
+18
161 if {abs
($r)<9.22337203685477580800e+18} {
164 puts "do_test $tname-2.$i.1 \173"
166 puts " SELECT t1.* FROM t1, t2 WHERE t1.rowid=$r AND t2.a=t1.a"
169 puts "do_test $tname-2.$i.2 \173"
171 puts " SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='$x'"
174 puts "do_test $tname-2.$i.3 \173"
176 puts " SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=$a"
181 foreach op
{> >= < <=} subno
{gt ge lt le
} {
183 ################################################################ 2.x.y.1
189 lappend aset
$t1ra($rx)
192 puts "do_test $tname-2.$i.$subno.1 \173"
194 puts " SELECT t2.a FROM t1 JOIN t2 USING(a)"
195 puts " WHERE t1.rowid $op $r ORDER BY t2.a"
197 puts "\175 {[sort $aset]}"
199 ################################################################ 2.x.y.2
200 puts "do_test $tname-2.$i.$subno.2 \173"
202 puts " SELECT t2.a FROM t2 NATURAL JOIN t1"
203 puts " WHERE t1.rowid $op $r ORDER BY t1.a DESC"
205 puts "\175 {[reverse [sort $aset]]}"
208 ################################################################ 2.x.y.3
211 foreach rx
[sort
$rset] {
212 lappend aset
$t1ra($rx)
214 puts "do_test $tname-2.$i.$subno.3 \173"
216 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
217 puts " WHERE t2.a=$ax"
218 puts " ORDER BY t1.rowid"
222 ################################################################ 2.x.y.4
224 foreach rx
[reverse
[sort
$rset]] {
225 lappend aset
$t1ra($rx)
227 puts "do_test $tname-2.$i.$subno.4 \173"
229 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
230 puts " WHERE t2.a=$ax"
231 puts " ORDER BY t1.rowid DESC"
235 ################################################################ 2.x.y.5
239 lappend xset
$t1rx($rx)
241 foreach x
[sort
$xset] {
243 lappend aset
$t1ra($rx)
245 puts "do_test $tname-2.$i.$subno.5 \173"
247 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op t2.r"
248 puts " WHERE t2.a=$ax"
253 ################################################################ 2.x.y.10
254 if {[string length
$r5]>15} continue
262 foreach rx
[sort
$rset] {
263 lappend aset
$t1ra($rx)
265 puts "do_test $tname-2.$i.$subno.10 \173"
267 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op CAST(t2.r AS real)"
268 puts " WHERE t2.a=$ax"
269 puts " ORDER BY t1.rowid"
273 ################################################################ 2.x.y.11
275 foreach rx
[reverse
[sort
$rset]] {
276 lappend aset
$t1ra($rx)
278 puts "do_test $tname-2.$i.$subno.11 \173"
280 puts " SELECT t1.a FROM t1 JOIN t2 ON t1.rowid $op CAST(t2.r AS real)"
281 puts " WHERE t2.a=$ax"
282 puts " ORDER BY t1.rowid DESC"