wasCSharpSQLite – Blame information for rev 7
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | # 2011 March 15 |
2 | # |
||
3 | # The author disclaims copyright to this source code. In place of |
||
4 | # a legal notice, here is a blessing: |
||
5 | # |
||
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. |
||
9 | # |
||
10 | #*********************************************************************** |
||
11 | # This file implements regression tests for SQLite library. |
||
12 | # |
||
13 | # This file checks to make sure SQLite is able to gracefully |
||
14 | # handle malformed UTF-8. |
||
15 | # |
||
16 | |||
17 | set testdir [file dirname $argv0] |
||
18 | source $testdir/tester.tcl |
||
19 | |||
20 | proc utf8_to_ustr2 {s} { |
||
21 | set r "" |
||
22 | foreach i [split $s ""] { |
||
23 | scan $i %c c |
||
24 | append r [format \\u%04.4X $c] |
||
25 | } |
||
26 | set r |
||
27 | } |
||
28 | |||
29 | proc utf8_to_hstr {in} { |
||
30 | regsub -all -- {(..)} $in {%[format "%s" \1]} out |
||
31 | subst $out |
||
32 | } |
||
33 | |||
34 | proc utf8_to_xstr {in} { |
||
35 | regsub -all -- {(..)} $in {\\\\x[format "%s" \1]} out |
||
36 | subst $out |
||
37 | } |
||
38 | |||
39 | proc utf8_to_ustr {in} { |
||
40 | regsub -all -- {(..)} $in {\\\\u[format "%04.4X" 0x\1]} out |
||
41 | subst $out |
||
42 | } |
||
43 | |||
44 | do_test badutf2-1.0 { |
||
45 | db close |
||
46 | forcedelete test.db |
||
47 | sqlite3 db test.db |
||
48 | db eval "PRAGMA encoding = 'UTF-8'" |
||
49 | } {} |
||
50 | |||
51 | do_test badutf2-4.0 { |
||
52 | set S [sqlite3_prepare_v2 db "SELECT ?" -1 dummy] |
||
53 | sqlite3_expired $S |
||
54 | } {0} |
||
55 | |||
56 | foreach { i len uval xstr ustr u2u } { |
||
57 | 1 1 00 \x00 "\\u0000" 00 |
||
58 | 2 1 01 \x01 "\\u0001" 01 |
||
59 | 3 1 3F \x3F "\\u003F" 3F |
||
60 | 4 1 7F \x7F "\\u007F" 7F |
||
61 | |||
62 | } { |
||
63 | if 0 { |
||
64 | # skip UTF16 tests |
||
65 | 5 1 80 \x80 "\\u0080" C280 |
||
66 | 6 1 C3BF \xFF "\\u00FF" C3BF |
||
67 | 7 3 EFBFBD \xEF\xBF\xBD "\\uFFFD" {} |
||
68 | } |
||
69 | |||
70 | set hstr [ utf8_to_hstr $uval ] |
||
71 | |||
72 | ifcapable bloblit { |
||
73 | if {$hstr != "%00"} { |
||
74 | do_test badutf2-2.1.$i { |
||
75 | set sql "SELECT '$hstr'=CAST(x'$uval' AS text) AS x;" |
||
76 | set res [ sqlite3_exec db $sql ] |
||
77 | lindex [ lindex $res 1] 1 |
||
78 | } {1} |
||
79 | do_test badutf2-2.2.$i { |
||
80 | set sql "SELECT CAST('$hstr' AS blob)=x'$uval' AS x;" |
||
81 | set res [ sqlite3_exec db $sql ] |
||
82 | lindex [ lindex $res 1] 1 |
||
83 | } {1} |
||
84 | } |
||
85 | do_test badutf2-2.3.$i { |
||
86 | set sql "SELECT hex(CAST(x'$uval' AS text)) AS x;" |
||
87 | set res [ sqlite3_exec db $sql ] |
||
88 | lindex [ lindex $res 1] 1 |
||
89 | } $uval |
||
90 | do_test badutf2-2.4.$i { |
||
91 | set sql "SELECT hex(CAST(x'$uval' AS text)) AS x;" |
||
92 | set res [ sqlite3_exec db $sql ] |
||
93 | lindex [ lindex $res 1] 1 |
||
94 | } $uval |
||
95 | } |
||
96 | |||
97 | if {$hstr != "%00"} { |
||
98 | do_test badutf2-3.1.$i { |
||
99 | set sql "SELECT hex('$hstr') AS x;" |
||
100 | set res [ sqlite3_exec db $sql ] |
||
101 | lindex [ lindex $res 1] 1 |
||
102 | } $uval |
||
103 | } |
||
104 | |||
105 | do_test badutf2-4.1.$i { |
||
106 | sqlite3_reset $S |
||
107 | sqlite3_bind_text $S 1 $xstr $len |
||
108 | sqlite3_step $S |
||
109 | utf8_to_ustr2 [ sqlite3_column_text $S 0 ] |
||
110 | } $ustr |
||
111 | |||
112 | ifcapable debug { |
||
113 | do_test badutf2-5.1.$i { |
||
114 | utf8_to_utf8 $uval |
||
115 | } $u2u |
||
116 | } |
||
117 | |||
118 | } |
||
119 | |||
120 | do_test badutf2-4.2 { |
||
121 | sqlite3_finalize $S |
||
122 | } {SQLITE_OK} |
||
123 | |||
124 | |||
125 | finish_test |