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]
36 PRAGMA encoding=UTF16;
38 id INTEGER PRIMARY KEY,
40 a TEXT COLLATE utf16_aligned,
41 b TEXT COLLATE utf16_unaligned
43 INSERT INTO t1(a) VALUES("abc");
44 INSERT INTO t1(a) VALUES("defghi");
45 INSERT INTO t1(a) VALUES("jklmnopqrstuv");
46 INSERT INTO t1(a) VALUES("wxyz0123456789-");
47 UPDATE t1 SET b=a||'-'||a;
48 INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
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) VALUES('one','two');
52 INSERT INTO t1(a,b) SELECT a, b FROM t1;
53 UPDATE t1 SET spacer = CASE WHEN rowid&1 THEN 'x' ELSE 'xx' END;
54 SELECT count(*) FROM t1;
57 do_test utf16align-1.1 {
58 set unaligned_string_counter
61 # Creating an index that uses the unaligned collation. We should see
62 # some unaligned strings passed to the collating function.
64 do_test utf16align-1.2 {
66 CREATE INDEX t1i1 ON t1(spacer, b);
68 # puts $unaligned_string_counter
69 expr {$unaligned_string_counter>0}
72 # Create another index that uses the aligned collation. This time
73 # there should be no unaligned accesses
75 do_test utf16align-1.3 {
76 set unaligned_string_counter 0
78 CREATE INDEX t1i2 ON t1(spacer, a);
80 expr {$unaligned_string_counter>0}
82 integrity_check utf16align-1.4
88 do_test utf16align-2.1 {
90 PRAGMA encoding=UTF16be;
91 SELECT hex(ltrim(x'6efcda'));