/*
* Test method for 'java.awt.font.NumericShaper.shape(char[], int, int)'
*/
public final void testShapeCharArrayIntInt() {
NumericShaper ns;
/*************************/
/* Non-Contextual shaper */
/*************************/
ns = NumericShaper.getShaper(NumericShaper.BENGALI);
// test text that starts with the digit char and ends with nonDigit char
char[] chars = testStringNoContext1.toCharArray();
ns.shape(chars, 0, chars.length);
for (int i=0; i < chars.length; i++){
assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliStringNoContext1.charAt(i), chars[i]);
}
// text starts with the nonDigit char and ends with digit char
chars = testStringNoContext2.toCharArray();
ns.shape(chars, 0, chars.length);
for (int i=0; i < chars.length; i++){
assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliStringNoContext2.charAt(i), chars[i]);
}
/*********************/
/* Contextual shaper */
/*********************/
// shaper without default context
ns = NumericShaper.getContextualShaper(NumericShaper.BENGALI | NumericShaper.DEVANAGARI);
// test text starts with the BENGALI context digit char and ends with nonDigit char
chars = testStringContext1.toCharArray();
ns.shape(chars, 0, chars.length);
for (int i=0; i < chars.length; i++){
assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliDevanagariStringContext1.charAt(i), chars[i]);
}
// text starts with the nonDigit char and ends with digit char
// the first set of digits in text folows by "\u0909" char from the DEVANGARI script
// the second set of digits in text folows by "\u0983" char from the BENGALI script
chars = testStringContext2.toCharArray();
ns.shape(chars, 0, chars.length);
for (int i=0; i < chars.length; i++){
assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenBengaliDevanagariStringContext2.charAt(i), chars[i]);
}
// shaper with acceptable default context
ns = NumericShaper.getContextualShaper(NumericShaper.TAMIL | NumericShaper.DEVANAGARI, NumericShaper.DEVANAGARI);
// text starts with Digit char and ends with digit char
// These digits must be replaced with default context digits
chars = testStringContext3.toCharArray();
ns.shape(chars, 0, chars.length);
for (int i=0; i < chars.length; i++){
assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)goldenTamilDevanagariStringContext3.charAt(i), chars[i]);
}
// shaper with nonacceptable default context
ns = NumericShaper.getContextualShaper(NumericShaper.TAMIL | NumericShaper.DEVANAGARI, NumericShaper.KANNADA);
// text starts with Digit char and ends with digit char
// All digits must stay without changes
chars = testStringContext3.toCharArray();
ns.shape(chars, 0, chars.length);
for (int i=0; i < chars.length; i++){
assertEquals("shaped char at pos[" + i + "] not equals to the golden one", (int)testStringContext3.charAt(i), chars[i]);
}
// offset >= length
try{
ns.shape(chars, chars.length + 1, 1);
fail("IndexOutOfBoundsException expected but wasn't thrown!");
} catch (IndexOutOfBoundsException e){
// expected
}
// offset < 0
try{
ns.shape(chars, -1, 1);
fail("IndexOutOfBoundsException expected but wasn't thrown!");
} catch (IndexOutOfBoundsException e){
// expected
}
// offset+length out of range
try{
ns.shape(chars, chars.length -1, 2);
fail("IndexOutOfBoundsException expected but wasn't thrown!");
} catch (IndexOutOfBoundsException e){
// expected
}