3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file contains code to verify that the SQLITE_UTF16_ALIGNED
13 # flag passed into the sqlite3_create_collation() function insures
14 # that all strings passed to that function are aligned on an even
17 # $Id: utf16align.test,v 1.2 2008/11/07 03:29:34 drh Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
22 # Skip this entire test if we do not support UTF16
29 # Create a database with a UTF16 encoding. Put in lots of string
30 # data of varying lengths.
32 do_test utf16align-1.0 {
33 set unaligned_string_counter 0
34 add_alignment_test_collations [sqlite3_connection_pointer db]
35 sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1
37 PRAGMA encoding=UTF16;
39 id INTEGER PRIMARY KEY,
41 a TEXT COLLATE utf16_aligned,
42 b TEXT COLLATE utf16_unaligned
44 INSERT INTO t1(a) VALUES("abc");
45 INSERT INTO t1(a) VALUES("defghi");
46 INSERT INTO t1(a) VALUES("jklmnopqrstuv");
47 INSERT INTO t1(a) VALUES("wxyz0123456789-");
48 UPDATE t1 SET b=a||'-'||a;
49 INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
50 INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
51 INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
52 INSERT INTO t1(a,b) VALUES('one','two');
53 INSERT INTO t1(a,b) SELECT a, b FROM t1;
54 UPDATE t1 SET spacer = CASE WHEN rowid&1 THEN 'x' ELSE 'xx' END;
55 SELECT count(*) FROM t1;
58 do_test utf16align-1.1 {
59 set unaligned_string_counter
62 # Creating an index that uses the unaligned collation. We should see
63 # some unaligned strings passed to the collating function.
65 do_test utf16align-1.2 {
67 CREATE INDEX t1i1 ON t1(spacer, b);
69 # puts $unaligned_string_counter
70 expr {$unaligned_string_counter>0}
73 # Create another index that uses the aligned collation. This time
74 # there should be no unaligned accesses
76 do_test utf16align-1.3 {
77 set unaligned_string_counter 0
79 CREATE INDEX t1i2 ON t1(spacer, a);
81 expr {$unaligned_string_counter>0}
83 integrity_check utf16align-1.4
89 do_test utf16align-2.1 {
91 PRAGMA encoding=UTF16be;
92 SELECT hex(ltrim(x'6efcda'));