2 *******************************************************************************
3 * Copyright (C) 2001-2010, International Business Machines Corporation and *
4 * others. All Rights Reserved. *
5 *******************************************************************************
9 * Port From: ICU4C v1.8.1 : format : IntlTestDecimalFormatSymbols
10 * Source File: $ICU4CRoot/source/test/intltest/tsdcfmsy.cpp
13 package com.ibm.icu.dev.test.format;
15 import java.text.FieldPosition;
16 import java.util.Locale;
18 import com.ibm.icu.text.DecimalFormat;
19 import com.ibm.icu.text.DecimalFormatSymbols;
22 * Tests for DecimalFormatSymbols
24 public class IntlTestDecimalFormatSymbolsC extends com.ibm.icu.dev.test.TestFmwk {
26 public static void main(String[] args) throws Exception {
27 new IntlTestDecimalFormatSymbolsC().run(args);
31 * Test the API of DecimalFormatSymbols; primarily a simple get/set set.
33 public void TestSymbols() {
34 DecimalFormatSymbols fr = new DecimalFormatSymbols(Locale.FRENCH);
35 DecimalFormatSymbols en = new DecimalFormatSymbols(Locale.ENGLISH);
38 errln("ERROR: English DecimalFormatSymbols equal to French");
41 // just do some VERY basic tests to make sure that get/set work
43 char zero = en.getZeroDigit();
44 fr.setZeroDigit(zero);
45 if (fr.getZeroDigit() != en.getZeroDigit()) {
46 errln("ERROR: get/set ZeroDigit failed");
49 char group = en.getGroupingSeparator();
50 fr.setGroupingSeparator(group);
51 if (fr.getGroupingSeparator() != en.getGroupingSeparator()) {
52 errln("ERROR: get/set GroupingSeparator failed");
55 char decimal = en.getDecimalSeparator();
56 fr.setDecimalSeparator(decimal);
57 if (fr.getDecimalSeparator() != en.getDecimalSeparator()) {
58 errln("ERROR: get/set DecimalSeparator failed");
61 char perMill = en.getPerMill();
62 fr.setPerMill(perMill);
63 if (fr.getPerMill() != en.getPerMill()) {
64 errln("ERROR: get/set PerMill failed");
67 char percent = en.getPercent();
68 fr.setPercent(percent);
69 if (fr.getPercent() != en.getPercent()) {
70 errln("ERROR: get/set Percent failed");
73 char digit = en.getDigit();
75 if (fr.getPercent() != en.getPercent()) {
76 errln("ERROR: get/set Percent failed");
79 char patternSeparator = en.getPatternSeparator();
80 fr.setPatternSeparator(patternSeparator);
81 if (fr.getPatternSeparator() != en.getPatternSeparator()) {
82 errln("ERROR: get/set PatternSeparator failed");
85 String infinity = en.getInfinity();
86 fr.setInfinity(infinity);
87 String infinity2 = fr.getInfinity();
88 if (!infinity.equals(infinity2)) {
89 errln("ERROR: get/set Infinity failed");
92 String nan = en.getNaN();
94 String nan2 = fr.getNaN();
95 if (!nan.equals(nan2)) {
96 errln("ERROR: get/set NaN failed");
99 char minusSign = en.getMinusSign();
100 fr.setMinusSign(minusSign);
101 if (fr.getMinusSign() != en.getMinusSign()) {
102 errln("ERROR: get/set MinusSign failed");
105 // char exponential = en.getExponentialSymbol();
106 // fr.setExponentialSymbol(exponential);
107 // if(fr.getExponentialSymbol() != en.getExponentialSymbol()) {
108 // errln("ERROR: get/set Exponential failed");
111 //DecimalFormatSymbols foo = new DecimalFormatSymbols(); //The variable is never used
113 en = (DecimalFormatSymbols) fr.clone();
115 if (!en.equals(fr)) {
116 errln("ERROR: Clone failed");
119 DecimalFormatSymbols sym = new DecimalFormatSymbols(Locale.US);
121 verify(34.5, "00.00", sym, "34.50");
122 sym.setDecimalSeparator('S');
123 verify(34.5, "00.00", sym, "34S50");
125 verify(34.5, "00 %", sym, "3450 P");
126 sym.setCurrencySymbol("D");
127 verify(34.5, "\u00a4##.##", sym, "D34.5");
128 sym.setGroupingSeparator('|');
129 verify(3456.5, "0,000.##", sym, "3|456S5");
132 /** helper functions**/
133 public void verify(double value, String pattern, DecimalFormatSymbols sym, String expected) {
134 DecimalFormat df = new DecimalFormat(pattern, sym);
135 StringBuffer buffer = new StringBuffer("");
136 FieldPosition pos = new FieldPosition(-1);
137 buffer = df.format(value, buffer, pos);
138 if(!buffer.toString().equals(expected)){
139 errln("ERROR: format failed after setSymbols()\n Expected" +
140 expected + ", Got " + buffer);