Exemple #1
0
        public void Test_equalsLjava_lang_Object()
        {
            Collator c  = ILOG.J2CsMapping.Text.Collator.GetInstance(Locale.ENGLISH);
            Collator c2 = (Collator)c.Clone();

            NUnit.Framework.Assert.IsTrue(c.Equals(c2), "Cloned collators not equal");
            c2.SetStrength(ILOG.J2CsMapping.Text.Collator.SECONDARY);
            NUnit.Framework.Assert.IsTrue(!c.Equals(c2), "Collators with different strengths equal");
        }
Exemple #2
0
        public void Test_getInstance()
        {
            Collator c1 = ILOG.J2CsMapping.Text.Collator.GetInstance();
            Collator c2 = ILOG.J2CsMapping.Text.Collator.GetInstance(Locale.GetDefault());

            NUnit.Framework.Assert.IsTrue(c1.Equals(c2), "Wrong locale");
        }
Exemple #3
0
        public void TestCollation()
        {
            ULocale defLoc = ULocale.GetDefault();

            ULocale.SetDefault(_DEFAULT_LOCALE);
            for (int i = 0; i < _LOCALE_NUMBER; i++)
            {
                ULocale oldLoc = _LOCALES[i][0];
                ULocale newLoc = _LOCALES[i][1];
                if (availableMap.Get(_LOCALES[i][1]) == null)
                {
                    Logln(_LOCALES[i][1] + " is not available. Skipping!");
                    continue;
                }
                Collator c1 = Collator.GetInstance(oldLoc);
                Collator c2 = Collator.GetInstance(newLoc);

                if (!c1.Equals(c2))
                {
                    Errln("CollationTest: c1!=c2: newLoc= " + newLoc + " oldLoc= " + oldLoc);
                }

                Logln("Collation old:" + oldLoc + "   new:" + newLoc);
            }
            ULocale.SetDefault(defLoc);
        }
Exemple #4
0
        public void TestCollation()
        {
            using (new ThreadCultureChange(_DEFAULT_LOCALE, _DEFAULT_LOCALE))
            {
                for (int i = 0; i < _LOCALE_NUMBER; i++)
                {
                    UCultureInfo oldLoc = _LOCALES[i][0];
                    UCultureInfo newLoc = _LOCALES[i][1];
                    if (!availableMap.TryGetValue(_LOCALES[i][1], out object value) || value == null)
                    {
                        Logln(_LOCALES[i][1] + " is not available. Skipping!");
                        continue;
                    }
                    Collator c1 = Collator.GetInstance(oldLoc);
                    Collator c2 = Collator.GetInstance(newLoc);

                    if (!c1.Equals(c2))
                    {
                        Errln("CollationTest: c1!=c2: newLoc= " + newLoc + " oldLoc= " + oldLoc);
                    }

                    Logln("Collation old:" + oldLoc + "   new:" + newLoc);
                }
            }
        }
Exemple #5
0
        public void Test_clone()
        {
            Collator c  = ILOG.J2CsMapping.Text.Collator.GetInstance(Locale.GERMAN);
            Collator c2 = (Collator)c.Clone();

            NUnit.Framework.Assert.IsTrue(c.Equals(c2), "Clones answered false to equals");
            NUnit.Framework.Assert.IsTrue(c != c2, "Clones were equivalent");
        }
