|
1 # 2007 April 27 |
|
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 # The focus of the tests in this file are to verify that the |
|
14 # underlying TEXT or BLOB representation of an sqlite3_value |
|
15 # changes appropriately when APIs from the following set are |
|
16 # called: |
|
17 # |
|
18 # sqlite3_value_text() |
|
19 # sqlite3_value_text16() |
|
20 # sqlite3_value_blob() |
|
21 # sqlite3_value_bytes() |
|
22 # sqlite3_value_bytes16() |
|
23 # |
|
24 # $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $ |
|
25 |
|
26 set testdir [file dirname $argv0] |
|
27 source $testdir/tester.tcl |
|
28 |
|
29 ifcapable !bloblit { |
|
30 finish_test |
|
31 return |
|
32 } |
|
33 |
|
34 # Register the "pointer_change" SQL function. |
|
35 # |
|
36 sqlite3_create_function db |
|
37 |
|
38 do_test ptrchng-1.1 { |
|
39 execsql { |
|
40 CREATE TABLE t1(x INTEGER PRIMARY KEY, y BLOB); |
|
41 INSERT INTO t1 VALUES(1, 'abc'); |
|
42 INSERT INTO t1 VALUES(2, |
|
43 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789'); |
|
44 INSERT INTO t1 VALUES(3, x'626c6f62'); |
|
45 INSERT INTO t1 VALUES(4, |
|
46 x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324' |
|
47 ); |
|
48 SELECT count(*) FROM t1; |
|
49 } |
|
50 } {4} |
|
51 |
|
52 # For the short entries that fit in the Mem.zBuf[], the pointer should |
|
53 # never change regardless of what type conversions occur. |
|
54 # |
|
55 # UPDATE: No longer true, as Mem.zBuf[] has been removed. |
|
56 # |
|
57 do_test ptrchng-2.1 { |
|
58 execsql { |
|
59 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1 |
|
60 } |
|
61 } {0} |
|
62 do_test ptrchng-2.2 { |
|
63 execsql { |
|
64 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1 |
|
65 } |
|
66 } {0} |
|
67 ifcapable utf16 { |
|
68 do_test ptrchng-2.3 { |
|
69 execsql { |
|
70 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1 |
|
71 } |
|
72 } {1} |
|
73 do_test ptrchng-2.4 { |
|
74 execsql { |
|
75 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1 |
|
76 } |
|
77 } {1} |
|
78 do_test ptrchng-2.5 { |
|
79 execsql { |
|
80 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1 |
|
81 } |
|
82 } {0} |
|
83 do_test ptrchng-2.6 { |
|
84 execsql { |
|
85 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1 |
|
86 } |
|
87 } {1} |
|
88 } |
|
89 do_test ptrchng-2.11 { |
|
90 execsql { |
|
91 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3 |
|
92 } |
|
93 } {0} |
|
94 do_test ptrchng-2.12 { |
|
95 execsql { |
|
96 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3 |
|
97 } |
|
98 } {0} |
|
99 ifcapable utf16 { |
|
100 do_test ptrchng-2.13 { |
|
101 execsql { |
|
102 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3 |
|
103 } |
|
104 } {1} |
|
105 do_test ptrchng-2.14 { |
|
106 execsql { |
|
107 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3 |
|
108 } |
|
109 } {1} |
|
110 do_test ptrchng-2.15 { |
|
111 execsql { |
|
112 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3 |
|
113 } |
|
114 } {0} |
|
115 do_test ptrchng-2.16 { |
|
116 execsql { |
|
117 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3 |
|
118 } |
|
119 } {1} |
|
120 } |
|
121 |
|
122 # For the long entries that do not fit in the Mem.zBuf[], the pointer |
|
123 # should change sometimes. |
|
124 # |
|
125 do_test ptrchng-3.1 { |
|
126 execsql { |
|
127 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2 |
|
128 } |
|
129 } {0} |
|
130 do_test ptrchng-3.2 { |
|
131 execsql { |
|
132 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2 |
|
133 } |
|
134 } {0} |
|
135 ifcapable utf16 { |
|
136 do_test ptrchng-3.3 { |
|
137 execsql { |
|
138 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2 |
|
139 } |
|
140 } {1} |
|
141 do_test ptrchng-3.4 { |
|
142 execsql { |
|
143 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2 |
|
144 } |
|
145 } {1} |
|
146 do_test ptrchng-3.5 { |
|
147 execsql { |
|
148 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2 |
|
149 } |
|
150 } {0} |
|
151 do_test ptrchng-3.6 { |
|
152 execsql { |
|
153 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2 |
|
154 } |
|
155 } {1} |
|
156 } |
|
157 do_test ptrchng-3.11 { |
|
158 execsql { |
|
159 SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4 |
|
160 } |
|
161 } {0} |
|
162 do_test ptrchng-3.12 { |
|
163 execsql { |
|
164 SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4 |
|
165 } |
|
166 } {0} |
|
167 ifcapable utf16 { |
|
168 do_test ptrchng-3.13 { |
|
169 execsql { |
|
170 SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4 |
|
171 } |
|
172 } {1} |
|
173 do_test ptrchng-3.14 { |
|
174 execsql { |
|
175 SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4 |
|
176 } |
|
177 } {1} |
|
178 do_test ptrchng-3.15 { |
|
179 execsql { |
|
180 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4 |
|
181 } |
|
182 } {0} |
|
183 do_test ptrchng-3.16 { |
|
184 execsql { |
|
185 SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4 |
|
186 } |
|
187 } {1} |
|
188 } |
|
189 |
|
190 # A call to _bytes() should never reformat a _text() or _blob(). |
|
191 # |
|
192 do_test ptrchng-4.1 { |
|
193 execsql { |
|
194 SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1 |
|
195 } |
|
196 } {0 0 0 0} |
|
197 do_test ptrchng-4.2 { |
|
198 execsql { |
|
199 SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1 |
|
200 } |
|
201 } {0 0 0 0} |
|
202 |
|
203 # A call to _blob() should never trigger a reformat |
|
204 # |
|
205 do_test ptrchng-5.1 { |
|
206 execsql { |
|
207 SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1 |
|
208 } |
|
209 } {0 0 0 0} |
|
210 ifcapable utf16 { |
|
211 do_test ptrchng-5.2 { |
|
212 execsql { |
|
213 SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 |
|
214 } |
|
215 } {0 0 0 0} |
|
216 do_test ptrchng-5.3 { |
|
217 execsql { |
|
218 SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1 |
|
219 } |
|
220 } {0 0 0 0} |
|
221 } |
|
222 |
|
223 finish_test |