コード例 #1
0
        public void Test_getFormatsByArgumentIndex()
        {
            // Test for method java.text.Format [] test_getFormatsByArgumentIndex()

            // test with repeating formats and max argument index < max offset
            Format[] formats        = format1.GetFormatsByArgumentIndex();
            Format[] correctFormats = new Format[] { IBM.ICU.Text.DateFormat.GetDateInstance(),
                                                     new ChoiceFormat("0#off|1#on"), IBM.ICU.Text.DateFormat.GetTimeInstance(),
                                                     IBM.ICU.Text.NumberFormat.GetCurrencyInstance(), null };

            NUnit.Framework.Assert.AreEqual(correctFormats.Length, formats.Length, "Test1:Returned wrong number of formats:");
            for (int i = 0; i < correctFormats.Length; i++)
            {
                NUnit.Framework.Assert.AreEqual(correctFormats[i], formats[i], "Test1:wrong format for argument index " + i + ":");
            }

            // test with max argument index > max offset
            formats        = format2.GetFormatsByArgumentIndex();
            correctFormats = new Format[] { IBM.ICU.Text.DateFormat.GetDateInstance(),
                                            new ChoiceFormat("0#off|1#on"), null,
                                            IBM.ICU.Text.NumberFormat.GetCurrencyInstance(), null, null, null, null,
                                            IBM.ICU.Text.DateFormat.GetTimeInstance() };

            NUnit.Framework.Assert.AreEqual(correctFormats.Length, formats.Length, "Test2:Returned wrong number of formats:");
            for (int i_0 = 0; i_0 < correctFormats.Length; i_0++)
            {
                NUnit.Framework.Assert.AreEqual(correctFormats[i_0], formats[i_0], "Test2:wrong format for argument index " + i_0 + ":");
            }

            // test with argument number being zero
            formats = format3.GetFormatsByArgumentIndex();
            NUnit.Framework.Assert.AreEqual(0, formats.Length, "Test3: Returned wrong number of formats:");
        }
コード例 #2
0
        public void Test_setFormatsByArgumentIndex_Ljava_text_Format()
        {
            // test for method setFormatByArgumentIndex(Format[])
            IBM.ICU.Text.MessageFormat f1 = (IBM.ICU.Text.MessageFormat)format1.Clone();

            // test with repeating formats and max argument index < max offset
            // compare getFormatsByArgumentIndex() results after calls to
            // setFormatsByArgumentIndex(Format[])
            Format[] correctFormats = new Format[] { IBM.ICU.Text.DateFormat.GetTimeInstance(),
                                                     new ChoiceFormat("0#off|1#on"), IBM.ICU.Text.DateFormat.GetTimeInstance(),
                                                     IBM.ICU.Text.NumberFormat.GetCurrencyInstance(),
                                                     new ChoiceFormat("1#few|2#ok|3#a lot") };

            f1.SetFormatsByArgumentIndex(correctFormats);
            Format[] formats = f1.GetFormatsByArgumentIndex();

            NUnit.Framework.Assert.AreEqual(correctFormats.Length, formats.Length, "Test1A:Returned wrong number of formats:");
            for (int i = 0; i < correctFormats.Length; i++)
            {
                NUnit.Framework.Assert.AreEqual(correctFormats[i], formats[i], "Test1B:wrong format for argument index " + i + ":");
            }

            // compare getFormats() results after calls to
            // setFormatByArgumentIndex()
            formats        = f1.GetFormats();
            correctFormats = new Format[] { IBM.ICU.Text.NumberFormat.GetCurrencyInstance(),
                                                IBM.ICU.Text.DateFormat.GetTimeInstance(), IBM.ICU.Text.DateFormat.GetTimeInstance(),
                                            new ChoiceFormat("1#few|2#ok|3#a lot"),
                                            new ChoiceFormat("0#off|1#on"), IBM.ICU.Text.DateFormat.GetTimeInstance(), };

            NUnit.Framework.Assert.AreEqual(correctFormats.Length, formats.Length, "Test1C:Returned wrong number of formats:");
            for (int i_0 = 0; i_0 < correctFormats.Length; i_0++)
            {
                NUnit.Framework.Assert.AreEqual(correctFormats[i_0], formats[i_0], "Test1D:wrong format for pattern index " + i_0 + ":");
            }

            // test setting argumentIndexes that are not used
            IBM.ICU.Text.MessageFormat f2 = (IBM.ICU.Text.MessageFormat)format2.Clone();
            Format[] inputFormats         = new Format[] { IBM.ICU.Text.DateFormat.GetDateInstance(),
                                                           new ChoiceFormat("0#off|1#on"),
                                                           IBM.ICU.Text.NumberFormat.GetPercentInstance(),
                                                           IBM.ICU.Text.NumberFormat.GetCurrencyInstance(),
                                                           IBM.ICU.Text.DateFormat.GetTimeInstance(), null, null, null,
                                                           IBM.ICU.Text.DateFormat.GetTimeInstance() };
            f2.SetFormatsByArgumentIndex(inputFormats);

            formats        = f2.GetFormatsByArgumentIndex();
            correctFormats = format2.GetFormatsByArgumentIndex();

            NUnit.Framework.Assert.AreEqual(correctFormats.Length, formats.Length, "Test2A:Returned wrong number of formats:");
            for (int i_1 = 0; i_1 < correctFormats.Length; i_1++)
            {
                NUnit.Framework.Assert.AreEqual(correctFormats[i_1], formats[i_1], "Test2B:wrong format for argument index " + i_1 + ":");
            }

            formats        = f2.GetFormats();
            correctFormats = new Format[] { IBM.ICU.Text.NumberFormat.GetCurrencyInstance(),
                                                IBM.ICU.Text.DateFormat.GetTimeInstance(), IBM.ICU.Text.DateFormat.GetDateInstance(),
                                                null, new ChoiceFormat("0#off|1#on"),
                                            IBM.ICU.Text.DateFormat.GetDateInstance() };

            NUnit.Framework.Assert.AreEqual(correctFormats.Length, formats.Length, "Test2C:Returned wrong number of formats:");
            for (int i_2 = 0; i_2 < correctFormats.Length; i_2++)
            {
                NUnit.Framework.Assert.AreEqual(correctFormats[i_2], formats[i_2], "Test2D:wrong format for pattern index " + i_2 + ":");
            }

            // test exceeding the argumentIndex number
            IBM.ICU.Text.MessageFormat f3 = (IBM.ICU.Text.MessageFormat)format3.Clone();
            f3.SetFormatsByArgumentIndex(inputFormats);

            formats = f3.GetFormatsByArgumentIndex();
            NUnit.Framework.Assert.AreEqual(0, formats.Length, "Test3A:Returned wrong number of formats:");

            formats = f3.GetFormats();
            NUnit.Framework.Assert.AreEqual(0, formats.Length, "Test3B:Returned wrong number of formats:");
        }