Exemple #6
0
        /// @tests java.text.Collator#setDecomposition(int)
        // FIXME This test fails on Harmony ClassLibrary
        public void Failing_test_setDecompositionI()
        {
            Collator c = ILOG.J2CsMapping.Text.Collator.GetInstance(Locale.FRENCH);

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.IDENTICAL);
            c.SetDecomposition(ILOG.J2CsMapping.Text.Collator.NO_DECOMPOSITION);
            NUnit.Framework.Assert.IsTrue(!c.Equals("\u212B", "\u00C5"), "Collator should not be using decomposition");    // "ANGSTROM SIGN" and "LATIN
            // CAPITAL
            // LETTER A WITH RING ABOVE"
            c.SetDecomposition(ILOG.J2CsMapping.Text.Collator.CANONICAL_DECOMPOSITION);
            NUnit.Framework.Assert.IsTrue(c.Equals("\u212B", "\u00C5"), "Collator should be using decomposition");    // "ANGSTROM SIGN" and "LATIN
            // CAPITAL LETTER A WITH
            // RING ABOVE"
            NUnit.Framework.Assert.IsTrue(!c.Equals("\u2163", "IV"), "Should not be equal under canonical decomposition"); // roman number "IV"
            c.SetDecomposition(ILOG.J2CsMapping.Text.Collator.FULL_DECOMPOSITION);
            NUnit.Framework.Assert.IsTrue(c.Equals("\u2163", "IV"), "Should be equal under full decomposition");           // roman number "IV"
        }
        public void TestCollator_GetInstance()
        {
            Collator coll = ILOG.J2CsMapping.Text.Collator.GetInstance();
            Object   obj1 = "a";
            Object   obj2 = "b";

            NUnit.Framework.Assert.AreEqual(-1, coll.Compare(obj1, obj2));

            ILOG.J2CsMapping.Text.Collator.GetInstance();
            NUnit.Framework.Assert.IsFalse(coll.Equals("A", "\uFF21"));
        }
Exemple #8
0
        public void Test_equalsLjava_lang_StringLjava_lang_String()
        {
            Collator c = ILOG.J2CsMapping.Text.Collator.GetInstance(Locale.FRENCH);

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.IDENTICAL);
            NUnit.Framework.Assert.IsTrue(!c.Equals("E", "F"), "a) Failed on primary difference");
            NUnit.Framework.Assert.IsTrue(!c.Equals("e", "\u00e9"), "a) Failed on secondary difference");
            NUnit.Framework.Assert.IsTrue(!c.Equals("e", "E"), "a) Failed on tertiary difference");
            NUnit.Framework.Assert.IsTrue(!c.Equals("\u0001", "\u0002"), "a) Failed on identical");
            NUnit.Framework.Assert.IsTrue(c.Equals("e", "e"), "a) Failed on equivalence");

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.TERTIARY);
            NUnit.Framework.Assert.IsTrue(!c.Equals("E", "F"), "b) Failed on primary difference");
            NUnit.Framework.Assert.IsTrue(!c.Equals("e", "\u00e9"), "b) Failed on secondary difference");
            NUnit.Framework.Assert.IsTrue(!c.Equals("e", "E"), "b) Failed on tertiary difference");
            NUnit.Framework.Assert.IsTrue(c.Equals("\u0001", "\u0002"), "b) Failed on identical");
            NUnit.Framework.Assert.IsTrue(c.Equals("e", "e"), "b) Failed on equivalence");

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.SECONDARY);
            NUnit.Framework.Assert.IsTrue(!c.Equals("E", "F"), "c) Failed on primary difference");
            NUnit.Framework.Assert.IsTrue(!c.Equals("e", "\u00e9"), "c) Failed on secondary difference");
            NUnit.Framework.Assert.IsTrue(c.Equals("e", "E"), "c) Failed on tertiary difference");
            NUnit.Framework.Assert.IsTrue(c.Equals("\u0001", "\u0002"), "c) Failed on identical");
            NUnit.Framework.Assert.IsTrue(c.Equals("e", "e"), "c) Failed on equivalence");

            c.SetStrength(ILOG.J2CsMapping.Text.Collator.PRIMARY);
            NUnit.Framework.Assert.IsTrue(!c.Equals("E", "F"), "d) Failed on primary difference");
            NUnit.Framework.Assert.IsTrue(c.Equals("e", "\u00e9"), "d) Failed on secondary difference");
            NUnit.Framework.Assert.IsTrue(c.Equals("e", "E"), "d) Failed on tertiary difference");
            NUnit.Framework.Assert.IsTrue(c.Equals("\u0001", "\u0002"), "d) Failed on identical");
            NUnit.Framework.Assert.IsTrue(c.Equals("e", "e"), "d) Failed on equivalence");
        }
