Additional test cases for the tointeger() and toreal() SQL functions when converting from a BLOB.

FossilOrigin-Name: e1814452faa698946ef77f06a42665277ee59cc1
This commit is contained in:
mistachkin 2013-09-04 00:58:00 +00:00
parent 1c215c9fd4
commit aeddf19e60
3 changed files with 198 additions and 58 deletions

View File

@ -1,5 +1,5 @@
C Merge\supdates\sfrom\strunk.
D 2013-09-01T23:36:44.564
C Additional\stest\scases\sfor\sthe\stointeger()\sand\storeal()\sSQL\sfunctions\swhen\sconverting\sfrom\sa\sBLOB.
D 2013-09-04T00:58:00.238
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -562,7 +562,7 @@ F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
F test/func.test cd25cf605c5a345d038dc7b84232204c6a901c84
F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
F test/func3.test 001021e5b88bd02a3b365a5c5fd8f6f49d39744a
F test/func4.test 4eaa19eed2fd37a39b4bb274c4bf84b142a9a40a
F test/func4.test 488c8deabf6a282e47aa5fcde782c6657e7625bc
F test/fuzz-oss1.test 4912e528ec9cf2f42134456933659d371c9e0d74
F test/fuzz.test 77fd50afc12847af50fcf1941679d90adebadde6
F test/fuzz2.test 207d0f9d06db3eaf47a6b7bfc835b8e2fc397167
@ -1110,7 +1110,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
P c4c53acb985a248c89db2d75025d941e3a4899bc c94933f13208f3f7d6d1b117ce6d2821100655a4
R 78e6edd05b7acf1ce753e27ea742b6df
P 2982725e12715fba425a46ae024f317f031b6a54
R c95b9007057313a186c90146fdfe015a
U mistachkin
Z e29db6a65ca4b79187ca51ff7b874db3
Z e95b03ef226de372c05086e066827ed5

View File

@ -1 +1 @@
2982725e12715fba425a46ae024f317f031b6a54
e1814452faa698946ef77f06a42665277ee59cc1

View File

