//##header J2SE15 /* ********************************************************************** * Copyright (c) 2004-2009, International Business Machines * Corporation and others. All Rights Reserved. ********************************************************************** * Author: Alan Liu * Created: April 6, 2004 * Since: ICU 3.0 ********************************************************************** */ package com.ibm.icu.dev.test.format; import java.text.AttributedCharacterIterator; import java.text.AttributedString; import java.text.ChoiceFormat; import java.text.FieldPosition; import java.text.Format; import java.text.ParseException; import java.text.ParsePosition; import java.util.Date; import java.util.Iterator; import java.util.Locale; import java.util.HashMap; import java.util.Map; import java.util.Set; import com.ibm.icu.text.DateFormat; import com.ibm.icu.text.DecimalFormat; import com.ibm.icu.text.DecimalFormatSymbols; import com.ibm.icu.text.MessageFormat; import com.ibm.icu.text.NumberFormat; import com.ibm.icu.text.SimpleDateFormat; import com.ibm.icu.text.UFormat; import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.ULocale; public class TestMessageFormat extends com.ibm.icu.dev.test.TestFmwk { public static void main(String[] args) throws Exception { new TestMessageFormat().run(args); } public void TestBug3() { double myNumber = -123456; DecimalFormat form = null; Locale locale[] = { new Locale("ar", "", ""), new Locale("be", "", ""), new Locale("bg", "", ""), new Locale("ca", "", ""), new Locale("cs", "", ""), new Locale("da", "", ""), new Locale("de", "", ""), new Locale("de", "AT", ""), new Locale("de", "CH", ""), new Locale("el", "", ""), // 10 new Locale("en", "CA", ""), new Locale("en", "GB", ""), new Locale("en", "IE", ""), new Locale("en", "US", ""), new Locale("es", "", ""), new Locale("et", "", ""), new Locale("fi", "", ""), new Locale("fr", "", ""), new Locale("fr", "BE", ""), new Locale("fr", "CA", ""), // 20 new Locale("fr", "CH", ""), new Locale("he", "", ""), new Locale("hr", "", ""), new Locale("hu", "", ""), new Locale("is", "", ""), new Locale("it", "", ""), new Locale("it", "CH", ""), new Locale("ja", "", ""), new Locale("ko", "", ""), new Locale("lt", "", ""), // 30 new Locale("lv", "", ""), new Locale("mk", "", ""), new Locale("nl", "", ""), new Locale("nl", "BE", ""), new Locale("no", "", ""), new Locale("pl", "", ""), new Locale("pt", "", ""), new Locale("ro", "", ""), new Locale("ru", "", ""), new Locale("sh", "", ""), // 40 new Locale("sk", "", ""), new Locale("sl", "", ""), new Locale("sq", "", ""), new Locale("sr", "", ""), new Locale("sv", "", ""), new Locale("tr", "", ""), new Locale("uk", "", ""), new Locale("zh", "", ""), new Locale("zh", "TW", "") // 49 }; StringBuffer buffer = new StringBuffer(); ParsePosition parsePos = new ParsePosition(0); int i; for (i= 0; i < 49; i++) { // form = (DecimalFormat)NumberFormat.getCurrencyInstance(locale[i]); form = (DecimalFormat)NumberFormat.getInstance(locale[i]); if (form == null) { errln("Number format creation failed for " + locale[i].getDisplayName()); continue; } FieldPosition pos = new FieldPosition(0); buffer.setLength(0); form.format(myNumber, buffer, pos); parsePos.setIndex(0); Object result = form.parse(buffer.toString(), parsePos); logln(locale[i].getDisplayName() + " -> " + result); if (parsePos.getIndex() != buffer.length()) { errln("Number format parse failed."); } } } public void TestBug1() { final double limit[] = {0.0, 1.0, 2.0}; final String formats[] = {"0.0<=Arg<1.0", "1.0<=Arg<2.0", "2.0<-Arg"}; ChoiceFormat cf = new ChoiceFormat(limit, formats); assertEquals("ChoiceFormat.format", formats[1], cf.format(1)); } public void TestBug2() { // {sfb} use double format in pattern, so result will match (not strictly necessary) final String pattern = "There {0,choice,0.0#are no files|1.0#is one file|1.0 " + result); if (i != 3) { // TODO: fix this, for now skip ordinal parsing (format string at index 3) try { Object[] parsedArgs = fmt.parse(result); if (parsedArgs.length != 1) { errln("parse returned " + parsedArgs.length + " args"); } else if (!parsedArgs[0].equals(num)) { errln("parsed argument " + parsedArgs[0] + " != " + num); } } catch (Exception e) { errln("parse of '" + result + " returned exception: " + e.getMessage()); } } } } } public void TestSetGetFormats() { Object arguments[] = { new Double(456.83), new Date(871068000000L), "deposit" }; StringBuffer result = new StringBuffer(); String formatStr = "At