Beispiel #1
0
        [Timeout(120000)] // ICU4N: This test can take awhile because of the slowness of adding items to SortedSet
        public void TestUnicodeMapGeneralCategory()
        {
            Logln("Setting General Category");
            UnicodeMap <String>           map1 = new UnicodeMap <string>();
            IDictionary <Integer, String> map2 = new JCG.Dictionary <Integer, String>();

            //Map<Integer, String> map3 = new TreeMap<Integer, String>();
            map1 = new UnicodeMap <String>();
            map2 = new JCG.SortedDictionary <Integer, String>();

            for (int cp = 0; cp <= SET_LIMIT; ++cp)
            {
                int enumValue = UChar.GetIntPropertyValue(cp, propEnum);
                //if (enumValue <= 0) continue; // for smaller set
                String value = UChar.GetPropertyValueName(propEnum, enumValue, NameChoice.Long);
                map1.Put(cp, value);
                map2[new Integer(cp)] = value;
            }
            checkNext(map1, map2, int.MaxValue);

            Logln("Comparing General Category");
            check(map1, map2, -1);
            Logln("Comparing Values");
            ISet <String> values1 = new JCG.SortedSet <String>(StringComparer.Ordinal); map1.GetAvailableValues(values1);
            ISet <String> values2 = new JCG.SortedSet <String>(map2.Values.Distinct(), StringComparer.Ordinal); // ICU4N NOTE: Added Distinct()

            if (!TestBoilerplate <string> .VerifySetsIdentical(this, values1, values2))
            {
                throw new ArgumentException("Halting");
            }
            Logln("Comparing Sets");
            foreach (string value in values1)
            {
                Logln(value == null ? "null" : value);
                UnicodeSet set1 = map1.KeySet(value);
                UnicodeSet set2 = TestBoilerplate <string> .GetSet(map2, value);

                if (!TestBoilerplate <string> .VerifySetsIdentical(this, set1, set2))
                {
                    throw new ArgumentException("Halting");
                }
            }
        }
Beispiel #2
0
        public void TestPropertyNames()
        {
            int        v, rev;
            UProperty  p;
            NameChoice choice;

            for (p = 0; ; ++p)
            {
                bool sawProp = false;
                for (choice = 0; ; ++choice)
                {
                    string name = null;
                    try
                    {
                        name = UChar.GetPropertyName(p, choice);
                        if (!sawProp)
                        {
                            Log("prop " + p + ":");
                        }
                        string n = (name != null) ? ("\"" + name + '"') : "null";
                        Log(" " + choice + "=" + n);
                        sawProp = true;
                    }
                    catch (ArgumentException e)
                    {
                        if (choice > 0)
                        {
                            break;
                        }
                    }
                    if (name != null)
                    {
                        /* test reverse mapping */
                        rev = UChar.GetPropertyEnum(name);
                        if (rev != (int)p)
                        {
                            Errln("Property round-trip failure: " + p + " -> " +
                                  name + " -> " + rev);
                        }
                    }
                }
                if (sawProp)
                {
                    /* looks like a valid property; check the values */
                    string pname = UChar.GetPropertyName(p, NameChoice.Long);
                    int    max   = 0;
                    if (p == UProperty.Canonical_Combining_Class)
                    {
                        max = 255;
                    }
                    else if (p == UProperty.General_Category_Mask)
                    {
                        /* it's far too slow to iterate all the way up to
                         * the real max, U_GC_P_MASK */
                        max = 0x1000; // U_GC_NL_MASK;
                    }
                    else if (p == UProperty.Block)
                    {
                        /* UBlockCodes, unlike other values, start at 1 */
                        max = 1;
                    }
                    Logln("");
                    for (v = -1; ; ++v)
                    {
                        bool sawValue = false;
                        for (choice = 0; ; ++choice)
                        {
                            string vname = null;
                            try
                            {
                                vname = UChar.GetPropertyValueName(p, v, choice);
                                string n = (vname != null) ? ("\"" + vname + '"') : "null";
                                if (!sawValue)
                                {
                                    Log(" " + pname + ", value " + v + ":");
                                }
                                Log(" " + choice + "=" + n);
                                sawValue = true;
                            }
                            catch (ArgumentException e)
                            {
                                if (choice > 0)
                                {
                                    break;
                                }
                            }
                            if (vname != null)
                            {
                                /* test reverse mapping */
                                rev = UChar.GetPropertyValueEnum(p, vname);
                                if (rev != v)
                                {
                                    Errln("Value round-trip failure (" + pname +
                                          "): " + v + " -> " +
                                          vname + " -> " + rev);
                                }
                            }
                        }
                        if (sawValue)
                        {
                            Logln("");
                        }
                        if (!sawValue && v >= max)
                        {
                            break;
                        }
                    }
                }
                if (!sawProp)
                {
                    if (p >= UPropertyConstants.String_Limit)
                    {
                        break;
                    }
                    else if (p >= UPropertyConstants.Double_Limit)
                    {
                        p = UPropertyConstants.String_Start - 1;
                    }
                    else if (p >= UPropertyConstants.Mask_Limit)
                    {
                        p = UPropertyConstants.Double_Start - 1;
                    }
                    else if (p >= UPropertyConstants.Int_Limit)
                    {
                        p = UPropertyConstants.Mask_Start - 1;
                    }
                    else if (p >= UPropertyConstants.Binary_Limit)
                    {
                        p = UPropertyConstants.Int_Start - 1;
                    }
                }
            }

            int i = UChar.GetIntPropertyMinValue(
                UProperty.Canonical_Combining_Class);

            try
            {
                for (; i <= UChar.GetIntPropertyMaxValue(
                         UProperty.Canonical_Combining_Class);
                     i++)
                {
                    UChar.GetPropertyValueName(
                        UProperty.Canonical_Combining_Class,
                        i, NameChoice.Long);
                }
            }
            catch (ArgumentException e)
            {
                Errln("0x" + i.ToHexString()
                      + " should have a null property value name");
            }
        }