use of android.icu.text.CollationElementIterator in project j2objc by google.
the class CollationTest method doTest.
// package private methods ----------------------------------------------
static void doTest(TestFmwk test, RuleBasedCollator col, String source, String target, int result) {
doTestVariant(test, col, source, target, result);
if (result == -1) {
doTestVariant(test, col, target, source, 1);
} else if (result == 1) {
doTestVariant(test, col, target, source, -1);
} else {
doTestVariant(test, col, target, source, 0);
}
CollationElementIterator iter = col.getCollationElementIterator(source);
backAndForth(test, iter);
iter.setText(target);
backAndForth(test, iter);
}
use of android.icu.text.CollationElementIterator in project j2objc by google.
the class CollationAPITest method TestRuleBasedColl.
/**
* This tests the RuleBasedCollator
* - constructor/destructor
* - getRules
*/
@Test
public void TestRuleBasedColl() {
RuleBasedCollator col1 = null, col2 = null, col3 = null, col4 = null;
String ruleset1 = "&9 < a, A < b, B < c, C; ch, cH, Ch, CH < d, D, e, E";
String ruleset2 = "&9 < a, A < b, B < c, C < d, D, e, E";
String ruleset3 = "&";
try {
col1 = new RuleBasedCollator(ruleset1);
} catch (Exception e) {
// only first error needs to be a warning since we exit function
warnln("RuleBased Collator creation failed.");
return;
}
try {
col2 = new RuleBasedCollator(ruleset2);
} catch (Exception e) {
errln("RuleBased Collator creation failed.");
return;
}
try {
// empty rules fail
col3 = new RuleBasedCollator(ruleset3);
errln("Failure: Empty rules for the collator should fail");
return;
} catch (MissingResourceException e) {
warnln(e.getMessage());
} catch (Exception e) {
logln("PASS: Empty rules for the collator failed as expected");
}
Locale locale = new Locale("aa", "AA");
try {
col3 = (RuleBasedCollator) Collator.getInstance(locale);
} catch (Exception e) {
errln("Fallback Collator creation failed.: %s");
return;
}
try {
col3 = (RuleBasedCollator) Collator.getInstance();
} catch (Exception e) {
errln("Default Collator creation failed.: %s");
return;
}
String rule1 = col1.getRules();
String rule2 = col2.getRules();
String rule3 = col3.getRules();
doAssert(!rule1.equals(rule2), "Default collator getRules failed");
doAssert(!rule2.equals(rule3), "Default collator getRules failed");
doAssert(!rule1.equals(rule3), "Default collator getRules failed");
try {
col4 = new RuleBasedCollator(rule2);
} catch (Exception e) {
errln("RuleBased Collator creation failed.");
return;
}
String rule4 = col4.getRules();
doAssert(rule2.equals(rule4), "Default collator getRules failed");
// tests that modifier ! is always ignored
String exclamationrules = "!&a<b";
// java does not allow ! to be the start of the rule
String thaistr = "\u0e40\u0e01\u0e2d";
try {
RuleBasedCollator col5 = new RuleBasedCollator(exclamationrules);
RuleBasedCollator encol = (RuleBasedCollator) Collator.getInstance(Locale.ENGLISH);
CollationElementIterator col5iter = col5.getCollationElementIterator(thaistr);
CollationElementIterator encoliter = encol.getCollationElementIterator(thaistr);
while (true) {
// testing with en since thai has its own tailoring
int ce = col5iter.next();
int ce2 = encoliter.next();
if (ce2 != ce) {
errln("! modifier test failed");
}
if (ce == CollationElementIterator.NULLORDER) {
break;
}
}
} catch (Exception e) {
errln("RuleBased Collator creation failed for ! modifier.");
return;
}
}
use of android.icu.text.CollationElementIterator in project j2objc by google.
the class CollationDummyTest method TestJB1401.
@Test
public void TestJB1401() {
Collator myCollator = null;
char[] NFD_UnsafeStartChars = { // Tibetan Vowel Sign II
0x0f73, // Tibetan Vowel Sign UU
0x0f75, // Tibetan Vowel Sign Reversed II
0x0f81, 0 };
int i;
try {
myCollator = Collator.getInstance(Locale.ENGLISH);
} catch (Exception e) {
errln("ERROR: Failed to create the collator for ENGLISH");
return;
}
myCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
for (i = 0; ; i++) {
// Get the next funny character to be tested, and set up the
// three test strings X, Y, Z, consisting of an A-grave + test char,
// in original form, NFD, and then NFC form.
char c = NFD_UnsafeStartChars[i];
if (c == 0) {
break;
}
// \u00C0 is A Grave
String x = "\u00C0" + c;
String y;
String z;
try {
y = Normalizer.decompose(x, false);
z = Normalizer.decompose(y, true);
} catch (Exception e) {
errln("ERROR: Failed to normalize test of character" + c);
return;
}
// Collation test. All three strings should be equal.
// doTest does both strcoll and sort keys, with params in both orders.
doTest(myCollator, x, y, 0);
doTest(myCollator, x, z, 0);
doTest(myCollator, y, z, 0);
// Run collation element iterators over the three strings. Results should be same for each.
{
CollationElementIterator ceiX, ceiY, ceiZ;
int ceX, ceY, ceZ;
int j;
try {
ceiX = ((RuleBasedCollator) myCollator).getCollationElementIterator(x);
ceiY = ((RuleBasedCollator) myCollator).getCollationElementIterator(y);
ceiZ = ((RuleBasedCollator) myCollator).getCollationElementIterator(z);
} catch (Exception e) {
errln("ERROR: getCollationElementIterator failed");
return;
}
for (j = 0; ; j++) {
try {
ceX = ceiX.next();
ceY = ceiY.next();
ceZ = ceiZ.next();
} catch (Exception e) {
errln("ERROR: CollationElementIterator.next failed for iteration " + j);
break;
}
if (ceX != ceY || ceY != ceZ) {
errln("ERROR: ucol_next failed for iteration " + j);
break;
}
if (ceX == CollationElementIterator.NULLORDER) {
break;
}
}
}
}
}
use of android.icu.text.CollationElementIterator in project j2objc by google.
the class CollationIteratorTest method TestClearBuffers.
/*
* @bug 4157299
*/
@Test
public void TestClearBuffers() /* char* par */
{
RuleBasedCollator c = null;
try {
c = new RuleBasedCollator("&a < b < c & ab = d");
} catch (Exception e) {
warnln("Couldn't create a RuleBasedCollator.");
return;
}
String source = "abcd";
CollationElementIterator i = c.getCollationElementIterator(source);
int e0 = 0;
try {
// save the first collation element
e0 = i.next();
} catch (Exception e) {
errln("call to i.next() failed.");
return;
}
try {
// go to the expanding character
i.setOffset(3);
} catch (Exception e) {
errln("call to i.setOffset(3) failed.");
return;
}
try {
// but only use up half of it
i.next();
} catch (Exception e) {
errln("call to i.next() failed.");
return;
}
try {
// go back to the beginning
i.setOffset(0);
} catch (Exception e) {
errln("call to i.setOffset(0) failed. ");
}
int e = 0;
try {
// and get this one again
e = i.next();
} catch (Exception ee) {
errln("call to i.next() failed. ");
return;
}
if (e != e0) {
errln("got 0x" + Integer.toHexString(e) + ", expected 0x" + Integer.toHexString(e0));
}
}
use of android.icu.text.CollationElementIterator in project j2objc by google.
the class CollationIteratorTest method TestSetText.
/**
* Test for setText()
*/
@Test
public void TestSetText() /* char* par */
{
RuleBasedCollator en_us = (RuleBasedCollator) Collator.getInstance(Locale.US);
CollationElementIterator iter1 = en_us.getCollationElementIterator(test1);
CollationElementIterator iter2 = en_us.getCollationElementIterator(test2);
// Run through the second iterator just to exercise it
int c = iter2.next();
int i = 0;
while (++i < 10 && c != CollationElementIterator.NULLORDER) {
try {
c = iter2.next();
} catch (Exception e) {
errln("iter2.next() returned an error.");
break;
}
}
// Now set it to point to the same string as the first iterator
try {
iter2.setText(test1);
} catch (Exception e) {
errln("call to iter2->setText(test1) failed.");
return;
}
assertEqual(iter1, iter2);
iter1.reset();
// now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text
CharacterIterator chariter = new StringCharacterIterator(test1);
try {
iter2.setText(chariter);
} catch (Exception e) {
errln("call to iter2->setText(chariter(test1)) failed.");
return;
}
assertEqual(iter1, iter2);
iter1.reset();
// now use the overloaded setText(ChracterIterator&, UErrorCode) function to set the text
UCharacterIterator uchariter = UCharacterIterator.getInstance(test1);
try {
iter2.setText(uchariter);
} catch (Exception e) {
errln("call to iter2->setText(uchariter(test1)) failed.");
return;
}
assertEqual(iter1, iter2);
}
Aggregations