persistentstorage/sqlite3api/TEST/TclScript/utf16align.test
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     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.1 2006/02/16 18:16:38 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   execsql {
       
    36     PRAGMA encoding=UTF16;
       
    37     CREATE TABLE t1(
       
    38       id INTEGER PRIMARY KEY,
       
    39       spacer TEXT,
       
    40       a TEXT COLLATE utf16_aligned,
       
    41       b TEXT COLLATE utf16_unaligned
       
    42     );
       
    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;
       
    55   }
       
    56 } 66
       
    57 do_test utf16align-1.1 {
       
    58   set unaligned_string_counter
       
    59 } 0
       
    60 
       
    61 # Creating an index that uses the unaligned collation.  We should see
       
    62 # some unaligned strings passed to the collating function.
       
    63 #
       
    64 do_test utf16align-1.2 {
       
    65   execsql {
       
    66     CREATE INDEX t1i1 ON t1(spacer, b);
       
    67   }
       
    68   # puts $unaligned_string_counter
       
    69   expr {$unaligned_string_counter>0}
       
    70 } 1
       
    71 
       
    72 # Create another index that uses the aligned collation.  This time
       
    73 # there should be no unaligned accesses
       
    74 #
       
    75 do_test utf16align-1.3 {
       
    76   set unaligned_string_counter 0
       
    77   execsql {
       
    78     CREATE INDEX t1i2 ON t1(spacer, a);
       
    79   }
       
    80   expr {$unaligned_string_counter>0}
       
    81 } 0
       
    82 integrity_check utf16align-1.4
       
    83 
       
    84 finish_test