sl@0: # 2007 April 27 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # The focus of the tests in this file are to verify that the sl@0: # underlying TEXT or BLOB representation of an sqlite3_value sl@0: # changes appropriately when APIs from the following set are sl@0: # called: sl@0: # sl@0: # sqlite3_value_text() sl@0: # sqlite3_value_text16() sl@0: # sqlite3_value_blob() sl@0: # sqlite3_value_bytes() sl@0: # sqlite3_value_bytes16() sl@0: # sl@0: # $Id: ptrchng.test,v 1.5 2008/07/12 14:52:20 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !bloblit { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Register the "pointer_change" SQL function. sl@0: # sl@0: sqlite3_create_function db sl@0: sl@0: do_test ptrchng-1.1 { sl@0: execsql { sl@0: CREATE TABLE t1(x INTEGER PRIMARY KEY, y BLOB); sl@0: INSERT INTO t1 VALUES(1, 'abc'); sl@0: INSERT INTO t1 VALUES(2, sl@0: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234356789'); sl@0: INSERT INTO t1 VALUES(3, x'626c6f62'); sl@0: INSERT INTO t1 VALUES(4, sl@0: x'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324' sl@0: ); sl@0: SELECT count(*) FROM t1; sl@0: } sl@0: } {4} sl@0: sl@0: # For the short entries that fit in the Mem.zBuf[], the pointer should sl@0: # never change regardless of what type conversions occur. sl@0: # sl@0: # UPDATE: No longer true, as Mem.zBuf[] has been removed. sl@0: # sl@0: do_test ptrchng-2.1 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=1 sl@0: } sl@0: } {0} sl@0: do_test ptrchng-2.2 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=1 sl@0: } sl@0: } {0} sl@0: ifcapable utf16 { sl@0: do_test ptrchng-2.3 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=1 sl@0: } sl@0: } {1} sl@0: do_test ptrchng-2.4 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=1 sl@0: } sl@0: } {1} sl@0: do_test ptrchng-2.5 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=1 sl@0: } sl@0: } {0} sl@0: do_test ptrchng-2.6 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=1 sl@0: } sl@0: } {1} sl@0: } sl@0: do_test ptrchng-2.11 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=3 sl@0: } sl@0: } {0} sl@0: do_test ptrchng-2.12 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=3 sl@0: } sl@0: } {0} sl@0: ifcapable utf16 { sl@0: do_test ptrchng-2.13 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=3 sl@0: } sl@0: } {1} sl@0: do_test ptrchng-2.14 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=3 sl@0: } sl@0: } {1} sl@0: do_test ptrchng-2.15 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=3 sl@0: } sl@0: } {0} sl@0: do_test ptrchng-2.16 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=3 sl@0: } sl@0: } {1} sl@0: } sl@0: sl@0: # For the long entries that do not fit in the Mem.zBuf[], the pointer sl@0: # should change sometimes. sl@0: # sl@0: do_test ptrchng-3.1 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=2 sl@0: } sl@0: } {0} sl@0: do_test ptrchng-3.2 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=2 sl@0: } sl@0: } {0} sl@0: ifcapable utf16 { sl@0: do_test ptrchng-3.3 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=2 sl@0: } sl@0: } {1} sl@0: do_test ptrchng-3.4 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=2 sl@0: } sl@0: } {1} sl@0: do_test ptrchng-3.5 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=2 sl@0: } sl@0: } {0} sl@0: do_test ptrchng-3.6 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=2 sl@0: } sl@0: } {1} sl@0: } sl@0: do_test ptrchng-3.11 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'noop', 'blob') FROM t1 WHERE x=4 sl@0: } sl@0: } {0} sl@0: do_test ptrchng-3.12 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'noop', 'text') FROM t1 WHERE x=4 sl@0: } sl@0: } {0} sl@0: ifcapable utf16 { sl@0: do_test ptrchng-3.13 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'noop', 'text16') FROM t1 WHERE x=4 sl@0: } sl@0: } {1} sl@0: do_test ptrchng-3.14 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'noop', 'text16') FROM t1 WHERE x=4 sl@0: } sl@0: } {1} sl@0: do_test ptrchng-3.15 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 WHERE x=4 sl@0: } sl@0: } {0} sl@0: do_test ptrchng-3.16 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'text') FROM t1 WHERE x=4 sl@0: } sl@0: } {1} sl@0: } sl@0: sl@0: # A call to _bytes() should never reformat a _text() or _blob(). sl@0: # sl@0: do_test ptrchng-4.1 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'bytes', 'text') FROM t1 sl@0: } sl@0: } {0 0 0 0} sl@0: do_test ptrchng-4.2 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'blob', 'bytes', 'blob') FROM t1 sl@0: } sl@0: } {0 0 0 0} sl@0: sl@0: # A call to _blob() should never trigger a reformat sl@0: # sl@0: do_test ptrchng-5.1 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text', 'bytes', 'blob') FROM t1 sl@0: } sl@0: } {0 0 0 0} sl@0: ifcapable utf16 { sl@0: do_test ptrchng-5.2 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'noop', 'blob') FROM t1 sl@0: } sl@0: } {0 0 0 0} sl@0: do_test ptrchng-5.3 { sl@0: execsql { sl@0: SELECT pointer_change(y, 'text16', 'bytes16', 'blob') FROM t1 sl@0: } sl@0: } {0 0 0 0} sl@0: } sl@0: sl@0: finish_test