@ -20,6 +20,9 @@ source $testdir/tester.tcl
set saved_tcl_precision $tcl_precision
set tcl_precision 0
set highPrecision(1) [expr \
{[memdbsql {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}]
do_execsql_test func4-1.1 {
SELECT tointeger(NULL);
} {{}}
@ -128,9 +131,11 @@ do_execsql_test func4-1.35 {
do_execsql_test func4-1.36 {
SELECT tointeger(9223372036854775807);
} {9223372036854775807}
do_execsql_test func4-1.37 {
SELECT tointeger(9223372036854775807 + 1);
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-1.37 {
SELECT tointeger(9223372036854775807 + 1);
} {{}}
}
do_execsql_test func4-1.38 {
SELECT tointeger(1.79769313486232e308 - 1);
} {{}}
@ -164,18 +169,20 @@ do_execsql_test func4-1.47 {
do_execsql_test func4-1.48 {
SELECT tointeger(9223372036854775807);
} {9223372036854775807}
do_execsql_test func4-1.49 {
SELECT tointeger(9223372036854775807 + 1);
} {{}}
do_execsql_test func4-1.50 {
SELECT tointeger(9223372036854775808 - 1);
} {{}}
do_execsql_test func4-1.51 {
SELECT tointeger(9223372036854775808);
} {{}}
do_execsql_test func4-1.52 {
SELECT tointeger(9223372036854775808 + 1);
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-1.49 {
SELECT tointeger(9223372036854775807 + 1);
} {{}}
do_execsql_test func4-1.50 {
SELECT tointeger(9223372036854775808 - 1);
} {{}}
do_execsql_test func4-1.51 {
SELECT tointeger(9223372036854775808);
} {{}}
do_execsql_test func4-1.52 {
SELECT tointeger(9223372036854775808 + 1);
} {{}}
}
do_execsql_test func4-1.53 {
SELECT tointeger(18446744073709551616 - 1);
} {{}}
@ -187,7 +194,7 @@ do_execsql_test func4-1.55 {
} {{}}
ifcapable floatingpoint {
set highPrecision [expr \
set highPrecision(2) [expr \
{[memdbsql {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}]
do_execsql_test func4-2.1 {
@ -262,7 +269,7 @@ ifcapable floatingpoint {
do_execsql_test func4-2.24 {
SELECT toreal(-9223372036854775808);
} {-9.223372036854776e+18}
if {$highPrecision} {
if {$highPrecision(2)} {
do_execsql_test func4-2.25 {
SELECT toreal(-9223372036854775808 + 1);
} {{}}
@ -270,7 +277,7 @@ ifcapable floatingpoint {
do_execsql_test func4-2.26 {
SELECT toreal(-9223372036854775807 - 1);
} {-9.223372036854776e+18}
if {$highPrecision} {
if {$highPrecision(2)} {
do_execsql_test func4-2.27 {
SELECT toreal(-9223372036854775807);
} {{}}
@ -296,13 +303,15 @@ ifcapable floatingpoint {
do_execsql_test func4-2.34 {
SELECT toreal(2147483647 + 1);
} {2147483648.0}
if {$highPrecision} {
if {$highPrecision(2)} {
do_execsql_test func4-2.35 {
SELECT toreal(9223372036854775807 - 1);
} {{}}
do_execsql_test func4-2.36 {
SELECT toreal(9223372036854775807);
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-2.36 {
SELECT toreal(9223372036854775807);
} {{}}
}
}
do_execsql_test func4-2.37 {
SELECT toreal(9223372036854775807 + 1);
@ -331,7 +340,7 @@ ifcapable floatingpoint {
do_execsql_test func4-2.45 {
SELECT toreal(9007199254740992);
} {9007199254740992.0}
if {$highPrecision} {
if {$highPrecision(2)} {
do_execsql_test func4-2.46 {
SELECT toreal(9007199254740992 + 1);
} {{}}
@ -342,12 +351,14 @@ ifcapable floatingpoint {
do_execsql_test func4-2.48 {
SELECT toreal(tointeger(9223372036854775808) - 1);
} {{}}
do_execsql_test func4-2.49 {
SELECT toreal(tointeger(9223372036854775808));
} {{}}
do_execsql_test func4-2.50 {
SELECT toreal(tointeger(9223372036854775808) + 1);
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-2.49 {
SELECT toreal(tointeger(9223372036854775808));
} {{}}
do_execsql_test func4-2.50 {
SELECT toreal(tointeger(9223372036854775808) + 1);
} {{}}
}
do_execsql_test func4-2.51 {
SELECT toreal(tointeger(18446744073709551616) - 1);
} {{}}
@ -450,11 +461,13 @@ ifcapable check {
INSERT INTO t1 (x) VALUES ('-9223372036854775809');
}
} {1 {constraint failed}}
do_test func4-3.19 {
catchsql {
INSERT INTO t1 (x) VALUES (9223372036854775808);
}
} {1 {constraint failed}}
if {$highPrecision(1)} {
do_test func4-3.19 {
catchsql {
INSERT INTO t1 (x) VALUES (9223372036854775808);
}
} {1 {constraint failed}}
}
do_execsql_test func4-3.20 {
SELECT x FROM t1 ORDER BY x;
} {1234 1234 1234}
@ -563,7 +576,7 @@ ifcapable floatingpoint {
do_execsql_test func4-5.7 {
SELECT tointeger(toreal(-9223372036854775808));
} {-9223372036854775808}
if {$highPrecision} {
if {$highPrecision(2)} {
do_execsql_test func4-5.8 {
SELECT tointeger(toreal(-9223372036854775808 + 1));
} {{}}
@ -589,12 +602,14 @@ ifcapable floatingpoint {
do_execsql_test func4-5.15 {
SELECT tointeger(toreal(9223372036854775807 - 1));
} {{}}
do_execsql_test func4-5.16 {
SELECT tointeger(toreal(9223372036854775807));
} {{}}
do_execsql_test func4-5.17 {
SELECT tointeger(toreal(9223372036854775807 + 1));
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-5.16 {
SELECT tointeger(toreal(9223372036854775807));
} {{}}
do_execsql_test func4-5.17 {
SELECT tointeger(toreal(9223372036854775807 + 1));
} {{}}
}
do_execsql_test func4-5.18 {
SELECT tointeger(toreal(4503599627370496 - 1));
} {4503599627370495}
@ -610,7 +625,7 @@ ifcapable floatingpoint {
do_execsql_test func4-5.22 {
SELECT tointeger(toreal(9007199254740992));
} {9007199254740992}
if {$highPrecision} {
if {$highPrecision(2)} {
do_execsql_test func4-5.23 {
SELECT tointeger(toreal(9007199254740992 + 1));
} {{}}
@ -618,15 +633,17 @@ ifcapable floatingpoint {
do_execsql_test func4-5.24 {
SELECT tointeger(toreal(9007199254740992 + 2));
} {9007199254740994}
do_execsql_test func4-5.25 {
SELECT tointeger(toreal(9223372036854775808 - 1));
} {{}}
do_execsql_test func4-5.26 {
SELECT tointeger(toreal(9223372036854775808));
} {{}}
do_execsql_test func4-5.27 {
SELECT tointeger(toreal(9223372036854775808 + 1));
} {{}}
if {$highPrecision(1)} {
do_execsql_test func4-5.25 {
SELECT tointeger(toreal(9223372036854775808 - 1));
} {{}}
do_execsql_test func4-5.26 {
SELECT tointeger(toreal(9223372036854775808));
} {{}}
do_execsql_test func4-5.27 {
SELECT tointeger(toreal(9223372036854775808 + 1));
} {{}}
}
do_execsql_test func4-5.28 {
SELECT tointeger(toreal(18446744073709551616 - 1));
} {{}}
@ -638,6 +655,129 @@ ifcapable floatingpoint {
} {{}}
}
for {set i 0} {$i < 10} {incr i} {
if {$i == 8} continue
do_execsql_test func4-6.1.$i.1 [subst {
SELECT tointeger(x'[string repeat 01 $i]');
}] {{}}
ifcapable floatingpoint {
do_execsql_test func4-6.1.$i.2 [subst {
SELECT toreal(x'[string repeat 01 $i]');
}] {{}}
}
}
proc swapHexBytes { value } {
if {[string length $value] % 2 != 0} {
error "value \"$value\" must have an even number of characters"
}
if {![string is xdigit -strict $value]} then {
error "value \"$value\" must contain only hexadecimal digits"
}
join [lreverse [regexp -all -inline {.{2}} $value]] ""
}
proc swapIntegerHexBytes { value } {
if {![info exists ::tcl_platform(byteOrder)] || \
$::tcl_platform(byteOrder) eq "littleEndian"} {
return $value
}
return [swapHexBytes $value]
}
proc swapDoubleHexBytes { value } {
if {![info exists ::tcl_platform(byteOrder)] || \
$::tcl_platform(byteOrder) ne "littleEndian"} {
return $value
}
return [swapHexBytes $value]
}
do_execsql_test func4-6.2.1 [subst {
SELECT tointeger(x'[swapIntegerHexBytes 0102030405060708]');
}] {578437695752307201}
do_execsql_test func4-6.2.2 [subst {
SELECT tointeger(x'[swapIntegerHexBytes 0807060504030201]');
}] {72623859790382856}
ifcapable floatingpoint {
do_execsql_test func4-6.3.1 [subst {
SELECT toreal(x'[swapDoubleHexBytes ffefffffffffffff]');
}] {-1.7976931348623157e+308}
do_execsql_test func4-6.3.2 [subst {
SELECT toreal(x'[swapDoubleHexBytes 8010000000000000]');
}] {-2.2250738585072014e-308}
do_execsql_test func4-6.3.3 [subst {
SELECT toreal(x'[swapDoubleHexBytes c000000000000000]');
}] {-2.0}
do_execsql_test func4-6.3.4 [subst {
SELECT toreal(x'[swapDoubleHexBytes bff0000000000000]');
}] {-1.0}
do_execsql_test func4-6.3.5 [subst {
SELECT toreal(x'[swapDoubleHexBytes 8000000000000000]');
}] {-0.0}
do_execsql_test func4-6.3.6 [subst {
SELECT toreal(x'[swapDoubleHexBytes 0000000000000000]');
}] {0.0}
do_execsql_test func4-6.3.7 [subst {
SELECT toreal(x'[swapDoubleHexBytes 3ff0000000000000]');
}] {1.0}
do_execsql_test func4-6.3.8 [subst {
SELECT toreal(x'[swapDoubleHexBytes 4000000000000000]');
}] {2.0}
do_execsql_test func4-6.3.9 [subst {
SELECT toreal(x'[swapDoubleHexBytes 0010000000000000]');
}] {2.2250738585072014e-308}
do_execsql_test func4-6.3.10 [subst {
SELECT toreal(x'[swapDoubleHexBytes 7fefffffffffffff]');
}] {1.7976931348623157e+308}
do_execsql_test func4-6.3.11 [subst {
SELECT toreal(x'[swapDoubleHexBytes 8000000000000001]');
}] {-5e-324}
do_execsql_test func4-6.3.12 [subst {
SELECT toreal(x'[swapDoubleHexBytes 800fffffffffffff]');
}] {-2.225073858507201e-308}
do_execsql_test func4-6.3.13 [subst {
SELECT toreal(x'[swapDoubleHexBytes 0000000000000001]');
}] {5e-324}
do_execsql_test func4-6.3.14 [subst {
SELECT toreal(x'[swapDoubleHexBytes 000fffffffffffff]');
}] {2.225073858507201e-308}
do_execsql_test func4-6.3.15 [subst {
SELECT toreal(x'[swapDoubleHexBytes fff0000000000000]');
}] {-Inf}
do_execsql_test func4-6.3.16 [subst {
SELECT toreal(x'[swapDoubleHexBytes 7ff0000000000000]');
}] {Inf}
do_execsql_test func4-6.3.17 [subst {
SELECT toreal(x'[swapDoubleHexBytes fff8000000000000]');
}] {{}}
do_execsql_test func4-6.3.18 [subst {
SELECT toreal(x'[swapDoubleHexBytes fff0000000000001]');
}] {{}}
do_execsql_test func4-6.3.19 [subst {
SELECT toreal(x'[swapDoubleHexBytes fff7ffffffffffff]');
}] {{}}
do_execsql_test func4-6.3.20 [subst {
SELECT toreal(x'[swapDoubleHexBytes 7ff0000000000001]');
}] {{}}
do_execsql_test func4-6.3.21 [subst {
SELECT toreal(x'[swapDoubleHexBytes 7ff7ffffffffffff]');
}] {{}}
do_execsql_test func4-6.3.22 [subst {
SELECT toreal(x'[swapDoubleHexBytes fff8000000000001]');
}] {{}}
do_execsql_test func4-6.3.23 [subst {
SELECT toreal(x'[swapDoubleHexBytes ffffffffffffffff]');
}] {{}}
do_execsql_test func4-6.3.24 [subst {
SELECT toreal(x'[swapDoubleHexBytes 7ff8000000000000]');
}] {{}}
do_execsql_test func4-6.3.25 [subst {
SELECT toreal(x'[swapDoubleHexBytes 7fffffffffffffff]');
}] {{}}
}
set tcl_precision $saved_tcl_precision
unset saved_tcl_precision
finish_test