-//##header\r
-/*****************************************************************************************\r
- *\r
- * Copyright (C) 1996-2009, International Business Machines\r
- * Corporation and others. All Rights Reserved.\r
- **/\r
-/** \r
- * Port From: JDK 1.4b1 : java.text.Format.IntlTestNumberFormatAPI\r
- * Source File: java/text/format/IntlTestNumberFormatAPI.java\r
- **/\r
-\r
-/*\r
- @test 1.4 98/03/06\r
- @summary test International Number Format API\r
-*/\r
-\r
-package com.ibm.icu.dev.test.format;\r
-\r
-import com.ibm.icu.text.*;\r
-import com.ibm.icu.util.ULocale;\r
-\r
-import java.util.Locale;\r
-\r
-import java.math.BigInteger;\r
-import java.text.FieldPosition;\r
-import java.text.ParsePosition;\r
-import java.text.ParseException;\r
-\r
-public class IntlTestNumberFormatAPI extends com.ibm.icu.dev.test.TestFmwk\r
-{\r
- public static void main(String[] args) throws Exception {\r
- new IntlTestNumberFormatAPI().run(args);\r
- }\r
-\r
- // This test checks various generic API methods in DecimalFormat to achieve 100% API coverage.\r
- public void TestAPI()\r
- {\r
- logln("NumberFormat API test---"); logln("");\r
- Locale.setDefault(Locale.ENGLISH);\r
-\r
- // ======= Test constructors\r
-\r
- logln("Testing NumberFormat constructors");\r
-\r
- NumberFormat def = NumberFormat.getInstance();\r
-\r
- NumberFormat fr = NumberFormat.getInstance(Locale.FRENCH);\r
-\r
- NumberFormat cur = NumberFormat.getCurrencyInstance();\r
-\r
- NumberFormat cur_fr = NumberFormat.getCurrencyInstance(Locale.FRENCH);\r
-\r
- NumberFormat per = NumberFormat.getPercentInstance();\r
-\r
- NumberFormat per_fr = NumberFormat.getPercentInstance(Locale.FRENCH);\r
- \r
- NumberFormat integer = NumberFormat.getIntegerInstance();\r
- \r
- NumberFormat int_fr = NumberFormat.getIntegerInstance(Locale.FRENCH);\r
- \r
- //Fix "The variable is never used" compilation warnings\r
- logln("Currency : " + cur.format(1234.5));\r
- logln("Percent : " + per.format(1234.5));\r
- logln("Integer : " + integer.format(1234.5));\r
- logln("Int_fr : " + int_fr.format(1234.5));\r
- \r
- // ======= Test equality\r
-\r
- logln("Testing equality operator");\r
-\r
- if( per_fr.equals(cur_fr) ) {\r
- errln("ERROR: == failed");\r
- }\r
-\r
- // ======= Test various format() methods\r
-\r
- logln("Testing various format() methods");\r
-\r
-// final double d = -10456.0037; // this appears as -10456.003700000001 on NT\r
-// final double d = -1.04560037e-4; // this appears as -1.0456003700000002E-4 on NT\r
- final double d = -10456.00370000000000; // this works!\r
- final long l = 100000000;\r
-\r
- String res1 = new String();\r
- String res2 = new String();\r
- StringBuffer res3 = new StringBuffer();\r
- StringBuffer res4 = new StringBuffer();\r
- StringBuffer res5 = new StringBuffer();\r
- StringBuffer res6 = new StringBuffer();\r
- FieldPosition pos1 = new FieldPosition(0);\r
- FieldPosition pos2 = new FieldPosition(0);\r
- FieldPosition pos3 = new FieldPosition(0);\r
- FieldPosition pos4 = new FieldPosition(0);\r
-\r
- res1 = cur_fr.format(d);\r
- logln( "" + d + " formatted to " + res1);\r
-\r
- res2 = cur_fr.format(l);\r
- logln("" + l + " formatted to " + res2);\r
-\r
- res3 = cur_fr.format(d, res3, pos1);\r
- logln( "" + d + " formatted to " + res3);\r
-\r
- res4 = cur_fr.format(l, res4, pos2);\r
- logln("" + l + " formatted to " + res4);\r
-\r
- res5 = cur_fr.format(d, res5, pos3);\r
- logln("" + d + " formatted to " + res5);\r
-\r
- res6 = cur_fr.format(l, res6, pos4);\r
- logln("" + l + " formatted to " + res6);\r
-\r
-\r
- // ======= Test parse()\r
-\r
- logln("Testing parse()");\r
-\r
-// String text = new String("-10,456.0037");\r
- String text = new String("-10456,0037");\r
- ParsePosition pos = new ParsePosition(0);\r
- ParsePosition pos01 = new ParsePosition(0);\r
- double d1 = ((Number)fr.parseObject(text, pos)).doubleValue();\r
- if(d1 != d) {\r
- errln("ERROR: Roundtrip failed (via parse()) for " + text);\r
- }\r
- logln(text + " parsed into " + d1);\r
-\r
- double d2 = fr.parse(text, pos01).doubleValue();\r
- if(d2 != d) {\r
- errln("ERROR: Roundtrip failed (via parse()) for " + text);\r
- }\r
- logln(text + " parsed into " + d2);\r
-\r
- double d3 = 0;\r
- try {\r
- d3 = fr.parse(text).doubleValue();\r
- }\r
- catch (ParseException e) {\r
- errln("ERROR: parse() failed");\r
- }\r
- if(d3 != d) {\r
- errln("ERROR: Roundtrip failed (via parse()) for " + text);\r
- }\r
- logln(text + " parsed into " + d3);\r
-\r
-\r
- // ======= Test getters and setters\r
-\r
- logln("Testing getters and setters");\r
-\r
- final Locale[] locales = NumberFormat.getAvailableLocales();\r
- long count = locales.length;\r
- logln("Got " + count + " locales" );\r
- for(int i = 0; i < count; i++) {\r
- String name;\r
- name = locales[i].getDisplayName();\r
- logln(name);\r
- }\r
-\r
- fr.setParseIntegerOnly( def.isParseIntegerOnly() );\r
- if(fr.isParseIntegerOnly() != def.isParseIntegerOnly() ) {\r
- errln("ERROR: setParseIntegerOnly() failed");\r
- }\r
-\r
- fr.setGroupingUsed( def.isGroupingUsed() );\r
- if(fr.isGroupingUsed() != def.isGroupingUsed() ) {\r
- errln("ERROR: setGroupingUsed() failed");\r
- }\r
-\r
- fr.setMaximumIntegerDigits( def.getMaximumIntegerDigits() );\r
- if(fr.getMaximumIntegerDigits() != def.getMaximumIntegerDigits() ) {\r
- errln("ERROR: setMaximumIntegerDigits() failed");\r
- }\r
-\r
- fr.setMinimumIntegerDigits( def.getMinimumIntegerDigits() );\r
- if(fr.getMinimumIntegerDigits() != def.getMinimumIntegerDigits() ) {\r
- errln("ERROR: setMinimumIntegerDigits() failed");\r
- }\r
-\r
- fr.setMaximumFractionDigits( def.getMaximumFractionDigits() );\r
- if(fr.getMaximumFractionDigits() != def.getMaximumFractionDigits() ) {\r
- errln("ERROR: setMaximumFractionDigits() failed");\r
- }\r
-\r
- fr.setMinimumFractionDigits( def.getMinimumFractionDigits() );\r
- if(fr.getMinimumFractionDigits() != def.getMinimumFractionDigits() ) {\r
- errln("ERROR: setMinimumFractionDigits() failed");\r
- }\r
-\r
- // ======= Test getStaticClassID()\r
-\r
-// logln("Testing instanceof()");\r
-\r
-// try {\r
-// NumberFormat test = new DecimalFormat();\r
-\r
-// if (! (test instanceof DecimalFormat)) {\r
-// errln("ERROR: instanceof failed");\r
-// }\r
-// }\r
-// catch (Exception e) {\r
-// errln("ERROR: Couldn't create a DecimalFormat");\r
-// }\r
- }\r
- \r
- // Jitterbug 4451, for coverage\r
- public void TestCoverage(){\r
- class StubNumberFormat extends NumberFormat{\r
- /**\r
- * For serialization\r
- */\r
- private static final long serialVersionUID = 3768385020503005993L;\r
- public void run(){\r
- String p = NumberFormat.getPattern(ULocale.getDefault().toLocale(),0);\r
- if (!p.equals(NumberFormat.getPattern(ULocale.getDefault(),0))){\r
- errln("NumberFormat.getPattern(Locale, int) should delegate to (ULocale,)");\r
- }\r
- }\r
- public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {return null;}\r
- public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {return null;}\r
- public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) {return null;}\r
-//#if defined(FOUNDATION10)\r
-//#else\r
- public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) {return null;}\r
-//#endif\r
- public StringBuffer format(com.ibm.icu.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) {return null;}\r
- public Number parse(String text, ParsePosition parsePosition) {return null;}\r
- }\r
- new StubNumberFormat().run();\r
- }\r
-}\r
+//##header J2SE15
+/*****************************************************************************************
+ *
+ * Copyright (C) 1996-2009, International Business Machines
+ * Corporation and others. All Rights Reserved.
+ **/
+/**
+ * Port From: JDK 1.4b1 : java.text.Format.IntlTestNumberFormatAPI
+ * Source File: java/text/format/IntlTestNumberFormatAPI.java
+ **/
+
+/*
+ @test 1.4 98/03/06
+ @summary test International Number Format API
+*/
+
+package com.ibm.icu.dev.test.format;
+
+import com.ibm.icu.text.*;
+import com.ibm.icu.util.ULocale;
+
+import java.util.Locale;
+
+import java.math.BigInteger;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+import java.text.ParseException;
+
+public class IntlTestNumberFormatAPI extends com.ibm.icu.dev.test.TestFmwk
+{
+ public static void main(String[] args) throws Exception {
+ new IntlTestNumberFormatAPI().run(args);
+ }
+
+ // This test checks various generic API methods in DecimalFormat to achieve 100% API coverage.
+ public void TestAPI()
+ {
+ logln("NumberFormat API test---"); logln("");
+ Locale.setDefault(Locale.ENGLISH);
+
+ // ======= Test constructors
+
+ logln("Testing NumberFormat constructors");
+
+ NumberFormat def = NumberFormat.getInstance();
+
+ NumberFormat fr = NumberFormat.getInstance(Locale.FRENCH);
+
+ NumberFormat cur = NumberFormat.getCurrencyInstance();
+
+ NumberFormat cur_fr = NumberFormat.getCurrencyInstance(Locale.FRENCH);
+
+ NumberFormat per = NumberFormat.getPercentInstance();
+
+ NumberFormat per_fr = NumberFormat.getPercentInstance(Locale.FRENCH);
+
+ NumberFormat integer = NumberFormat.getIntegerInstance();
+
+ NumberFormat int_fr = NumberFormat.getIntegerInstance(Locale.FRENCH);
+
+ //Fix "The variable is never used" compilation warnings
+ logln("Currency : " + cur.format(1234.5));
+ logln("Percent : " + per.format(1234.5));
+ logln("Integer : " + integer.format(1234.5));
+ logln("Int_fr : " + int_fr.format(1234.5));
+
+ // ======= Test equality
+
+ logln("Testing equality operator");
+
+ if( per_fr.equals(cur_fr) ) {
+ errln("ERROR: == failed");
+ }
+
+ // ======= Test various format() methods
+
+ logln("Testing various format() methods");
+
+// final double d = -10456.0037; // this appears as -10456.003700000001 on NT
+// final double d = -1.04560037e-4; // this appears as -1.0456003700000002E-4 on NT
+ final double d = -10456.00370000000000; // this works!
+ final long l = 100000000;
+
+ String res1 = new String();
+ String res2 = new String();
+ StringBuffer res3 = new StringBuffer();
+ StringBuffer res4 = new StringBuffer();
+ StringBuffer res5 = new StringBuffer();
+ StringBuffer res6 = new StringBuffer();
+ FieldPosition pos1 = new FieldPosition(0);
+ FieldPosition pos2 = new FieldPosition(0);
+ FieldPosition pos3 = new FieldPosition(0);
+ FieldPosition pos4 = new FieldPosition(0);
+
+ res1 = cur_fr.format(d);
+ logln( "" + d + " formatted to " + res1);
+
+ res2 = cur_fr.format(l);
+ logln("" + l + " formatted to " + res2);
+
+ res3 = cur_fr.format(d, res3, pos1);
+ logln( "" + d + " formatted to " + res3);
+
+ res4 = cur_fr.format(l, res4, pos2);
+ logln("" + l + " formatted to " + res4);
+
+ res5 = cur_fr.format(d, res5, pos3);
+ logln("" + d + " formatted to " + res5);
+
+ res6 = cur_fr.format(l, res6, pos4);
+ logln("" + l + " formatted to " + res6);
+
+
+ // ======= Test parse()
+
+ logln("Testing parse()");
+
+// String text = new String("-10,456.0037");
+ String text = new String("-10456,0037");
+ ParsePosition pos = new ParsePosition(0);
+ ParsePosition pos01 = new ParsePosition(0);
+ double d1 = ((Number)fr.parseObject(text, pos)).doubleValue();
+ if(d1 != d) {
+ errln("ERROR: Roundtrip failed (via parse()) for " + text);
+ }
+ logln(text + " parsed into " + d1);
+
+ double d2 = fr.parse(text, pos01).doubleValue();
+ if(d2 != d) {
+ errln("ERROR: Roundtrip failed (via parse()) for " + text);
+ }
+ logln(text + " parsed into " + d2);
+
+ double d3 = 0;
+ try {
+ d3 = fr.parse(text).doubleValue();
+ }
+ catch (ParseException e) {
+ errln("ERROR: parse() failed");
+ }
+ if(d3 != d) {
+ errln("ERROR: Roundtrip failed (via parse()) for " + text);
+ }
+ logln(text + " parsed into " + d3);
+
+
+ // ======= Test getters and setters
+
+ logln("Testing getters and setters");
+
+ final Locale[] locales = NumberFormat.getAvailableLocales();
+ long count = locales.length;
+ logln("Got " + count + " locales" );
+ for(int i = 0; i < count; i++) {
+ String name;
+ name = locales[i].getDisplayName();
+ logln(name);
+ }
+
+ fr.setParseIntegerOnly( def.isParseIntegerOnly() );
+ if(fr.isParseIntegerOnly() != def.isParseIntegerOnly() ) {
+ errln("ERROR: setParseIntegerOnly() failed");
+ }
+
+ fr.setGroupingUsed( def.isGroupingUsed() );
+ if(fr.isGroupingUsed() != def.isGroupingUsed() ) {
+ errln("ERROR: setGroupingUsed() failed");
+ }
+
+ fr.setMaximumIntegerDigits( def.getMaximumIntegerDigits() );
+ if(fr.getMaximumIntegerDigits() != def.getMaximumIntegerDigits() ) {
+ errln("ERROR: setMaximumIntegerDigits() failed");
+ }
+
+ fr.setMinimumIntegerDigits( def.getMinimumIntegerDigits() );
+ if(fr.getMinimumIntegerDigits() != def.getMinimumIntegerDigits() ) {
+ errln("ERROR: setMinimumIntegerDigits() failed");
+ }
+
+ fr.setMaximumFractionDigits( def.getMaximumFractionDigits() );
+ if(fr.getMaximumFractionDigits() != def.getMaximumFractionDigits() ) {
+ errln("ERROR: setMaximumFractionDigits() failed");
+ }
+
+ fr.setMinimumFractionDigits( def.getMinimumFractionDigits() );
+ if(fr.getMinimumFractionDigits() != def.getMinimumFractionDigits() ) {
+ errln("ERROR: setMinimumFractionDigits() failed");
+ }
+
+ // ======= Test getStaticClassID()
+
+// logln("Testing instanceof()");
+
+// try {
+// NumberFormat test = new DecimalFormat();
+
+// if (! (test instanceof DecimalFormat)) {
+// errln("ERROR: instanceof failed");
+// }
+// }
+// catch (Exception e) {
+// errln("ERROR: Couldn't create a DecimalFormat");
+// }
+ }
+
+ // Jitterbug 4451, for coverage
+ public void TestCoverage(){
+ class StubNumberFormat extends NumberFormat{
+ /**
+ * For serialization
+ */
+ private static final long serialVersionUID = 3768385020503005993L;
+ public void run(){
+ String p = NumberFormat.getPattern(ULocale.getDefault().toLocale(),0);
+ if (!p.equals(NumberFormat.getPattern(ULocale.getDefault(),0))){
+ errln("NumberFormat.getPattern(Locale, int) should delegate to (ULocale,)");
+ }
+ }
+ public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
+ public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
+ public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
+//#if defined(FOUNDATION10)
+//#else
+ public StringBuffer format(java.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
+//#endif
+ public StringBuffer format(com.ibm.icu.math.BigDecimal number, StringBuffer toAppendTo, FieldPosition pos) {return null;}
+ public Number parse(String text, ParsePosition parsePosition) {return null;}
+ }
+ new StubNumberFormat().run();
+ }
+}