ICU-6955 Add test for LMBCS.

X-SVN-Rev: 26134
This commit is contained in:
Michael Ow 2009-06-19 23:12:47 +00:00
parent 1be173845b
commit 8e2c79480a
2 changed files with 64 additions and 0 deletions

View file

@ -108,6 +108,17 @@ public abstract class CharsetICU extends Charset{
private static final HashMap<String, String> algorithmicCharsets = new HashMap<String, String>();
static{
algorithmicCharsets.put("LMBCS-1", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-2", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-3", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-4", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-5", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-6", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-8", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-11", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-16", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-17", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-18", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("LMBCS-19", "com.ibm.icu.charset.CharsetLMBCS");
algorithmicCharsets.put("BOCU-1", "com.ibm.icu.charset.CharsetBOCU1" );
algorithmicCharsets.put("SCSU", "com.ibm.icu.charset.CharsetSCSU" );
algorithmicCharsets.put("US-ASCII", "com.ibm.icu.charset.CharsetASCII" );

View file

@ -5383,4 +5383,57 @@ public class TestCharset extends TestFmwk {
}
errln("IllegalArgumentException should have been thrown.");
}
public void TestCharsetLMBCS() {
String []lmbcsNames = {
"LMBCS-1",
"LMBCS-2",
"LMBCS-3",
"LMBCS-4",
"LMBCS-5",
"LMBCS-6",
"LMBCS-8",
"LMBCS-11",
"LMBCS-16",
"LMBCS-17",
"LMBCS-18",
"LMBCS-19"
};
char[] src = {
0x0192, 0x0041, 0x0061, 0x00D0, 0x00F6, 0x0100, 0x0174, 0x02E4, 0x03F5, 0x03FB,
0x05D3, 0x05D4, 0x05EA, 0x0684, 0x0685, 0x1801, 0x11B3, 0x11E8, 0x1F9A, 0x2EB4,
0x3157, 0x3336, 0x3304, 0xD881, 0xDC88
};
CharBuffer cbInput = CharBuffer.wrap(src);
CharsetProviderICU provider = new CharsetProviderICU();
for (int i = 0; i < lmbcsNames.length; i++) {
Charset charset = provider.charsetForName(lmbcsNames[i]);
if (charset == null) {
errln("Unable to create LMBCS charset: " + lmbcsNames[i]);
return;
}
CharsetEncoder encoder = charset.newEncoder();
CharsetDecoder decoder = charset.newDecoder();
try {
cbInput.position(0);
ByteBuffer bbTmp = encoder.encode(cbInput);
CharBuffer cbOutput = decoder.decode(bbTmp);
if (!equals(cbInput, cbOutput)) {
errln("Roundtrip test failed for charset: " + lmbcsNames[i]);
}
} catch (Exception ex) {
if (i >= 8) {
/* Expected exceptions */
continue;
}
errln("Exception thrown: " + ex + " while using charset: " + lmbcsNames[i]);
}
}
}
}