Exemple #9
0
        public void TestRegisterFactory()
        {
            UCultureInfo fu_FU     = new UCultureInfo("fu_FU");
            UCultureInfo fu_FU_FOO = new UCultureInfo("fu_FU_FOO");

            IDictionary <object, object> fuFUNames = new Dictionary <object, object>
            {
                { fu_FU, "ze leetle bunny Fu-Fu" },
                { fu_FU_FOO, "zee leetel bunny Foo-Foo" },
                { new UCultureInfo("en_US"), "little bunny Foo Foo" }
            };

            Collator frcol = Collator.GetInstance(new UCultureInfo("fr_FR"));

            /* Collator uscol = */
            Collator.GetInstance(new UCultureInfo("en_US"));
            Collator gecol = Collator.GetInstance(new UCultureInfo("de_DE"));
            Collator jpcol = Collator.GetInstance(new UCultureInfo("ja_JP"));
            Collator fucol = Collator.GetInstance(fu_FU);

            CollatorInfo[] info =
            {
                new CollatorInfo(new UCultureInfo("en_US"), frcol, null),
                new CollatorInfo(new UCultureInfo("fr_FR"), gecol, null),
                new CollatorInfo(fu_FU,                     jpcol, fuFUNames),
            };
            TestFactory factory = null;

            try
            {
                factory = new TestFactory(info);
            }
            catch (MissingManifestResourceException ex)
            {
                Warnln("Could not load locale data.");
            }
            // coverage
            {
                TestFactoryWrapper wrapper = new TestFactoryWrapper(factory); // in java, gc lets us easily multiply reference!
                Object             key     = Collator.RegisterFactory(wrapper);
                String             name    = null;
                try
                {
                    name = Collator.GetDisplayName(fu_FU, fu_FU_FOO);
                }
                catch (MissingManifestResourceException ex)
                {
                    Warnln("Could not load locale data.");
                }
                Logln("*** default name: " + name);
                Collator.Unregister(key);

                UCultureInfo bar_BAR   = new UCultureInfo("bar_BAR");
                Collator     col       = Collator.GetInstance(bar_BAR);
                UCultureInfo valid     = col.ValidCulture;
                String       validName = valid.FullName;
                if (validName.Length != 0 && !validName.Equals("root"))
                {
                    Errln("Collation from bar_BAR is really \"" + validName + "\" but should be root");
                }
            }

            int n1 = checkAvailable("before registerFactory");

            {
                Object key = Collator.RegisterFactory(factory);

                int n2 = checkAvailable("after registerFactory");

                Collator ncol = Collator.GetInstance(new UCultureInfo("en_US"));
                if (!frcol.Equals(ncol))
                {
                    Errln("frcoll for en_US failed");
                }

                ncol = Collator.GetInstance(fu_FU_FOO);
                if (!jpcol.Equals(ncol))
                {
                    Errln("jpcol for fu_FU_FOO failed, got: " + ncol);
                }

                UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures);
                bool           found   = false;
                for (int i = 0; i < locales.Length; ++i)
                {
                    if (locales[i].Equals(fu_FU))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Errln("new locale fu_FU not reported as supported locale");
                }

                String name = Collator.GetDisplayName(fu_FU);
                if (!"little bunny Foo Foo".Equals(name))
                {
                    Errln("found " + name + " for fu_FU");
                }

                name = Collator.GetDisplayName(fu_FU, fu_FU_FOO);
                if (!"zee leetel bunny Foo-Foo".Equals(name))
                {
                    Errln("found " + name + " for fu_FU in fu_FU_FOO");
                }

                if (!Collator.Unregister(key))
                {
                    Errln("failed to unregister factory");
                }

                int n3 = checkAvailable("after unregister");
                assertTrue("register increases count", n2 > n1);
                assertTrue("unregister restores count", n3 == n1);

                ncol = Collator.GetInstance(fu_FU);
                if (!fucol.Equals(ncol))
                {
                    Errln("collator after unregister does not match original fu_FU");
                }
            }
        }
