ICU-6955 Update code coverage test for SCSU and BOCU.

X-SVN-Rev: 26136
This commit is contained in:
Michael Ow 2009-06-21 06:55:31 +00:00
parent 2868b4dbc6
commit 283c484852
4 changed files with 126 additions and 44 deletions

View File

@ -834,6 +834,14 @@ conversion:table(nofallback) {
:intvector{},
:int{1}, :int{0}, "", "0", :bin{""}
}
{
"BOCU-1",
:bin{ fe0053c6 },
"\u0003\u0076",
:intvector{},
:int{1}, :int{0}, "", "0", :bin{""}
}
//Improve code coverage for SCSU
{
"SCSU",
@ -842,6 +850,13 @@ conversion:table(nofallback) {
:intvector{},
:int{1}, :int{0}, "", "0", :bin{""}
}
{
"SCSU",
:bin{ 41df1281035f10df1b03df1c88800bbfffff },
"\u0041\u00df\u0401\u015f\u00df\u01df\uf000\udbff\udfff",
:intvector{},
:int{1}, :int{0}, "", ".", :bin{""}
}
}
}

View File

@ -1158,48 +1158,31 @@ class CharsetSCSU extends CharsetICU{
/*write the output character byte from c and length*/
/*from the first if in the loop we know that targetCapacity>0*/
if(length<=targetCapacity){
if(offsets==null){
switch(length){
/*each branch falls through the next one*/
case 4:
target.put((byte)(c>>24));
case 3:
target.put((byte)(c>>16));
case 2:
target.put((byte)(c>>8));
case 1:
target.put((byte)c);
default:
/*will never occur*/
break;
}
}else {
switch(length){
/*each branch falls through to the next one*/
case 4:
target.put((byte)(c>>24));
if(offsets!=null){
offsets.put(sourceIndex);
}
case 3:
target.put((byte)(c>>16));
if(offsets!=null){
offsets.put(sourceIndex);
}
case 2:
target.put((byte)(c>>8));
if(offsets!=null){
offsets.put(sourceIndex);
}
case 1:
target.put((byte)c);
if(offsets!=null){
offsets.put(sourceIndex);
}
default:
/*will never occur*/
break;
}
switch(length){
/*each branch falls through the next one*/
case 4:
target.put((byte)(c>>24));
if(offsets!=null){
offsets.put(sourceIndex);
}
case 3:
target.put((byte)(c>>16));
if(offsets!=null){
offsets.put(sourceIndex);
}
case 2:
target.put((byte)(c>>8));
if(offsets!=null){
offsets.put(sourceIndex);
}
case 1:
target.put((byte)c);
if(offsets!=null){
offsets.put(sourceIndex);
}
default:
/*will never occur*/
break;
}
targetCapacity-=length;

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7519a822ce8a3697adbad3fe85f070e8663b1fde3b8f310cac0243345f13b902
size 772303
oid sha256:64afad09d989cb4175ee8cac27bc635053264d550b8369a6feeafca713dc2dda
size 772407

View File

@ -5250,6 +5250,90 @@ public class TestCharset extends TestFmwk {
}
}
}
/* Monkey test */
{
char[] monkeyIn = {
0x00A8, 0x3003, 0x3005, 0x2015, 0xFF5E, 0x2016, 0x2026, 0x2018, 0x000D, 0x000A,
0x2019, 0x201C, 0x201D, 0x3014, 0x3015, 0x3008, 0x3009, 0x300A, 0x000D, 0x000A,
0x300B, 0x300C, 0x300D, 0x300E, 0x300F, 0x3016, 0x3017, 0x3010, 0x000D, 0x000A,
0x3011, 0x00B1, 0x00D7, 0x00F7, 0x2236, 0x2227, 0x7FC1, 0x8956, 0x000D, 0x000A,
0x9D2C, 0x9D0E, 0x9EC4, 0x5CA1, 0x6C96, 0x837B, 0x5104, 0x5C4B, 0x000D, 0x000A,
0x61B6, 0x81C6, 0x6876, 0x7261, 0x4E59, 0x4FFA, 0x5378, 0x57F7, 0x000D, 0x000A,
0x57F4, 0x57F9, 0x57FA, 0x57FC, 0x5800, 0x5802, 0x5805, 0x5806, 0x000D, 0x000A,
0x580A, 0x581E, 0x6BB5, 0x6BB7, 0x6BBA, 0x6BBC, 0x9CE2, 0x977C, 0x000D, 0x000A,
0x6BBF, 0x6BC1, 0x6BC5, 0x6BC6, 0x6BCB, 0x6BCD, 0x6BCF, 0x6BD2, 0x000D, 0x000A,
0x6BD3, 0x6BD4, 0x6BD6, 0x6BD7, 0x6BD8, 0x6BDB, 0x6BEB, 0x6BEC, 0x000D, 0x000A,
0x6C05, 0x6C08, 0x6C0F, 0x6C11, 0x6C13, 0x6C23, 0x6C34, 0x0041, 0x000D, 0x000A,
0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x000D, 0x000A,
0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x000D, 0x000A,
0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x000D, 0x000A,
0x005B, 0x9792, 0x9CCC, 0x9CCD, 0x9CCE, 0x9CCF, 0x9CD0, 0x9CD3, 0x000D, 0x000A,
0x9CD4, 0x9CD5, 0x9CD7, 0x9CD8, 0x9CD9, 0x9CDC, 0x9CDD, 0x9CDF, 0x000D, 0x000A,
0x9785, 0x9791, 0x00BD, 0x0390, 0x0385, 0x0386, 0x0388, 0x0389, 0x000D, 0x000A,
0x038E, 0x038F, 0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x000D, 0x000A,
0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x038A, 0x038C, 0x039C, 0x000D, 0x000A,
/* test non-BMP code points */
0xD869, 0xDE99, 0xD869, 0xDE9C, 0xD869, 0xDE9D, 0xD869, 0xDE9E, 0xD869, 0xDE9F,
0xD869, 0xDEA0, 0xD869, 0xDEA5, 0xD869, 0xDEA6, 0xD869, 0xDEA7, 0xD869, 0xDEA8,
0xD869, 0xDEAB, 0xD869, 0xDEAC, 0xD869, 0xDEAD, 0xD869, 0xDEAE, 0xD869, 0xDEAF,
0xD869, 0xDEB0, 0xD869, 0xDEB1, 0xD869, 0xDEB3, 0xD869, 0xDEB5, 0xD869, 0xDEB6,
0xD869, 0xDEB7, 0xD869, 0xDEB8, 0xD869, 0xDEB9, 0xD869, 0xDEBA, 0xD869, 0xDEBB,
0xD869, 0xDEBC, 0xD869, 0xDEBD, 0xD869, 0xDEBE, 0xD869, 0xDEBF, 0xD869, 0xDEC0,
0xD869, 0xDEC1, 0xD869, 0xDEC2, 0xD869, 0xDEC3, 0xD869, 0xDEC4, 0xD869, 0xDEC8,
0xD869, 0xDECA, 0xD869, 0xDECB, 0xD869, 0xDECD, 0xD869, 0xDECE, 0xD869, 0xDECF,
0xD869, 0xDED0, 0xD869, 0xDED1, 0xD869, 0xDED2, 0xD869, 0xDED3, 0xD869, 0xDED4,
0xD869, 0xDED5, 0xD800, 0xDC00, 0xD800, 0xDC00, 0xD800, 0xDC00, 0xDBFF, 0xDFFF,
0xDBFF, 0xDFFF, 0xDBFF, 0xDFFF,
0x4DB3, 0x4DB4, 0x4DB5, 0x4E00, 0x4E00, 0x4E01, 0x4E02, 0x4E03, 0x000D, 0x000A,
0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x33E0, 0x33E6, 0x000D, 0x000A,
0x4E05, 0x4E07, 0x4E04, 0x4E08, 0x4E08, 0x4E09, 0x4E0A, 0x4E0B, 0x000D, 0x000A,
0x4E0C, 0x0021, 0x0022, 0x0023, 0x0024, 0xFF40, 0xFF41, 0xFF42, 0x000D, 0x000A,
0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0x000D, 0x000A,
};
encode.reset();
decode.reset();
CharBuffer monkeyCB = CharBuffer.wrap(monkeyIn);
try {
ByteBuffer monkeyBB = encode.encode(monkeyCB);
CharBuffer monkeyEndResult = decode.decode(monkeyBB);
} catch (Exception ex) {
errln("Exception thrown while encoding/decoding monkey test in SCSU: " + ex);
}
}
// Test malformed
{
char[] malformedSequence = {
0xD899, 0xDC7F, 0xDC88, 0xDC88, 0xD888, 0xDDF9
};
encode.reset();
CharBuffer malformedSrc = CharBuffer.wrap(malformedSequence);
try {
encode.encode(malformedSrc);
errln("Malformed error should have thrown an exception.");
} catch (Exception ex) {
}
}
// Test overflow buffer
{
byte[] testOverflow = {
0x41,(byte) 0xdf, 0x12,(byte) 0x81, 0x03, 0x5f, 0x10, (byte)0xdf, 0x1b, 0x03,
(byte)0xdf, 0x1c,(byte) 0x88,(byte) 0x80, 0x0b, (byte)0xbf,(byte) 0xff,(byte) 0xff
};
decode.reset();
try {
smBufDecode(decode, "SCSU overflow test", ByteBuffer.wrap(testOverflow), CharBuffer.allocate(8), true, true);
errln("Buffer overflow exception should have been thrown.");
} catch (BufferOverflowException ex) {
} catch (Exception ex) {
errln("Buffer overflow exception should have been thrown.");
}
}
}
/* Test for BOCU1 converter*/