Example #1
0
        //  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");
            }
        }
Example #2
0
        private void DoTestToUnicode(String src, String expected, IDNA2003Options options, Object expectedException)
        {
            if (!IDNAReference.IsReady)
            {
                Logln("Transliterator is not available on this environment.  Skipping doTestToUnicode.");
                return;
            }

            StringBuffer       inBuf  = new StringBuffer(src);
            UCharacterIterator inIter = UCharacterIterator.GetInstance(src);

            try
            {
                StringBuffer @out = IDNAReference.ConvertToUnicode(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 || !ex.Equals(expectedException))
                {
                    Errln("convertToUnicode did not get the expected exception for source: " + Prettify(src) + " Got:  " + ex.ToString());
                }
            }
            try
            {
                StringBuffer @out = IDNAReference.ConvertToUnicode(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 || !ex.Equals(expectedException))
                {
                    Errln("convertToUnicode did not get the expected exception for source: " + Prettify(src) + " Got:  " + ex.ToString());
                }
            }

            try
            {
                StringBuffer @out = IDNAReference.ConvertToUnicode(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 || !ex.Equals(expectedException))
                {
                    Errln("Did not get the expected exception for source: " + Prettify(src) + " Got:  " + ex.ToString());
                }
            }
        }