summaryrefslogtreecommitdiffstats
path: root/test/ptrchng.test
blob: 75525f981c5755ad13cbd5896bcd010abd7dfc2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# 2007 April 27
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# The focus of the tests in this file are to verify that the
# underlying TEXT or BLOB representation of an sqlite3_value
# changes appropriately when APIs from the following set are
# called:
#
#     sqlite3_value_text()
#     sqlite3_value_text16()
#     sqlite3_value_blob()
#     sqlite3_value_bytes()
#     sqlite3_value_bytes16()
#
# $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !bloblit {
  finish_test
  return
}

# Register the "pointer_change" SQL function.
#
sqlite3_create_function db

do_test ptrchng-1.1 {
  execsql {
    CREATE TABLE t1(x INTEGER PRIMARY KEY, y BLOB);
    INSERT INTO t1 VALUES(1, 'abc');
    INSERT INTO t1 VALUES(2, 
       'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789');
    INSERT INTO t1 VALUES(3, x'626c6f62');
    INSERT INTO t1 VALUES(4,
 x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324'
    );
    SELECT count(*) FROM t1;
  }
} {4}

# For the short entries that fit in the Mem.zBuf[], the pointer should
# never change regardless of what type conversions occur.
#
# UPDATE: No longer true, as Mem.zBuf[] has been removed.
#
do_test ptrchng-2.1 {
  execsql {
    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
  }
} {0}
do_test ptrchng-2.2 {
  execsql {
    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
  }
} {0}
ifcapable utf16 {
  do_test ptrchng-2.3 {
    execsql {
      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1
    }
  } {1}
  do_test ptrchng-2.4 {
    execsql {
      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1
    }
  } {1}
  do_test ptrchng-2.5 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1
    }
  } {0}
  do_test ptrchng-2.6 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1
    }
  } {1}
}
do_test ptrchng-2.11 {
  execsql {
    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
  }
} {0}
do_test ptrchng-2.12 {
  execsql {
    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
  }
} {0}
ifcapable utf16 {
  do_test ptrchng-2.13 {
    execsql {
      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3
    }
  } {1}
  do_test ptrchng-2.14 {
    execsql {
      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3
    }
  } {1}
  do_test ptrchng-2.15 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3
    }
  } {0}
  do_test ptrchng-2.16 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
    }
  } {1}
}

# For the long entries that do not fit in the Mem.zBuf[], the pointer
# should change sometimes.
#
do_test ptrchng-3.1 {
  execsql {
    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
  }
} {0}
do_test ptrchng-3.2 {
  execsql {
    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
  }
} {0}
ifcapable utf16 {
  do_test ptrchng-3.3 {
    execsql {
      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2
    }
  } {1}
  do_test ptrchng-3.4 {
    execsql {
      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2
    }
  } {1}
  do_test ptrchng-3.5 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2
    }
  } {0}
  do_test ptrchng-3.6 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2
    }
  } {1}
}
do_test ptrchng-3.11 {
  execsql {
    SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
  }
} {0}
do_test ptrchng-3.12 {
  execsql {
    SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
  }
} {0}
ifcapable utf16 {
  do_test ptrchng-3.13 {
    execsql {
      SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4
    }
  } {1}
  do_test ptrchng-3.14 {
    execsql {
      SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4
    }
  } {1}
  do_test ptrchng-3.15 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4
    }
  } {0}
  do_test ptrchng-3.16 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4
    }
  } {1}
}

# A call to _bytes() should never reformat a _text() or _blob().
#
do_test ptrchng-4.1 {
  execsql {
    SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
  }
} {0 0 0 0}
do_test ptrchng-4.2 {
  execsql {
    SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
  }
} {0 0 0 0}

# A call to _blob() should never trigger a reformat
#
do_test ptrchng-5.1 {
  execsql {
    SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
  }
} {0 0 0 0}
ifcapable utf16 {
  do_test ptrchng-5.2 {
    execsql {
      SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
    }
  } {0 0 0 0}
  do_test ptrchng-5.3 {
    execsql {
      SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1
    }
  } {0 0 0 0}
}

finish_test