diff --git a/manifest b/manifest index c39b2dfd27..cc8535da39 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Store\sthe\stext\sencoding\sin\sthe\sdatabase\s(as\smeta\svalue\s4).\s(CVS\s1435) -D 2004-05-22T08:09:11 +C Tests\sfor\sthe\sfunctions\sin\sutf.c.\s(CVS\s1436) +D 2004-05-22T08:16:11 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -88,6 +88,7 @@ F test/copy.test f07ea8d60878da7a67416ab62f78e9706b9d3c45 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/date.test aed5030482ebc02bd8d386c6c86a29f694ab068d F test/delete.test 92256384f1801760180ded129f7427884cf28886 +F test/enc.test a55481d45ff493804e8d88357feb4642fc50a6b2 F test/expr.test 8b62f3fcac64fbd5c3d43d7a7984245743dcbe65 F test/fkey1.test d65c824459916249bee501532d6154ddab0b5db7 F test/format3.test 149cc166c97923fa60def047e90dd3fb32bba916 @@ -195,7 +196,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P b3581d2796c8cb6581b7156774698a05fc8f800e -R 4a21a58cde782ee5391b183bd4ae3e26 +P 7f00ca5801889724c0e768961aa15f5ce0b8e7b5 +R 8442d8a6a5753b4c2931adc8bac1ca3e U danielk1977 -Z ae26e12ee15e175d842a96dadc5dd1c3 +Z 0cdfb634a2070ac93ca8bd36da159a9e diff --git a/manifest.uuid b/manifest.uuid index c68e5bff6e..0c9be072cb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7f00ca5801889724c0e768961aa15f5ce0b8e7b5 \ No newline at end of file +802d65affcafffda33e2ff1cbd4e4869dc3814df \ No newline at end of file diff --git a/test/enc.test b/test/enc.test new file mode 100644 index 0000000000..28fd78e733 --- /dev/null +++ b/test/enc.test @@ -0,0 +1,147 @@ +# 2002 May 24 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The focus of +# this file is testing the SQLite routines used for converting between the +# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and +# UTF-16be). +# +# $Id: enc.test,v 1.1 2004/05/22 08:16:11 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc do_bincmp_test {testname got expect} { + binary scan $expect \c* expectvals + binary scan $got \c* gotvals + do_test $testname [list set dummy $gotvals] $expectvals +} + +# $utf16 is a UTF-16 encoded string. Swap each pair of bytes around +# to change the byte-order of the string. +proc swap_byte_order {utf16} { + binary scan $utf16 \c* ints + + foreach {a b} $ints { + lappend ints2 $b + lappend ints2 $a + } + + return [binary format \c* $ints2] +} + +# +# Test that the SQLite routines for converting between UTF encodings +# produce the same results as their TCL counterparts. +# +# $testname is the prefix to be used for the test names. +# $str is a string to use for testing (encoded in UTF-8, as normal for TCL). +# +# The test procedure is: +# 1. Convert the string from UTF-8 to UTF-16le and check that the TCL and +# SQLite routines produce the same results. +# +# 2. Convert the string from UTF-8 to UTF-16be and check that the TCL and +# SQLite routines produce the same results. +# +# 3. Use the SQLite routines to convert the native machine order UTF-16 +# representation back to the original UTF-8. Check that the result +# matches the original representation. +# +# 4. Add a byte-order mark to each of the UTF-16 representations and +# check that the SQLite routines can convert them back to UTF-8. For +# byte-order mark info, refer to section 3.10 of the unicode standard. +# +# 5. Take the byte-order marked UTF-16 strings from step 4 and ensure +# that SQLite can convert them both to native byte order UTF-16 +# strings, sans BOM. +# +# Coverage: +# +# sqlite_utf8to16be (step 2) +# sqlite_utf8to16le (step 1) +# sqlite_utf16to8 (steps 3, 4) +# sqlite_utf16to16le (step 5) +# sqlite_utf16to16be (step 5) +# +proc test_conversion {testname str} { + + # Step 1. + set utf16le_sqlite [sqlite_utf8to16le $str] + set utf16le_tcl [encoding convertto unicode $str] + append utf16le_tcl "\x00\x00" + if { $::tcl_platform(byteOrder)!="littleEndian" } { + set utf16le_tcl [swap_byte_order $utf16le_tcl] + } + do_bincmp_test $testname.1 $utf16le_sqlite $utf16le_tcl + set utf16le $utf16le_tcl + + # Step 2. + set utf16be_sqlite [sqlite_utf8to16be $str] + set utf16be_tcl [encoding convertto unicode $str] + append utf16be_tcl "\x00\x00" + if { $::tcl_platform(byteOrder)=="littleEndian" } { + set utf16be_tcl [swap_byte_order $utf16be_tcl] + } + do_bincmp_test $testname.2 $utf16be_sqlite $utf16be_tcl + set utf16be $utf16be_tcl + + # Step 3. + if { $::tcl_platform(byteOrder)=="littleEndian" } { + set utf16 $utf16le + } else { + set utf16 $utf16be + } + set utf8_sqlite [sqlite_utf16to8 $utf16] + do_bincmp_test $testname.3 $utf8_sqlite [binarize $str] + + # Step 4 (little endian). + append utf16le_bom "\xFF\xFE" $utf16le + set utf8_sqlite [sqlite_utf16to8 $utf16le_bom] + do_bincmp_test $testname.4.le $utf8_sqlite [binarize $str] + + # Step 4 (big endian). + append utf16be_bom "\xFE\xFF" $utf16be + set utf8_sqlite [sqlite_utf16to8 $utf16be_bom] + do_bincmp_test $testname.4.be $utf8_sqlite [binarize $str] + + # Step 5 (little endian to little endian). + set utf16_sqlite [sqlite_utf16to16le $utf16le_bom] + do_bincmp_test $testname.5.le.le $utf16_sqlite $utf16le + + # Step 5 (big endian to big endian). + set utf16_sqlite [sqlite_utf16to16be $utf16be_bom] + do_bincmp_test $testname.5.be.be $utf16_sqlite $utf16be + + # Step 5 (big endian to little endian). + set utf16_sqlite [sqlite_utf16to16le $utf16be_bom] + do_bincmp_test $testname.5.be.le $utf16_sqlite $utf16le + + # Step 5 (little endian to big endian). + set utf16_sqlite [sqlite_utf16to16be $utf16le_bom] + do_bincmp_test $testname.5.le.be $utf16_sqlite $utf16be +} + + +test_conversion enc-1 "hello world" +test_conversion enc-2 "sqlite" +test_conversion enc-3 "" +test_conversion enc-4 "\u1234" +test_conversion enc-5 "\u4321abc" +test_conversion enc-6 "\u4321\u1234" +test_conversion enc-7 [string repeat "abcde\u00EF\u00EE\uFFFCabc" 100] +test_conversion enc-8 [string repeat "\u007E\u007F\u0080\u0081" 100] +test_conversion enc-9 [string repeat "\u07FE\u07FF\u0800\u0801\uFFF0" 100] + +finish_test + + + +