utf16align.test 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. # Skip this entire test if we do not support UTF16
  21. #
  22. ifcapable !utf16 {
  23. finish_test
  24. return
  25. }
  26. # Create a database with a UTF16 encoding. Put in lots of string
  27. # data of varying lengths.
  28. #
  29. do_test utf16align-1.0 {
  30. set unaligned_string_counter 0
  31. add_alignment_test_collations [sqlite3_connection_pointer db]
  32. execsql {
  33. PRAGMA encoding=UTF16;
  34. CREATE TABLE t1(
  35. id INTEGER PRIMARY KEY,
  36. spacer TEXT,
  37. a TEXT COLLATE utf16_aligned,
  38. b TEXT COLLATE utf16_unaligned
  39. );
  40. INSERT INTO t1(a) VALUES("abc");
  41. INSERT INTO t1(a) VALUES("defghi");
  42. INSERT INTO t1(a) VALUES("jklmnopqrstuv");
  43. INSERT INTO t1(a) VALUES("wxyz0123456789-");
  44. UPDATE t1 SET b=a||'-'||a;
  45. INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
  46. INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
  47. INSERT INTO t1(a,b) SELECT a||b, b||a FROM t1;
  48. INSERT INTO t1(a,b) VALUES('one','two');
  49. INSERT INTO t1(a,b) SELECT a, b FROM t1;
  50. UPDATE t1 SET spacer = CASE WHEN rowid&1 THEN 'x' ELSE 'xx' END;
  51. SELECT count(*) FROM t1;
  52. }
  53. } 66
  54. do_test utf16align-1.1 {
  55. set unaligned_string_counter
  56. } 0
  57. # Creating an index that uses the unaligned collation. We should see
  58. # some unaligned strings passed to the collating function.
  59. #
  60. do_test utf16align-1.2 {
  61. execsql {
  62. CREATE INDEX t1i1 ON t1(spacer, b);
  63. }
  64. # puts $unaligned_string_counter
  65. expr {$unaligned_string_counter>0}
  66. } 1
  67. # Create another index that uses the aligned collation. This time
  68. # there should be no unaligned accesses
  69. #
  70. do_test utf16align-1.3 {
  71. set unaligned_string_counter 0
  72. execsql {
  73. CREATE INDEX t1i2 ON t1(spacer, a);
  74. }
  75. expr {$unaligned_string_counter>0}
  76. } 0
  77. integrity_check utf16align-1.4
  78. # ticket #3482
  79. #
  80. db close
  81. sqlite3 db :memory:
  82. do_test utf16align-2.1 {
  83. db eval {
  84. PRAGMA encoding=UTF16be;
  85. SELECT hex(ltrim(x'6efcda'));
  86. }
  87. } {6EFC}
  88. finish_test