sl@0: # 2006 February 16 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: # sl@0: # This file contains code to verify that the SQLITE_UTF16_ALIGNED sl@0: # flag passed into the sqlite3_create_collation() function insures sl@0: # that all strings passed to that function are aligned on an even sl@0: # byte boundary. sl@0: # sl@0: # $Id: utf16align.test,v 1.1 2006/02/16 18:16:38 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # Skip this entire test if we do not support UTF16 sl@0: # sl@0: ifcapable !utf16 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Create a database with a UTF16 encoding. Put in lots of string sl@0: # data of varying lengths. sl@0: # sl@0: do_test utf16align-1.0 { sl@0: set unaligned_string_counter 0 sl@0: add_alignment_test_collations [sqlite3_connection_pointer db] sl@0: execsql { sl@0: PRAGMA encoding=UTF16; sl@0: CREATE TABLE t1( sl@0: id INTEGER PRIMARY KEY, sl@0: spacer TEXT, sl@0: a TEXT COLLATE utf16_aligned, sl@0: b TEXT COLLATE utf16_unaligned sl@0: ); sl@0: INSERT INTO t1(a) VALUES("abc"); sl@0: INSERT INTO t1(a) VALUES("defghi"); sl@0: INSERT INTO t1(a) VALUES("jklmnopqrstuv"); sl@0: INSERT INTO t1(a) VALUES("wxyz0123456789-"); sl@0: UPDATE t1 SET b=a||'-'||a; sl@0: INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1; sl@0: INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1; sl@0: INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1; sl@0: INSERT INTO t1(a,b) VALUES('one','two'); sl@0: INSERT INTO t1(a,b) SELECT a, b FROM t1; sl@0: UPDATE t1 SET spacer = CASE WHEN rowid&1 THEN 'x' ELSE 'xx' END; sl@0: SELECT count(*) FROM t1; sl@0: } sl@0: } 66 sl@0: do_test utf16align-1.1 { sl@0: set unaligned_string_counter sl@0: } 0 sl@0: sl@0: # Creating an index that uses the unaligned collation. We should see sl@0: # some unaligned strings passed to the collating function. sl@0: # sl@0: do_test utf16align-1.2 { sl@0: execsql { sl@0: CREATE INDEX t1i1 ON t1(spacer, b); sl@0: } sl@0: # puts $unaligned_string_counter sl@0: expr {$unaligned_string_counter>0} sl@0: } 1 sl@0: sl@0: # Create another index that uses the aligned collation. This time sl@0: # there should be no unaligned accesses sl@0: # sl@0: do_test utf16align-1.3 { sl@0: set unaligned_string_counter 0 sl@0: execsql { sl@0: CREATE INDEX t1i2 ON t1(spacer, a); sl@0: } sl@0: expr {$unaligned_string_counter>0} sl@0: } 0 sl@0: integrity_check utf16align-1.4 sl@0: sl@0: finish_test