shifted com.ibm.icu.test.text to com.ibm.test.text
X-SVN-Rev: 3900
This commit is contained in:
parent
a0d544a0ad
commit
3ad68a0aa2
@ -1,313 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterCompare.java,v $
|
||||
* $Date: 2001/02/28 21:00:03 $
|
||||
* $Revision: 1.3 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import com.ibm.text.UCharacter;
|
||||
import com.ibm.text.UCharacterCategory;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* A class to compare the difference in methods between java.lang.Character and
|
||||
* UCharacter
|
||||
* @author Syn Wee Quek
|
||||
* @since oct 06 2000
|
||||
* @see com.ibm.text.UCharacter
|
||||
*/
|
||||
|
||||
public final class UCharacterCompare
|
||||
{
|
||||
// private variables ================================================
|
||||
|
||||
private static Hashtable m_hashtable_ = new Hashtable();
|
||||
|
||||
// public methods ======================================================
|
||||
|
||||
/**
|
||||
* Main testing method
|
||||
*/
|
||||
public static void main(String arg[])
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter f;
|
||||
if (arg.length == 0)
|
||||
f = new FileWriter("compare.txt");
|
||||
else
|
||||
f = new FileWriter(arg[0]);
|
||||
PrintWriter p = new PrintWriter(f);
|
||||
p.print("char character name ");
|
||||
p.println("method name ucharacter character");
|
||||
for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i ++)
|
||||
{
|
||||
if (UCharacter.isDefined(i) != Character.isDefined(i))
|
||||
trackDifference(p, i, "isDefined()", "" + UCharacter.isDefined(i),
|
||||
"" + Character.isDefined(i));
|
||||
else
|
||||
{
|
||||
if (UCharacter.digit(i, 10) != Character.digit(i, 10))
|
||||
trackDifference(p, i, "digit()", "" + UCharacter.digit(i, 10),
|
||||
"" + Character.digit(i, 10));
|
||||
if (UCharacter.getNumericValue(i) != Character.getNumericValue(i))
|
||||
trackDifference(p, i, "getNumericValue()",
|
||||
"" + UCharacter.getNumericValue(i),
|
||||
"" + Character.getNumericValue(i));
|
||||
if (!compareType(UCharacter.getType(i), Character.getType(i)))
|
||||
trackDifference(p, i, "getType()", "" + UCharacter.getType(i),
|
||||
"" + Character.getType(i));
|
||||
if (UCharacter.isDigit(i) != Character.isDigit(i))
|
||||
trackDifference(p, i, "isDigit()",
|
||||
"" + UCharacter.isDigit(i),
|
||||
"" + Character.isDigit(i));
|
||||
if (UCharacter.isISOControl(i) != Character.isISOControl(i))
|
||||
trackDifference(p, i, "isISOControl()",
|
||||
"" + UCharacter.isISOControl(i),
|
||||
"" + Character.isISOControl(i));
|
||||
if (UCharacter.isLetter(i) != Character.isLetter(i))
|
||||
trackDifference(p, i, "isLetter()", "" + UCharacter.isLetter(i),
|
||||
"" + Character.isLetter(i));
|
||||
if (UCharacter.isLetterOrDigit(i) != Character.isLetterOrDigit(i))
|
||||
trackDifference(p, i, "isLetterOrDigit()",
|
||||
"" + UCharacter.isLetterOrDigit(i),
|
||||
"" + Character.isLetterOrDigit(i));
|
||||
if (UCharacter.isLowerCase(i) != Character.isLowerCase(i))
|
||||
trackDifference(p, i, "isLowerCase()",
|
||||
"" + UCharacter.isLowerCase(i),
|
||||
"" + Character.isLowerCase(i));
|
||||
if (UCharacter.isWhitespace(i) != Character.isWhitespace(i))
|
||||
trackDifference(p, i, "isWhitespace()",
|
||||
"" + UCharacter.isWhitespace(i),
|
||||
"" + Character.isWhitespace(i));
|
||||
if (UCharacter.isSpaceChar(i) != Character.isSpaceChar(i))
|
||||
trackDifference(p, i, "isSpaceChar()",
|
||||
"" + UCharacter.isSpaceChar(i),
|
||||
"" + Character.isSpaceChar(i));
|
||||
if (UCharacter.isTitleCase(i) != Character.isTitleCase(i))
|
||||
trackDifference(p, i, "isTitleChar()",
|
||||
"" + UCharacter.isTitleCase(i),
|
||||
"" + Character.isTitleCase(i));
|
||||
if (UCharacter.isUnicodeIdentifierPart(i) !=
|
||||
Character.isUnicodeIdentifierPart(i))
|
||||
trackDifference(p, i, "isUnicodeIdentifierPart()",
|
||||
"" + UCharacter.isUnicodeIdentifierPart(i),
|
||||
"" + Character.isUnicodeIdentifierPart(i));
|
||||
if (UCharacter.isUnicodeIdentifierStart(i) !=
|
||||
Character.isUnicodeIdentifierStart(i))
|
||||
trackDifference(p, i, "isUnicodeIdentifierStart()",
|
||||
"" + UCharacter.isUnicodeIdentifierStart(i),
|
||||
"" + Character.isUnicodeIdentifierStart(i));
|
||||
if (UCharacter.isIdentifierIgnorable(i) !=
|
||||
Character.isIdentifierIgnorable(i))
|
||||
trackDifference(p, i, "isIdentifierIgnorable()",
|
||||
"" + UCharacter.isIdentifierIgnorable(i),
|
||||
"" + Character.isIdentifierIgnorable(i));
|
||||
if (UCharacter.isUpperCase(i) != Character.isUpperCase(i))
|
||||
trackDifference(p, i, "isUpperCase()",
|
||||
"" + UCharacter.isUpperCase(i),
|
||||
"" + Character.isUpperCase(i));
|
||||
if (UCharacter.toLowerCase(i) != Character.toLowerCase(i))
|
||||
trackDifference(p, i, "toLowerCase()",
|
||||
Integer.toHexString(UCharacter.toLowerCase(i)),
|
||||
Integer.toHexString(Character.toLowerCase(i)));
|
||||
if (!UCharacter.toString(i).equals(new Character(i).toString()))
|
||||
trackDifference(p, i, "toString()",
|
||||
UCharacter.toString(i),
|
||||
new Character(i).toString());
|
||||
if (UCharacter.toTitleCase(i) != Character.toTitleCase(i))
|
||||
trackDifference(p, i, "toTitleCase()",
|
||||
Integer.toHexString(UCharacter.toTitleCase(i)),
|
||||
Integer.toHexString(Character.toTitleCase(i)));
|
||||
if (UCharacter.toUpperCase(i) != Character.toUpperCase(i))
|
||||
trackDifference(p, i, "toUpperCase()",
|
||||
Integer.toHexString(UCharacter.toUpperCase(i)),
|
||||
Integer.toHexString(Character.toUpperCase(i)));
|
||||
}
|
||||
}
|
||||
summary(p);
|
||||
p.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// private methods ===================================================
|
||||
|
||||
/**
|
||||
* Comparing types
|
||||
* @param uchartype UCharacter type
|
||||
* @param jchartype java.lang.Character type
|
||||
*/
|
||||
private static boolean compareType(int uchartype, int jchartype)
|
||||
{
|
||||
if (uchartype == UCharacterCategory.UNASSIGNED &&
|
||||
jchartype == Character.UNASSIGNED)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.UPPERCASE_LETTER &&
|
||||
jchartype == Character.UPPERCASE_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.LOWERCASE_LETTER &&
|
||||
jchartype == Character.LOWERCASE_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.TITLECASE_LETTER &&
|
||||
jchartype == Character.TITLECASE_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.MODIFIER_LETTER &&
|
||||
jchartype == Character.MODIFIER_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.OTHER_LETTER &&
|
||||
jchartype == Character.OTHER_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.NON_SPACING_MARK &&
|
||||
jchartype == Character.NON_SPACING_MARK)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.ENCLOSING_MARK &&
|
||||
jchartype == Character.ENCLOSING_MARK)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.COMBINING_SPACING_MARK &&
|
||||
jchartype == Character.COMBINING_SPACING_MARK)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.DECIMAL_DIGIT_NUMBER &&
|
||||
jchartype == Character.DECIMAL_DIGIT_NUMBER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.LETTER_NUMBER &&
|
||||
jchartype == Character.LETTER_NUMBER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.OTHER_NUMBER &&
|
||||
jchartype == Character.OTHER_NUMBER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.SPACE_SEPARATOR &&
|
||||
jchartype == Character.SPACE_SEPARATOR)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.LINE_SEPARATOR &&
|
||||
jchartype == Character.LINE_SEPARATOR)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.PARAGRAPH_SEPARATOR &&
|
||||
jchartype == Character.PARAGRAPH_SEPARATOR)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.CONTROL &&
|
||||
jchartype == Character.CONTROL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.FORMAT &&
|
||||
jchartype == Character.FORMAT)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.PRIVATE_USE &&
|
||||
jchartype == Character.PRIVATE_USE)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.SURROGATE &&
|
||||
jchartype == Character.SURROGATE)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.DASH_PUNCTUATION &&
|
||||
jchartype == Character.DASH_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.START_PUNCTUATION &&
|
||||
jchartype == Character.START_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.END_PUNCTUATION &&
|
||||
jchartype == Character.END_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.CONNECTOR_PUNCTUATION &&
|
||||
jchartype == Character.CONNECTOR_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.OTHER_PUNCTUATION &&
|
||||
jchartype == Character.OTHER_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.MATH_SYMBOL &&
|
||||
jchartype == Character.MATH_SYMBOL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.CURRENCY_SYMBOL &&
|
||||
jchartype == Character.CURRENCY_SYMBOL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.MODIFIER_SYMBOL &&
|
||||
jchartype == Character.MODIFIER_SYMBOL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.OTHER_SYMBOL &&
|
||||
jchartype == Character.OTHER_SYMBOL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.INITIAL_PUNCTUATION &&
|
||||
jchartype == Character.START_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.FINAL_PUNCTUATION &&
|
||||
jchartype == Character.END_PUNCTUATION)
|
||||
return true;
|
||||
/*if (uchartype == UCharacterCategory.GENERAL_OTHER_TYPES &&
|
||||
jchartype == Character.GENERAL_OTHER_TYPES)
|
||||
return true;*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Difference writing to file
|
||||
* @param f file outputstream
|
||||
* @param ch code point
|
||||
* @param method for testing
|
||||
* @param ucharval UCharacter value after running method
|
||||
* @param charval Character value after running method
|
||||
* @exception thrown when error occur in writing to file
|
||||
*/
|
||||
private static void trackDifference(PrintWriter f, int ch, String method,
|
||||
String ucharval, String charval)
|
||||
throws Exception
|
||||
{
|
||||
if (m_hashtable_.containsKey(method))
|
||||
{
|
||||
Integer value = (Integer)m_hashtable_.get(method);
|
||||
m_hashtable_.put(method, new Integer(value.intValue() + 1));
|
||||
}
|
||||
else
|
||||
m_hashtable_.put(method, new Integer(1));
|
||||
|
||||
String temp = Integer.toHexString(ch);
|
||||
StringBuffer s = new StringBuffer(temp);
|
||||
for (int i = 0; i < 6 - temp.length(); i ++)
|
||||
s.append(' ');
|
||||
temp = UCharacter.getName(ch);
|
||||
if (temp == null)
|
||||
temp = " ";
|
||||
s.append(temp);
|
||||
for (int i = 0; i < 73 - temp.length(); i ++)
|
||||
s.append(' ');
|
||||
|
||||
s.append(method);
|
||||
for (int i = 0; i < 27 - method.length(); i ++)
|
||||
s.append(' ');
|
||||
s.append(ucharval);
|
||||
for (int i = 0; i < 11 - ucharval.length(); i ++)
|
||||
s.append(' ');
|
||||
s.append(charval);
|
||||
f.println(s.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Does up a summary of the differences
|
||||
* @param f file outputstream
|
||||
*/
|
||||
private static void summary(PrintWriter f)
|
||||
{
|
||||
f.println("==================================================");
|
||||
f.println("Summary of differences");
|
||||
for (Enumeration e = m_hashtable_.keys() ; e.hasMoreElements() ;)
|
||||
{
|
||||
StringBuffer method = new StringBuffer((String)e.nextElement());
|
||||
int count = ((Integer)m_hashtable_.get(method.toString())).intValue();
|
||||
for (int i = 30 - method.length(); i > 0; i --)
|
||||
method.append(' ');
|
||||
f.println(method + " " + count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,652 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterTest.java,v $
|
||||
* $Date: 2001/02/28 21:00:03 $
|
||||
* $Revision: 1.5 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Locale;
|
||||
import com.ibm.test.TestFmwk;
|
||||
import com.ibm.text.UCharacter;
|
||||
import com.ibm.text.UCharacterCategory;
|
||||
import com.ibm.text.UCharacterDirection;
|
||||
import com.ibm.text.UTF16;
|
||||
|
||||
/**
|
||||
* Testing class for UCharacter
|
||||
* Mostly following the test cases for ICU
|
||||
* @author Syn Wee Quek
|
||||
* @since nov 04 2000
|
||||
*/
|
||||
public final class UCharacterTest extends TestFmwk
|
||||
{
|
||||
// private variables =============================================
|
||||
|
||||
/**
|
||||
* ICU4J data version number
|
||||
*/
|
||||
private final String VERSION_ = "3.0.0.0";
|
||||
|
||||
// constructor ===================================================
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public UCharacterTest()
|
||||
{
|
||||
}
|
||||
|
||||
// public methods ================================================
|
||||
|
||||
/**
|
||||
* Testing the uppercase and lowercase function of UCharacter
|
||||
*/
|
||||
public void TestUpperLower()
|
||||
{
|
||||
// variables to test the uppercase and lowercase characters
|
||||
int upper[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0xb1, 0xb2,
|
||||
0xb3, 0x48, 0x49, 0x4a, 0x2e, 0x3f, 0x3a, 0x4b, 0x4c,
|
||||
0x4d, 0x4e, 0x4f, 0x01c4, 0x01c8, 0x000c, 0x0000};
|
||||
int lower[] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0xb1, 0x00b2,
|
||||
0xb3, 0x68, 0x69, 0x6a, 0x2e, 0x3f, 0x3a, 0x6b, 0x6c,
|
||||
0x6d, 0x6e, 0x6f, 0x01c6, 0x01c9, 0x000c, 0x0000};
|
||||
|
||||
int size = upper.length;
|
||||
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (UCharacter.isLetter(lower[i]) && !UCharacter.isLowerCase(lower[i]))
|
||||
{
|
||||
errln("FAIL isLowerCase test for 0x" +
|
||||
Integer.toHexString(lower[i]));
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isLetter(upper[i]) && !(UCharacter.isUpperCase(upper[i])
|
||||
|| UCharacter.isTitleCase(upper[i])))
|
||||
{
|
||||
errln("FAIL isUpperCase test for 0x" +
|
||||
Integer.toHexString(upper[i]));
|
||||
break;
|
||||
}
|
||||
if (lower[i] != UCharacter.toLowerCase(upper[i]) ||
|
||||
(upper[i] != UCharacter.toUpperCase(lower[i]) &&
|
||||
upper[i] != UCharacter.toTitleCase(lower[i])))
|
||||
{
|
||||
errln("FAIL case conversion test for 0x" +
|
||||
Integer.toHexString(upper[i]) + " to 0x" +
|
||||
Integer.toHexString(lower[i]));
|
||||
break;
|
||||
}
|
||||
if (lower[i] != UCharacter.toLowerCase(lower[i]))
|
||||
{
|
||||
errln("FAIL lower case conversion test for 0x" +
|
||||
Integer.toHexString(lower[i]));
|
||||
break;
|
||||
}
|
||||
if (upper[i] != UCharacter.toUpperCase(upper[i]) &&
|
||||
upper[i] != UCharacter.toTitleCase(upper[i]))
|
||||
{
|
||||
errln("FAIL upper case conversion test for 0x" +
|
||||
Integer.toHexString(upper[i]));
|
||||
break;
|
||||
}
|
||||
logln("Ok 0x" + Integer.toHexString(upper[i]) + " and 0x" +
|
||||
Integer.toHexString(lower[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the letter and number determination in UCharacter
|
||||
*/
|
||||
public void TestLetterNumber()
|
||||
{
|
||||
for (int i = 0x0041; i < 0x005B; i ++)
|
||||
if (!UCharacter.isLetter(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) + " expected to be a letter");
|
||||
|
||||
for (int i = 0x0660; i < 0x066A; i ++)
|
||||
if (UCharacter.isLetter(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) +
|
||||
" expected not to be a letter");
|
||||
|
||||
for (int i = 0x0660; i < 0x066A; i ++)
|
||||
if (!UCharacter.isDigit(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) + " expected to be a digit");
|
||||
|
||||
for (int i = 0x0041; i < 0x005B; i ++)
|
||||
if (!UCharacter.isLetterOrDigit(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) +
|
||||
" expected not to be a digit");
|
||||
|
||||
for (int i = 0x0660; i < 0x066A; i ++)
|
||||
if (!UCharacter.isLetterOrDigit(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) +
|
||||
"expected to be either a letter or a digit");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for space determination in UCharacter
|
||||
*/
|
||||
public void TestSpaces()
|
||||
{
|
||||
int spaces[] = {0x0020, 0x00a0, 0x2000, 0x2001, 0x2005};
|
||||
int nonspaces[] = {0x61, 0x62, 0x63, 0x64, 0x74};
|
||||
int whitespaces[] = {0x2008, 0x2009, 0x200a, 0x001c, 0x000c};
|
||||
int nonwhitespaces[] = {0x61, 0x62, 0x3c, 0x28, 0x3f};
|
||||
|
||||
int size = spaces.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (!UCharacter.isSpaceChar(spaces[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(spaces[i]) +
|
||||
" expected to be a space character");
|
||||
break;
|
||||
}
|
||||
|
||||
if (UCharacter.isSpaceChar(nonspaces[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonspaces[i]) +
|
||||
" expected not to be space character");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!UCharacter.isWhitespace(whitespaces[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(whitespaces[i]) +
|
||||
" expected to be a white space character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isWhitespace(nonwhitespaces[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonwhitespaces[i]) +
|
||||
" expected not to be a space character");
|
||||
break;
|
||||
}
|
||||
logln("Ok 0x" + Integer.toHexString(spaces[i]) + " and 0x" +
|
||||
Integer.toHexString(nonspaces[i]) + " and 0x" +
|
||||
Integer.toHexString(whitespaces[i]) + " and 0x" +
|
||||
Integer.toHexString(nonwhitespaces[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for defined and undefined characters
|
||||
*/
|
||||
public void TestDefined()
|
||||
{
|
||||
int undefined[] = {0xfff1, 0xfff7, 0xfa30};
|
||||
int defined[] = {0x523E, 0x4f88, 0xfffd};
|
||||
|
||||
int size = undefined.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (UCharacter.isDefined(undefined[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(undefined[i]) +
|
||||
" expected not to be defined");
|
||||
break;
|
||||
}
|
||||
if (!UCharacter.isDefined(defined[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(defined[i]) +
|
||||
" expected defined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for base characters and their cellwidth
|
||||
*/
|
||||
public void TestBase()
|
||||
{
|
||||
int base[] = {0x0061, 0x0031, 0x03d2};
|
||||
int nonbase[] = {0x002B, 0x0020, 0x203B};
|
||||
int size = base.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (UCharacter.isBaseForm(nonbase[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonbase[i]) +
|
||||
" expected not to be a base character");
|
||||
break;
|
||||
}
|
||||
if (!UCharacter.isBaseForm(base[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(base[i]) +
|
||||
" expected to be a base character");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for digit characters
|
||||
*/
|
||||
public void TestDigits()
|
||||
{
|
||||
int digits[] = {0x0030, 0x0662, 0x0F23, 0x0ED5, 0x2160};
|
||||
|
||||
//special characters not in the properties table
|
||||
int digits2[] = {0x3007, 0x4e00, 0x4e8c, 0x4e09, 0x56d8, 0x4e94, 0x516d,
|
||||
0x4e03, 0x516b, 0x4e5d};
|
||||
int nondigits[] = {0x0010, 0x0041, 0x0122, 0x68FE};
|
||||
|
||||
int digitvalues[] = {0, 2, 3, 5, 1};
|
||||
int digitvalues2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
int size = digits.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
if (UCharacter.isDigit(digits[i]) &&
|
||||
UCharacter.digit(digits[i]) != digitvalues[i])
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(digits[i]) +
|
||||
" expected digit with value " + digitvalues[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
size = nondigits.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
if (UCharacter.isDigit(nondigits[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nondigits[i]) +
|
||||
" expected nondigit");
|
||||
break;
|
||||
}
|
||||
|
||||
size = digits2.length;
|
||||
for (int i = 0; i < 10; i ++)
|
||||
if (UCharacter.isDigit(digits2[i]) &&
|
||||
UCharacter.digit(digits2[i]) != digitvalues2[i])
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(digits2[i]) +
|
||||
" expected digit with value " + digitvalues2[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for version
|
||||
*/
|
||||
public void TestVersion()
|
||||
{
|
||||
String version = UCharacter.getUnicodeVersion();
|
||||
if (!version.equals(VERSION_))
|
||||
errln("FAIL expected " + VERSION_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for control characters
|
||||
*/
|
||||
public void TestControl()
|
||||
{
|
||||
int control[] = {0x001b, 0x0097, 0x0082};
|
||||
int noncontrol[] = {0x61, 0x0031, 0x00e2};
|
||||
|
||||
int size = control.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (!UCharacter.isControl(control[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(control[i]) +
|
||||
" expected to be a control character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isControl(noncontrol[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(noncontrol[i]) +
|
||||
" expected to be not a control character");
|
||||
break;
|
||||
}
|
||||
|
||||
logln("Ok 0x" + Integer.toHexString(control[i]) + " and 0x" +
|
||||
Integer.toHexString(noncontrol[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for printable characters
|
||||
*/
|
||||
public void TestPrint()
|
||||
{
|
||||
int printable[] = {0x0042, 0x005f, 0x2014};
|
||||
int nonprintable[] = {0x200c, 0x009f, 0x001b};
|
||||
|
||||
int size = printable.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (!UCharacter.isPrintable(printable[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(printable[i]) +
|
||||
" expected to be a printable character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isPrintable(nonprintable[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonprintable[i]) +
|
||||
" expected not to be a printable character");
|
||||
break;
|
||||
}
|
||||
logln("Ok 0x" + Integer.toHexString(printable[i]) + " and 0x" +
|
||||
Integer.toHexString(nonprintable[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing for identifier characters
|
||||
*/
|
||||
public void TestIdentifier()
|
||||
{
|
||||
int unicodeidstart[] = {0x0250, 0x00e2, 0x0061};
|
||||
int nonunicodeidstart[] = {0x2000, 0x000a, 0x2019};
|
||||
int unicodeidpart[] = {0x005f, 0x0032, 0x0045};
|
||||
int nonunicodeidpart[] = {0x2030, 0x00a3, 0x0020};
|
||||
int idignore[] = {0x070F, 0x180B, 0x180C};
|
||||
int nonidignore[] = {0x0075, 0x00a3, 0x0061};
|
||||
|
||||
int size = unicodeidstart.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (!UCharacter.isUnicodeIdentifierStart(unicodeidstart[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(unicodeidstart[i]) +
|
||||
" expected to be a unicode identifier start character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isUnicodeIdentifierStart(nonunicodeidstart[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonunicodeidstart[i]) +
|
||||
" expected not to be a unicode identifier start character");
|
||||
break;
|
||||
}
|
||||
if (!UCharacter.isUnicodeIdentifierPart(unicodeidpart[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(unicodeidpart[i]) +
|
||||
" expected to be a unicode identifier part character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isUnicodeIdentifierPart(nonunicodeidpart[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonunicodeidpart[i]) +
|
||||
" expected not to be a unicode identifier part character");
|
||||
break;
|
||||
}
|
||||
if (!UCharacter.isIdentifierIgnorable(idignore[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(idignore[i]) +
|
||||
" expected to be a ignorable unicode character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isIdentifierIgnorable(nonidignore[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonidignore[i]) +
|
||||
" expected not to be a ignorable unicode character");
|
||||
break;
|
||||
}
|
||||
logln("Ok 0x" + Integer.toHexString(unicodeidstart[i]) + " and 0x" +
|
||||
Integer.toHexString(nonunicodeidstart[i]) + " and 0x" +
|
||||
Integer.toHexString(unicodeidpart[i]) + " and 0x" +
|
||||
Integer.toHexString(nonunicodeidpart[i]) + " and 0x" +
|
||||
Integer.toHexString(idignore[i]) + " and 0x" +
|
||||
Integer.toHexString(nonidignore[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the character types, direction.<br>
|
||||
* This method reads in UnicodeData.txt file for testing purposes. A default
|
||||
* path is provided relative to the class path, however if the user could
|
||||
* set a system property to change the path.<br>
|
||||
* e.g. java -DUnicodeData="anyfile.dat" com.ibm.icu.test.text.UCharacterTest
|
||||
*/
|
||||
public void TestUnicodeData()
|
||||
{
|
||||
// this is the 2 char category types used in the UnicodeData file
|
||||
final String TYPE =
|
||||
"LuLlLtLmLoMnMeMcNdNlNoZsZlZpCcCfCoCsPdPsPePcPoSmScSkSoPiPf";
|
||||
|
||||
// directory types used in the UnicodeData file
|
||||
// padded by spaces to make each type size 4
|
||||
final String DIR =
|
||||
"L R EN ES ET AN CS B S WS ON LRE LRO AL RLE RLO PDF NSM BN ";
|
||||
|
||||
// default unicode data file name
|
||||
final String UNICODE_DATA_FILE = "src//data//unicode//UnicodeData.txt";
|
||||
|
||||
// unicode data file path system name
|
||||
final String UNICODE_DATA_SYSTEM_NAME = "UnicodeData";
|
||||
String s = System.getProperty(UNICODE_DATA_SYSTEM_NAME);
|
||||
if (s == null)
|
||||
s = UNICODE_DATA_FILE;
|
||||
|
||||
final int LASTUNICODECHAR = 0xFFFD;
|
||||
int ch = 0,
|
||||
index = 0,
|
||||
type = 0,
|
||||
dir = 0;
|
||||
|
||||
try
|
||||
{
|
||||
// reading in the UnicodeData file
|
||||
FileReader fr = new FileReader(s);
|
||||
BufferedReader input = new BufferedReader(fr);
|
||||
|
||||
while (ch != LASTUNICODECHAR)
|
||||
{
|
||||
s= input.readLine();
|
||||
|
||||
// geting the unicode character, its type and its direction
|
||||
ch = Integer.parseInt(s.substring(0, 4), 16);
|
||||
index = s.indexOf(';', 5);
|
||||
String t = s.substring(index + 1, index + 3);
|
||||
index += 4;
|
||||
byte cc = (byte)(Integer.parseInt(s.substring(index,
|
||||
s.indexOf(';', index))));
|
||||
index = s.indexOf(';', index);
|
||||
String d = s.substring(index + 1, s.indexOf(';', index + 1));
|
||||
|
||||
// testing the category
|
||||
// we override the general category of some control characters
|
||||
if (ch == 9 || ch == 0xb || ch == 0x1f)
|
||||
type = UCharacterCategory.SPACE_SEPARATOR;
|
||||
else
|
||||
if (ch == 0xc)
|
||||
type = UCharacterCategory.LINE_SEPARATOR;
|
||||
else
|
||||
if (ch == 0xa || ch == 0xd || ch == 0x1c || ch == 0x1d ||
|
||||
ch == 0x1e || ch == 0x85)
|
||||
type = UCharacterCategory.PARAGRAPH_SEPARATOR;
|
||||
else
|
||||
{
|
||||
type = TYPE.indexOf(t);
|
||||
if (type < 0)
|
||||
type = 0;
|
||||
else
|
||||
type = (type >> 1) + 1;
|
||||
}
|
||||
|
||||
if (UCharacter.getType(ch) != type)
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(ch) + " expected type " +
|
||||
type);
|
||||
break;
|
||||
}
|
||||
|
||||
// testing combining class
|
||||
if (UCharacter.getCombiningClass(ch) != cc)
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(ch) + " expected combining " +
|
||||
"class " + cc);
|
||||
break;
|
||||
}
|
||||
|
||||
// testing the direction
|
||||
if (d.length() == 1)
|
||||
d = d + " ";
|
||||
|
||||
dir = DIR.indexOf(d) >> 2;
|
||||
if (UCharacter.getDirection(ch) != dir)
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(ch) +
|
||||
" expected wrong direction " + dir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
input.close();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
errln("FAIL UnicodeData.txt not found\n" +
|
||||
"Configure the system setting UnicodeData to the right path\n" +
|
||||
"e.g. java -DUnicodeData=\"anyfile.dat\" " +
|
||||
"com.ibm.icu.test.text.UCharacterTest");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (UCharacter.getDirection(0x10001) !=
|
||||
UCharacterDirection.LEFT_TO_RIGHT)
|
||||
errln("FAIL 0x10001 expected direction " +
|
||||
UCharacterDirection.toString(UCharacterDirection.LEFT_TO_RIGHT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the character names
|
||||
*/
|
||||
public void TestNames()
|
||||
{
|
||||
int c[] = {0x0061, 0x0284, 0x3401, 0x7fed, 0xac00, 0xd7a3, 0xff08, 0xffe5};
|
||||
String name[] = {"LATIN SMALL LETTER A",
|
||||
"LATIN SMALL LETTER DOTLESS J WITH STROKE AND HOOK",
|
||||
"CJK UNIFIED IDEOGRAPH-3401",
|
||||
"CJK UNIFIED IDEOGRAPH-7FED", "HANGUL SYLLABLE GA",
|
||||
"HANGUL SYLLABLE HIH", "FULLWIDTH LEFT PARENTHESIS",
|
||||
"FULLWIDTH YEN SIGN"};
|
||||
String oldname[] = {"", "LATIN SMALL LETTER DOTLESS J BAR HOOK", "", "",
|
||||
"", "", "FULLWIDTH OPENING PARENTHESIS", ""};
|
||||
int size = c.length;
|
||||
String str;
|
||||
int uc;
|
||||
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
// modern Unicode character name
|
||||
str = UCharacter.getName(c[i]);
|
||||
if (!str.equalsIgnoreCase(name[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(c[i]) + " expected name " +
|
||||
name[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
// 1.0 Unicode character name
|
||||
str = UCharacter.getName1_0(c[i]);
|
||||
if ((str == null && oldname[i].length() > 0) ||
|
||||
(str != null && !str.equalsIgnoreCase(oldname[i])))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(c[i]) + " expected 1.0 name " +
|
||||
oldname[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
// retrieving unicode character from modern name
|
||||
uc = UCharacter.getCharFromName(name[i]);
|
||||
if (uc != c[i])
|
||||
{
|
||||
errln("FAIL " + name[i] + " expected character 0x" +
|
||||
Integer.toHexString(c[i]));
|
||||
break;
|
||||
}
|
||||
|
||||
//retrieving unicode character from 1.0 name
|
||||
uc = UCharacter.getCharFromName1_0(oldname[i]);
|
||||
if (uc != c[i] && i != 0 && (i == 1 || i == 6))
|
||||
{
|
||||
errln("FAIL " + name[i] + " expected 1.0 character " +
|
||||
Integer.toHexString(c[i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// extra testing different from icu
|
||||
for (int i = UCharacter.MIN_VALUE; i < UCharacter.MAX_VALUE; i ++)
|
||||
{
|
||||
str = UCharacter.getName(i);
|
||||
if (str != null && UCharacter.getCharFromName(str) != i)
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(i) + " " + str +
|
||||
" retrieval of name and vice versa" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the strings case mapping methods
|
||||
*/
|
||||
public void TestCaseMapping()
|
||||
{
|
||||
String beforeLower = "\u0061\u0042\u0049\u03a3\u00df\u03a3\u002f\ud93f\udfff",
|
||||
lowerRoot = "\u0061\u0062\u0069\u03c3\u00df\u03c2\u002f\ud93f\udfff",
|
||||
lowerTurkish = "\u0061\u0062\u0131\u03c3\u00df\u03c2\u002f\ud93f\udfff",
|
||||
beforeUpper = "\u0061\u0042\u0069\u03c2\u00df\u03c3\u002f\ufb03\ud93f\udfff",
|
||||
upperRoot = "\u0041\u0042\u0049\u03a3\u0053\u0053\u03a3\u002f\u0046\u0046\u0049\ud93f\udfff",
|
||||
upperTurkish = "\u0041\u0042\u0130\u03a3\u0053\u0053\u03a3\u002f\u0046\u0046\u0049\ud93f\udfff";
|
||||
|
||||
String result = UCharacter.toLowerCase(beforeLower);
|
||||
if (!lowerRoot.equals(result))
|
||||
errln("Fail " + beforeLower + " after lowercase should be " + lowerRoot);
|
||||
|
||||
// lowercase with turkish locale
|
||||
result = UCharacter.toLowerCase(new Locale("tr", "TR"), beforeLower);
|
||||
if (!lowerTurkish.equals(result))
|
||||
errln("Fail " + beforeLower + " after turkish-sensitive lowercase " +
|
||||
"should be " + lowerRoot);
|
||||
|
||||
// uppercase with root locale and in the same buffer
|
||||
result = UCharacter.toUpperCase(beforeUpper);
|
||||
if (!upperRoot.equals(result))
|
||||
errln("Fail " + beforeUpper + " after uppercase should be " + upperRoot);
|
||||
|
||||
// uppercase with turkish locale and separate buffers
|
||||
result = UCharacter.toUpperCase(new Locale("tr", "TR"), beforeUpper);
|
||||
if (!upperTurkish.equals(result))
|
||||
errln("Fail " + beforeUpper + " after turkish-sensitive uppercase " +
|
||||
"should be " + upperTurkish);
|
||||
|
||||
// test preflighting
|
||||
result = UCharacter.toLowerCase(beforeLower);
|
||||
if (!lowerRoot.equals(result))
|
||||
errln("Fail " + beforeLower + " after lower case should be " +
|
||||
lowerRoot);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
UCharacterTest test = new UCharacterTest();
|
||||
test.run(arg);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,222 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/lang/UTF16Test.java,v $
|
||||
* $Date: 2001/02/28 21:00:03 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import com.ibm.test.TestFmwk;
|
||||
import com.ibm.text.UCharacter;
|
||||
import com.ibm.text.UTF16;
|
||||
|
||||
/**
|
||||
* Testing class for UTF16
|
||||
* @author Syn Wee Quek
|
||||
* @since feb 09 2001
|
||||
*/
|
||||
public final class UTF16Test extends TestFmwk
|
||||
{
|
||||
// constructor ===================================================
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public UTF16Test()
|
||||
{
|
||||
}
|
||||
|
||||
// public methods ================================================
|
||||
|
||||
/**
|
||||
* Testing UTF16 class methods append, getCharCount and bounds
|
||||
*/
|
||||
public void TestUTF16AppendBoundCount()
|
||||
{
|
||||
StringBuffer str = new StringBuffer("this is a string ");
|
||||
int initstrsize = str.length();
|
||||
int length;
|
||||
|
||||
for (int i = UCharacter.MIN_VALUE; i < UCharacter.MAX_VALUE; i += 100)
|
||||
{
|
||||
length = str.length();
|
||||
UTF16.append(str, i);
|
||||
|
||||
// this is to cater for the combination of 0xDBXX 0xDC50 which forms
|
||||
// a supplementary character
|
||||
if (i == 0xDC50)
|
||||
initstrsize --;
|
||||
|
||||
if (UTF16.countCP(str.toString()) != initstrsize + (i / 100) + 1)
|
||||
{
|
||||
errln("FAIL Counting code points in string appended with " +
|
||||
" 0x" + Integer.toHexString(i));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!UCharacter.isSupplementary(i))
|
||||
{
|
||||
if (UTF16.getCharCount(i) != 1)
|
||||
{
|
||||
errln("FAIL Counting BMP character size error" );
|
||||
break;
|
||||
}
|
||||
if (str.length() != length + 1)
|
||||
{
|
||||
errln("FAIL Adding a BMP character error" );
|
||||
break;
|
||||
}
|
||||
if (!UTF16.isSurrogate((char)i) &&
|
||||
(UTF16.bounds(str.toString(), str.length() - 1) !=
|
||||
UTF16.SINGLE_CHAR_BOUNDARY ||
|
||||
UTF16.boundsAtCPOffset(str.toString(), initstrsize + (i /100))
|
||||
!= UTF16.SINGLE_CHAR_BOUNDARY))
|
||||
{
|
||||
errln("FAIL Finding BMP character bounds error" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UTF16.getCharCount(i) != 2)
|
||||
{
|
||||
errln("FAIL Counting Supplementary character size error" );
|
||||
break;
|
||||
}
|
||||
if (str.length() != length + 2)
|
||||
{
|
||||
errln("FAIL Adding a Supplementary character error" );
|
||||
break;
|
||||
}
|
||||
length = str.length();
|
||||
if (UTF16.bounds(str.toString(), str.length() - 2) !=
|
||||
UTF16.LEAD_SURROGATE_BOUNDARY ||
|
||||
UTF16.bounds(str.toString(), str.length() - 1) !=
|
||||
UTF16.TRAIL_SURROGATE_BOUNDARY ||
|
||||
UTF16.boundsAtCPOffset(str.toString(), initstrsize + (i / 100))
|
||||
!= UTF16.LEAD_SURROGATE_BOUNDARY)
|
||||
{
|
||||
errln("FAIL Finding Supplementary character bounds error with " +
|
||||
"string appended with 0x" + Integer.toHexString(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing UTF16 class methods findCPOffset, findOffsetFromCP, charAt and
|
||||
* charAtCP
|
||||
*/
|
||||
public void TestUTF16OffsetCharAt()
|
||||
{
|
||||
StringBuffer str = new StringBuffer("12345");
|
||||
UTF16.append(str, 0x10001);
|
||||
str.append("67890");
|
||||
UTF16.append(str, 0x10002);
|
||||
String s = str.toString();
|
||||
if (UTF16.charAt(s, 0) != '1' || UTF16.charAt(s, 2) != '3' ||
|
||||
UTF16.charAt(s, 5) != 0x10001 || UTF16.charAt(s, 6) != 0x10001 ||
|
||||
UTF16.charAt(s, 12) != 0x10002 || UTF16.charAt(s, 13) != 0x10002 ||
|
||||
UTF16.charAtCPOffset(s, 0) != '1' || UTF16.charAtCPOffset(s, 2) != '3' ||
|
||||
UTF16.charAtCPOffset(s, 5) != 0x10001 ||
|
||||
UTF16.charAtCPOffset(s, 6) != '6' ||
|
||||
UTF16.charAtCPOffset(s, 11) != 0x10002)
|
||||
errln("FAIL Getting character from string error" );
|
||||
|
||||
if (UTF16.findCPOffset(s, 3) != 3 || UTF16.findCPOffset(s, 5) != 5 ||
|
||||
UTF16.findCPOffset(s, 6) != 5)
|
||||
errln("FAIL Getting codepoint offset from string error" );
|
||||
if (UTF16.findOffsetFromCP(s, 3) != 3 ||
|
||||
UTF16.findOffsetFromCP(s, 5) != 5 ||
|
||||
UTF16.findOffsetFromCP(s, 6) != 7)
|
||||
errln("FAIL Getting UTF16 offset from codepoint in string error" );
|
||||
|
||||
UTF16.setCharAt(str, 3, '3');
|
||||
UTF16.setCharAtCPOffset(str, 4, '3');
|
||||
if (UTF16.charAt(str.toString(), 3) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 3) != '3' ||
|
||||
UTF16.charAt(str.toString(), 4) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 4) != '3')
|
||||
errln("FAIL Setting non-supplementary characters at a " +
|
||||
"non-supplementary position");
|
||||
|
||||
UTF16.setCharAt(str, 5, '3');
|
||||
if (UTF16.charAt(str.toString(), 5) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != '3' ||
|
||||
UTF16.charAt(str.toString(), 6) != '6' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != '6')
|
||||
errln("FAIL Setting non-supplementary characters at a " +
|
||||
"supplementary position");
|
||||
|
||||
UTF16.setCharAt(str, 5, 0x10001);
|
||||
if (UTF16.charAt(str.toString(), 5) != 0x10001 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != 0x10001 ||
|
||||
UTF16.charAt(str.toString(), 7) != '6' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != '6')
|
||||
errln("FAIL Setting supplementary characters at a " +
|
||||
"non-supplementary position");
|
||||
|
||||
UTF16.setCharAtCPOffset(str, 5, '3');
|
||||
if (UTF16.charAt(str.toString(), 5) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != '3' ||
|
||||
UTF16.charAt(str.toString(), 6) != '6' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != '6')
|
||||
errln("FAIL Setting non-supplementary characters at a " +
|
||||
"supplementary position");
|
||||
|
||||
UTF16.setCharAt(str, 5, 0x10001);
|
||||
if (UTF16.charAt(str.toString(), 5) != 0x10001 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != 0x10001 ||
|
||||
UTF16.charAt(str.toString(), 7) != '6' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != '6')
|
||||
errln("FAIL Setting supplementary characters at a " +
|
||||
"non-supplementary position");
|
||||
|
||||
|
||||
UTF16.setCharAt(str, 5, 0xD800);
|
||||
UTF16.setCharAt(str, 6, 0xD800);
|
||||
if (UTF16.charAt(str.toString(), 5) != 0xD800 ||
|
||||
UTF16.charAt(str.toString(), 6) != 0xD800 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != 0xD800 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != 0xD800)
|
||||
errln("FAIL Setting lead characters at a supplementary position");
|
||||
|
||||
UTF16.setCharAt(str, 5, 0xDDDD);
|
||||
if (UTF16.charAt(str.toString(), 5) != 0xDDDD ||
|
||||
UTF16.charAt(str.toString(), 6) != 0xD800 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != 0xDDDD ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != 0xD800)
|
||||
errln("FAIL Setting trail characters at a surrogate position");
|
||||
|
||||
UTF16.setCharAt(str, 5, '3');
|
||||
if (UTF16.charAt(str.toString(), 5) != '3' ||
|
||||
UTF16.charAt(str.toString(), 6) != 0xD800 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != 0xD800)
|
||||
errln("FAIL Setting non-supplementary characters at a surrogate " +
|
||||
"position");
|
||||
}
|
||||
|
||||
public static void main(String[] arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
UTF16Test test = new UTF16Test();
|
||||
test.run(arg);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,408 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import com.ibm.text.ArabicShaping;
|
||||
import com.ibm.text.ArabicShapingException;
|
||||
|
||||
/**
|
||||
* Regression test for Arabic shaping.
|
||||
*/
|
||||
public class ArabicShapingRegTest {
|
||||
|
||||
/* constants copied from ArabicShaping for convenience */
|
||||
|
||||
public static final int LENGTH_GROW_SHRINK = 0;
|
||||
public static final int LENGTH_FIXED_SPACES_NEAR = 1;
|
||||
public static final int LENGTH_FIXED_SPACES_AT_END = 2;
|
||||
public static final int LENGTH_FIXED_SPACES_AT_BEGINNING = 3;
|
||||
|
||||
public static final int TEXT_DIRECTION_LOGICAL = 0;
|
||||
public static final int TEXT_DIRECTION_VISUAL_LTR = 4;
|
||||
|
||||
public static final int LETTERS_NOOP = 0;
|
||||
public static final int LETTERS_SHAPE = 8;
|
||||
public static final int LETTERS_UNSHAPE = 0x10;
|
||||
public static final int LETTERS_SHAPE_EXCEPT_TASHKEEL = 0x18;
|
||||
|
||||
public static final int DIGITS_NOOP = 0;
|
||||
public static final int DIGITS_EN2AN = 0x20;
|
||||
public static final int DIGITS_AN2EN = 0x40;
|
||||
public static final int DIGITS_EN2AN_INIT_LR = 0x60;
|
||||
public static final int DIGITS_EN2AN_INIT_AL = 0x80;
|
||||
private static final int DIGITS_RESERVED = 0xa0;
|
||||
|
||||
public static final int DIGIT_TYPE_AN = 0;
|
||||
public static final int DIGIT_TYPE_AN_EXTENDED = 0x100;
|
||||
|
||||
public static class TestData {
|
||||
public int type;
|
||||
public String source;
|
||||
public int flags;
|
||||
public String result;
|
||||
public int length;
|
||||
public Class error;
|
||||
|
||||
public static final int STANDARD = 0;
|
||||
public static final int PREFLIGHT = 1;
|
||||
public static final int ERROR = 2;
|
||||
|
||||
public static TestData standard(String source, int flags, String result) {
|
||||
return new TestData(STANDARD, source, flags, result, 0, null);
|
||||
}
|
||||
|
||||
public static TestData preflight(String source, int flags, int length) {
|
||||
return new TestData(PREFLIGHT, source, flags, null, length, null);
|
||||
}
|
||||
|
||||
public static TestData error(String source, int flags, Class error) {
|
||||
return new TestData(ERROR, source, flags, null, 0, error);
|
||||
}
|
||||
|
||||
private TestData(int type, String source, int flags, String result, int length, Class error) {
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
this.flags = flags;
|
||||
this.result = result;
|
||||
this.length = length;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
private static final String[] typenames = { "standard", "preflight", "error" };
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(super.toString());
|
||||
buf.append("[\n");
|
||||
buf.append(typenames[type]);
|
||||
buf.append(",\n");
|
||||
if (source == null) {
|
||||
buf.append("null");
|
||||
} else {
|
||||
buf.append('"');
|
||||
buf.append(escapedString(source));
|
||||
buf.append('"');
|
||||
}
|
||||
buf.append(",\n");
|
||||
buf.append(Integer.toHexString(flags));
|
||||
buf.append(",\n");
|
||||
if (result == null) {
|
||||
buf.append("null");
|
||||
} else {
|
||||
buf.append('"');
|
||||
buf.append(escapedString(result));
|
||||
buf.append('"');
|
||||
}
|
||||
buf.append(",\n");
|
||||
buf.append(length);
|
||||
buf.append(",\n");
|
||||
buf.append(error);
|
||||
buf.append(']');
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String lamAlefSpecialVLTR =
|
||||
"\u0020\u0646\u0622\u0644\u0627\u0020" +
|
||||
"\u0646\u0623\u064E\u0644\u0627\u0020" +
|
||||
"\u0646\u0627\u0670\u0644\u0627\u0020" +
|
||||
"\u0646\u0622\u0653\u0644\u0627\u0020" +
|
||||
"\u0646\u0625\u0655\u0644\u0627\u0020" +
|
||||
"\u0646\u0622\u0654\u0644\u0627\u0020" +
|
||||
"\uFEFC\u0639";
|
||||
|
||||
private static final String tashkeelSpecialVLTR =
|
||||
"\u064A\u0628\u0631\u0639\u0020" +
|
||||
"\u064A\u0628\u0651\u0631\u064E\u0639\u0020" +
|
||||
"\u064C\u064A\u0628\u0631\u064F\u0639\u0020" +
|
||||
"\u0628\u0670\u0631\u0670\u0639\u0020" +
|
||||
"\u0628\u0653\u0631\u0653\u0639\u0020" +
|
||||
"\u0628\u0654\u0631\u0654\u0639\u0020" +
|
||||
"\u0628\u0655\u0631\u0655\u0639\u0020";
|
||||
|
||||
private static final String logicalUnshape =
|
||||
"\u0020\u0020\u0020\uFE8D\uFEF5\u0020\uFEE5\u0020\uFE8D\uFEF7\u0020" +
|
||||
"\uFED7\uFEFC\u0020\uFEE1\u0020\uFE8D\uFEDF\uFECC\uFEAE\uFE91\uFEF4" +
|
||||
"\uFE94\u0020\uFE8D\uFEDF\uFEA4\uFEAE\uFE93\u0020\u0020\u0020\u0020";
|
||||
|
||||
private static final String numSource =
|
||||
"\u0031" + /* en:1 */
|
||||
"\u0627" + /* arabic:alef */
|
||||
"\u0032" + /* en:2 */
|
||||
"\u06f3" + /* an:3 */
|
||||
"\u0061" + /* latin:a */
|
||||
"\u0034"; /* en:4 */
|
||||
|
||||
private static final TestData[] tests = {
|
||||
/* lam alef special visual ltr */
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\u0020\ufee5\u0020\ufef5\ufe8d\u0020" +
|
||||
"\ufee5\u0020\ufe76\ufef7\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0670\ufefb\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0653\ufef5\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0655\ufef9\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_AT_END,
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb\u0020\u0020\u0020\u0020" +
|
||||
"\u0020\u0020"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_AT_BEGINNING,
|
||||
"\u0020\u0020\u0020\u0020\u0020\u0020" +
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_GROW_SHRINK,
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\u0020\ufee5\u0020\ufef5\ufe8d\u0020" +
|
||||
"\ufee5\u0020\ufe76\ufef7\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0670\ufefb\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0653\ufef5\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0655\ufef9\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_AT_END,
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb\u0020\u0020\u0020\u0020" +
|
||||
"\u0020\u0020"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_AT_BEGINNING,
|
||||
"\u0020\u0020\u0020\u0020\u0020\u0020" +
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_GROW_SHRINK,
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
|
||||
/* tashkeel special visual ltr */
|
||||
TestData.standard(tashkeelSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\ufef2\ufe91\ufeae\ufecb\u0020" +
|
||||
"\ufef2\ufe91\ufe7c\ufeae\ufe77\ufecb\u0020" +
|
||||
"\ufe72\ufef2\ufe91\ufeae\ufe79\ufecb\u0020" +
|
||||
"\ufe8f\u0670\ufeae\u0670\ufecb\u0020" +
|
||||
"\ufe8f\u0653\ufeae\u0653\ufecb\u0020" +
|
||||
"\ufe8f\u0654\ufeae\u0654\ufecb\u0020" +
|
||||
"\ufe8f\u0655\ufeae\u0655\ufecb\u0020"),
|
||||
TestData.standard(tashkeelSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\ufef2\ufe91\ufeae\ufecb\u0020" +
|
||||
"\ufef2\ufe91\ufe7c\ufeae\ufe76\ufecb\u0020" +
|
||||
"\ufe72\ufef2\ufe91\ufeae\ufe78\ufecb\u0020" +
|
||||
"\ufe8f\u0670\ufeae\u0670\ufecb\u0020" +
|
||||
"\ufe8f\u0653\ufeae\u0653\ufecb\u0020" +
|
||||
"\ufe8f\u0654\ufeae\u0654\ufecb\u0020" +
|
||||
"\ufe8f\u0655\ufeae\u0655\ufecb\u0020"),
|
||||
|
||||
/* logical unshape */
|
||||
TestData.standard(logicalUnshape,
|
||||
LETTERS_UNSHAPE | TEXT_DIRECTION_LOGICAL | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\u0020\u0020\u0020\u0627\u0644\u0622\u0646\u0020\u0627\u0644\u0623\u0642\u0644\u0627" +
|
||||
"\u0645\u0020\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u0020\u0627\u0644\u062d\u0631" +
|
||||
"\u0629\u0020\u0020\u0020\u0020"),
|
||||
TestData.standard(logicalUnshape,
|
||||
LETTERS_UNSHAPE | TEXT_DIRECTION_LOGICAL | LENGTH_FIXED_SPACES_AT_END,
|
||||
"\u0020\u0020\u0020\u0627\u0644\u0622\u0020\u0646\u0020\u0627\u0644\u0623\u0020\u0642" +
|
||||
"\u0644\u0627\u0020\u0645\u0020\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u0020\u0627" +
|
||||
"\u0644\u062d\u0631\u0629\u0020"),
|
||||
TestData.standard(logicalUnshape,
|
||||
LETTERS_UNSHAPE | TEXT_DIRECTION_LOGICAL | LENGTH_FIXED_SPACES_AT_BEGINNING,
|
||||
"\u0627\u0644\u0622\u0020\u0646\u0020\u0627\u0644\u0623\u0020\u0642\u0644\u0627\u0020" +
|
||||
"\u0645\u0020\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u0020\u0627\u0644\u062d\u0631" +
|
||||
"\u0629\u0020\u0020\u0020\u0020"),
|
||||
TestData.standard(logicalUnshape,
|
||||
LETTERS_UNSHAPE | TEXT_DIRECTION_LOGICAL | LENGTH_GROW_SHRINK,
|
||||
"\u0020\u0020\u0020\u0627\u0644\u0622\u0020\u0646\u0020\u0627\u0644\u0623\u0020\u0642" +
|
||||
"\u0644\u0627\u0020\u0645\u0020\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u0020\u0627" +
|
||||
"\u0644\u062d\u0631\u0629\u0020\u0020\u0020\u0020"),
|
||||
|
||||
/* numbers */
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN | DIGIT_TYPE_AN,
|
||||
"\u0661\u0627\u0662\u06f3\u0061\u0664"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_AN2EN | DIGIT_TYPE_AN_EXTENDED,
|
||||
"\u0031\u0627\u0032\u0033\u0061\u0034"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN_INIT_LR | DIGIT_TYPE_AN,
|
||||
"\u0031\u0627\u0662\u06f3\u0061\u0034"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN_INIT_AL | DIGIT_TYPE_AN_EXTENDED,
|
||||
"\u06f1\u0627\u06f2\u06f3\u0061\u0034"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN_INIT_LR | DIGIT_TYPE_AN | TEXT_DIRECTION_VISUAL_LTR,
|
||||
"\u0661\u0627\u0032\u06f3\u0061\u0034"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN_INIT_AL | DIGIT_TYPE_AN_EXTENDED | TEXT_DIRECTION_VISUAL_LTR,
|
||||
"\u06f1\u0627\u0032\u06f3\u0061\u06f4"),
|
||||
|
||||
/* no-op */
|
||||
TestData.standard(numSource,
|
||||
0,
|
||||
numSource),
|
||||
|
||||
/* preflight */
|
||||
TestData.preflight("\u0644\u0627",
|
||||
LETTERS_SHAPE | LENGTH_GROW_SHRINK,
|
||||
1),
|
||||
|
||||
TestData.preflight("\u0644\u0627\u0031",
|
||||
DIGITS_EN2AN | DIGIT_TYPE_AN_EXTENDED | LENGTH_GROW_SHRINK,
|
||||
3),
|
||||
|
||||
TestData.preflight("\u0644\u0644",
|
||||
LETTERS_SHAPE | LENGTH_GROW_SHRINK,
|
||||
2),
|
||||
|
||||
TestData.preflight("\ufef7",
|
||||
LETTERS_UNSHAPE | LENGTH_GROW_SHRINK,
|
||||
2),
|
||||
|
||||
/* bad data */
|
||||
TestData.error("\u0020\ufef7\u0644\u0020",
|
||||
LETTERS_UNSHAPE | LENGTH_FIXED_SPACES_NEAR,
|
||||
ArabicShapingException.class),
|
||||
|
||||
TestData.error("\u0020\ufef7",
|
||||
LETTERS_UNSHAPE | LENGTH_FIXED_SPACES_AT_END,
|
||||
ArabicShapingException.class),
|
||||
|
||||
TestData.error("\ufef7\u0020",
|
||||
LETTERS_UNSHAPE | LENGTH_FIXED_SPACES_AT_BEGINNING,
|
||||
ArabicShapingException.class),
|
||||
|
||||
/* bad options */
|
||||
TestData.error("\ufef7",
|
||||
0xffffffff,
|
||||
IllegalArgumentException.class),
|
||||
};
|
||||
|
||||
private static void runStandardTests() {
|
||||
for (int i = 0; i < tests.length; ++i) {
|
||||
TestData test = tests[i];
|
||||
|
||||
Exception ex = null;
|
||||
String result = null;
|
||||
ArabicShaping shaper = null;
|
||||
try {
|
||||
shaper = new ArabicShaping(test.flags);
|
||||
result = shaper.shape(test.source);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ex = e;
|
||||
}
|
||||
|
||||
switch (test.type) {
|
||||
case TestData.STANDARD:
|
||||
if (!test.result.equals(result)) {
|
||||
reportTestFailure(i, test, shaper, result, ex);
|
||||
}
|
||||
break;
|
||||
|
||||
case TestData.PREFLIGHT:
|
||||
if (result == null || test.length != result.length()) {
|
||||
reportTestFailure(i, test, shaper, result, ex);
|
||||
}
|
||||
break;
|
||||
|
||||
case TestData.ERROR:
|
||||
if (!test.error.isInstance(ex)) {
|
||||
reportTestFailure(i, test, shaper, result, ex);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reportTestFailure(int index, TestData test, ArabicShaping shaper, String result, Exception error) {
|
||||
System.out.println("*** test failure ***");
|
||||
System.out.println("index: " + index);
|
||||
System.out.println("test: " + test);
|
||||
System.out.println("shaper: " + shaper);
|
||||
System.out.println("result: " + escapedString(result));
|
||||
System.out.println("error: " + error);
|
||||
|
||||
if (result != null && test.result != null && !test.result.equals(result)) {
|
||||
for (int i = 0; i < Math.max(test.result.length(), result.length()); ++i) {
|
||||
String temp = Integer.toString(i);
|
||||
if (temp.length() < 2) {
|
||||
temp = " ".concat(temp);
|
||||
}
|
||||
char trg = i < test.result.length() ? test.result.charAt(i) : '\uffff';
|
||||
char res = i < result.length() ? result.charAt(i) : '\uffff';
|
||||
|
||||
System.out.print("[" + temp + "] ");
|
||||
System.out.print(escapedString("" + trg) + " ");
|
||||
System.out.print(escapedString("" + res) + " ");
|
||||
if (trg != res) {
|
||||
System.out.print("***");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String escapedString(String str) {
|
||||
StringBuffer buf = new StringBuffer(str.length() * 6);
|
||||
for (int i = 0; i < str.length(); ++i) {
|
||||
char ch = str.charAt(i);
|
||||
buf.append("\\u");
|
||||
if (ch < 0x1000) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (ch < 0x0100) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (ch < 0x0010) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(Integer.toHexString(ch));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static void runAPITests() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
runStandardTests();
|
||||
runAPITests();
|
||||
}
|
||||
}
|
||||
|
@ -1,285 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import com.ibm.text.ArabicShaping;
|
||||
import com.ibm.text.ArabicShapingException;
|
||||
|
||||
/**
|
||||
* Interactive test for Arabic shaping.
|
||||
* Invoke from a command line passing args and strings. Use '-help' to see description of arguments.
|
||||
*/
|
||||
public class ArabicShapingTest {
|
||||
private static final int COPY = 0;
|
||||
private static final int INPLACE = 1;
|
||||
private static final int STRING = 2;
|
||||
|
||||
public static final void main(String[] args) {
|
||||
int testtype = COPY;
|
||||
int options = 0;
|
||||
int ss = 0;
|
||||
int sl = -1;
|
||||
int ds = 0;
|
||||
int dl = -1;
|
||||
String text = "$22.4 test 123 \ufef6\u0644\u0622 456 \u0664\u0665\u0666!";
|
||||
|
||||
for (int i = 0; i < args.length; ++i) {
|
||||
String arg = args[i];
|
||||
if (arg.charAt(0) == '-') {
|
||||
String opt = arg.substring(1);
|
||||
String val = opt;
|
||||
int index = arg.indexOf(':');
|
||||
if (index != -1) {
|
||||
opt = opt.substring(0, Math.min(index, 3));
|
||||
val = arg.substring(index + 1);
|
||||
}
|
||||
|
||||
if (opt.equalsIgnoreCase("len")) {
|
||||
options &= ~ArabicShaping.LENGTH_MASK;
|
||||
if (val.equalsIgnoreCase("gs")) {
|
||||
options |= ArabicShaping.LENGTH_GROW_SHRINK;
|
||||
} else if (val.equalsIgnoreCase("sn")) {
|
||||
options |= ArabicShaping.LENGTH_FIXED_SPACES_NEAR;
|
||||
} else if (val.equalsIgnoreCase("se")) {
|
||||
options |= ArabicShaping.LENGTH_FIXED_SPACES_AT_END;
|
||||
} else if (val.equalsIgnoreCase("sb")) {
|
||||
options |= ArabicShaping.LENGTH_FIXED_SPACES_AT_BEGINNING;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("dir")) {
|
||||
options &= ~ArabicShaping.TEXT_DIRECTION_MASK;
|
||||
if (val.equalsIgnoreCase("log")) {
|
||||
options |= ArabicShaping.TEXT_DIRECTION_LOGICAL;
|
||||
} else if (val.equalsIgnoreCase("vis")) {
|
||||
options |= ArabicShaping.TEXT_DIRECTION_VISUAL_LTR;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("let")) {
|
||||
options &= ~ArabicShaping.LETTERS_MASK;
|
||||
if (val.equalsIgnoreCase("no")) {
|
||||
options |= ArabicShaping.LETTERS_NOOP;
|
||||
} else if (val.equalsIgnoreCase("sh")) {
|
||||
options |= ArabicShaping.LETTERS_SHAPE;
|
||||
} else if (val.equalsIgnoreCase("un")) {
|
||||
options |= ArabicShaping.LETTERS_UNSHAPE;
|
||||
} else if (val.equalsIgnoreCase("ta")) {
|
||||
options |= ArabicShaping.LETTERS_SHAPE_EXCEPT_TASHKEEL;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("dig")) {
|
||||
options &= ~ArabicShaping.DIGITS_MASK;
|
||||
if (val.equalsIgnoreCase("no")) {
|
||||
options |= ArabicShaping.DIGITS_NOOP;
|
||||
} else if (val.equalsIgnoreCase("ea")) {
|
||||
options |= ArabicShaping.DIGITS_EN2AN;
|
||||
} else if (val.equalsIgnoreCase("ae")) {
|
||||
options |= ArabicShaping.DIGITS_AN2EN;
|
||||
} else if (val.equalsIgnoreCase("lr")) {
|
||||
options |= ArabicShaping.DIGITS_EN2AN_INIT_LR;
|
||||
} else if (val.equalsIgnoreCase("al")) {
|
||||
options |= ArabicShaping.DIGITS_EN2AN_INIT_AL;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("typ")) {
|
||||
options &= ~ArabicShaping.DIGIT_TYPE_MASK;
|
||||
if (val.equalsIgnoreCase("an")) {
|
||||
options |= ArabicShaping.DIGIT_TYPE_AN;
|
||||
} else if (val.equalsIgnoreCase("ex")) {
|
||||
options |= ArabicShaping.DIGIT_TYPE_AN_EXTENDED;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("dst")) {
|
||||
try {
|
||||
ds = Integer.parseInt(val);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("dln")) {
|
||||
try {
|
||||
dl = Integer.parseInt(val);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("sst")) {
|
||||
try {
|
||||
ss = Integer.parseInt(val);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("sln")) {
|
||||
try {
|
||||
sl = Integer.parseInt(val);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("tes")) {
|
||||
if (val.equalsIgnoreCase("cp")) {
|
||||
testtype = COPY;
|
||||
} else if (val.equalsIgnoreCase("ip")) {
|
||||
testtype = INPLACE;
|
||||
} else if (val.equalsIgnoreCase("st")) {
|
||||
testtype = STRING;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("help")) {
|
||||
System.out.println(usage);
|
||||
} else {
|
||||
throwOptError(opt);
|
||||
}
|
||||
} else {
|
||||
// assume text
|
||||
text = parseText(arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (sl < 0) {
|
||||
sl = text.length() - ss;
|
||||
System.out.println("sl defaulting to " + sl);
|
||||
}
|
||||
if (dl < 0) {
|
||||
dl = 2 * sl;
|
||||
System.out.println("dl defaulting to " + dl);
|
||||
}
|
||||
|
||||
ArabicShaping shaper = new ArabicShaping(options);
|
||||
System.out.println("shaper: " + shaper);
|
||||
|
||||
char[] src = text.toCharArray();
|
||||
System.out.println(" input: '" + escapedText(src, ss, sl) + "'");
|
||||
if (testtype != STRING) {
|
||||
System.out.println("start: " + ss + " length: " + sl + " total length: " + src.length);
|
||||
}
|
||||
|
||||
int result = -1;
|
||||
char[] dest = null;
|
||||
|
||||
try {
|
||||
switch (testtype) {
|
||||
case COPY:
|
||||
dest = new char[ds + dl];
|
||||
result = shaper.shape(src, ss, sl, dest, ds, dl);
|
||||
break;
|
||||
|
||||
case INPLACE:
|
||||
shaper.shape(src, ss, sl);
|
||||
ds = ss;
|
||||
result = sl;
|
||||
dest = src;
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
dest = shaper.shape(text).toCharArray();
|
||||
ds = 0;
|
||||
result = dest.length;
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println("output: '" + escapedText(dest, ds, result) + "'");
|
||||
System.out.println("length: " + result);
|
||||
if (ds != 0 || result != dest.length) {
|
||||
System.out.println("full output: '" + escapedText(dest, 0, dest.length) + "'");
|
||||
}
|
||||
}
|
||||
catch (ArabicShapingException e) {
|
||||
System.out.println("Caught ArabicShapingException");
|
||||
System.out.println(e);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Caught Exception");
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void throwOptError(String opt) {
|
||||
throwUsageError("unknown option: " + opt);
|
||||
}
|
||||
|
||||
private static void throwValError(String opt, String val) {
|
||||
throwUsageError("unknown value: " + val + " for option: " + opt);
|
||||
}
|
||||
|
||||
private static void throwUsageError(String message) {
|
||||
StringBuffer buf = new StringBuffer("*** usage error ***\n");
|
||||
buf.append(message);
|
||||
buf.append("\n");
|
||||
buf.append(usage);
|
||||
throw new Error(buf.toString());
|
||||
}
|
||||
|
||||
private static final String usage =
|
||||
"Usage: [option]* [text]\n" +
|
||||
" where option is in the format '-opt[:val]'\n" +
|
||||
" options are:\n" +
|
||||
" -len:[gs|sn|se|sb] (length: grow/shrink, spaces near, spaces end, spaces beginning)\n" +
|
||||
" -dir:[log|vis] (direction: logical, visual)\n" +
|
||||
" -let:[no|sh|un|ta] (letters: noop, shape, unshape, tashkeel)\n" +
|
||||
" -dig:[no|ea|ae|lr|al] (digits: noop, en2an, an2en, en2an_lr, en2an_al)\n" +
|
||||
" -typ:[an|ex] (digit type: arabic, arabic extended)\n" +
|
||||
" -dst:# (dest start: [integer])\n" +
|
||||
" -dln:# (dest length (max size): [integer])\n" +
|
||||
" -sst:# (source start: [integer])\n" +
|
||||
" -sln:# (source length: [integer])\n" +
|
||||
" -tes:[cp|ip|st] (test type: copy, in place, string)\n" +
|
||||
" -help (print this help message)\n" +
|
||||
" text can contain unicode escape values in the format '\\uXXXX' only\n";
|
||||
|
||||
private static String escapedText(char[] text, int start, int length) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = start, e = start + length; i < e; ++i) {
|
||||
char ch = text[i];
|
||||
if (ch < 0x20 || ch > 0x7e) {
|
||||
buf.append("\\u");
|
||||
if (ch < 0x1000) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (ch < 0x100) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (ch < 0x10) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(Integer.toHexString(ch));
|
||||
} else {
|
||||
buf.append(ch);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static String parseText(String text) {
|
||||
// process unicode escapes (only)
|
||||
StringBuffer buf = new StringBuffer();
|
||||
char[] chars = text.toCharArray();
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
char ch = chars[i];
|
||||
if (ch == '\\') {
|
||||
if ((i < chars.length - 1) &&
|
||||
(chars[i+1] == 'u')) {
|
||||
int val = Integer.parseInt(text.substring(i+2, i+6), 16);
|
||||
buf.append((char)val);
|
||||
i += 5;
|
||||
} else {
|
||||
buf.append('\\');
|
||||
}
|
||||
} else {
|
||||
buf.append(ch);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
@ -1,408 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import com.ibm.text.ArabicShaping;
|
||||
import com.ibm.text.ArabicShapingException;
|
||||
|
||||
/**
|
||||
* Regression test for Arabic shaping.
|
||||
*/
|
||||
public class ArabicShapingRegTest {
|
||||
|
||||
/* constants copied from ArabicShaping for convenience */
|
||||
|
||||
public static final int LENGTH_GROW_SHRINK = 0;
|
||||
public static final int LENGTH_FIXED_SPACES_NEAR = 1;
|
||||
public static final int LENGTH_FIXED_SPACES_AT_END = 2;
|
||||
public static final int LENGTH_FIXED_SPACES_AT_BEGINNING = 3;
|
||||
|
||||
public static final int TEXT_DIRECTION_LOGICAL = 0;
|
||||
public static final int TEXT_DIRECTION_VISUAL_LTR = 4;
|
||||
|
||||
public static final int LETTERS_NOOP = 0;
|
||||
public static final int LETTERS_SHAPE = 8;
|
||||
public static final int LETTERS_UNSHAPE = 0x10;
|
||||
public static final int LETTERS_SHAPE_EXCEPT_TASHKEEL = 0x18;
|
||||
|
||||
public static final int DIGITS_NOOP = 0;
|
||||
public static final int DIGITS_EN2AN = 0x20;
|
||||
public static final int DIGITS_AN2EN = 0x40;
|
||||
public static final int DIGITS_EN2AN_INIT_LR = 0x60;
|
||||
public static final int DIGITS_EN2AN_INIT_AL = 0x80;
|
||||
private static final int DIGITS_RESERVED = 0xa0;
|
||||
|
||||
public static final int DIGIT_TYPE_AN = 0;
|
||||
public static final int DIGIT_TYPE_AN_EXTENDED = 0x100;
|
||||
|
||||
public static class TestData {
|
||||
public int type;
|
||||
public String source;
|
||||
public int flags;
|
||||
public String result;
|
||||
public int length;
|
||||
public Class error;
|
||||
|
||||
public static final int STANDARD = 0;
|
||||
public static final int PREFLIGHT = 1;
|
||||
public static final int ERROR = 2;
|
||||
|
||||
public static TestData standard(String source, int flags, String result) {
|
||||
return new TestData(STANDARD, source, flags, result, 0, null);
|
||||
}
|
||||
|
||||
public static TestData preflight(String source, int flags, int length) {
|
||||
return new TestData(PREFLIGHT, source, flags, null, length, null);
|
||||
}
|
||||
|
||||
public static TestData error(String source, int flags, Class error) {
|
||||
return new TestData(ERROR, source, flags, null, 0, error);
|
||||
}
|
||||
|
||||
private TestData(int type, String source, int flags, String result, int length, Class error) {
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
this.flags = flags;
|
||||
this.result = result;
|
||||
this.length = length;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
private static final String[] typenames = { "standard", "preflight", "error" };
|
||||
|
||||
public String toString() {
|
||||
StringBuffer buf = new StringBuffer(super.toString());
|
||||
buf.append("[\n");
|
||||
buf.append(typenames[type]);
|
||||
buf.append(",\n");
|
||||
if (source == null) {
|
||||
buf.append("null");
|
||||
} else {
|
||||
buf.append('"');
|
||||
buf.append(escapedString(source));
|
||||
buf.append('"');
|
||||
}
|
||||
buf.append(",\n");
|
||||
buf.append(Integer.toHexString(flags));
|
||||
buf.append(",\n");
|
||||
if (result == null) {
|
||||
buf.append("null");
|
||||
} else {
|
||||
buf.append('"');
|
||||
buf.append(escapedString(result));
|
||||
buf.append('"');
|
||||
}
|
||||
buf.append(",\n");
|
||||
buf.append(length);
|
||||
buf.append(",\n");
|
||||
buf.append(error);
|
||||
buf.append(']');
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String lamAlefSpecialVLTR =
|
||||
"\u0020\u0646\u0622\u0644\u0627\u0020" +
|
||||
"\u0646\u0623\u064E\u0644\u0627\u0020" +
|
||||
"\u0646\u0627\u0670\u0644\u0627\u0020" +
|
||||
"\u0646\u0622\u0653\u0644\u0627\u0020" +
|
||||
"\u0646\u0625\u0655\u0644\u0627\u0020" +
|
||||
"\u0646\u0622\u0654\u0644\u0627\u0020" +
|
||||
"\uFEFC\u0639";
|
||||
|
||||
private static final String tashkeelSpecialVLTR =
|
||||
"\u064A\u0628\u0631\u0639\u0020" +
|
||||
"\u064A\u0628\u0651\u0631\u064E\u0639\u0020" +
|
||||
"\u064C\u064A\u0628\u0631\u064F\u0639\u0020" +
|
||||
"\u0628\u0670\u0631\u0670\u0639\u0020" +
|
||||
"\u0628\u0653\u0631\u0653\u0639\u0020" +
|
||||
"\u0628\u0654\u0631\u0654\u0639\u0020" +
|
||||
"\u0628\u0655\u0631\u0655\u0639\u0020";
|
||||
|
||||
private static final String logicalUnshape =
|
||||
"\u0020\u0020\u0020\uFE8D\uFEF5\u0020\uFEE5\u0020\uFE8D\uFEF7\u0020" +
|
||||
"\uFED7\uFEFC\u0020\uFEE1\u0020\uFE8D\uFEDF\uFECC\uFEAE\uFE91\uFEF4" +
|
||||
"\uFE94\u0020\uFE8D\uFEDF\uFEA4\uFEAE\uFE93\u0020\u0020\u0020\u0020";
|
||||
|
||||
private static final String numSource =
|
||||
"\u0031" + /* en:1 */
|
||||
"\u0627" + /* arabic:alef */
|
||||
"\u0032" + /* en:2 */
|
||||
"\u06f3" + /* an:3 */
|
||||
"\u0061" + /* latin:a */
|
||||
"\u0034"; /* en:4 */
|
||||
|
||||
private static final TestData[] tests = {
|
||||
/* lam alef special visual ltr */
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\u0020\ufee5\u0020\ufef5\ufe8d\u0020" +
|
||||
"\ufee5\u0020\ufe76\ufef7\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0670\ufefb\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0653\ufef5\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0655\ufef9\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_AT_END,
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb\u0020\u0020\u0020\u0020" +
|
||||
"\u0020\u0020"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_AT_BEGINNING,
|
||||
"\u0020\u0020\u0020\u0020\u0020\u0020" +
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_GROW_SHRINK,
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\u0020\ufee5\u0020\ufef5\ufe8d\u0020" +
|
||||
"\ufee5\u0020\ufe76\ufef7\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0670\ufefb\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0653\ufef5\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0655\ufef9\ufe8d\u0020" +
|
||||
"\ufee5\u0020\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_AT_END,
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb\u0020\u0020\u0020\u0020" +
|
||||
"\u0020\u0020"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_AT_BEGINNING,
|
||||
"\u0020\u0020\u0020\u0020\u0020\u0020" +
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
TestData.standard(lamAlefSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_GROW_SHRINK,
|
||||
"\u0020\ufee5\ufef5\ufe8d\u0020\ufee5" +
|
||||
"\ufe76\ufef7\ufe8d\u0020\ufee5\u0670" +
|
||||
"\ufefb\ufe8d\u0020\ufee5\u0653\ufef5" +
|
||||
"\ufe8d\u0020\ufee5\u0655\ufef9\ufe8d" +
|
||||
"\u0020\ufee5\u0654\ufef5\ufe8d\u0020" +
|
||||
"\ufefc\ufecb"),
|
||||
|
||||
/* tashkeel special visual ltr */
|
||||
TestData.standard(tashkeelSpecialVLTR,
|
||||
LETTERS_SHAPE | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\ufef2\ufe91\ufeae\ufecb\u0020" +
|
||||
"\ufef2\ufe91\ufe7c\ufeae\ufe77\ufecb\u0020" +
|
||||
"\ufe72\ufef2\ufe91\ufeae\ufe79\ufecb\u0020" +
|
||||
"\ufe8f\u0670\ufeae\u0670\ufecb\u0020" +
|
||||
"\ufe8f\u0653\ufeae\u0653\ufecb\u0020" +
|
||||
"\ufe8f\u0654\ufeae\u0654\ufecb\u0020" +
|
||||
"\ufe8f\u0655\ufeae\u0655\ufecb\u0020"),
|
||||
TestData.standard(tashkeelSpecialVLTR,
|
||||
LETTERS_SHAPE_EXCEPT_TASHKEEL | TEXT_DIRECTION_VISUAL_LTR | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\ufef2\ufe91\ufeae\ufecb\u0020" +
|
||||
"\ufef2\ufe91\ufe7c\ufeae\ufe76\ufecb\u0020" +
|
||||
"\ufe72\ufef2\ufe91\ufeae\ufe78\ufecb\u0020" +
|
||||
"\ufe8f\u0670\ufeae\u0670\ufecb\u0020" +
|
||||
"\ufe8f\u0653\ufeae\u0653\ufecb\u0020" +
|
||||
"\ufe8f\u0654\ufeae\u0654\ufecb\u0020" +
|
||||
"\ufe8f\u0655\ufeae\u0655\ufecb\u0020"),
|
||||
|
||||
/* logical unshape */
|
||||
TestData.standard(logicalUnshape,
|
||||
LETTERS_UNSHAPE | TEXT_DIRECTION_LOGICAL | LENGTH_FIXED_SPACES_NEAR,
|
||||
"\u0020\u0020\u0020\u0627\u0644\u0622\u0646\u0020\u0627\u0644\u0623\u0642\u0644\u0627" +
|
||||
"\u0645\u0020\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u0020\u0627\u0644\u062d\u0631" +
|
||||
"\u0629\u0020\u0020\u0020\u0020"),
|
||||
TestData.standard(logicalUnshape,
|
||||
LETTERS_UNSHAPE | TEXT_DIRECTION_LOGICAL | LENGTH_FIXED_SPACES_AT_END,
|
||||
"\u0020\u0020\u0020\u0627\u0644\u0622\u0020\u0646\u0020\u0627\u0644\u0623\u0020\u0642" +
|
||||
"\u0644\u0627\u0020\u0645\u0020\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u0020\u0627" +
|
||||
"\u0644\u062d\u0631\u0629\u0020"),
|
||||
TestData.standard(logicalUnshape,
|
||||
LETTERS_UNSHAPE | TEXT_DIRECTION_LOGICAL | LENGTH_FIXED_SPACES_AT_BEGINNING,
|
||||
"\u0627\u0644\u0622\u0020\u0646\u0020\u0627\u0644\u0623\u0020\u0642\u0644\u0627\u0020" +
|
||||
"\u0645\u0020\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u0020\u0627\u0644\u062d\u0631" +
|
||||
"\u0629\u0020\u0020\u0020\u0020"),
|
||||
TestData.standard(logicalUnshape,
|
||||
LETTERS_UNSHAPE | TEXT_DIRECTION_LOGICAL | LENGTH_GROW_SHRINK,
|
||||
"\u0020\u0020\u0020\u0627\u0644\u0622\u0020\u0646\u0020\u0627\u0644\u0623\u0020\u0642" +
|
||||
"\u0644\u0627\u0020\u0645\u0020\u0627\u0644\u0639\u0631\u0628\u064a\u0629\u0020\u0627" +
|
||||
"\u0644\u062d\u0631\u0629\u0020\u0020\u0020\u0020"),
|
||||
|
||||
/* numbers */
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN | DIGIT_TYPE_AN,
|
||||
"\u0661\u0627\u0662\u06f3\u0061\u0664"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_AN2EN | DIGIT_TYPE_AN_EXTENDED,
|
||||
"\u0031\u0627\u0032\u0033\u0061\u0034"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN_INIT_LR | DIGIT_TYPE_AN,
|
||||
"\u0031\u0627\u0662\u06f3\u0061\u0034"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN_INIT_AL | DIGIT_TYPE_AN_EXTENDED,
|
||||
"\u06f1\u0627\u06f2\u06f3\u0061\u0034"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN_INIT_LR | DIGIT_TYPE_AN | TEXT_DIRECTION_VISUAL_LTR,
|
||||
"\u0661\u0627\u0032\u06f3\u0061\u0034"),
|
||||
TestData.standard(numSource,
|
||||
DIGITS_EN2AN_INIT_AL | DIGIT_TYPE_AN_EXTENDED | TEXT_DIRECTION_VISUAL_LTR,
|
||||
"\u06f1\u0627\u0032\u06f3\u0061\u06f4"),
|
||||
|
||||
/* no-op */
|
||||
TestData.standard(numSource,
|
||||
0,
|
||||
numSource),
|
||||
|
||||
/* preflight */
|
||||
TestData.preflight("\u0644\u0627",
|
||||
LETTERS_SHAPE | LENGTH_GROW_SHRINK,
|
||||
1),
|
||||
|
||||
TestData.preflight("\u0644\u0627\u0031",
|
||||
DIGITS_EN2AN | DIGIT_TYPE_AN_EXTENDED | LENGTH_GROW_SHRINK,
|
||||
3),
|
||||
|
||||
TestData.preflight("\u0644\u0644",
|
||||
LETTERS_SHAPE | LENGTH_GROW_SHRINK,
|
||||
2),
|
||||
|
||||
TestData.preflight("\ufef7",
|
||||
LETTERS_UNSHAPE | LENGTH_GROW_SHRINK,
|
||||
2),
|
||||
|
||||
/* bad data */
|
||||
TestData.error("\u0020\ufef7\u0644\u0020",
|
||||
LETTERS_UNSHAPE | LENGTH_FIXED_SPACES_NEAR,
|
||||
ArabicShapingException.class),
|
||||
|
||||
TestData.error("\u0020\ufef7",
|
||||
LETTERS_UNSHAPE | LENGTH_FIXED_SPACES_AT_END,
|
||||
ArabicShapingException.class),
|
||||
|
||||
TestData.error("\ufef7\u0020",
|
||||
LETTERS_UNSHAPE | LENGTH_FIXED_SPACES_AT_BEGINNING,
|
||||
ArabicShapingException.class),
|
||||
|
||||
/* bad options */
|
||||
TestData.error("\ufef7",
|
||||
0xffffffff,
|
||||
IllegalArgumentException.class),
|
||||
};
|
||||
|
||||
private static void runStandardTests() {
|
||||
for (int i = 0; i < tests.length; ++i) {
|
||||
TestData test = tests[i];
|
||||
|
||||
Exception ex = null;
|
||||
String result = null;
|
||||
ArabicShaping shaper = null;
|
||||
try {
|
||||
shaper = new ArabicShaping(test.flags);
|
||||
result = shaper.shape(test.source);
|
||||
}
|
||||
catch (Exception e) {
|
||||
ex = e;
|
||||
}
|
||||
|
||||
switch (test.type) {
|
||||
case TestData.STANDARD:
|
||||
if (!test.result.equals(result)) {
|
||||
reportTestFailure(i, test, shaper, result, ex);
|
||||
}
|
||||
break;
|
||||
|
||||
case TestData.PREFLIGHT:
|
||||
if (result == null || test.length != result.length()) {
|
||||
reportTestFailure(i, test, shaper, result, ex);
|
||||
}
|
||||
break;
|
||||
|
||||
case TestData.ERROR:
|
||||
if (!test.error.isInstance(ex)) {
|
||||
reportTestFailure(i, test, shaper, result, ex);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reportTestFailure(int index, TestData test, ArabicShaping shaper, String result, Exception error) {
|
||||
System.out.println("*** test failure ***");
|
||||
System.out.println("index: " + index);
|
||||
System.out.println("test: " + test);
|
||||
System.out.println("shaper: " + shaper);
|
||||
System.out.println("result: " + escapedString(result));
|
||||
System.out.println("error: " + error);
|
||||
|
||||
if (result != null && test.result != null && !test.result.equals(result)) {
|
||||
for (int i = 0; i < Math.max(test.result.length(), result.length()); ++i) {
|
||||
String temp = Integer.toString(i);
|
||||
if (temp.length() < 2) {
|
||||
temp = " ".concat(temp);
|
||||
}
|
||||
char trg = i < test.result.length() ? test.result.charAt(i) : '\uffff';
|
||||
char res = i < result.length() ? result.charAt(i) : '\uffff';
|
||||
|
||||
System.out.print("[" + temp + "] ");
|
||||
System.out.print(escapedString("" + trg) + " ");
|
||||
System.out.print(escapedString("" + res) + " ");
|
||||
if (trg != res) {
|
||||
System.out.print("***");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String escapedString(String str) {
|
||||
StringBuffer buf = new StringBuffer(str.length() * 6);
|
||||
for (int i = 0; i < str.length(); ++i) {
|
||||
char ch = str.charAt(i);
|
||||
buf.append("\\u");
|
||||
if (ch < 0x1000) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (ch < 0x0100) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (ch < 0x0010) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(Integer.toHexString(ch));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static void runAPITests() {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
runStandardTests();
|
||||
runAPITests();
|
||||
}
|
||||
}
|
||||
|
@ -1,285 +0,0 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2001, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import com.ibm.text.ArabicShaping;
|
||||
import com.ibm.text.ArabicShapingException;
|
||||
|
||||
/**
|
||||
* Interactive test for Arabic shaping.
|
||||
* Invoke from a command line passing args and strings. Use '-help' to see description of arguments.
|
||||
*/
|
||||
public class ArabicShapingTest {
|
||||
private static final int COPY = 0;
|
||||
private static final int INPLACE = 1;
|
||||
private static final int STRING = 2;
|
||||
|
||||
public static final void main(String[] args) {
|
||||
int testtype = COPY;
|
||||
int options = 0;
|
||||
int ss = 0;
|
||||
int sl = -1;
|
||||
int ds = 0;
|
||||
int dl = -1;
|
||||
String text = "$22.4 test 123 \ufef6\u0644\u0622 456 \u0664\u0665\u0666!";
|
||||
|
||||
for (int i = 0; i < args.length; ++i) {
|
||||
String arg = args[i];
|
||||
if (arg.charAt(0) == '-') {
|
||||
String opt = arg.substring(1);
|
||||
String val = opt;
|
||||
int index = arg.indexOf(':');
|
||||
if (index != -1) {
|
||||
opt = opt.substring(0, Math.min(index, 3));
|
||||
val = arg.substring(index + 1);
|
||||
}
|
||||
|
||||
if (opt.equalsIgnoreCase("len")) {
|
||||
options &= ~ArabicShaping.LENGTH_MASK;
|
||||
if (val.equalsIgnoreCase("gs")) {
|
||||
options |= ArabicShaping.LENGTH_GROW_SHRINK;
|
||||
} else if (val.equalsIgnoreCase("sn")) {
|
||||
options |= ArabicShaping.LENGTH_FIXED_SPACES_NEAR;
|
||||
} else if (val.equalsIgnoreCase("se")) {
|
||||
options |= ArabicShaping.LENGTH_FIXED_SPACES_AT_END;
|
||||
} else if (val.equalsIgnoreCase("sb")) {
|
||||
options |= ArabicShaping.LENGTH_FIXED_SPACES_AT_BEGINNING;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("dir")) {
|
||||
options &= ~ArabicShaping.TEXT_DIRECTION_MASK;
|
||||
if (val.equalsIgnoreCase("log")) {
|
||||
options |= ArabicShaping.TEXT_DIRECTION_LOGICAL;
|
||||
} else if (val.equalsIgnoreCase("vis")) {
|
||||
options |= ArabicShaping.TEXT_DIRECTION_VISUAL_LTR;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("let")) {
|
||||
options &= ~ArabicShaping.LETTERS_MASK;
|
||||
if (val.equalsIgnoreCase("no")) {
|
||||
options |= ArabicShaping.LETTERS_NOOP;
|
||||
} else if (val.equalsIgnoreCase("sh")) {
|
||||
options |= ArabicShaping.LETTERS_SHAPE;
|
||||
} else if (val.equalsIgnoreCase("un")) {
|
||||
options |= ArabicShaping.LETTERS_UNSHAPE;
|
||||
} else if (val.equalsIgnoreCase("ta")) {
|
||||
options |= ArabicShaping.LETTERS_SHAPE_EXCEPT_TASHKEEL;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("dig")) {
|
||||
options &= ~ArabicShaping.DIGITS_MASK;
|
||||
if (val.equalsIgnoreCase("no")) {
|
||||
options |= ArabicShaping.DIGITS_NOOP;
|
||||
} else if (val.equalsIgnoreCase("ea")) {
|
||||
options |= ArabicShaping.DIGITS_EN2AN;
|
||||
} else if (val.equalsIgnoreCase("ae")) {
|
||||
options |= ArabicShaping.DIGITS_AN2EN;
|
||||
} else if (val.equalsIgnoreCase("lr")) {
|
||||
options |= ArabicShaping.DIGITS_EN2AN_INIT_LR;
|
||||
} else if (val.equalsIgnoreCase("al")) {
|
||||
options |= ArabicShaping.DIGITS_EN2AN_INIT_AL;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("typ")) {
|
||||
options &= ~ArabicShaping.DIGIT_TYPE_MASK;
|
||||
if (val.equalsIgnoreCase("an")) {
|
||||
options |= ArabicShaping.DIGIT_TYPE_AN;
|
||||
} else if (val.equalsIgnoreCase("ex")) {
|
||||
options |= ArabicShaping.DIGIT_TYPE_AN_EXTENDED;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("dst")) {
|
||||
try {
|
||||
ds = Integer.parseInt(val);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("dln")) {
|
||||
try {
|
||||
dl = Integer.parseInt(val);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("sst")) {
|
||||
try {
|
||||
ss = Integer.parseInt(val);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("sln")) {
|
||||
try {
|
||||
sl = Integer.parseInt(val);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("tes")) {
|
||||
if (val.equalsIgnoreCase("cp")) {
|
||||
testtype = COPY;
|
||||
} else if (val.equalsIgnoreCase("ip")) {
|
||||
testtype = INPLACE;
|
||||
} else if (val.equalsIgnoreCase("st")) {
|
||||
testtype = STRING;
|
||||
} else {
|
||||
throwValError(opt, val);
|
||||
}
|
||||
} else if (opt.equalsIgnoreCase("help")) {
|
||||
System.out.println(usage);
|
||||
} else {
|
||||
throwOptError(opt);
|
||||
}
|
||||
} else {
|
||||
// assume text
|
||||
text = parseText(arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (sl < 0) {
|
||||
sl = text.length() - ss;
|
||||
System.out.println("sl defaulting to " + sl);
|
||||
}
|
||||
if (dl < 0) {
|
||||
dl = 2 * sl;
|
||||
System.out.println("dl defaulting to " + dl);
|
||||
}
|
||||
|
||||
ArabicShaping shaper = new ArabicShaping(options);
|
||||
System.out.println("shaper: " + shaper);
|
||||
|
||||
char[] src = text.toCharArray();
|
||||
System.out.println(" input: '" + escapedText(src, ss, sl) + "'");
|
||||
if (testtype != STRING) {
|
||||
System.out.println("start: " + ss + " length: " + sl + " total length: " + src.length);
|
||||
}
|
||||
|
||||
int result = -1;
|
||||
char[] dest = null;
|
||||
|
||||
try {
|
||||
switch (testtype) {
|
||||
case COPY:
|
||||
dest = new char[ds + dl];
|
||||
result = shaper.shape(src, ss, sl, dest, ds, dl);
|
||||
break;
|
||||
|
||||
case INPLACE:
|
||||
shaper.shape(src, ss, sl);
|
||||
ds = ss;
|
||||
result = sl;
|
||||
dest = src;
|
||||
break;
|
||||
|
||||
case STRING:
|
||||
dest = shaper.shape(text).toCharArray();
|
||||
ds = 0;
|
||||
result = dest.length;
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println("output: '" + escapedText(dest, ds, result) + "'");
|
||||
System.out.println("length: " + result);
|
||||
if (ds != 0 || result != dest.length) {
|
||||
System.out.println("full output: '" + escapedText(dest, 0, dest.length) + "'");
|
||||
}
|
||||
}
|
||||
catch (ArabicShapingException e) {
|
||||
System.out.println("Caught ArabicShapingException");
|
||||
System.out.println(e);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Caught Exception");
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void throwOptError(String opt) {
|
||||
throwUsageError("unknown option: " + opt);
|
||||
}
|
||||
|
||||
private static void throwValError(String opt, String val) {
|
||||
throwUsageError("unknown value: " + val + " for option: " + opt);
|
||||
}
|
||||
|
||||
private static void throwUsageError(String message) {
|
||||
StringBuffer buf = new StringBuffer("*** usage error ***\n");
|
||||
buf.append(message);
|
||||
buf.append("\n");
|
||||
buf.append(usage);
|
||||
throw new Error(buf.toString());
|
||||
}
|
||||
|
||||
private static final String usage =
|
||||
"Usage: [option]* [text]\n" +
|
||||
" where option is in the format '-opt[:val]'\n" +
|
||||
" options are:\n" +
|
||||
" -len:[gs|sn|se|sb] (length: grow/shrink, spaces near, spaces end, spaces beginning)\n" +
|
||||
" -dir:[log|vis] (direction: logical, visual)\n" +
|
||||
" -let:[no|sh|un|ta] (letters: noop, shape, unshape, tashkeel)\n" +
|
||||
" -dig:[no|ea|ae|lr|al] (digits: noop, en2an, an2en, en2an_lr, en2an_al)\n" +
|
||||
" -typ:[an|ex] (digit type: arabic, arabic extended)\n" +
|
||||
" -dst:# (dest start: [integer])\n" +
|
||||
" -dln:# (dest length (max size): [integer])\n" +
|
||||
" -sst:# (source start: [integer])\n" +
|
||||
" -sln:# (source length: [integer])\n" +
|
||||
" -tes:[cp|ip|st] (test type: copy, in place, string)\n" +
|
||||
" -help (print this help message)\n" +
|
||||
" text can contain unicode escape values in the format '\\uXXXX' only\n";
|
||||
|
||||
private static String escapedText(char[] text, int start, int length) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i = start, e = start + length; i < e; ++i) {
|
||||
char ch = text[i];
|
||||
if (ch < 0x20 || ch > 0x7e) {
|
||||
buf.append("\\u");
|
||||
if (ch < 0x1000) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (ch < 0x100) {
|
||||
buf.append('0');
|
||||
}
|
||||
if (ch < 0x10) {
|
||||
buf.append('0');
|
||||
}
|
||||
buf.append(Integer.toHexString(ch));
|
||||
} else {
|
||||
buf.append(ch);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
private static String parseText(String text) {
|
||||
// process unicode escapes (only)
|
||||
StringBuffer buf = new StringBuffer();
|
||||
char[] chars = text.toCharArray();
|
||||
for (int i = 0; i < chars.length; ++i) {
|
||||
char ch = chars[i];
|
||||
if (ch == '\\') {
|
||||
if ((i < chars.length - 1) &&
|
||||
(chars[i+1] == 'u')) {
|
||||
int val = Integer.parseInt(text.substring(i+2, i+6), 16);
|
||||
buf.append((char)val);
|
||||
i += 5;
|
||||
} else {
|
||||
buf.append('\\');
|
||||
}
|
||||
} else {
|
||||
buf.append(ch);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
@ -1,313 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/test/text/Attic/UCharacterCompare.java,v $
|
||||
* $Date: 2001/02/28 21:00:03 $
|
||||
* $Revision: 1.3 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import com.ibm.text.UCharacter;
|
||||
import com.ibm.text.UCharacterCategory;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* A class to compare the difference in methods between java.lang.Character and
|
||||
* UCharacter
|
||||
* @author Syn Wee Quek
|
||||
* @since oct 06 2000
|
||||
* @see com.ibm.text.UCharacter
|
||||
*/
|
||||
|
||||
public final class UCharacterCompare
|
||||
{
|
||||
// private variables ================================================
|
||||
|
||||
private static Hashtable m_hashtable_ = new Hashtable();
|
||||
|
||||
// public methods ======================================================
|
||||
|
||||
/**
|
||||
* Main testing method
|
||||
*/
|
||||
public static void main(String arg[])
|
||||
{
|
||||
try
|
||||
{
|
||||
FileWriter f;
|
||||
if (arg.length == 0)
|
||||
f = new FileWriter("compare.txt");
|
||||
else
|
||||
f = new FileWriter(arg[0]);
|
||||
PrintWriter p = new PrintWriter(f);
|
||||
p.print("char character name ");
|
||||
p.println("method name ucharacter character");
|
||||
for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i ++)
|
||||
{
|
||||
if (UCharacter.isDefined(i) != Character.isDefined(i))
|
||||
trackDifference(p, i, "isDefined()", "" + UCharacter.isDefined(i),
|
||||
"" + Character.isDefined(i));
|
||||
else
|
||||
{
|
||||
if (UCharacter.digit(i, 10) != Character.digit(i, 10))
|
||||
trackDifference(p, i, "digit()", "" + UCharacter.digit(i, 10),
|
||||
"" + Character.digit(i, 10));
|
||||
if (UCharacter.getNumericValue(i) != Character.getNumericValue(i))
|
||||
trackDifference(p, i, "getNumericValue()",
|
||||
"" + UCharacter.getNumericValue(i),
|
||||
"" + Character.getNumericValue(i));
|
||||
if (!compareType(UCharacter.getType(i), Character.getType(i)))
|
||||
trackDifference(p, i, "getType()", "" + UCharacter.getType(i),
|
||||
"" + Character.getType(i));
|
||||
if (UCharacter.isDigit(i) != Character.isDigit(i))
|
||||
trackDifference(p, i, "isDigit()",
|
||||
"" + UCharacter.isDigit(i),
|
||||
"" + Character.isDigit(i));
|
||||
if (UCharacter.isISOControl(i) != Character.isISOControl(i))
|
||||
trackDifference(p, i, "isISOControl()",
|
||||
"" + UCharacter.isISOControl(i),
|
||||
"" + Character.isISOControl(i));
|
||||
if (UCharacter.isLetter(i) != Character.isLetter(i))
|
||||
trackDifference(p, i, "isLetter()", "" + UCharacter.isLetter(i),
|
||||
"" + Character.isLetter(i));
|
||||
if (UCharacter.isLetterOrDigit(i) != Character.isLetterOrDigit(i))
|
||||
trackDifference(p, i, "isLetterOrDigit()",
|
||||
"" + UCharacter.isLetterOrDigit(i),
|
||||
"" + Character.isLetterOrDigit(i));
|
||||
if (UCharacter.isLowerCase(i) != Character.isLowerCase(i))
|
||||
trackDifference(p, i, "isLowerCase()",
|
||||
"" + UCharacter.isLowerCase(i),
|
||||
"" + Character.isLowerCase(i));
|
||||
if (UCharacter.isWhitespace(i) != Character.isWhitespace(i))
|
||||
trackDifference(p, i, "isWhitespace()",
|
||||
"" + UCharacter.isWhitespace(i),
|
||||
"" + Character.isWhitespace(i));
|
||||
if (UCharacter.isSpaceChar(i) != Character.isSpaceChar(i))
|
||||
trackDifference(p, i, "isSpaceChar()",
|
||||
"" + UCharacter.isSpaceChar(i),
|
||||
"" + Character.isSpaceChar(i));
|
||||
if (UCharacter.isTitleCase(i) != Character.isTitleCase(i))
|
||||
trackDifference(p, i, "isTitleChar()",
|
||||
"" + UCharacter.isTitleCase(i),
|
||||
"" + Character.isTitleCase(i));
|
||||
if (UCharacter.isUnicodeIdentifierPart(i) !=
|
||||
Character.isUnicodeIdentifierPart(i))
|
||||
trackDifference(p, i, "isUnicodeIdentifierPart()",
|
||||
"" + UCharacter.isUnicodeIdentifierPart(i),
|
||||
"" + Character.isUnicodeIdentifierPart(i));
|
||||
if (UCharacter.isUnicodeIdentifierStart(i) !=
|
||||
Character.isUnicodeIdentifierStart(i))
|
||||
trackDifference(p, i, "isUnicodeIdentifierStart()",
|
||||
"" + UCharacter.isUnicodeIdentifierStart(i),
|
||||
"" + Character.isUnicodeIdentifierStart(i));
|
||||
if (UCharacter.isIdentifierIgnorable(i) !=
|
||||
Character.isIdentifierIgnorable(i))
|
||||
trackDifference(p, i, "isIdentifierIgnorable()",
|
||||
"" + UCharacter.isIdentifierIgnorable(i),
|
||||
"" + Character.isIdentifierIgnorable(i));
|
||||
if (UCharacter.isUpperCase(i) != Character.isUpperCase(i))
|
||||
trackDifference(p, i, "isUpperCase()",
|
||||
"" + UCharacter.isUpperCase(i),
|
||||
"" + Character.isUpperCase(i));
|
||||
if (UCharacter.toLowerCase(i) != Character.toLowerCase(i))
|
||||
trackDifference(p, i, "toLowerCase()",
|
||||
Integer.toHexString(UCharacter.toLowerCase(i)),
|
||||
Integer.toHexString(Character.toLowerCase(i)));
|
||||
if (!UCharacter.toString(i).equals(new Character(i).toString()))
|
||||
trackDifference(p, i, "toString()",
|
||||
UCharacter.toString(i),
|
||||
new Character(i).toString());
|
||||
if (UCharacter.toTitleCase(i) != Character.toTitleCase(i))
|
||||
trackDifference(p, i, "toTitleCase()",
|
||||
Integer.toHexString(UCharacter.toTitleCase(i)),
|
||||
Integer.toHexString(Character.toTitleCase(i)));
|
||||
if (UCharacter.toUpperCase(i) != Character.toUpperCase(i))
|
||||
trackDifference(p, i, "toUpperCase()",
|
||||
Integer.toHexString(UCharacter.toUpperCase(i)),
|
||||
Integer.toHexString(Character.toUpperCase(i)));
|
||||
}
|
||||
}
|
||||
summary(p);
|
||||
p.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// private methods ===================================================
|
||||
|
||||
/**
|
||||
* Comparing types
|
||||
* @param uchartype UCharacter type
|
||||
* @param jchartype java.lang.Character type
|
||||
*/
|
||||
private static boolean compareType(int uchartype, int jchartype)
|
||||
{
|
||||
if (uchartype == UCharacterCategory.UNASSIGNED &&
|
||||
jchartype == Character.UNASSIGNED)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.UPPERCASE_LETTER &&
|
||||
jchartype == Character.UPPERCASE_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.LOWERCASE_LETTER &&
|
||||
jchartype == Character.LOWERCASE_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.TITLECASE_LETTER &&
|
||||
jchartype == Character.TITLECASE_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.MODIFIER_LETTER &&
|
||||
jchartype == Character.MODIFIER_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.OTHER_LETTER &&
|
||||
jchartype == Character.OTHER_LETTER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.NON_SPACING_MARK &&
|
||||
jchartype == Character.NON_SPACING_MARK)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.ENCLOSING_MARK &&
|
||||
jchartype == Character.ENCLOSING_MARK)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.COMBINING_SPACING_MARK &&
|
||||
jchartype == Character.COMBINING_SPACING_MARK)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.DECIMAL_DIGIT_NUMBER &&
|
||||
jchartype == Character.DECIMAL_DIGIT_NUMBER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.LETTER_NUMBER &&
|
||||
jchartype == Character.LETTER_NUMBER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.OTHER_NUMBER &&
|
||||
jchartype == Character.OTHER_NUMBER)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.SPACE_SEPARATOR &&
|
||||
jchartype == Character.SPACE_SEPARATOR)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.LINE_SEPARATOR &&
|
||||
jchartype == Character.LINE_SEPARATOR)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.PARAGRAPH_SEPARATOR &&
|
||||
jchartype == Character.PARAGRAPH_SEPARATOR)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.CONTROL &&
|
||||
jchartype == Character.CONTROL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.FORMAT &&
|
||||
jchartype == Character.FORMAT)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.PRIVATE_USE &&
|
||||
jchartype == Character.PRIVATE_USE)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.SURROGATE &&
|
||||
jchartype == Character.SURROGATE)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.DASH_PUNCTUATION &&
|
||||
jchartype == Character.DASH_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.START_PUNCTUATION &&
|
||||
jchartype == Character.START_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.END_PUNCTUATION &&
|
||||
jchartype == Character.END_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.CONNECTOR_PUNCTUATION &&
|
||||
jchartype == Character.CONNECTOR_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.OTHER_PUNCTUATION &&
|
||||
jchartype == Character.OTHER_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.MATH_SYMBOL &&
|
||||
jchartype == Character.MATH_SYMBOL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.CURRENCY_SYMBOL &&
|
||||
jchartype == Character.CURRENCY_SYMBOL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.MODIFIER_SYMBOL &&
|
||||
jchartype == Character.MODIFIER_SYMBOL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.OTHER_SYMBOL &&
|
||||
jchartype == Character.OTHER_SYMBOL)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.INITIAL_PUNCTUATION &&
|
||||
jchartype == Character.START_PUNCTUATION)
|
||||
return true;
|
||||
if (uchartype == UCharacterCategory.FINAL_PUNCTUATION &&
|
||||
jchartype == Character.END_PUNCTUATION)
|
||||
return true;
|
||||
/*if (uchartype == UCharacterCategory.GENERAL_OTHER_TYPES &&
|
||||
jchartype == Character.GENERAL_OTHER_TYPES)
|
||||
return true;*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Difference writing to file
|
||||
* @param f file outputstream
|
||||
* @param ch code point
|
||||
* @param method for testing
|
||||
* @param ucharval UCharacter value after running method
|
||||
* @param charval Character value after running method
|
||||
* @exception thrown when error occur in writing to file
|
||||
*/
|
||||
private static void trackDifference(PrintWriter f, int ch, String method,
|
||||
String ucharval, String charval)
|
||||
throws Exception
|
||||
{
|
||||
if (m_hashtable_.containsKey(method))
|
||||
{
|
||||
Integer value = (Integer)m_hashtable_.get(method);
|
||||
m_hashtable_.put(method, new Integer(value.intValue() + 1));
|
||||
}
|
||||
else
|
||||
m_hashtable_.put(method, new Integer(1));
|
||||
|
||||
String temp = Integer.toHexString(ch);
|
||||
StringBuffer s = new StringBuffer(temp);
|
||||
for (int i = 0; i < 6 - temp.length(); i ++)
|
||||
s.append(' ');
|
||||
temp = UCharacter.getName(ch);
|
||||
if (temp == null)
|
||||
temp = " ";
|
||||
s.append(temp);
|
||||
for (int i = 0; i < 73 - temp.length(); i ++)
|
||||
s.append(' ');
|
||||
|
||||
s.append(method);
|
||||
for (int i = 0; i < 27 - method.length(); i ++)
|
||||
s.append(' ');
|
||||
s.append(ucharval);
|
||||
for (int i = 0; i < 11 - ucharval.length(); i ++)
|
||||
s.append(' ');
|
||||
s.append(charval);
|
||||
f.println(s.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Does up a summary of the differences
|
||||
* @param f file outputstream
|
||||
*/
|
||||
private static void summary(PrintWriter f)
|
||||
{
|
||||
f.println("==================================================");
|
||||
f.println("Summary of differences");
|
||||
for (Enumeration e = m_hashtable_.keys() ; e.hasMoreElements() ;)
|
||||
{
|
||||
StringBuffer method = new StringBuffer((String)e.nextElement());
|
||||
int count = ((Integer)m_hashtable_.get(method.toString())).intValue();
|
||||
for (int i = 30 - method.length(); i > 0; i --)
|
||||
method.append(' ');
|
||||
f.println(method + " " + count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,652 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/test/text/Attic/UCharacterTest.java,v $
|
||||
* $Date: 2001/02/28 21:00:03 $
|
||||
* $Revision: 1.5 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Locale;
|
||||
import com.ibm.test.TestFmwk;
|
||||
import com.ibm.text.UCharacter;
|
||||
import com.ibm.text.UCharacterCategory;
|
||||
import com.ibm.text.UCharacterDirection;
|
||||
import com.ibm.text.UTF16;
|
||||
|
||||
/**
|
||||
* Testing class for UCharacter
|
||||
* Mostly following the test cases for ICU
|
||||
* @author Syn Wee Quek
|
||||
* @since nov 04 2000
|
||||
*/
|
||||
public final class UCharacterTest extends TestFmwk
|
||||
{
|
||||
// private variables =============================================
|
||||
|
||||
/**
|
||||
* ICU4J data version number
|
||||
*/
|
||||
private final String VERSION_ = "3.0.0.0";
|
||||
|
||||
// constructor ===================================================
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public UCharacterTest()
|
||||
{
|
||||
}
|
||||
|
||||
// public methods ================================================
|
||||
|
||||
/**
|
||||
* Testing the uppercase and lowercase function of UCharacter
|
||||
*/
|
||||
public void TestUpperLower()
|
||||
{
|
||||
// variables to test the uppercase and lowercase characters
|
||||
int upper[] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0xb1, 0xb2,
|
||||
0xb3, 0x48, 0x49, 0x4a, 0x2e, 0x3f, 0x3a, 0x4b, 0x4c,
|
||||
0x4d, 0x4e, 0x4f, 0x01c4, 0x01c8, 0x000c, 0x0000};
|
||||
int lower[] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0xb1, 0x00b2,
|
||||
0xb3, 0x68, 0x69, 0x6a, 0x2e, 0x3f, 0x3a, 0x6b, 0x6c,
|
||||
0x6d, 0x6e, 0x6f, 0x01c6, 0x01c9, 0x000c, 0x0000};
|
||||
|
||||
int size = upper.length;
|
||||
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (UCharacter.isLetter(lower[i]) && !UCharacter.isLowerCase(lower[i]))
|
||||
{
|
||||
errln("FAIL isLowerCase test for 0x" +
|
||||
Integer.toHexString(lower[i]));
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isLetter(upper[i]) && !(UCharacter.isUpperCase(upper[i])
|
||||
|| UCharacter.isTitleCase(upper[i])))
|
||||
{
|
||||
errln("FAIL isUpperCase test for 0x" +
|
||||
Integer.toHexString(upper[i]));
|
||||
break;
|
||||
}
|
||||
if (lower[i] != UCharacter.toLowerCase(upper[i]) ||
|
||||
(upper[i] != UCharacter.toUpperCase(lower[i]) &&
|
||||
upper[i] != UCharacter.toTitleCase(lower[i])))
|
||||
{
|
||||
errln("FAIL case conversion test for 0x" +
|
||||
Integer.toHexString(upper[i]) + " to 0x" +
|
||||
Integer.toHexString(lower[i]));
|
||||
break;
|
||||
}
|
||||
if (lower[i] != UCharacter.toLowerCase(lower[i]))
|
||||
{
|
||||
errln("FAIL lower case conversion test for 0x" +
|
||||
Integer.toHexString(lower[i]));
|
||||
break;
|
||||
}
|
||||
if (upper[i] != UCharacter.toUpperCase(upper[i]) &&
|
||||
upper[i] != UCharacter.toTitleCase(upper[i]))
|
||||
{
|
||||
errln("FAIL upper case conversion test for 0x" +
|
||||
Integer.toHexString(upper[i]));
|
||||
break;
|
||||
}
|
||||
logln("Ok 0x" + Integer.toHexString(upper[i]) + " and 0x" +
|
||||
Integer.toHexString(lower[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the letter and number determination in UCharacter
|
||||
*/
|
||||
public void TestLetterNumber()
|
||||
{
|
||||
for (int i = 0x0041; i < 0x005B; i ++)
|
||||
if (!UCharacter.isLetter(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) + " expected to be a letter");
|
||||
|
||||
for (int i = 0x0660; i < 0x066A; i ++)
|
||||
if (UCharacter.isLetter(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) +
|
||||
" expected not to be a letter");
|
||||
|
||||
for (int i = 0x0660; i < 0x066A; i ++)
|
||||
if (!UCharacter.isDigit(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) + " expected to be a digit");
|
||||
|
||||
for (int i = 0x0041; i < 0x005B; i ++)
|
||||
if (!UCharacter.isLetterOrDigit(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) +
|
||||
" expected not to be a digit");
|
||||
|
||||
for (int i = 0x0660; i < 0x066A; i ++)
|
||||
if (!UCharacter.isLetterOrDigit(i))
|
||||
errln("FAIL 0x" + Integer.toHexString(i) +
|
||||
"expected to be either a letter or a digit");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for space determination in UCharacter
|
||||
*/
|
||||
public void TestSpaces()
|
||||
{
|
||||
int spaces[] = {0x0020, 0x00a0, 0x2000, 0x2001, 0x2005};
|
||||
int nonspaces[] = {0x61, 0x62, 0x63, 0x64, 0x74};
|
||||
int whitespaces[] = {0x2008, 0x2009, 0x200a, 0x001c, 0x000c};
|
||||
int nonwhitespaces[] = {0x61, 0x62, 0x3c, 0x28, 0x3f};
|
||||
|
||||
int size = spaces.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (!UCharacter.isSpaceChar(spaces[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(spaces[i]) +
|
||||
" expected to be a space character");
|
||||
break;
|
||||
}
|
||||
|
||||
if (UCharacter.isSpaceChar(nonspaces[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonspaces[i]) +
|
||||
" expected not to be space character");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!UCharacter.isWhitespace(whitespaces[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(whitespaces[i]) +
|
||||
" expected to be a white space character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isWhitespace(nonwhitespaces[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonwhitespaces[i]) +
|
||||
" expected not to be a space character");
|
||||
break;
|
||||
}
|
||||
logln("Ok 0x" + Integer.toHexString(spaces[i]) + " and 0x" +
|
||||
Integer.toHexString(nonspaces[i]) + " and 0x" +
|
||||
Integer.toHexString(whitespaces[i]) + " and 0x" +
|
||||
Integer.toHexString(nonwhitespaces[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for defined and undefined characters
|
||||
*/
|
||||
public void TestDefined()
|
||||
{
|
||||
int undefined[] = {0xfff1, 0xfff7, 0xfa30};
|
||||
int defined[] = {0x523E, 0x4f88, 0xfffd};
|
||||
|
||||
int size = undefined.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (UCharacter.isDefined(undefined[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(undefined[i]) +
|
||||
" expected not to be defined");
|
||||
break;
|
||||
}
|
||||
if (!UCharacter.isDefined(defined[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(defined[i]) +
|
||||
" expected defined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for base characters and their cellwidth
|
||||
*/
|
||||
public void TestBase()
|
||||
{
|
||||
int base[] = {0x0061, 0x0031, 0x03d2};
|
||||
int nonbase[] = {0x002B, 0x0020, 0x203B};
|
||||
int size = base.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (UCharacter.isBaseForm(nonbase[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonbase[i]) +
|
||||
" expected not to be a base character");
|
||||
break;
|
||||
}
|
||||
if (!UCharacter.isBaseForm(base[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(base[i]) +
|
||||
" expected to be a base character");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for digit characters
|
||||
*/
|
||||
public void TestDigits()
|
||||
{
|
||||
int digits[] = {0x0030, 0x0662, 0x0F23, 0x0ED5, 0x2160};
|
||||
|
||||
//special characters not in the properties table
|
||||
int digits2[] = {0x3007, 0x4e00, 0x4e8c, 0x4e09, 0x56d8, 0x4e94, 0x516d,
|
||||
0x4e03, 0x516b, 0x4e5d};
|
||||
int nondigits[] = {0x0010, 0x0041, 0x0122, 0x68FE};
|
||||
|
||||
int digitvalues[] = {0, 2, 3, 5, 1};
|
||||
int digitvalues2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
int size = digits.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
if (UCharacter.isDigit(digits[i]) &&
|
||||
UCharacter.digit(digits[i]) != digitvalues[i])
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(digits[i]) +
|
||||
" expected digit with value " + digitvalues[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
size = nondigits.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
if (UCharacter.isDigit(nondigits[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nondigits[i]) +
|
||||
" expected nondigit");
|
||||
break;
|
||||
}
|
||||
|
||||
size = digits2.length;
|
||||
for (int i = 0; i < 10; i ++)
|
||||
if (UCharacter.isDigit(digits2[i]) &&
|
||||
UCharacter.digit(digits2[i]) != digitvalues2[i])
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(digits2[i]) +
|
||||
" expected digit with value " + digitvalues2[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for version
|
||||
*/
|
||||
public void TestVersion()
|
||||
{
|
||||
String version = UCharacter.getUnicodeVersion();
|
||||
if (!version.equals(VERSION_))
|
||||
errln("FAIL expected " + VERSION_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for control characters
|
||||
*/
|
||||
public void TestControl()
|
||||
{
|
||||
int control[] = {0x001b, 0x0097, 0x0082};
|
||||
int noncontrol[] = {0x61, 0x0031, 0x00e2};
|
||||
|
||||
int size = control.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (!UCharacter.isControl(control[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(control[i]) +
|
||||
" expected to be a control character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isControl(noncontrol[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(noncontrol[i]) +
|
||||
" expected to be not a control character");
|
||||
break;
|
||||
}
|
||||
|
||||
logln("Ok 0x" + Integer.toHexString(control[i]) + " and 0x" +
|
||||
Integer.toHexString(noncontrol[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for printable characters
|
||||
*/
|
||||
public void TestPrint()
|
||||
{
|
||||
int printable[] = {0x0042, 0x005f, 0x2014};
|
||||
int nonprintable[] = {0x200c, 0x009f, 0x001b};
|
||||
|
||||
int size = printable.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (!UCharacter.isPrintable(printable[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(printable[i]) +
|
||||
" expected to be a printable character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isPrintable(nonprintable[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonprintable[i]) +
|
||||
" expected not to be a printable character");
|
||||
break;
|
||||
}
|
||||
logln("Ok 0x" + Integer.toHexString(printable[i]) + " and 0x" +
|
||||
Integer.toHexString(nonprintable[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing for identifier characters
|
||||
*/
|
||||
public void TestIdentifier()
|
||||
{
|
||||
int unicodeidstart[] = {0x0250, 0x00e2, 0x0061};
|
||||
int nonunicodeidstart[] = {0x2000, 0x000a, 0x2019};
|
||||
int unicodeidpart[] = {0x005f, 0x0032, 0x0045};
|
||||
int nonunicodeidpart[] = {0x2030, 0x00a3, 0x0020};
|
||||
int idignore[] = {0x070F, 0x180B, 0x180C};
|
||||
int nonidignore[] = {0x0075, 0x00a3, 0x0061};
|
||||
|
||||
int size = unicodeidstart.length;
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
if (!UCharacter.isUnicodeIdentifierStart(unicodeidstart[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(unicodeidstart[i]) +
|
||||
" expected to be a unicode identifier start character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isUnicodeIdentifierStart(nonunicodeidstart[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonunicodeidstart[i]) +
|
||||
" expected not to be a unicode identifier start character");
|
||||
break;
|
||||
}
|
||||
if (!UCharacter.isUnicodeIdentifierPart(unicodeidpart[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(unicodeidpart[i]) +
|
||||
" expected to be a unicode identifier part character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isUnicodeIdentifierPart(nonunicodeidpart[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonunicodeidpart[i]) +
|
||||
" expected not to be a unicode identifier part character");
|
||||
break;
|
||||
}
|
||||
if (!UCharacter.isIdentifierIgnorable(idignore[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(idignore[i]) +
|
||||
" expected to be a ignorable unicode character");
|
||||
break;
|
||||
}
|
||||
if (UCharacter.isIdentifierIgnorable(nonidignore[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(nonidignore[i]) +
|
||||
" expected not to be a ignorable unicode character");
|
||||
break;
|
||||
}
|
||||
logln("Ok 0x" + Integer.toHexString(unicodeidstart[i]) + " and 0x" +
|
||||
Integer.toHexString(nonunicodeidstart[i]) + " and 0x" +
|
||||
Integer.toHexString(unicodeidpart[i]) + " and 0x" +
|
||||
Integer.toHexString(nonunicodeidpart[i]) + " and 0x" +
|
||||
Integer.toHexString(idignore[i]) + " and 0x" +
|
||||
Integer.toHexString(nonidignore[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for the character types, direction.<br>
|
||||
* This method reads in UnicodeData.txt file for testing purposes. A default
|
||||
* path is provided relative to the class path, however if the user could
|
||||
* set a system property to change the path.<br>
|
||||
* e.g. java -DUnicodeData="anyfile.dat" com.ibm.icu.test.text.UCharacterTest
|
||||
*/
|
||||
public void TestUnicodeData()
|
||||
{
|
||||
// this is the 2 char category types used in the UnicodeData file
|
||||
final String TYPE =
|
||||
"LuLlLtLmLoMnMeMcNdNlNoZsZlZpCcCfCoCsPdPsPePcPoSmScSkSoPiPf";
|
||||
|
||||
// directory types used in the UnicodeData file
|
||||
// padded by spaces to make each type size 4
|
||||
final String DIR =
|
||||
"L R EN ES ET AN CS B S WS ON LRE LRO AL RLE RLO PDF NSM BN ";
|
||||
|
||||
// default unicode data file name
|
||||
final String UNICODE_DATA_FILE = "src//data//unicode//UnicodeData.txt";
|
||||
|
||||
// unicode data file path system name
|
||||
final String UNICODE_DATA_SYSTEM_NAME = "UnicodeData";
|
||||
String s = System.getProperty(UNICODE_DATA_SYSTEM_NAME);
|
||||
if (s == null)
|
||||
s = UNICODE_DATA_FILE;
|
||||
|
||||
final int LASTUNICODECHAR = 0xFFFD;
|
||||
int ch = 0,
|
||||
index = 0,
|
||||
type = 0,
|
||||
dir = 0;
|
||||
|
||||
try
|
||||
{
|
||||
// reading in the UnicodeData file
|
||||
FileReader fr = new FileReader(s);
|
||||
BufferedReader input = new BufferedReader(fr);
|
||||
|
||||
while (ch != LASTUNICODECHAR)
|
||||
{
|
||||
s= input.readLine();
|
||||
|
||||
// geting the unicode character, its type and its direction
|
||||
ch = Integer.parseInt(s.substring(0, 4), 16);
|
||||
index = s.indexOf(';', 5);
|
||||
String t = s.substring(index + 1, index + 3);
|
||||
index += 4;
|
||||
byte cc = (byte)(Integer.parseInt(s.substring(index,
|
||||
s.indexOf(';', index))));
|
||||
index = s.indexOf(';', index);
|
||||
String d = s.substring(index + 1, s.indexOf(';', index + 1));
|
||||
|
||||
// testing the category
|
||||
// we override the general category of some control characters
|
||||
if (ch == 9 || ch == 0xb || ch == 0x1f)
|
||||
type = UCharacterCategory.SPACE_SEPARATOR;
|
||||
else
|
||||
if (ch == 0xc)
|
||||
type = UCharacterCategory.LINE_SEPARATOR;
|
||||
else
|
||||
if (ch == 0xa || ch == 0xd || ch == 0x1c || ch == 0x1d ||
|
||||
ch == 0x1e || ch == 0x85)
|
||||
type = UCharacterCategory.PARAGRAPH_SEPARATOR;
|
||||
else
|
||||
{
|
||||
type = TYPE.indexOf(t);
|
||||
if (type < 0)
|
||||
type = 0;
|
||||
else
|
||||
type = (type >> 1) + 1;
|
||||
}
|
||||
|
||||
if (UCharacter.getType(ch) != type)
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(ch) + " expected type " +
|
||||
type);
|
||||
break;
|
||||
}
|
||||
|
||||
// testing combining class
|
||||
if (UCharacter.getCombiningClass(ch) != cc)
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(ch) + " expected combining " +
|
||||
"class " + cc);
|
||||
break;
|
||||
}
|
||||
|
||||
// testing the direction
|
||||
if (d.length() == 1)
|
||||
d = d + " ";
|
||||
|
||||
dir = DIR.indexOf(d) >> 2;
|
||||
if (UCharacter.getDirection(ch) != dir)
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(ch) +
|
||||
" expected wrong direction " + dir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
input.close();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
errln("FAIL UnicodeData.txt not found\n" +
|
||||
"Configure the system setting UnicodeData to the right path\n" +
|
||||
"e.g. java -DUnicodeData=\"anyfile.dat\" " +
|
||||
"com.ibm.icu.test.text.UCharacterTest");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (UCharacter.getDirection(0x10001) !=
|
||||
UCharacterDirection.LEFT_TO_RIGHT)
|
||||
errln("FAIL 0x10001 expected direction " +
|
||||
UCharacterDirection.toString(UCharacterDirection.LEFT_TO_RIGHT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for the character names
|
||||
*/
|
||||
public void TestNames()
|
||||
{
|
||||
int c[] = {0x0061, 0x0284, 0x3401, 0x7fed, 0xac00, 0xd7a3, 0xff08, 0xffe5};
|
||||
String name[] = {"LATIN SMALL LETTER A",
|
||||
"LATIN SMALL LETTER DOTLESS J WITH STROKE AND HOOK",
|
||||
"CJK UNIFIED IDEOGRAPH-3401",
|
||||
"CJK UNIFIED IDEOGRAPH-7FED", "HANGUL SYLLABLE GA",
|
||||
"HANGUL SYLLABLE HIH", "FULLWIDTH LEFT PARENTHESIS",
|
||||
"FULLWIDTH YEN SIGN"};
|
||||
String oldname[] = {"", "LATIN SMALL LETTER DOTLESS J BAR HOOK", "", "",
|
||||
"", "", "FULLWIDTH OPENING PARENTHESIS", ""};
|
||||
int size = c.length;
|
||||
String str;
|
||||
int uc;
|
||||
|
||||
for (int i = 0; i < size; i ++)
|
||||
{
|
||||
// modern Unicode character name
|
||||
str = UCharacter.getName(c[i]);
|
||||
if (!str.equalsIgnoreCase(name[i]))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(c[i]) + " expected name " +
|
||||
name[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
// 1.0 Unicode character name
|
||||
str = UCharacter.getName1_0(c[i]);
|
||||
if ((str == null && oldname[i].length() > 0) ||
|
||||
(str != null && !str.equalsIgnoreCase(oldname[i])))
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(c[i]) + " expected 1.0 name " +
|
||||
oldname[i]);
|
||||
break;
|
||||
}
|
||||
|
||||
// retrieving unicode character from modern name
|
||||
uc = UCharacter.getCharFromName(name[i]);
|
||||
if (uc != c[i])
|
||||
{
|
||||
errln("FAIL " + name[i] + " expected character 0x" +
|
||||
Integer.toHexString(c[i]));
|
||||
break;
|
||||
}
|
||||
|
||||
//retrieving unicode character from 1.0 name
|
||||
uc = UCharacter.getCharFromName1_0(oldname[i]);
|
||||
if (uc != c[i] && i != 0 && (i == 1 || i == 6))
|
||||
{
|
||||
errln("FAIL " + name[i] + " expected 1.0 character " +
|
||||
Integer.toHexString(c[i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// extra testing different from icu
|
||||
for (int i = UCharacter.MIN_VALUE; i < UCharacter.MAX_VALUE; i ++)
|
||||
{
|
||||
str = UCharacter.getName(i);
|
||||
if (str != null && UCharacter.getCharFromName(str) != i)
|
||||
{
|
||||
errln("FAIL 0x" + Integer.toHexString(i) + " " + str +
|
||||
" retrieval of name and vice versa" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing the strings case mapping methods
|
||||
*/
|
||||
public void TestCaseMapping()
|
||||
{
|
||||
String beforeLower = "\u0061\u0042\u0049\u03a3\u00df\u03a3\u002f\ud93f\udfff",
|
||||
lowerRoot = "\u0061\u0062\u0069\u03c3\u00df\u03c2\u002f\ud93f\udfff",
|
||||
lowerTurkish = "\u0061\u0062\u0131\u03c3\u00df\u03c2\u002f\ud93f\udfff",
|
||||
beforeUpper = "\u0061\u0042\u0069\u03c2\u00df\u03c3\u002f\ufb03\ud93f\udfff",
|
||||
upperRoot = "\u0041\u0042\u0049\u03a3\u0053\u0053\u03a3\u002f\u0046\u0046\u0049\ud93f\udfff",
|
||||
upperTurkish = "\u0041\u0042\u0130\u03a3\u0053\u0053\u03a3\u002f\u0046\u0046\u0049\ud93f\udfff";
|
||||
|
||||
String result = UCharacter.toLowerCase(beforeLower);
|
||||
if (!lowerRoot.equals(result))
|
||||
errln("Fail " + beforeLower + " after lowercase should be " + lowerRoot);
|
||||
|
||||
// lowercase with turkish locale
|
||||
result = UCharacter.toLowerCase(new Locale("tr", "TR"), beforeLower);
|
||||
if (!lowerTurkish.equals(result))
|
||||
errln("Fail " + beforeLower + " after turkish-sensitive lowercase " +
|
||||
"should be " + lowerRoot);
|
||||
|
||||
// uppercase with root locale and in the same buffer
|
||||
result = UCharacter.toUpperCase(beforeUpper);
|
||||
if (!upperRoot.equals(result))
|
||||
errln("Fail " + beforeUpper + " after uppercase should be " + upperRoot);
|
||||
|
||||
// uppercase with turkish locale and separate buffers
|
||||
result = UCharacter.toUpperCase(new Locale("tr", "TR"), beforeUpper);
|
||||
if (!upperTurkish.equals(result))
|
||||
errln("Fail " + beforeUpper + " after turkish-sensitive uppercase " +
|
||||
"should be " + upperTurkish);
|
||||
|
||||
// test preflighting
|
||||
result = UCharacter.toLowerCase(beforeLower);
|
||||
if (!lowerRoot.equals(result))
|
||||
errln("Fail " + beforeLower + " after lower case should be " +
|
||||
lowerRoot);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
UCharacterTest test = new UCharacterTest();
|
||||
test.run(arg);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,222 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2000, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/test/text/Attic/UTF16Test.java,v $
|
||||
* $Date: 2001/02/28 21:00:03 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.test.text;
|
||||
|
||||
import com.ibm.test.TestFmwk;
|
||||
import com.ibm.text.UCharacter;
|
||||
import com.ibm.text.UTF16;
|
||||
|
||||
/**
|
||||
* Testing class for UTF16
|
||||
* @author Syn Wee Quek
|
||||
* @since feb 09 2001
|
||||
*/
|
||||
public final class UTF16Test extends TestFmwk
|
||||
{
|
||||
// constructor ===================================================
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public UTF16Test()
|
||||
{
|
||||
}
|
||||
|
||||
// public methods ================================================
|
||||
|
||||
/**
|
||||
* Testing UTF16 class methods append, getCharCount and bounds
|
||||
*/
|
||||
public void TestUTF16AppendBoundCount()
|
||||
{
|
||||
StringBuffer str = new StringBuffer("this is a string ");
|
||||
int initstrsize = str.length();
|
||||
int length;
|
||||
|
||||
for (int i = UCharacter.MIN_VALUE; i < UCharacter.MAX_VALUE; i += 100)
|
||||
{
|
||||
length = str.length();
|
||||
UTF16.append(str, i);
|
||||
|
||||
// this is to cater for the combination of 0xDBXX 0xDC50 which forms
|
||||
// a supplementary character
|
||||
if (i == 0xDC50)
|
||||
initstrsize --;
|
||||
|
||||
if (UTF16.countCP(str.toString()) != initstrsize + (i / 100) + 1)
|
||||
{
|
||||
errln("FAIL Counting code points in string appended with " +
|
||||
" 0x" + Integer.toHexString(i));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!UCharacter.isSupplementary(i))
|
||||
{
|
||||
if (UTF16.getCharCount(i) != 1)
|
||||
{
|
||||
errln("FAIL Counting BMP character size error" );
|
||||
break;
|
||||
}
|
||||
if (str.length() != length + 1)
|
||||
{
|
||||
errln("FAIL Adding a BMP character error" );
|
||||
break;
|
||||
}
|
||||
if (!UTF16.isSurrogate((char)i) &&
|
||||
(UTF16.bounds(str.toString(), str.length() - 1) !=
|
||||
UTF16.SINGLE_CHAR_BOUNDARY ||
|
||||
UTF16.boundsAtCPOffset(str.toString(), initstrsize + (i /100))
|
||||
!= UTF16.SINGLE_CHAR_BOUNDARY))
|
||||
{
|
||||
errln("FAIL Finding BMP character bounds error" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UTF16.getCharCount(i) != 2)
|
||||
{
|
||||
errln("FAIL Counting Supplementary character size error" );
|
||||
break;
|
||||
}
|
||||
if (str.length() != length + 2)
|
||||
{
|
||||
errln("FAIL Adding a Supplementary character error" );
|
||||
break;
|
||||
}
|
||||
length = str.length();
|
||||
if (UTF16.bounds(str.toString(), str.length() - 2) !=
|
||||
UTF16.LEAD_SURROGATE_BOUNDARY ||
|
||||
UTF16.bounds(str.toString(), str.length() - 1) !=
|
||||
UTF16.TRAIL_SURROGATE_BOUNDARY ||
|
||||
UTF16.boundsAtCPOffset(str.toString(), initstrsize + (i / 100))
|
||||
!= UTF16.LEAD_SURROGATE_BOUNDARY)
|
||||
{
|
||||
errln("FAIL Finding Supplementary character bounds error with " +
|
||||
"string appended with 0x" + Integer.toHexString(i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing UTF16 class methods findCPOffset, findOffsetFromCP, charAt and
|
||||
* charAtCP
|
||||
*/
|
||||
public void TestUTF16OffsetCharAt()
|
||||
{
|
||||
StringBuffer str = new StringBuffer("12345");
|
||||
UTF16.append(str, 0x10001);
|
||||
str.append("67890");
|
||||
UTF16.append(str, 0x10002);
|
||||
String s = str.toString();
|
||||
if (UTF16.charAt(s, 0) != '1' || UTF16.charAt(s, 2) != '3' ||
|
||||
UTF16.charAt(s, 5) != 0x10001 || UTF16.charAt(s, 6) != 0x10001 ||
|
||||
UTF16.charAt(s, 12) != 0x10002 || UTF16.charAt(s, 13) != 0x10002 ||
|
||||
UTF16.charAtCPOffset(s, 0) != '1' || UTF16.charAtCPOffset(s, 2) != '3' ||
|
||||
UTF16.charAtCPOffset(s, 5) != 0x10001 ||
|
||||
UTF16.charAtCPOffset(s, 6) != '6' ||
|
||||
UTF16.charAtCPOffset(s, 11) != 0x10002)
|
||||
errln("FAIL Getting character from string error" );
|
||||
|
||||
if (UTF16.findCPOffset(s, 3) != 3 || UTF16.findCPOffset(s, 5) != 5 ||
|
||||
UTF16.findCPOffset(s, 6) != 5)
|
||||
errln("FAIL Getting codepoint offset from string error" );
|
||||
if (UTF16.findOffsetFromCP(s, 3) != 3 ||
|
||||
UTF16.findOffsetFromCP(s, 5) != 5 ||
|
||||
UTF16.findOffsetFromCP(s, 6) != 7)
|
||||
errln("FAIL Getting UTF16 offset from codepoint in string error" );
|
||||
|
||||
UTF16.setCharAt(str, 3, '3');
|
||||
UTF16.setCharAtCPOffset(str, 4, '3');
|
||||
if (UTF16.charAt(str.toString(), 3) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 3) != '3' ||
|
||||
UTF16.charAt(str.toString(), 4) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 4) != '3')
|
||||
errln("FAIL Setting non-supplementary characters at a " +
|
||||
"non-supplementary position");
|
||||
|
||||
UTF16.setCharAt(str, 5, '3');
|
||||
if (UTF16.charAt(str.toString(), 5) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != '3' ||
|
||||
UTF16.charAt(str.toString(), 6) != '6' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != '6')
|
||||
errln("FAIL Setting non-supplementary characters at a " +
|
||||
"supplementary position");
|
||||
|
||||
UTF16.setCharAt(str, 5, 0x10001);
|
||||
if (UTF16.charAt(str.toString(), 5) != 0x10001 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != 0x10001 ||
|
||||
UTF16.charAt(str.toString(), 7) != '6' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != '6')
|
||||
errln("FAIL Setting supplementary characters at a " +
|
||||
"non-supplementary position");
|
||||
|
||||
UTF16.setCharAtCPOffset(str, 5, '3');
|
||||
if (UTF16.charAt(str.toString(), 5) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != '3' ||
|
||||
UTF16.charAt(str.toString(), 6) != '6' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != '6')
|
||||
errln("FAIL Setting non-supplementary characters at a " +
|
||||
"supplementary position");
|
||||
|
||||
UTF16.setCharAt(str, 5, 0x10001);
|
||||
if (UTF16.charAt(str.toString(), 5) != 0x10001 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != 0x10001 ||
|
||||
UTF16.charAt(str.toString(), 7) != '6' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != '6')
|
||||
errln("FAIL Setting supplementary characters at a " +
|
||||
"non-supplementary position");
|
||||
|
||||
|
||||
UTF16.setCharAt(str, 5, 0xD800);
|
||||
UTF16.setCharAt(str, 6, 0xD800);
|
||||
if (UTF16.charAt(str.toString(), 5) != 0xD800 ||
|
||||
UTF16.charAt(str.toString(), 6) != 0xD800 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != 0xD800 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != 0xD800)
|
||||
errln("FAIL Setting lead characters at a supplementary position");
|
||||
|
||||
UTF16.setCharAt(str, 5, 0xDDDD);
|
||||
if (UTF16.charAt(str.toString(), 5) != 0xDDDD ||
|
||||
UTF16.charAt(str.toString(), 6) != 0xD800 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != 0xDDDD ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != 0xD800)
|
||||
errln("FAIL Setting trail characters at a surrogate position");
|
||||
|
||||
UTF16.setCharAt(str, 5, '3');
|
||||
if (UTF16.charAt(str.toString(), 5) != '3' ||
|
||||
UTF16.charAt(str.toString(), 6) != 0xD800 ||
|
||||
UTF16.charAtCPOffset(str.toString(), 5) != '3' ||
|
||||
UTF16.charAtCPOffset(str.toString(), 6) != 0xD800)
|
||||
errln("FAIL Setting non-supplementary characters at a surrogate " +
|
||||
"position");
|
||||
}
|
||||
|
||||
public static void main(String[] arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
UTF16Test test = new UTF16Test();
|
||||
test.run(arg);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user