gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/utf16align.test (about) 1 # 2006 February 16 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 # 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 15 # byte boundary. 16 # 17 # $Id: utf16align.test,v 1.2 2008/11/07 03:29:34 drh Exp $ 18 19 set testdir [file dirname $argv0] 20 source $testdir/tester.tcl 21 22 # Skip this entire test if we do not support UTF16 23 # 24 ifcapable !utf16 { 25 finish_test 26 return 27 } 28 29 # Create a database with a UTF16 encoding. Put in lots of string 30 # data of varying lengths. 31 # 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 36 execsql { 37 PRAGMA encoding=UTF16; 38 CREATE TABLE t1( 39 id INTEGER PRIMARY KEY, 40 spacer TEXT, 41 a TEXT COLLATE utf16_aligned, 42 b TEXT COLLATE utf16_unaligned 43 ); 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; 56 } 57 } 66 58 do_test utf16align-1.1 { 59 set unaligned_string_counter 60 } 0 61 62 # Creating an index that uses the unaligned collation. We should see 63 # some unaligned strings passed to the collating function. 64 # 65 do_test utf16align-1.2 { 66 execsql { 67 CREATE INDEX t1i1 ON t1(spacer, b); 68 } 69 # puts $unaligned_string_counter 70 expr {$unaligned_string_counter>0} 71 } 1 72 73 # Create another index that uses the aligned collation. This time 74 # there should be no unaligned accesses 75 # 76 do_test utf16align-1.3 { 77 set unaligned_string_counter 0 78 execsql { 79 CREATE INDEX t1i2 ON t1(spacer, a); 80 } 81 expr {$unaligned_string_counter>0} 82 } 0 83 integrity_check utf16align-1.4 84 85 # ticket #3482 86 # 87 db close 88 sqlite3 db :memory: 89 do_test utf16align-2.1 { 90 db eval { 91 PRAGMA encoding=UTF16be; 92 SELECT hex(ltrim(x'6efcda')); 93 } 94 } {6EFC} 95 96 finish_test