use of android.icu.text.SpoofChecker in project j2objc by google.
the class SpoofCheckerTest method TestBug11635.
@Test
public void TestBug11635() {
// The bug was an error in iterating through supplementary characters in IdentifierInfo.
// The three supplemental chars in the string are "123" from the mathematical bold digit range.
// Common script, Nd general category, and no other restrictions on allowed characters
// leaves "ABC123" as SINGLE_SCRIPT_RESTRICTIVE.
String identifier = Utility.unescape("ABC\\U0001D7CF\\U0001D7D0\\U0001D7D1");
CheckResult checkResult = new CheckResult();
SpoofChecker sc = new SpoofChecker.Builder().setChecks(SpoofChecker.RESTRICTION_LEVEL).build();
sc.failsChecks(identifier, checkResult);
assertEquals("", RestrictionLevel.SINGLE_SCRIPT_RESTRICTIVE, checkResult.restrictionLevel);
}
use of android.icu.text.SpoofChecker in project j2objc by google.
the class SpoofCheckerTest method TestOpenFromSourceRules.
/*
* Test build from source rules.
*/
@Test
public void TestOpenFromSourceRules() {
if (TestUtil.getJavaVendor() == JavaVendor.IBM && TestUtil.getJavaVersion() == 5) {
// Note: IBM Java 5 has a bug reading a large UTF-8 text contents
logln("Skip this test case because of the IBM Java 5 bug");
return;
}
String fileName;
Reader confusables;
try {
SpoofChecker rsc = null;
fileName = "unicode/confusables.txt";
confusables = TestUtil.getDataReader(fileName, "UTF-8");
try {
rsc = new SpoofChecker.Builder().setData(confusables).build();
} finally {
confusables.close();
}
if (rsc == null) {
errln("FAIL: null SpoofChecker");
return;
}
// Check that newly built-from-rules SpoofChecker is able to function.
checkSkeleton(rsc, "TestOpenFromSourceRules");
SpoofChecker.CheckResult result = new SpoofChecker.CheckResult();
rsc.failsChecks("Hello", result);
// The checker we just built from source rules should be equivalent to the
// default checker created from prebuilt rules baked into the ICU data.
SpoofChecker defaultChecker = new SpoofChecker.Builder().build();
assertEquals("Checker built from rules equals default", defaultChecker, rsc);
assertEquals("Checker built from rules has same hash code as default", defaultChecker.hashCode(), rsc.hashCode());
SpoofChecker optionChecker = new SpoofChecker.Builder().setRestrictionLevel(RestrictionLevel.UNRESTRICTIVE).build();
assertFalse("", optionChecker.equals(rsc));
String stubConfusables = "# Stub confusables data\n" + "05AD ; 0596 ; MA # ( ֭ → ֖ ) HEBREW ACCENT DEHI → HEBREW ACCENT TIPEHA #\n";
// Verify that re-using a builder doesn't alter SpoofCheckers that were
// previously created by that builder. (The builder could modify data
// being used by the existing checker)
SpoofChecker.Builder builder = new SpoofChecker.Builder();
SpoofChecker testChecker1 = builder.build();
assertTrue("", testChecker1.equals(defaultChecker));
builder.setData(new StringReader(stubConfusables));
builder.setRestrictionLevel(RestrictionLevel.UNRESTRICTIVE);
builder.setChecks(SpoofChecker.SINGLE_SCRIPT_CONFUSABLE);
Set<ULocale> allowedLocales = new HashSet<ULocale>();
allowedLocales.add(ULocale.JAPANESE);
allowedLocales.add(ULocale.FRENCH);
builder.setAllowedLocales(allowedLocales);
SpoofChecker testChecker2 = builder.build();
SpoofChecker testChecker3 = builder.build();
assertTrue("", testChecker1.equals(defaultChecker));
assertFalse("", testChecker2.equals(defaultChecker));
assertTrue("", testChecker2.equals(testChecker3));
} catch (java.io.IOException e) {
errln(e.toString());
} catch (ParseException e) {
errln(e.toString());
}
}
use of android.icu.text.SpoofChecker in project j2objc by google.
the class SpoofCheckerTest method TestDeprecated.
@Test
public void TestDeprecated() {
// getSkeleton
SpoofChecker sc = new SpoofChecker.Builder().build();
assertEquals("Deprecated version of getSkeleton method does not work", sc.getSkeleton(SpoofChecker.ANY_CASE, scMixed), sc.getSkeleton(scMixed));
// setData
try {
String fileName1 = "unicode/confusables.txt";
String fileName2 = "unicode/confusablesWholeScript.txt";
Reader reader1 = TestUtil.getDataReader(fileName1, "UTF-8");
Reader reader2 = TestUtil.getDataReader(fileName2, "UTF-8");
Reader reader3 = TestUtil.getDataReader(fileName1, "UTF-8");
try {
SpoofChecker sc2 = new SpoofChecker.Builder().setData(reader1, reader2).build();
SpoofChecker sc1 = new SpoofChecker.Builder().setData(reader3).build();
assertEquals("Deprecated version of setData method does not work", sc1, sc2);
} finally {
reader1.close();
reader2.close();
reader3.close();
}
} catch (IOException e) {
fail("Could not load confusables data");
} catch (ParseException e) {
fail("Could not parse confusables data");
}
}
use of android.icu.text.SpoofChecker in project j2objc by google.
the class SpoofCheckerTest method TestAllowedChars.
/*
* AllowedChars set/get the UnicodeSet of allowed characters.
*/
@Test
public void TestAllowedChars() {
SpoofChecker sc = new SpoofChecker.Builder().setChecks(SpoofChecker.CHAR_LIMIT).build();
UnicodeSet set;
UnicodeSet tmpSet;
boolean checkResults;
/* By default, we should see no restriction; the UnicodeSet should allow all characters. */
set = sc.getAllowedChars();
tmpSet = new UnicodeSet(0, 0x10ffff);
assertEquals("", tmpSet, set);
/* Remove a character that is in our good Latin test identifier from the allowed chars set. */
tmpSet.remove(goodLatin.charAt(1));
sc = new SpoofChecker.Builder().setChecks(SpoofChecker.CHAR_LIMIT).setAllowedChars(tmpSet).build();
/* Latin Identifier should now fail; other non-latin test cases should still be OK */
SpoofChecker.CheckResult result = new SpoofChecker.CheckResult();
checkResults = sc.failsChecks(goodLatin, result);
assertTrue("", checkResults);
assertEquals("", SpoofChecker.CHAR_LIMIT, result.checks);
}
use of android.icu.text.SpoofChecker in project j2objc by google.
the class SpoofCheckerTest method TestSkeleton.
@Test
public void TestSkeleton() {
SpoofChecker sc = new SpoofChecker.Builder().build();
checkSkeleton(sc, "TestSkeleton");
}
Aggregations