示例#1
0
        //  test and ascertain
        //  func(func(func(src))) == func(src)
        private void DoTestChainingToASCII(String source)
        {
            if (!IDNAReference.IsReady)
            {
                Logln("Transliterator is not available on this environment.  Skipping doTestChainingToASCII.");
                return;
            }

            StringBuffer expected;
            StringBuffer chained;

            // test convertIDNToASCII
            expected = IDNAReference.ConvertIDNToASCII(source, IDNAReference.DEFAULT);
            chained  = expected;
            for (int i = 0; i < 4; i++)
            {
                chained = IDNAReference.ConvertIDNtoASCII(chained, IDNAReference.DEFAULT);
            }
            if (!expected.ToString().Equals(chained.ToString()))
            {
                Errln("Chaining test failed for convertIDNToASCII");
            }
            // test convertIDNToA
            expected = IDNAReference.ConvertToASCII(source, IDNAReference.DEFAULT);
            chained  = expected;
            for (int i = 0; i < 4; i++)
            {
                chained = IDNAReference.ConvertToASCII(chained, IDNAReference.DEFAULT);
            }
            if (!expected.ToString().Equals(chained.ToString()))
            {
                Errln("Chaining test failed for convertToASCII");
            }
        }
示例#2
0
        private void DoTestIDNToASCII(String src, String expected, IDNA2003Options options, Object expectedException)
        {
            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 && [email protected]().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 && [email protected]().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 && [email protected]().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());
                }
            }
        }