xref: /sqlite-3.40.0/test/ptrchng.test (revision 8a29dfde)
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.4 2008/02/14 05:44:45 danielk1977 Exp $
25
26set testdir [file dirname $argv0]
27source $testdir/tester.tcl
28
29ifcapable !bloblit {
30  finish_test
31  return
32}
33
34# Register the "pointer_change" SQL function.
35#
36sqlite3_create_function db
37
38do_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#
57do_test ptrchng-2.1 {
58  execsql {
59    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
60  }
61} {0}
62do_test ptrchng-2.2 {
63  execsql {
64    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
65  }
66} {0}
67ifcapable 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}
89do_test ptrchng-2.11 {
90  execsql {
91    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
92  }
93} {0}
94do_test ptrchng-2.12 {
95  execsql {
96    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
97  }
98} {0}
99ifcapable 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 {
116btree_breakpoint
117    execsql {
118      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
119    }
120  } {1}
121}
122
123# For the long entries that do not fit in the Mem.zBuf[], the pointer
124# should change sometimes.
125#
126do_test ptrchng-3.1 {
127  execsql {
128    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
129  }
130} {0}
131do_test ptrchng-3.2 {
132  execsql {
133    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
134  }
135} {0}
136ifcapable utf16 {
137  do_test ptrchng-3.3 {
138    execsql {
139      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2
140    }
141  } {1}
142  do_test ptrchng-3.4 {
143    execsql {
144      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2
145    }
146  } {1}
147  do_test ptrchng-3.5 {
148    execsql {
149      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2
150    }
151  } {0}
152  do_test ptrchng-3.6 {
153    execsql {
154      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2
155    }
156  } {1}
157}
158do_test ptrchng-3.11 {
159  execsql {
160    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
161  }
162} {0}
163do_test ptrchng-3.12 {
164  execsql {
165    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
166  }
167} {0}
168ifcapable utf16 {
169  do_test ptrchng-3.13 {
170    execsql {
171      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4
172    }
173  } {1}
174  do_test ptrchng-3.14 {
175    execsql {
176      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4
177    }
178  } {1}
179  do_test ptrchng-3.15 {
180    execsql {
181      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4
182    }
183  } {0}
184  do_test ptrchng-3.16 {
185    execsql {
186      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4
187    }
188  } {1}
189}
190
191# A call to _bytes() should never reformat a _text() or _blob().
192#
193do_test ptrchng-4.1 {
194  execsql {
195    SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
196  }
197} {0 0 0 0}
198do_test ptrchng-4.2 {
199  execsql {
200    SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
201  }
202} {0 0 0 0}
203
204# A call to _blob() should never trigger a reformat
205#
206do_test ptrchng-5.1 {
207  execsql {
208    SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
209  }
210} {0 0 0 0}
211ifcapable utf16 {
212  do_test ptrchng-5.2 {
213    execsql {
214      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
215    }
216  } {0 0 0 0}
217  do_test ptrchng-5.3 {
218    execsql {
219      SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1
220    }
221  } {0 0 0 0}
222}
223
224finish_test
225