1: puts {# 2008 December 11
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.
12: #
13: # This file is automatically generated from a separate TCL script.
14: # This file seeks to exercise integer boundary values.
15: #
16: # $Id: boundary1.tcl,v 1.1.1.1 2012/02/21 17:04:16 misho Exp $
17:
18: set testdir [file dirname $argv0]
19: source $testdir/tester.tcl
20:
21: # Many of the boundary tests depend on a working 64-bit implementation.
22: if {![working_64bit_int]} { finish_test; return }
23: }
24:
25: expr srand(0)
26:
27: # Generate interesting boundary numbers
28: #
29: foreach x {
30: 0
31: 1
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
48: }
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)}]
54: }
55:
56: # Scramble the $inlist into a random order.
57: #
58: proc scramble {inlist} {
59: set y {}
60: foreach x $inlist {
61: lappend y [list [expr {rand()}] $x]
62: }
63: set y [lsort $y]
64: set outlist {}
65: foreach x $y {
66: lappend outlist [lindex $x 1]
67: }
68: return $outlist
69: }
70:
71: # A simple selection sort. Not trying to be efficient.
72: #
73: proc sort {inlist} {
74: set outlist {}
75: set mn [lindex $inlist 0]
76: foreach x $inlist {
77: if {$x<$mn} {set mn $x}
78: }
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
87: }
88: }
89: if {!$valid} break
90: lappend outlist $mn
91: set mx $mn
92: }
93: return $outlist
94: }
95:
96: # Reverse the order of a list
97: #
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]
103: }
104: return $outlist
105: }
106:
107: set nums1 [scramble [array names boundarynum]]
108: set nums2 [scramble [array names boundarynum]]
109:
110: set tname boundary1
111: puts "do_test $tname-1.1 \173"
112: puts " db eval \173"
113: puts " CREATE TABLE t1(a,x);"
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(oid,a,x) VALUES($r,$a,'$x');"
123: }
124: puts " CREATE INDEX t1i1 ON t1(a);"
125: puts " CREATE INDEX t1i2 ON t1(x);"
126: puts " \175"
127: puts "\175 {}"
128:
129: puts "do_test $tname-1.2 \173"
130: puts " db eval \173"
131: puts " SELECT count(*) FROM t1"
132: puts " \175"
133: puts "\175 {64}"
134:
135: set nums3 $nums2
136: lappend nums3 9.22337303685477580800e+18
137: lappend nums3 -9.22337303685477580800e+18
138:
139: set i 0
140: foreach r $nums3 {
141: incr i
142:
143: if {abs($r)<9.22337203685477580800e+18} {
144: set x $t1rx($r)
145: set a $t1ra($r)
146: set r5 $r.5
147: set r0 $r.0
148: puts "do_test $tname-2.$i.1 \173"
149: puts " db eval \173"
150: puts " SELECT * FROM t1 WHERE rowid=$r"
151: puts " \175"
152: puts "\175 {$a $x}"
153: puts "do_test $tname-2.$i.2 \173"
154: puts " db eval \173"
155: puts " SELECT rowid, a FROM t1 WHERE x='$x'"
156: puts " \175"
157: puts "\175 {$r $a}"
158: puts "do_test $tname-2.$i.3 \173"
159: puts " db eval \173"
160: puts " SELECT rowid, x FROM t1 WHERE a=$a"
161: puts " \175"
162: puts "\175 {$r $x}"
163: }
164:
165: foreach op {> >= < <=} subno {gt ge lt le} {
166:
167: ################################################################ 2.x.y.1
168: set rset {}
169: set aset {}
170: foreach rx $nums2 {
171: if "\$rx $op \$r" {
172: lappend rset $rx
173: lappend aset $t1ra($rx)
174: }
175: }
176: puts "do_test $tname-2.$i.$subno.1 \173"
177: puts " db eval \173"
178: puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a"
179: puts " \175"
180: puts "\175 {[sort $aset]}"
181:
182: ################################################################ 2.x.y.2
183: puts "do_test $tname-2.$i.$subno.2 \173"
184: puts " db eval \173"
185: puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a DESC"
186: puts " \175"
187: puts "\175 {[reverse [sort $aset]]}"
188:
189: ################################################################ 2.x.y.3
190: set aset {}
191: foreach rx [sort $rset] {
192: lappend aset $t1ra($rx)
193: }
194: puts "do_test $tname-2.$i.$subno.3 \173"
195: puts " db eval \173"
196: puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid"
197: puts " \175"
198: puts "\175 {$aset}"
199:
200: ################################################################ 2.x.y.4
201: set aset {}
202: foreach rx [reverse [sort $rset]] {
203: lappend aset $t1ra($rx)
204: }
205: puts "do_test $tname-2.$i.$subno.4 \173"
206: puts " db eval \173"
207: puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid DESC"
208: puts " \175"
209: puts "\175 {$aset}"
210:
211: ################################################################ 2.x.y.5
212: set aset {}
213: set xset {}
214: foreach rx $rset {
215: lappend xset $t1rx($rx)
216: }
217: foreach x [sort $xset] {
218: set rx $t1xr($x)
219: lappend aset $t1ra($rx)
220: }
221: puts "do_test $tname-2.$i.$subno.5 \173"
222: puts " db eval \173"
223: puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY x"
224: puts " \175"
225: puts "\175 {$aset}"
226:
227: ################################################################ 2.x.y.10
228: if {abs($r)>9223372036854775808 || [string length $r5]>15} continue
229: set rset {}
230: set aset {}
231: foreach rx $nums2 {
232: if "\$rx $op \$r0" {
233: lappend rset $rx
234: }
235: }
236: foreach rx [sort $rset] {
237: lappend aset $t1ra($rx)
238: }
239: puts "do_test $tname-2.$i.$subno.10 \173"
240: puts " db eval \173"
241: puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid"
242: puts " \175"
243: puts "\175 {$aset}"
244:
245: ################################################################ 2.x.y.11
246: set aset {}
247: foreach rx [reverse [sort $rset]] {
248: lappend aset $t1ra($rx)
249: }
250: puts "do_test $tname-2.$i.$subno.11 \173"
251: puts " db eval \173"
252: puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid DESC"
253: puts " \175"
254: puts "\175 {$aset}"
255:
256:
257: ################################################################ 2.x.y.12
258: set rset {}
259: set aset {}
260: foreach rx $nums2 {
261: if "\$rx $op \$r5" {
262: lappend rset $rx
263: }
264: }
265: foreach rx [sort $rset] {
266: lappend aset $t1ra($rx)
267: }
268: puts "do_test $tname-2.$i.$subno.12 \173"
269: puts " db eval \173"
270: puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid"
271: puts " \175"
272: puts "\175 {$aset}"
273:
274: ################################################################ 2.x.y.13
275: set aset {}
276: foreach rx [reverse [sort $rset]] {
277: lappend aset $t1ra($rx)
278: }
279: puts "do_test $tname-2.$i.$subno.13 \173"
280: puts " db eval \173"
281: puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid DESC"
282: puts " \175"
283: puts "\175 {$aset}"
284: }
285:
286: }
287:
288:
289: puts {finish_test}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>