mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 23:10:40 +00:00
ICU-5410 Increase code coverage for UTF32 up to desired level. Commented out unreachable code in UTF32 decoder.
X-SVN-Rev: 21954
This commit is contained in:
parent
217d931e35
commit
40268bd4fb
2 changed files with 200 additions and 9 deletions
|
@ -85,8 +85,10 @@ class CharsetUTF32 extends CharsetICU {
|
|||
|
||||
mode=state;
|
||||
source.position(pos);
|
||||
if(!cr.isError() && source.hasRemaining()){
|
||||
if(!isFirstBuffer){
|
||||
cr = decodeLoopImpl(source, target, offsets, flush);
|
||||
} else {
|
||||
cr = CoderResult.malformedForLength(pos);
|
||||
}
|
||||
|
||||
return cr;
|
||||
|
@ -126,7 +128,8 @@ class CharsetUTF32 extends CharsetICU {
|
|||
toUnicodeStatus = 0;
|
||||
toULength =0;
|
||||
|
||||
while (i < 4) {
|
||||
//this while loop is not entered because of the byte order mark checking
|
||||
/*while (i < 4) {
|
||||
if (sourceArrayIndex < source.limit()) {
|
||||
ch = (ch << 8) | ((byte)(source.get(sourceArrayIndex)) & UConverterConstants.UNSIGNED_BYTE_MASK);
|
||||
toUBytesArray[i++] = (byte) source.get(sourceArrayIndex++);
|
||||
|
@ -134,11 +137,11 @@ class CharsetUTF32 extends CharsetICU {
|
|||
else {
|
||||
/* stores a partially calculated target*/
|
||||
/* + 1 to make 0 a valid character */
|
||||
toUnicodeStatus = ch + 1;
|
||||
/*toUnicodeStatus = ch + 1;
|
||||
toULength = (byte) i;
|
||||
break donefornow;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (ch <= UConverterConstants.MAXIMUM_UTF && !isSurrogate(ch)) {
|
||||
/* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
|
||||
|
@ -243,7 +246,8 @@ class CharsetUTF32 extends CharsetICU {
|
|||
toUnicodeStatus = 0;
|
||||
toULength=0;
|
||||
|
||||
while (i < 4) {
|
||||
//this while loop is not entered because of the byte order mark checking
|
||||
/*while (i < 4) {
|
||||
if (sourceArrayIndex < source.limit()) {
|
||||
ch |= (source.get(sourceArrayIndex) & UConverterConstants.UNSIGNED_BYTE_MASK) << (i * 8);
|
||||
toUBytesArray[i++] = (byte) source.get(sourceArrayIndex++);
|
||||
|
@ -251,11 +255,11 @@ class CharsetUTF32 extends CharsetICU {
|
|||
else {
|
||||
/* stores a partially calculated target*/
|
||||
/* + 1 to make 0 a valid character */
|
||||
toUnicodeStatus = ch + 1;
|
||||
/* toUnicodeStatus = ch + 1;
|
||||
toULength = (byte) i;
|
||||
break donefornow;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (ch <= UConverterConstants.MAXIMUM_UTF && !isSurrogate(ch)) {
|
||||
/* Normal valid byte when the loop has not prematurely terminated (i < inBytes) */
|
||||
|
|
|
@ -3418,8 +3418,195 @@ public class TestCharset extends TestFmwk {
|
|||
if (!result.isMalformed()) {
|
||||
errln("Malform error while encoding UTF32 charset (6) should have occurred.");
|
||||
}
|
||||
|
||||
|
||||
//end of encoding code coverage
|
||||
}
|
||||
|
||||
//this method provides better code coverage decoding UTF32 LE/BE
|
||||
public void TestDecodeUTF32LEBE() {
|
||||
CoderResult result = CoderResult.UNDERFLOW;
|
||||
CharsetProvider provider = new CharsetProviderICU();
|
||||
CharsetDecoder decoder;
|
||||
CharBuffer us = CharBuffer.allocate(0x10);
|
||||
ByteBuffer bs = ByteBuffer.allocate(0x10);
|
||||
|
||||
//decode UTF32LE
|
||||
decoder = provider.charsetForName("UTF-32LE").newDecoder();
|
||||
//test overflow buffer
|
||||
bs.put((byte)0x41); bs.put((byte)0xFF); bs.put((byte)0x01); bs.put((byte)0x00);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32LE", bs, us, true, false);
|
||||
errln("Overflow exception while decoding UTF32LE (1) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
us.clear();
|
||||
bs.clear();
|
||||
//test malform buffer
|
||||
bs.put((byte)0x02); bs.put((byte)0xD9); bs.put((byte)0x00); bs.put((byte)0x00);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32LE", bs, us, true, false);
|
||||
errln("Malform exception while decoding UTF32LE (2) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
us.clear();
|
||||
bs.clear();
|
||||
//test malform buffer
|
||||
bs.put((byte)0xFF); bs.put((byte)0xFE); bs.put((byte)0x00); bs.put((byte)0x00);
|
||||
bs.put((byte)0xFF); bs.put((byte)0xDF); bs.put((byte)0x10);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32LE", bs, us, true, false);
|
||||
errln("Malform exception while decoding UTF32LE (3) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
us.clear();
|
||||
bs.clear();
|
||||
//test malform buffer
|
||||
bs.put((byte)0xFF); bs.put((byte)0xFE); bs.put((byte)0x00); bs.put((byte)0x00);
|
||||
bs.put((byte)0x02); bs.put((byte)0xD9); bs.put((byte)0x00); bs.put((byte)0x00);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32LE", bs, us, true, false);
|
||||
errln("Malform exception while decoding UTF32LE (4) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
us.clear();
|
||||
bs.clear();
|
||||
//test overflow buffer
|
||||
bs.put((byte)0xFF); bs.put((byte)0xFE); bs.put((byte)0x00); bs.put((byte)0x00);
|
||||
bs.put((byte)0xDD); bs.put((byte)0xFF); bs.put((byte)0x10); bs.put((byte)0x00);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32LE", bs, us, true, false);
|
||||
errln("Overflow exception while decoding UTF32LE (5) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
//end of decode UTF32LE
|
||||
|
||||
bs.clear();
|
||||
us.clear();
|
||||
|
||||
//decode UTF32BE
|
||||
decoder = provider.charsetForName("UTF-32BE").newDecoder();
|
||||
//test overflow buffer
|
||||
bs.put((byte)0x00); bs.put((byte)0x01); bs.put((byte)0xFF); bs.put((byte)0x41);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32BE", bs, us, true, false);
|
||||
errln("Overflow exception while decoding UTF32BE (1) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
bs.clear();
|
||||
us.clear();
|
||||
//test malform buffer
|
||||
bs.put((byte)0x00); bs.put((byte)0x00); bs.put((byte)0xD9); bs.put((byte)0x02);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32BE", bs, us, true, false);
|
||||
errln("Malform exception while decoding UTF32BE (2) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
bs.clear();
|
||||
us.clear();
|
||||
//test malform buffer
|
||||
bs.put((byte)0x00); bs.put((byte)0x00); bs.put((byte)0xFE); bs.put((byte)0xFF);
|
||||
bs.put((byte)0x10); bs.put((byte)0xFF); bs.put((byte)0xDF);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32BE", bs, us, true, false);
|
||||
errln("Malform exception while decoding UTF32BE (3) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
bs.clear();
|
||||
us.clear();
|
||||
//test overflow buffer
|
||||
bs.put((byte)0x00); bs.put((byte)0x00); bs.put((byte)0xFE); bs.put((byte)0xFF);
|
||||
bs.put((byte)0x00); bs.put((byte)0x10); bs.put((byte)0xFF); bs.put((byte)0xDD);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32BE", bs, us, true, false);
|
||||
errln("Overflow exception while decoding UTF32BE (4) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
|
||||
bs.clear();
|
||||
us.clear();
|
||||
//test malform buffer
|
||||
bs.put((byte)0x00); bs.put((byte)0x00); bs.put((byte)0xFE);
|
||||
us.put((char)0x0000);
|
||||
|
||||
us.limit(us.position());
|
||||
us.position(0);
|
||||
bs.limit(bs.position());
|
||||
bs.position(0);
|
||||
|
||||
try {
|
||||
smBufDecode(decoder, "UTF-32BE", bs, us, true, false);
|
||||
errln("Malform exception while decoding UTF32BE (5) should have been thrown.");
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
//end of decode UTF32BE
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue