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