Search in sources :

Example 16 with StringPrepParseException

use of android.icu.text.StringPrepParseException in project j2objc by google.

the class TestIDNARef method doTestIDNToUnicode.

private void doTestIDNToUnicode(String src, String expected, int options, Object expectedException) throws Exception {
    if (!IDNAReference.isReady()) {
        logln("Transliterator is not available on this environment.  Skipping doTestIDNToUnicode.");
        return;
    }
    StringBuffer inBuf = new StringBuffer(src);
    UCharacterIterator inIter = UCharacterIterator.getInstance(src);
    try {
        StringBuffer out = IDNAReference.convertIDNToUnicode(src, options);
        if (expected != null && out != null && !out.toString().equals(expected)) {
            errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + prettify(out));
        }
        if (expectedException != null && !unassignedException.equals(expectedException)) {
            errln("convertToUnicode did not get the expected exception. The operation succeeded!");
        }
    } catch (StringPrepParseException ex) {
        if (expectedException == null || !expectedException.equals(ex)) {
            errln("convertToUnicode did not get the expected exception for source: " + src + " Got:  " + ex.toString());
        }
    }
    try {
        StringBuffer out = IDNAReference.convertIDNToUnicode(inBuf, options);
        if (expected != null && out != null && !out.toString().equals(expected)) {
            errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + out);
        }
        if (expectedException != null && !unassignedException.equals(expectedException)) {
            errln("convertToUnicode did not get the expected exception. The operation succeeded!");
        }
    } catch (StringPrepParseException ex) {
        if (expectedException == null || !expectedException.equals(ex)) {
            errln("convertToUnicode did not get the expected exception for source: " + src + " Got:  " + ex.toString());
        }
    }
    try {
        StringBuffer out = IDNAReference.convertIDNToUnicode(inIter, options);
        if (expected != null && out != null && !out.toString().equals(expected)) {
            errln("convertToUnicode did not return expected result with options : " + options + " Expected: " + prettify(expected) + " Got: " + prettify(out));
        }
        if (expectedException != null && !unassignedException.equals(expectedException)) {
            errln("Did not get the expected exception. The operation succeeded!");
        }
    } catch (StringPrepParseException ex) {
        if (expectedException == null || !expectedException.equals(ex)) {
            errln("Did not get the expected exception for source: " + src + " Got:  " + ex.toString());
        }
    }
}
Also used : StringPrepParseException(android.icu.text.StringPrepParseException) UCharacterIterator(android.icu.text.UCharacterIterator)

Example 17 with StringPrepParseException

use of android.icu.text.StringPrepParseException in project j2objc by google.

the class TestIDNARef method doTestIDNToASCII.

private void doTestIDNToASCII(String src, String expected, int options, Object expectedException) throws Exception {
    if (!IDNAReference.isReady()) {
        logln("Transliterator is not available on this environment.  Skipping doTestIDNToASCII.");
        return;
    }
    StringBuffer inBuf = new StringBuffer(src);
    UCharacterIterator inIter = UCharacterIterator.getInstance(src);
    try {
        StringBuffer out = IDNAReference.convertIDNToASCII(src, options);
        if (expected != null && out != null && !out.toString().equals(expected)) {
            errln("convertToIDNAReferenceASCII did not return expected result with options : " + options + " Expected: " + expected + " Got: " + out);
        }
        if (expectedException != null && !unassignedException.equals(expectedException)) {
            errln("convertToIDNAReferenceASCII did not get the expected exception. The operation succeeded!");
        }
    } catch (StringPrepParseException ex) {
        if (expectedException == null || !ex.equals(expectedException)) {
            errln("convertToIDNAReferenceASCII did not get the expected exception for source: " + src + " Got:  " + ex.toString());
        }
    }
    try {
        StringBuffer out = IDNAReference.convertIDNtoASCII(inBuf, options);
        if (expected != null && out != null && !out.toString().equals(expected)) {
            errln("convertToIDNAReferenceASCII did not return expected result with options : " + options + " Expected: " + expected + " Got: " + out);
        }
        if (expectedException != null && !unassignedException.equals(expectedException)) {
            errln("convertToIDNAReferenceSCII did not get the expected exception. The operation succeeded!");
        }
    } catch (StringPrepParseException ex) {
        if (expectedException == null || !ex.equals(expectedException)) {
            errln("convertToIDNAReferenceSCII did not get the expected exception for source: " + src + " Got:  " + ex.toString());
        }
    }
    try {
        StringBuffer out = IDNAReference.convertIDNtoASCII(inIter, options);
        if (expected != null && out != null && !out.toString().equals(expected)) {
            errln("convertIDNToASCII did not return expected result with options : " + options + " Expected: " + expected + " Got: " + out);
        }
        if (expectedException != null && !unassignedException.equals(expectedException)) {
            errln("convertIDNToASCII did not get the expected exception. The operation succeeded!");
        }
    } catch (StringPrepParseException ex) {
        if (expectedException == null || !ex.equals(expectedException)) {
            errln("convertIDNToASCII did not get the expected exception for source: " + src + " Got:  " + ex.toString());
        }
    }
}
Also used : StringPrepParseException(android.icu.text.StringPrepParseException) UCharacterIterator(android.icu.text.UCharacterIterator)

