sl@0
|
1 |
# 2006 February 16
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# This file contains code to verify that the SQLITE_UTF16_ALIGNED
|
sl@0
|
13 |
# flag passed into the sqlite3_create_collation() function insures
|
sl@0
|
14 |
# that all strings passed to that function are aligned on an even
|
sl@0
|
15 |
# byte boundary.
|
sl@0
|
16 |
#
|
sl@0
|
17 |
# $Id: utf16align.test,v 1.1 2006/02/16 18:16:38 drh Exp $
|
sl@0
|
18 |
|
sl@0
|
19 |
set testdir [file dirname $argv0]
|
sl@0
|
20 |
source $testdir/tester.tcl
|
sl@0
|
21 |
|
sl@0
|
22 |
# Skip this entire test if we do not support UTF16
|
sl@0
|
23 |
#
|
sl@0
|
24 |
ifcapable !utf16 {
|
sl@0
|
25 |
finish_test
|
sl@0
|
26 |
return
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
# Create a database with a UTF16 encoding. Put in lots of string
|
sl@0
|
30 |
# data of varying lengths.
|
sl@0
|
31 |
#
|
sl@0
|
32 |
do_test utf16align-1.0 {
|
sl@0
|
33 |
set unaligned_string_counter 0
|
sl@0
|
34 |
add_alignment_test_collations [sqlite3_connection_pointer db]
|
sl@0
|
35 |
execsql {
|
sl@0
|
36 |
PRAGMA encoding=UTF16;
|
sl@0
|
37 |
CREATE TABLE t1(
|
sl@0
|
38 |
id INTEGER PRIMARY KEY,
|
sl@0
|
39 |
spacer TEXT,
|
sl@0
|
40 |
a TEXT COLLATE utf16_aligned,
|
sl@0
|
41 |
b TEXT COLLATE utf16_unaligned
|
sl@0
|
42 |
);
|
sl@0
|
43 |
INSERT INTO t1(a) VALUES("abc");
|
sl@0
|
44 |
INSERT INTO t1(a) VALUES("defghi");
|
sl@0
|
45 |
INSERT INTO t1(a) VALUES("jklmnopqrstuv");
|
sl@0
|
46 |
INSERT INTO t1(a) VALUES("wxyz0123456789-");
|
sl@0
|
47 |
UPDATE t1 SET b=a||'-'||a;
|
sl@0
|
48 |
INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
|
sl@0
|
49 |
INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
|
sl@0
|
50 |
INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
|
sl@0
|
51 |
INSERT INTO t1(a,b) VALUES('one','two');
|
sl@0
|
52 |
INSERT INTO t1(a,b) SELECT a, b FROM t1;
|
sl@0
|
53 |
UPDATE t1 SET spacer = CASE WHEN rowid&1 THEN 'x' ELSE 'xx' END;
|
sl@0
|
54 |
SELECT count(*) FROM t1;
|
sl@0
|
55 |
}
|
sl@0
|
56 |
} 66
|
sl@0
|
57 |
do_test utf16align-1.1 {
|
sl@0
|
58 |
set unaligned_string_counter
|
sl@0
|
59 |
} 0
|
sl@0
|
60 |
|
sl@0
|
61 |
# Creating an index that uses the unaligned collation. We should see
|
sl@0
|
62 |
# some unaligned strings passed to the collating function.
|
sl@0
|
63 |
#
|
sl@0
|
64 |
do_test utf16align-1.2 {
|
sl@0
|
65 |
execsql {
|
sl@0
|
66 |
CREATE INDEX t1i1 ON t1(spacer, b);
|
sl@0
|
67 |
}
|
sl@0
|
68 |
# puts $unaligned_string_counter
|
sl@0
|
69 |
expr {$unaligned_string_counter>0}
|
sl@0
|
70 |
} 1
|
sl@0
|
71 |
|
sl@0
|
72 |
# Create another index that uses the aligned collation. This time
|
sl@0
|
73 |
# there should be no unaligned accesses
|
sl@0
|
74 |
#
|
sl@0
|
75 |
do_test utf16align-1.3 {
|
sl@0
|
76 |
set unaligned_string_counter 0
|
sl@0
|
77 |
execsql {
|
sl@0
|
78 |
CREATE INDEX t1i2 ON t1(spacer, a);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
expr {$unaligned_string_counter>0}
|
sl@0
|
81 |
} 0
|
sl@0
|
82 |
integrity_check utf16align-1.4
|
sl@0
|
83 |
|
sl@0
|
84 |
finish_test
|