1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/utf16align.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,84 @@
1.4 +# 2006 February 16
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +#
1.15 +# This file contains code to verify that the SQLITE_UTF16_ALIGNED
1.16 +# flag passed into the sqlite3_create_collation() function insures
1.17 +# that all strings passed to that function are aligned on an even
1.18 +# byte boundary.
1.19 +#
1.20 +# $Id: utf16align.test,v 1.1 2006/02/16 18:16:38 drh Exp $
1.21 +
1.22 +set testdir [file dirname $argv0]
1.23 +source $testdir/tester.tcl
1.24 +
1.25 +# Skip this entire test if we do not support UTF16
1.26 +#
1.27 +ifcapable !utf16 {
1.28 + finish_test
1.29 + return
1.30 +}
1.31 +
1.32 +# Create a database with a UTF16 encoding. Put in lots of string
1.33 +# data of varying lengths.
1.34 +#
1.35 +do_test utf16align-1.0 {
1.36 + set unaligned_string_counter 0
1.37 + add_alignment_test_collations [sqlite3_connection_pointer db]
1.38 + execsql {
1.39 + PRAGMA encoding=UTF16;
1.40 + CREATE TABLE t1(
1.41 + id INTEGER PRIMARY KEY,
1.42 + spacer TEXT,
1.43 + a TEXT COLLATE utf16_aligned,
1.44 + b TEXT COLLATE utf16_unaligned
1.45 + );
1.46 + INSERT INTO t1(a) VALUES("abc");
1.47 + INSERT INTO t1(a) VALUES("defghi");
1.48 + INSERT INTO t1(a) VALUES("jklmnopqrstuv");
1.49 + INSERT INTO t1(a) VALUES("wxyz0123456789-");
1.50 + UPDATE t1 SET b=a||'-'||a;
1.51 + INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
1.52 + INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
1.53 + INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
1.54 + INSERT INTO t1(a,b) VALUES('one','two');
1.55 + INSERT INTO t1(a,b) SELECT a, b FROM t1;
1.56 + UPDATE t1 SET spacer = CASE WHEN rowid&1 THEN 'x' ELSE 'xx' END;
1.57 + SELECT count(*) FROM t1;
1.58 + }
1.59 +} 66
1.60 +do_test utf16align-1.1 {
1.61 + set unaligned_string_counter
1.62 +} 0
1.63 +
1.64 +# Creating an index that uses the unaligned collation. We should see
1.65 +# some unaligned strings passed to the collating function.
1.66 +#
1.67 +do_test utf16align-1.2 {
1.68 + execsql {
1.69 + CREATE INDEX t1i1 ON t1(spacer, b);
1.70 + }
1.71 + # puts $unaligned_string_counter
1.72 + expr {$unaligned_string_counter>0}
1.73 +} 1
1.74 +
1.75 +# Create another index that uses the aligned collation. This time
1.76 +# there should be no unaligned accesses
1.77 +#
1.78 +do_test utf16align-1.3 {
1.79 + set unaligned_string_counter 0
1.80 + execsql {
1.81 + CREATE INDEX t1i2 ON t1(spacer, a);
1.82 + }
1.83 + expr {$unaligned_string_counter>0}
1.84 +} 0
1.85 +integrity_check utf16align-1.4
1.86 +
1.87 +finish_test