public void Test_setFormatByArgumentIndexILjava_text_Format() { // test for method setFormatByArgumentIndex(int, Format) IBM.ICU.Text.MessageFormat f1 = (IBM.ICU.Text.MessageFormat)format1.Clone(); f1.SetFormatByArgumentIndex(0, IBM.ICU.Text.DateFormat.GetTimeInstance()); f1.SetFormatByArgumentIndex(4, new ChoiceFormat("1#few|2#ok|3#a lot")); // test with repeating formats and max argument index < max offset // compare getFormatsByArgumentIndex() results after calls to // setFormatByArgumentIndex() Format[] formats = f1.GetFormatsByArgumentIndex(); 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") }; 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(); f2.SetFormatByArgumentIndex(2, IBM.ICU.Text.NumberFormat.GetPercentInstance()); f2.SetFormatByArgumentIndex(4, IBM.ICU.Text.DateFormat.GetTimeInstance()); 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 = format2.GetFormats(); 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.SetFormatByArgumentIndex(1, IBM.ICU.Text.NumberFormat.GetCurrencyInstance()); 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:"); }