sl@0
|
1 |
# 2007 May 15
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# This file checks to make sure SQLite is able to gracefully
|
sl@0
|
14 |
# handle malformed UTF-8.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# $Id: badutf.test,v 1.2 2007/09/12 17:01:45 danielk1977 Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
set testdir [file dirname $argv0]
|
sl@0
|
19 |
source $testdir/tester.tcl
|
sl@0
|
20 |
|
sl@0
|
21 |
do_test badutf-1.1 {
|
sl@0
|
22 |
db eval {PRAGMA encoding=UTF8}
|
sl@0
|
23 |
sqlite3_exec db {SELECT hex('%80') AS x}
|
sl@0
|
24 |
} {0 {x 80}}
|
sl@0
|
25 |
do_test badutf-1.2 {
|
sl@0
|
26 |
sqlite3_exec db {SELECT hex('%81') AS x}
|
sl@0
|
27 |
} {0 {x 81}}
|
sl@0
|
28 |
do_test badutf-1.3 {
|
sl@0
|
29 |
sqlite3_exec db {SELECT hex('%bf') AS x}
|
sl@0
|
30 |
} {0 {x BF}}
|
sl@0
|
31 |
do_test badutf-1.4 {
|
sl@0
|
32 |
sqlite3_exec db {SELECT hex('%c0') AS x}
|
sl@0
|
33 |
} {0 {x C0}}
|
sl@0
|
34 |
do_test badutf-1.5 {
|
sl@0
|
35 |
sqlite3_exec db {SELECT hex('%e0') AS x}
|
sl@0
|
36 |
} {0 {x E0}}
|
sl@0
|
37 |
do_test badutf-1.6 {
|
sl@0
|
38 |
sqlite3_exec db {SELECT hex('%f0') AS x}
|
sl@0
|
39 |
} {0 {x F0}}
|
sl@0
|
40 |
do_test badutf-1.7 {
|
sl@0
|
41 |
sqlite3_exec db {SELECT hex('%ff') AS x}
|
sl@0
|
42 |
} {0 {x FF}}
|
sl@0
|
43 |
|
sl@0
|
44 |
sqlite3 db2 {}
|
sl@0
|
45 |
ifcapable utf16 {
|
sl@0
|
46 |
do_test badutf-1.10 {
|
sl@0
|
47 |
db2 eval {PRAGMA encoding=UTF16be}
|
sl@0
|
48 |
sqlite3_exec db2 {SELECT hex('%80') AS x}
|
sl@0
|
49 |
} {0 {x 0080}}
|
sl@0
|
50 |
do_test badutf-1.11 {
|
sl@0
|
51 |
sqlite3_exec db2 {SELECT hex('%81') AS x}
|
sl@0
|
52 |
} {0 {x 0081}}
|
sl@0
|
53 |
do_test badutf-1.12 {
|
sl@0
|
54 |
sqlite3_exec db2 {SELECT hex('%bf') AS x}
|
sl@0
|
55 |
} {0 {x 00BF}}
|
sl@0
|
56 |
do_test badutf-1.13 {
|
sl@0
|
57 |
sqlite3_exec db2 {SELECT hex('%c0') AS x}
|
sl@0
|
58 |
} {0 {x FFFD}}
|
sl@0
|
59 |
do_test badutf-1.14 {
|
sl@0
|
60 |
sqlite3_exec db2 {SELECT hex('%c1') AS x}
|
sl@0
|
61 |
} {0 {x FFFD}}
|
sl@0
|
62 |
do_test badutf-1.15 {
|
sl@0
|
63 |
sqlite3_exec db2 {SELECT hex('%c0%bf') AS x}
|
sl@0
|
64 |
} {0 {x FFFD}}
|
sl@0
|
65 |
do_test badutf-1.16 {
|
sl@0
|
66 |
sqlite3_exec db2 {SELECT hex('%c1%bf') AS x}
|
sl@0
|
67 |
} {0 {x FFFD}}
|
sl@0
|
68 |
do_test badutf-1.17 {
|
sl@0
|
69 |
sqlite3_exec db2 {SELECT hex('%c3%bf') AS x}
|
sl@0
|
70 |
} {0 {x 00FF}}
|
sl@0
|
71 |
do_test badutf-1.18 {
|
sl@0
|
72 |
sqlite3_exec db2 {SELECT hex('%e0') AS x}
|
sl@0
|
73 |
} {0 {x FFFD}}
|
sl@0
|
74 |
do_test badutf-1.19 {
|
sl@0
|
75 |
sqlite3_exec db2 {SELECT hex('%f0') AS x}
|
sl@0
|
76 |
} {0 {x FFFD}}
|
sl@0
|
77 |
do_test badutf-1.20 {
|
sl@0
|
78 |
sqlite3_exec db2 {SELECT hex('%ff') AS x}
|
sl@0
|
79 |
} {0 {x FFFD}}
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
|
sl@0
|
83 |
ifcapable bloblit {
|
sl@0
|
84 |
do_test badutf-2.1 {
|
sl@0
|
85 |
sqlite3_exec db {SELECT '%80'=CAST(x'80' AS text) AS x}
|
sl@0
|
86 |
} {0 {x 1}}
|
sl@0
|
87 |
do_test badutf-2.2 {
|
sl@0
|
88 |
sqlite3_exec db {SELECT CAST('%80' AS blob)=x'80' AS x}
|
sl@0
|
89 |
} {0 {x 1}}
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
do_test badutf-3.1 {
|
sl@0
|
93 |
sqlite3_exec db {SELECT length('%80') AS x}
|
sl@0
|
94 |
} {0 {x 1}}
|
sl@0
|
95 |
do_test badutf-3.2 {
|
sl@0
|
96 |
sqlite3_exec db {SELECT length('%61%62%63') AS x}
|
sl@0
|
97 |
} {0 {x 3}}
|
sl@0
|
98 |
do_test badutf-3.3 {
|
sl@0
|
99 |
sqlite3_exec db {SELECT length('%7f%80%81') AS x}
|
sl@0
|
100 |
} {0 {x 3}}
|
sl@0
|
101 |
do_test badutf-3.4 {
|
sl@0
|
102 |
sqlite3_exec db {SELECT length('%61%c0') AS x}
|
sl@0
|
103 |
} {0 {x 2}}
|
sl@0
|
104 |
do_test badutf-3.5 {
|
sl@0
|
105 |
sqlite3_exec db {SELECT length('%61%c0%80%80%80%80%80%80%80%80%80%80') AS x}
|
sl@0
|
106 |
} {0 {x 2}}
|
sl@0
|
107 |
do_test badutf-3.6 {
|
sl@0
|
108 |
sqlite3_exec db {SELECT length('%c0%80%80%80%80%80%80%80%80%80%80') AS x}
|
sl@0
|
109 |
} {0 {x 1}}
|
sl@0
|
110 |
do_test badutf-3.7 {
|
sl@0
|
111 |
sqlite3_exec db {SELECT length('%80%80%80%80%80%80%80%80%80%80') AS x}
|
sl@0
|
112 |
} {0 {x 10}}
|
sl@0
|
113 |
do_test badutf-3.8 {
|
sl@0
|
114 |
sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%80') AS x}
|
sl@0
|
115 |
} {0 {x 6}}
|
sl@0
|
116 |
do_test badutf-3.9 {
|
sl@0
|
117 |
sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%ff') AS x}
|
sl@0
|
118 |
} {0 {x 7}}
|
sl@0
|
119 |
|
sl@0
|
120 |
do_test badutf-4.1 {
|
sl@0
|
121 |
sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
|
sl@0
|
122 |
} {0 {x F0}}
|
sl@0
|
123 |
do_test badutf-4.2 {
|
sl@0
|
124 |
sqlite3_exec db {SELECT hex(ltrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
|
sl@0
|
125 |
} {0 {x F0808080FF}}
|
sl@0
|
126 |
do_test badutf-4.3 {
|
sl@0
|
127 |
sqlite3_exec db {SELECT hex(rtrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
|
sl@0
|
128 |
} {0 {x 808080F0}}
|
sl@0
|
129 |
do_test badutf-4.4 {
|
sl@0
|
130 |
sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%ff%80')) AS x}
|
sl@0
|
131 |
} {0 {x 808080F0808080FF}}
|
sl@0
|
132 |
do_test badutf-4.5 {
|
sl@0
|
133 |
sqlite3_exec db {SELECT hex(trim('%ff%80%80%f0%80%80%80%ff','%ff%80')) AS x}
|
sl@0
|
134 |
} {0 {x 80F0808080FF}}
|
sl@0
|
135 |
do_test badutf-4.6 {
|
sl@0
|
136 |
sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80')) AS x}
|
sl@0
|
137 |
} {0 {x F0808080FF}}
|
sl@0
|
138 |
do_test badutf-4.7 {
|
sl@0
|
139 |
sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80%80')) AS x}
|
sl@0
|
140 |
} {0 {x FF80F0808080FF}}
|
sl@0
|
141 |
|
sl@0
|
142 |
db2 close
|
sl@0
|
143 |
finish_test
|