Exemplo n.º 1
0
        public void Test_applyPatternLjava_lang_String()
        {
            // Test for method void
            // java.text.ChoiceFormat.applyPattern(java.lang.String)
            ChoiceFormat f = (ChoiceFormat)f1.Clone();

            f.ApplyPattern("0#0|1#1");
            NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetLimits(), new double[] { 0, 1 }), "Incorrect limits");
            NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetFormats(), new String[] { "0", "1" }), "Incorrect formats");

            // Regression for Harmony 540
            double[] choiceLimits  = { -1, 0, 1, ChoiceFormat.NextDouble(1) };
            String[] choiceFormats = { "is negative", "is zero or fraction",
                                       "is one",      "is more than 1" };

            f = new ChoiceFormat("");
            f.ApplyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1");
            NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetLimits(), choiceLimits), "Incorrect limits");
            NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetFormats(), choiceFormats), "Incorrect formats");

            f = new ChoiceFormat("");
            try
            {
                f.ApplyPattern("-1#is negative|0#is zero or fraction|-1#is one|1<is more than 1");
                NUnit.Framework.Assert.Fail("Expected IllegalArgumentException");
            }
            catch (ArgumentException e)
            {
                // Expected
            }

            f = new ChoiceFormat("");
            try
            {
                f.ApplyPattern("-1is negative|0#is zero or fraction|1#is one|1<is more than 1");
                NUnit.Framework.Assert.Fail("Expected IllegalArgumentException");
            }
            catch (ArgumentException e_0)
            {
                // Expected
            }

            f = new ChoiceFormat("");
            f.ApplyPattern("-1<is negative|0#is zero or fraction|1#is one|1<is more than 1");
            choiceLimits[0] = ChoiceFormat.NextDouble(-1);
            NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetLimits(), choiceLimits), "Incorrect limits");
            NUnit.Framework.Assert.IsTrue(ILOG.J2CsMapping.Collections.Arrays.Equals(f.GetFormats(), choiceFormats), "Incorrect formats");

            f = new ChoiceFormat("");
            f.ApplyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1");
            String str = "org.apache.harmony.tests.java.text.ChoiceFormat";

            f.ApplyPattern(str);
            String ptrn = f.ToPattern();

            NUnit.Framework.Assert.AreEqual(0, ptrn.Length, "Return value should be empty string for invalid pattern");
        }