xref: /sqlite-3.40.0/test/ptrchng.test (revision 4152e677)
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.2 2007/09/12 17:01: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#
55do_test ptrchng-2.1 {
56  execsql {
57    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
58  }
59} {0}
60do_test ptrchng-2.2 {
61  execsql {
62    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
63  }
64} {0}
65ifcapable utf16 {
66  do_test ptrchng-2.3 {
67    execsql {
68      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1
69    }
70  } {0}
71  do_test ptrchng-2.4 {
72    execsql {
73      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1
74    }
75  } {0}
76  do_test ptrchng-2.5 {
77    execsql {
78      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1
79    }
80  } {0}
81  do_test ptrchng-2.6 {
82    execsql {
83      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1
84    }
85  } {0}
86}
87do_test ptrchng-2.11 {
88  execsql {
89    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
90  }
91} {0}
92do_test ptrchng-2.12 {
93  execsql {
94    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
95  }
96} {0}
97ifcapable utf16 {
98  do_test ptrchng-2.13 {
99    execsql {
100      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3
101    }
102  } {0}
103  do_test ptrchng-2.14 {
104    execsql {
105      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3
106    }
107  } {0}
108  do_test ptrchng-2.15 {
109    execsql {
110      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3
111    }
112  } {0}
113  do_test ptrchng-2.16 {
114btree_breakpoint
115    execsql {
116      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
117    }
118  } {0}
119}
120
121# For the long entries that do not fit in the Mem.zBuf[], the pointer
122# should change sometimes.
123#
124do_test ptrchng-3.1 {
125  execsql {
126    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
127  }
128} {0}
129do_test ptrchng-3.2 {
130  execsql {
131    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
132  }
133} {0}
134ifcapable utf16 {
135  do_test ptrchng-3.3 {
136    execsql {
137      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2
138    }
139  } {1}
140  do_test ptrchng-3.4 {
141    execsql {
142      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2
143    }
144  } {1}
145  do_test ptrchng-3.5 {
146    execsql {
147      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2
148    }
149  } {0}
150  do_test ptrchng-3.6 {
151    execsql {
152      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2
153    }
154  } {1}
155}
156do_test ptrchng-3.11 {
157  execsql {
158    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
159  }
160} {0}
161do_test ptrchng-3.12 {
162  execsql {
163    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
164  }
165} {0}
166ifcapable utf16 {
167  do_test ptrchng-3.13 {
168    execsql {
169      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4
170    }
171  } {1}
172  do_test ptrchng-3.14 {
173    execsql {
174      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4
175    }
176  } {1}
177  do_test ptrchng-3.15 {
178    execsql {
179      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4
180    }
181  } {0}
182  do_test ptrchng-3.16 {
183    execsql {
184      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4
185    }
186  } {1}
187}
188
189# A call to _bytes() should never reformat a _text() or _blob().
190#
191do_test ptrchng-4.1 {
192  execsql {
193    SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
194  }
195} {0 0 0 0}
196do_test ptrchng-4.2 {
197  execsql {
198    SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
199  }
200} {0 0 0 0}
201
202# A call to _blob() should never trigger a reformat
203#
204do_test ptrchng-5.1 {
205  execsql {
206    SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
207  }
208} {0 0 0 0}
209ifcapable utf16 {
210  do_test ptrchng-5.2 {
211    execsql {
212      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
213    }
214  } {0 0 0 0}
215  do_test ptrchng-5.3 {
216    execsql {
217      SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1
218    }
219  } {0 0 0 0}
220}
221
222finish_test
223