Exemple #10
0
        public void TestRegister()
        {
            // register a singleton
            Collator frcol = Collator.GetInstance(new UCultureInfo("fr_FR"));
            Collator uscol = Collator.GetInstance(new UCultureInfo("en_US"));

            { // try override en_US collator
                Object   key  = Collator.RegisterInstance(frcol, new UCultureInfo("en_US"));
                Collator ncol = Collator.GetInstance(new UCultureInfo("en_US"));
                if (!frcol.Equals(ncol))
                {
                    Errln("register of french collator for en_US failed");
                }

                // coverage
                Collator test = Collator.GetInstance(new UCultureInfo("de_DE")); // CollatorFactory.handleCreate
                if (!test.ValidCulture.Equals(new UCultureInfo("de")))
                {
                    Errln("Collation from Germany is really " + test.ValidCulture);
                }

                if (!Collator.Unregister(key))
                {
                    Errln("failed to unregister french collator");
                }
                ncol = Collator.GetInstance(new UCultureInfo("en_US"));
                if (!uscol.Equals(ncol))
                {
                    Errln("collator after unregister does not match original");
                }
            }

            UCultureInfo fu_FU = new UCultureInfo("fu_FU_FOO");

            { // try create collator for new locale
                Collator fucol = Collator.GetInstance(fu_FU);
                Object   key   = Collator.RegisterInstance(frcol, fu_FU);
                Collator ncol  = Collator.GetInstance(fu_FU);
                if (!frcol.Equals(ncol))
                {
                    Errln("register of fr collator for fu_FU failed");
                }

                UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures);
                bool           found   = false;
                for (int i = 0; i < locales.Length; ++i)
                {
                    if (locales[i].Equals(fu_FU))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Errln("new locale fu_FU not reported as supported locale");
                }
                try
                {
                    String name = Collator.GetDisplayName(fu_FU);
                    if (!"fu (FU, FOO)".Equals(name) &&
                        !"fu_FU_FOO".Equals(name) /* no LocaleDisplayNamesImpl */)
                    {
                        Errln("found " + name + " for fu_FU");
                    }
                }
                catch (MissingManifestResourceException ex)
                {
                    Warnln("Could not load locale data.");
                }
                try
                {
                    String name = Collator.GetDisplayName(fu_FU, fu_FU);
                    if (!"fu (FU, FOO)".Equals(name) &&
                        !"fu_FU_FOO".Equals(name) /* no LocaleDisplayNamesImpl */)
                    {
                        Errln("found " + name + " for fu_FU");
                    }
                }
                catch (MissingManifestResourceException ex)
                {
                    Warnln("Could not load locale data.");
                }

                if (!Collator.Unregister(key))
                {
                    Errln("failed to unregister french collator");
                }
                ncol = Collator.GetInstance(fu_FU);
                if (!fucol.Equals(ncol))
                {
                    Errln("collator after unregister does not match original fu_FU");
                }
            }

            {
                // coverage after return to default
                UCultureInfo[] locales = Collator.GetUCultures(UCultureTypes.AllCultures);

                for (int i = 0; i < locales.Length; ++i)
                {
                    if (locales[i].Equals(fu_FU))
                    {
                        Errln("new locale fu_FU not reported as supported locale");
                        break;
                    }
                }

                Collator ncol = Collator.GetInstance(new UCultureInfo("en_US"));
                if (!ncol.ValidCulture.Equals(new UCultureInfo("en_US")))
                {
                    Errln("Collation from US is really " + ncol.ValidCulture);
                }
            }
        }