Exemple #1
0
            public override bool Equals(Object other)
            {
                LocaleDataTest.ExemplarGroup o = (LocaleDataTest.ExemplarGroup)other;
                bool r = ILOG.J2CsMapping.Collections.Arrays.Equals(scs, o.scs) && set.Equals(o.set);

                return(r);
            }
Exemple #2
0
        public void TestExemplarSet2()
        {
            int       equalCount      = 0;
            HashedSet testedExemplars = new HashedSet();

            for (int i = 0; i < availableLocales.Length; i++)
            {
                ULocale    locale      = availableLocales[i];
                LocaleData ld          = IBM.ICU.Util.LocaleData.GetInstance(locale);
                int[]      scriptCodes = IBM.ICU.Lang.UScript.GetCode(locale);
                if (scriptCodes == null)
                {
                    if (locale.ToString().IndexOf(("in")) < 0)
                    {
                        Errln("UScript.getCode returned null for locale: " + locale);
                    }
                    continue;
                }
                UnicodeSet[] exemplarSets = new UnicodeSet[4];

                for (int k = 0; k < 2; ++k)
                { // for casing option in (normal,
                    // uncased)
                    int option = (k == 0) ? 0 : IBM.ICU.Text.UnicodeSet.CASE;
                    for (int h = 0; h < 2; ++h)
                    {
                        int type = (h == 0) ? IBM.ICU.Util.LocaleData.ES_STANDARD
                                : IBM.ICU.Util.LocaleData.ES_AUXILIARY;

                        UnicodeSet exemplarSet = ld.GetExemplarSet(option, type);
                        exemplarSets[k * 2 + h] = exemplarSet;

                        LocaleDataTest.ExemplarGroup exGrp = new LocaleDataTest.ExemplarGroup(exemplarSet,
                                                                                              scriptCodes);
                        if (!ILOG.J2CsMapping.Collections.Collections.Contains(exGrp, testedExemplars))
                        {
                            ILOG.J2CsMapping.Collections.Generics.Collections.Add(testedExemplars, exGrp);
                            UnicodeSet[] sets = new UnicodeSet[scriptCodes.Length];
                            // create the UnicodeSets for the script
                            for (int j = 0; j < scriptCodes.Length; j++)
                            {
                                sets[j] = new UnicodeSet("[:"
                                                         + IBM.ICU.Lang.UScript.GetShortName(scriptCodes[j])
                                                         + ":]");
                            }
                            bool existsInScript     = false;
                            UnicodeSetIterator iter = new UnicodeSetIterator(
                                exemplarSet);
                            // iterate over the
                            while (!existsInScript && iter.NextRange())
                            {
                                if (iter.codepoint != IBM.ICU.Text.UnicodeSetIterator.IS_STRING)
                                {
                                    for (int j_0 = 0; j_0 < sets.Length; j_0++)
                                    {
                                        if (sets[j_0].Contains(iter.codepoint,
                                                               iter.codepointEnd))
                                        {
                                            existsInScript = true;
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int j_1 = 0; j_1 < sets.Length; j_1++)
                                    {
                                        if (sets[j_1].Contains(iter.str0))
                                        {
                                            existsInScript = true;
                                            break;
                                        }
                                    }
                                }
                            }
                            // TODO: How to verify LocaleData.ES_AUXILIARY ???
                            if (existsInScript == false && h == 0)
                            {
                                Errln("ExemplarSet containment failed for locale,option,type : "
                                      + locale + ", " + option + ", " + type);
                            }
                        }
                    }
                }
                // This is expensive, so only do it if it will be visible
                if (IsVerbose())
                {
                    Logln(locale.ToString() + " exemplar(ES_STANDARD)"
                          + exemplarSets[0]);
                    Logln(locale.ToString() + " exemplar(ES_AUXILIARY) "
                          + exemplarSets[1]);
                    Logln(locale.ToString() + " exemplar(case-folded,ES_STANDARD) "
                          + exemplarSets[2]);
                    Logln(locale.ToString()
                          + " exemplar(case-folded,ES_AUXILIARY) "
                          + exemplarSets[3]);
                }
                AssertTrue(locale.ToString() + " case-folded is a superset",
                           exemplarSets[2].ContainsAll(exemplarSets[0]));
                AssertTrue(locale.ToString() + " case-folded is a superset",
                           exemplarSets[3].ContainsAll(exemplarSets[1]));
                if (exemplarSets[2].Equals(exemplarSets[0]))
                {
                    ++equalCount;
                }
                if (exemplarSets[3].Equals(exemplarSets[1]))
                {
                    ++equalCount;
                }
            }
            // Note: The case-folded set should sometimes be a strict superset
            // and sometimes be equal.
            AssertTrue(
                "case-folded is sometimes a strict superset, and sometimes equal",
                equalCount > 0 && equalCount < availableLocales.Length * 2);
        }
Exemple #3
0
        public void TestExemplarSet()
        {
            HashedSet testedExemplars = new HashedSet();
            int       equalCount      = 0;

            for (int i = 0; i < availableLocales.Length; i++)
            {
                ULocale locale      = availableLocales[i];
                int[]   scriptCodes = IBM.ICU.Lang.UScript.GetCode(locale);
                if (scriptCodes == null)
                {
                    // I hate the JDK's solution for deprecated language codes.
                    // Why does the Locale constructor change the string I passed to
                    // it ?
                    // such a broken hack !!!!!
                    // so in effect I can never test the script code for Indonesian
                    // :(
                    if (locale.ToString().IndexOf(("in")) < 0)
                    {
                        Errln("UScript.getCode returned null for locale: " + locale);
                    }
                    continue;
                }
                UnicodeSet[] exemplarSets = new UnicodeSet[2];
                for (int k = 0; k < 2; ++k)
                { // for casing option in (normal,
                    // caseInsensitive)
                    int        option      = (k == 0) ? 0 : IBM.ICU.Text.UnicodeSet.CASE;
                    UnicodeSet exemplarSet = IBM.ICU.Util.LocaleData.GetExemplarSet(locale,
                                                                                    option);
                    exemplarSets[k] = exemplarSet;
                    LocaleDataTest.ExemplarGroup exGrp = new LocaleDataTest.ExemplarGroup(exemplarSet,
                                                                                          scriptCodes);
                    if (!ILOG.J2CsMapping.Collections.Collections.Contains(exGrp, testedExemplars))
                    {
                        ILOG.J2CsMapping.Collections.Generics.Collections.Add(testedExemplars, exGrp);
                        UnicodeSet[] sets = new UnicodeSet[scriptCodes.Length];
                        // create the UnicodeSets for the script
                        for (int j = 0; j < scriptCodes.Length; j++)
                        {
                            sets[j] = new UnicodeSet("[:"
                                                     + IBM.ICU.Lang.UScript.GetShortName(scriptCodes[j]) + ":]");
                        }
                        bool existsInScript     = false;
                        UnicodeSetIterator iter = new UnicodeSetIterator(
                            exemplarSet);
                        // iterate over the
                        while (!existsInScript && iter.NextRange())
                        {
                            if (iter.codepoint != IBM.ICU.Text.UnicodeSetIterator.IS_STRING)
                            {
                                for (int j_0 = 0; j_0 < sets.Length; j_0++)
                                {
                                    if (sets[j_0].Contains(iter.codepoint,
                                                           iter.codepointEnd))
                                    {
                                        existsInScript = true;
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                for (int j_1 = 0; j_1 < sets.Length; j_1++)
                                {
                                    if (sets[j_1].Contains(iter.str0))
                                    {
                                        existsInScript = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (existsInScript == false)
                        {
                            Errln("ExemplarSet containment failed for locale : "
                                  + locale);
                        }
                    }
                }
                // This is expensive, so only do it if it will be visible
                if (IsVerbose())
                {
                    Logln(locale.ToString() + " exemplar " + exemplarSets[0]);
                    Logln(locale.ToString() + " exemplar(case-folded) "
                          + exemplarSets[1]);
                }
                AssertTrue(locale.ToString() + " case-folded is a superset",
                           exemplarSets[1].ContainsAll(exemplarSets[0]));
                if (exemplarSets[1].Equals(exemplarSets[0]))
                {
                    ++equalCount;
                }
            }
            // Note: The case-folded set should sometimes be a strict superset
            // and sometimes be equal.
            AssertTrue(
                "case-folded is sometimes a strict superset, and sometimes equal",
                equalCount > 0 && equalCount < availableLocales.Length);
        }