// test and ascertain // func(func(func(src))) == func(src) public void DoTestChainingToUnicode(String source) { if (!IDNAReference.IsReady) { Logln("Transliterator is not available on this environment. Skipping doTestChainingToUnicode."); return; } StringBuffer expected; StringBuffer chained; // test convertIDNToUnicode expected = IDNAReference.ConvertIDNToUnicode(source, IDNAReference.DEFAULT); chained = expected; for (int i = 0; i < 4; i++) { chained = IDNAReference.ConvertIDNToUnicode(chained, IDNAReference.DEFAULT); } if (!expected.ToString().Equals(chained.ToString())) { Errln("Chaining test failed for convertIDNToUnicode"); } // test convertIDNToA expected = IDNAReference.ConvertToUnicode(source, IDNAReference.DEFAULT); chained = expected; for (int i = 0; i < 4; i++) { chained = IDNAReference.ConvertToUnicode(chained, IDNAReference.DEFAULT); } if (!expected.ToString().Equals(chained.ToString())) { Errln("Chaining test failed for convertToUnicode"); } }
private void DoTestIDNToUnicode(String src, String expected, IDNA2003Options options, Object expectedException) { 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 && [email protected]().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 && [email protected]().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 && [email protected]().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()); } } }