drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | # |
drh | e8f52c5 | 2008-07-12 14:52:20 +0000 | [diff] [blame] | 24 | # $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $ |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 25 | |
| 26 | set testdir [file dirname $argv0] |
| 27 | source $testdir/tester.tcl |
| 28 | |
danielk1977 | 4152e67 | 2007-09-12 17:01:45 +0000 | [diff] [blame] | 29 | ifcapable !bloblit { |
| 30 | finish_test |
| 31 | return |
| 32 | } |
| 33 | |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | # |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 55 | # UPDATE: No longer true, as Mem.zBuf[] has been removed. |
| 56 | # |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | } |
danielk1977 | 131b0ef | 2008-02-14 05:44:45 +0000 | [diff] [blame] | 66 | } {0} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | } |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 72 | } {1} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 73 | do_test ptrchng-2.4 { |
| 74 | execsql { |
| 75 | SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1 |
| 76 | } |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 77 | } {1} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | } |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 87 | } {1} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | } |
danielk1977 | 131b0ef | 2008-02-14 05:44:45 +0000 | [diff] [blame] | 98 | } {0} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | } |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 104 | } {1} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 105 | do_test ptrchng-2.14 { |
| 106 | execsql { |
| 107 | SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3 |
| 108 | } |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 109 | } {1} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 { |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 116 | execsql { |
| 117 | SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3 |
| 118 | } |
danielk1977 | a7a8e14 | 2008-02-13 18:25:27 +0000 | [diff] [blame] | 119 | } {1} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | } |
danielk1977 | 131b0ef | 2008-02-14 05:44:45 +0000 | [diff] [blame] | 134 | } {0} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 | } |
danielk1977 | 131b0ef | 2008-02-14 05:44:45 +0000 | [diff] [blame] | 166 | } {0} |
drh | 9310ef2 | 2007-04-27 17:16:20 +0000 | [diff] [blame] | 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 |