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