1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/badutf.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,143 @@
1.4 +# 2007 May 15
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library.
1.15 +#
1.16 +# This file checks to make sure SQLite is able to gracefully
1.17 +# handle malformed UTF-8.
1.18 +#
1.19 +# $Id: badutf.test,v 1.2 2007/09/12 17:01:45 danielk1977 Exp $
1.20 +
1.21 +set testdir [file dirname $argv0]
1.22 +source $testdir/tester.tcl
1.23 +
1.24 +do_test badutf-1.1 {
1.25 + db eval {PRAGMA encoding=UTF8}
1.26 + sqlite3_exec db {SELECT hex('%80') AS x}
1.27 +} {0 {x 80}}
1.28 +do_test badutf-1.2 {
1.29 + sqlite3_exec db {SELECT hex('%81') AS x}
1.30 +} {0 {x 81}}
1.31 +do_test badutf-1.3 {
1.32 + sqlite3_exec db {SELECT hex('%bf') AS x}
1.33 +} {0 {x BF}}
1.34 +do_test badutf-1.4 {
1.35 + sqlite3_exec db {SELECT hex('%c0') AS x}
1.36 +} {0 {x C0}}
1.37 +do_test badutf-1.5 {
1.38 + sqlite3_exec db {SELECT hex('%e0') AS x}
1.39 +} {0 {x E0}}
1.40 +do_test badutf-1.6 {
1.41 + sqlite3_exec db {SELECT hex('%f0') AS x}
1.42 +} {0 {x F0}}
1.43 +do_test badutf-1.7 {
1.44 + sqlite3_exec db {SELECT hex('%ff') AS x}
1.45 +} {0 {x FF}}
1.46 +
1.47 +sqlite3 db2 {}
1.48 +ifcapable utf16 {
1.49 + do_test badutf-1.10 {
1.50 + db2 eval {PRAGMA encoding=UTF16be}
1.51 + sqlite3_exec db2 {SELECT hex('%80') AS x}
1.52 + } {0 {x 0080}}
1.53 + do_test badutf-1.11 {
1.54 + sqlite3_exec db2 {SELECT hex('%81') AS x}
1.55 + } {0 {x 0081}}
1.56 + do_test badutf-1.12 {
1.57 + sqlite3_exec db2 {SELECT hex('%bf') AS x}
1.58 + } {0 {x 00BF}}
1.59 + do_test badutf-1.13 {
1.60 + sqlite3_exec db2 {SELECT hex('%c0') AS x}
1.61 + } {0 {x FFFD}}
1.62 + do_test badutf-1.14 {
1.63 + sqlite3_exec db2 {SELECT hex('%c1') AS x}
1.64 + } {0 {x FFFD}}
1.65 + do_test badutf-1.15 {
1.66 + sqlite3_exec db2 {SELECT hex('%c0%bf') AS x}
1.67 + } {0 {x FFFD}}
1.68 + do_test badutf-1.16 {
1.69 + sqlite3_exec db2 {SELECT hex('%c1%bf') AS x}
1.70 + } {0 {x FFFD}}
1.71 + do_test badutf-1.17 {
1.72 + sqlite3_exec db2 {SELECT hex('%c3%bf') AS x}
1.73 + } {0 {x 00FF}}
1.74 + do_test badutf-1.18 {
1.75 + sqlite3_exec db2 {SELECT hex('%e0') AS x}
1.76 + } {0 {x FFFD}}
1.77 + do_test badutf-1.19 {
1.78 + sqlite3_exec db2 {SELECT hex('%f0') AS x}
1.79 + } {0 {x FFFD}}
1.80 + do_test badutf-1.20 {
1.81 + sqlite3_exec db2 {SELECT hex('%ff') AS x}
1.82 + } {0 {x FFFD}}
1.83 +}
1.84 +
1.85 +
1.86 +ifcapable bloblit {
1.87 + do_test badutf-2.1 {
1.88 + sqlite3_exec db {SELECT '%80'=CAST(x'80' AS text) AS x}
1.89 + } {0 {x 1}}
1.90 + do_test badutf-2.2 {
1.91 + sqlite3_exec db {SELECT CAST('%80' AS blob)=x'80' AS x}
1.92 + } {0 {x 1}}
1.93 +}
1.94 +
1.95 +do_test badutf-3.1 {
1.96 + sqlite3_exec db {SELECT length('%80') AS x}
1.97 +} {0 {x 1}}
1.98 +do_test badutf-3.2 {
1.99 + sqlite3_exec db {SELECT length('%61%62%63') AS x}
1.100 +} {0 {x 3}}
1.101 +do_test badutf-3.3 {
1.102 + sqlite3_exec db {SELECT length('%7f%80%81') AS x}
1.103 +} {0 {x 3}}
1.104 +do_test badutf-3.4 {
1.105 + sqlite3_exec db {SELECT length('%61%c0') AS x}
1.106 +} {0 {x 2}}
1.107 +do_test badutf-3.5 {
1.108 + sqlite3_exec db {SELECT length('%61%c0%80%80%80%80%80%80%80%80%80%80') AS x}
1.109 +} {0 {x 2}}
1.110 +do_test badutf-3.6 {
1.111 + sqlite3_exec db {SELECT length('%c0%80%80%80%80%80%80%80%80%80%80') AS x}
1.112 +} {0 {x 1}}
1.113 +do_test badutf-3.7 {
1.114 + sqlite3_exec db {SELECT length('%80%80%80%80%80%80%80%80%80%80') AS x}
1.115 +} {0 {x 10}}
1.116 +do_test badutf-3.8 {
1.117 + sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%80') AS x}
1.118 +} {0 {x 6}}
1.119 +do_test badutf-3.9 {
1.120 + sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%ff') AS x}
1.121 +} {0 {x 7}}
1.122 +
1.123 +do_test badutf-4.1 {
1.124 + sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
1.125 +} {0 {x F0}}
1.126 +do_test badutf-4.2 {
1.127 + sqlite3_exec db {SELECT hex(ltrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
1.128 +} {0 {x F0808080FF}}
1.129 +do_test badutf-4.3 {
1.130 + sqlite3_exec db {SELECT hex(rtrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
1.131 +} {0 {x 808080F0}}
1.132 +do_test badutf-4.4 {
1.133 + sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%ff%80')) AS x}
1.134 +} {0 {x 808080F0808080FF}}
1.135 +do_test badutf-4.5 {
1.136 + sqlite3_exec db {SELECT hex(trim('%ff%80%80%f0%80%80%80%ff','%ff%80')) AS x}
1.137 +} {0 {x 80F0808080FF}}
1.138 +do_test badutf-4.6 {
1.139 + sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80')) AS x}
1.140 +} {0 {x F0808080FF}}
1.141 +do_test badutf-4.7 {
1.142 + sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80%80')) AS x}
1.143 +} {0 {x FF80F0808080FF}}
1.144 +
1.145 +db2 close
1.146 +finish_test