예제 #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");
            }
        }
예제 #2
0
        private void DoTestCompare(String s1, String s2, bool isEqual)
        {
            if (!IDNAReference.IsReady)
            {
                Logln("Transliterator is not available on this environment.  Skipping doTestCompare.");
                return;
            }

            try
            {
                int retVal = IDNAReference.Compare(s1, s2, IDNA2003Options.Default);
                if (isEqual == true && retVal != 0)
                {
                    Errln("Did not get the expected result for s1: " + Prettify(s1) +
                          " s2: " + Prettify(s2));
                }
                retVal = IDNAReference.Compare(new StringBuffer(s1), new StringBuffer(s2), IDNA2003Options.Default);
                if (isEqual == true && retVal != 0)
                {
                    Errln("Did not get the expected result for s1: " + Prettify(s1) +
                          " s2: " + Prettify(s2));
                }
                retVal = IDNAReference.Compare(UCharacterIterator.GetInstance(s1), UCharacterIterator.GetInstance(s2), IDNA2003Options.Default);
                if (isEqual == true && retVal != 0)
                {
                    Errln("Did not get the expected result for s1: " + Prettify(s1) +
                          " s2: " + Prettify(s2));
                }
            }
            catch (Exception e)
            {
                e.PrintStackTrace();
                Errln("Unexpected exception thrown by IDNAReference.compare");
            }

            try
            {
                int retVal = IDNAReference.Compare(s1, s2, IDNA2003Options.AllowUnassigned);
                if (isEqual == true && retVal != 0)
                {
                    Errln("Did not get the expected result for s1: " + Prettify(s1) +
                          " s2: " + Prettify(s2));
                }
                retVal = IDNAReference.Compare(new StringBuffer(s1), new StringBuffer(s2), IDNA2003Options.AllowUnassigned);
                if (isEqual == true && retVal != 0)
                {
                    Errln("Did not get the expected result for s1: " + Prettify(s1) +
                          " s2: " + Prettify(s2));
                }
                retVal = IDNAReference.Compare(UCharacterIterator.GetInstance(s1), UCharacterIterator.GetInstance(s2), IDNA2003Options.AllowUnassigned);
                if (isEqual == true && retVal != 0)
                {
                    Errln("Did not get the expected result for s1: " + Prettify(s1) +
                          " s2: " + Prettify(s2));
                }
            }
            catch (Exception e)
            {
                Errln("Unexpected exception thrown by IDNAReference.compare");
            }
        }
예제 #3
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());
                }
            }
        }