Example 18 with StringPrepParseException

use of android.icu.text.StringPrepParseException in project j2objc by google.

the class TestStringPrep method TestSetPreContext.

/* Tests the private void setPreContext(char[] str, int pos) */
@Test
public void TestSetPreContext() {
    String WordAtLeast16Characters = "abcdefghijklmnopqrstuvwxyz";
    for (int i = 0; i < 5; i++) {
        try {
            @SuppressWarnings("unused") StringPrepParseException sppe = new StringPrepParseException("dummy", i, WordAtLeast16Characters, 0, 0);
            sppe = new StringPrepParseException(WordAtLeast16Characters, i, "dummy", 0, 0);
        } catch (Exception e) {
            errln("StringPrepParseException.setPreContext was not suppose to return an exception");
        }
    }
}
Also used : StringPrepParseException(android.icu.text.StringPrepParseException) StringPrepParseException(android.icu.text.StringPrepParseException) Test(org.junit.Test)

Example 19 with StringPrepParseException

use of android.icu.text.StringPrepParseException in project j2objc by google.

the class TestStringPrep method TestStringPrepParseExceptionEquals.

/* Tests the method public boolean equals(Object other) for StringPrepParseException */
@Test
public void TestStringPrepParseExceptionEquals() {
    StringPrepParseException sppe = new StringPrepParseException("dummy", 0, "dummy", 0, 0);
    StringPrepParseException sppe_clone = new StringPrepParseException("dummy", 0, "dummy", 0, 0);
    StringPrepParseException sppe1 = new StringPrepParseException("dummy1", 1, "dummy1", 0, 0);
    // Tests when "if(!(other instanceof StringPrepParseException))" is true
    if (sppe.equals(0)) {
        errln("StringPrepParseException.equals(Object) is suppose to return false when " + "passing integer '0'");
    }
    if (sppe.equals(0.0)) {
        errln("StringPrepParseException.equals(Object) is suppose to return false when " + "passing float/double '0.0'");
    }
    if (sppe.equals("0")) {
        errln("StringPrepParseException.equals(Object) is suppose to return false when " + "passing string '0'");
    }
    // Tests when "if(!(other instanceof StringPrepParseException))" is true
    if (!sppe.equals(sppe)) {
        errln("StringPrepParseException.equals(Object) is suppose to return true when " + "comparing to the same object");
    }
    if (!sppe.equals(sppe_clone)) {
        errln("StringPrepParseException.equals(Object) is suppose to return true when " + "comparing to the same initiated object");
    }
    if (sppe.equals(sppe1)) {
        errln("StringPrepParseException.equals(Object) is suppose to return false when " + "comparing to another object that isn't the same");
    }
}
Also used : StringPrepParseException(android.icu.text.StringPrepParseException) Test(org.junit.Test)

Example 20 with StringPrepParseException

use of android.icu.text.StringPrepParseException in project j2objc by google.

the class TestStringPrep method TestStringPrepParseException.

/*
     * Tests the constructor public StringPrepParseException(String message, int error, String rules, int pos, int
     * lineNumber)
     */
@Test
public void TestStringPrepParseException() {
    Locale[] locales = { Locale.US, Locale.FRENCH, Locale.SIMPLIFIED_CHINESE };
    String rules = "This is a very odd little set of rules, just for testing, you know...";
    StringPrepParseException[] exceptions = new StringPrepParseException[locales.length];
    for (int i = 0; i < locales.length; i += 1) {
        exceptions[i] = new StringPrepParseException(locales[i].toString(), i, rules, i, i);
    }
}
Also used : Locale(java.util.Locale) StringPrepParseException(android.icu.text.StringPrepParseException) Test(org.junit.Test)

Aggregations

StringPrepParseException (android.icu.text.StringPrepParseException)24 UCharacterIterator (android.icu.text.UCharacterIterator)16 Test (org.junit.Test)7 StringPrep (android.icu.text.StringPrep)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Locale (java.util.Locale)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1