ptrchng.test 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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.5 2008/07/12 14:52:20 drh Exp $
  25. set testdir [file dirname $argv0]
  26. source $testdir/tester.tcl
  27. ifcapable !bloblit {
  28. finish_test
  29. return
  30. }
  31. # Register the "pointer_change" SQL function.
  32. #
  33. sqlite3_create_function db
  34. do_test ptrchng-1.1 {
  35. execsql {
  36. CREATE TABLE t1(x INTEGER PRIMARY KEY, y BLOB);
  37. INSERT INTO t1 VALUES(1, 'abc');
  38. INSERT INTO t1 VALUES(2,
  39. 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789');
  40. INSERT INTO t1 VALUES(3, x'626c6f62');
  41. INSERT INTO t1 VALUES(4,
  42. x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324'
  43. );
  44. SELECT count(*) FROM t1;
  45. }
  46. } {4}
  47. # For the short entries that fit in the Mem.zBuf[], the pointer should
  48. # never change regardless of what type conversions occur.
  49. #
  50. # UPDATE: No longer true, as Mem.zBuf[] has been removed.
  51. #
  52. do_test ptrchng-2.1 {
  53. execsql {
  54. SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1
  55. }
  56. } {0}
  57. do_test ptrchng-2.2 {
  58. execsql {
  59. SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1
  60. }
  61. } {0}
  62. ifcapable utf16 {
  63. do_test ptrchng-2.3 {
  64. execsql {
  65. SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1
  66. }
  67. } {1}
  68. do_test ptrchng-2.4 {
  69. execsql {
  70. SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1
  71. }
  72. } {1}
  73. do_test ptrchng-2.5 {
  74. execsql {
  75. SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1
  76. }
  77. } {0}
  78. do_test ptrchng-2.6 {
  79. execsql {
  80. SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1
  81. }
  82. } {1}
  83. }
  84. do_test ptrchng-2.11 {
  85. execsql {
  86. SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3
  87. }
  88. } {0}
  89. do_test ptrchng-2.12 {
  90. execsql {
  91. SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3
  92. }
  93. } {0}
  94. ifcapable utf16 {
  95. do_test ptrchng-2.13 {
  96. execsql {
  97. SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3
  98. }
  99. } {1}
  100. do_test ptrchng-2.14 {
  101. execsql {
  102. SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3
  103. }
  104. } {1}
  105. do_test ptrchng-2.15 {
  106. execsql {
  107. SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3
  108. }
  109. } {0}
  110. do_test ptrchng-2.16 {
  111. execsql {
  112. SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3
  113. }
  114. } {1}
  115. }
  116. # For the long entries that do not fit in the Mem.zBuf[], the pointer
  117. # should change sometimes.
  118. #
  119. do_test ptrchng-3.1 {
  120. execsql {
  121. SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2
  122. }
  123. } {0}
  124. do_test ptrchng-3.2 {
  125. execsql {
  126. SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2
  127. }
  128. } {0}
  129. ifcapable 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. }
  151. do_test ptrchng-3.11 {
  152. execsql {
  153. SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4
  154. }
  155. } {0}
  156. do_test ptrchng-3.12 {
  157. execsql {
  158. SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4
  159. }
  160. } {0}
  161. ifcapable 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. # A call to _bytes() should never reformat a _text() or _blob().
  184. #
  185. do_test ptrchng-4.1 {
  186. execsql {
  187. SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1
  188. }
  189. } {0 0 0 0}
  190. do_test ptrchng-4.2 {
  191. execsql {
  192. SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1
  193. }
  194. } {0 0 0 0}
  195. # A call to _blob() should never trigger a reformat
  196. #
  197. do_test ptrchng-5.1 {
  198. execsql {
  199. SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1
  200. }
  201. } {0 0 0 0}
  202. ifcapable utf16 {
  203. do_test ptrchng-5.2 {
  204. execsql {
  205. SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1
  206. }
  207. } {0 0 0 0}
  208. do_test ptrchng-5.3 {
  209. execsql {
  210. SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1
  211. }
  212. } {0 0 0 0}
  213. }
  214. finish_test