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 checks to make sure SQLite is able to gracefully
14 # handle malformed UTF-8.
16 # $Id: badutf.test,v 1.2 2007/09/12 17:01:45 danielk1977 Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
22 db eval {PRAGMA encoding=UTF8}
23 sqlite3_exec db {SELECT hex('%80') AS x}
26 sqlite3_exec db {SELECT hex('%81') AS x}
29 sqlite3_exec db {SELECT hex('%bf') AS x}
32 sqlite3_exec db {SELECT hex('%c0') AS x}
35 sqlite3_exec db {SELECT hex('%e0') AS x}
38 sqlite3_exec db {SELECT hex('%f0') AS x}
41 sqlite3_exec db {SELECT hex('%ff') AS x}
47 db2 eval {PRAGMA encoding=UTF16be}
48 sqlite3_exec db2 {SELECT hex('%80') AS x}
51 sqlite3_exec db2 {SELECT hex('%81') AS x}
54 sqlite3_exec db2 {SELECT hex('%bf') AS x}
57 sqlite3_exec db2 {SELECT hex('%c0') AS x}
60 sqlite3_exec db2 {SELECT hex('%c1') AS x}
63 sqlite3_exec db2 {SELECT hex('%c0%bf') AS x}
66 sqlite3_exec db2 {SELECT hex('%c1%bf') AS x}
69 sqlite3_exec db2 {SELECT hex('%c3%bf') AS x}
72 sqlite3_exec db2 {SELECT hex('%e0') AS x}
75 sqlite3_exec db2 {SELECT hex('%f0') AS x}
78 sqlite3_exec db2 {SELECT hex('%ff') AS x}
85 sqlite3_exec db {SELECT '%80'=CAST(x'80' AS text) AS x}
88 sqlite3_exec db {SELECT CAST('%80' AS blob)=x'80' AS x}
93 sqlite3_exec db {SELECT length('%80') AS x}
96 sqlite3_exec db {SELECT length('%61%62%63') AS x}
99 sqlite3_exec db {SELECT length('%7f%80%81') AS x}
102 sqlite3_exec db {SELECT length('%61%c0') AS x}
105 sqlite3_exec db {SELECT length('%61%c0%80%80%80%80%80%80%80%80%80%80') AS x}
108 sqlite3_exec db {SELECT length('%c0%80%80%80%80%80%80%80%80%80%80') AS x}
111 sqlite3_exec db {SELECT length('%80%80%80%80%80%80%80%80%80%80') AS x}
114 sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%80') AS x}
117 sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%ff') AS x}
121 sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
124 sqlite3_exec db {SELECT hex(ltrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
127 sqlite3_exec db {SELECT hex(rtrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
130 sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%ff%80')) AS x}
131 } {0 {x 808080F0808080FF}}
133 sqlite3_exec db {SELECT hex(trim('%ff%80%80%f0%80%80%80%ff','%ff%80')) AS x}
134 } {0 {x 80F0808080FF}}
136 sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80')) AS x}
139 sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80%80')) AS x}
140 } {0 {x FF80F0808080FF}}