]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_8_1_1/main/tests/core/src/com/ibm/icu/dev/test/format/IntlTestDecimalFormatSymbolsC.java
Added flags.
[Dictionary.git] / jars / icu4j-4_8_1_1 / main / tests / core / src / com / ibm / icu / dev / test / format / IntlTestDecimalFormatSymbolsC.java
1 /*
2  *******************************************************************************
3  * Copyright (C) 2001-2010, International Business Machines Corporation and    *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7
8 /** 
9  * Port From:   ICU4C v1.8.1 : format : IntlTestDecimalFormatSymbols
10  * Source File: $ICU4CRoot/source/test/intltest/tsdcfmsy.cpp
11  **/
12
13 package com.ibm.icu.dev.test.format;
14
15 import java.text.FieldPosition;
16 import java.util.Locale;
17
18 import com.ibm.icu.text.DecimalFormat;
19 import com.ibm.icu.text.DecimalFormatSymbols;
20
21 /**
22  * Tests for DecimalFormatSymbols
23  **/
24 public class IntlTestDecimalFormatSymbolsC extends com.ibm.icu.dev.test.TestFmwk {
25     
26     public static void main(String[] args) throws Exception {
27         new IntlTestDecimalFormatSymbolsC().run(args);
28     }
29
30     /**
31      * Test the API of DecimalFormatSymbols; primarily a simple get/set set.
32      */
33     public void TestSymbols() {    
34         DecimalFormatSymbols fr = new DecimalFormatSymbols(Locale.FRENCH);    
35         DecimalFormatSymbols en = new DecimalFormatSymbols(Locale.ENGLISH);
36     
37         if (en.equals(fr)) {
38             errln("ERROR: English DecimalFormatSymbols equal to French");
39         }
40     
41         // just do some VERY basic tests to make sure that get/set work
42     
43         char zero = en.getZeroDigit();
44         fr.setZeroDigit(zero);
45         if (fr.getZeroDigit() != en.getZeroDigit()) {
46             errln("ERROR: get/set ZeroDigit failed");
47         }
48     
49         char group = en.getGroupingSeparator();
50         fr.setGroupingSeparator(group);
51         if (fr.getGroupingSeparator() != en.getGroupingSeparator()) {
52             errln("ERROR: get/set GroupingSeparator failed");
53         }
54     
55         char decimal = en.getDecimalSeparator();
56         fr.setDecimalSeparator(decimal);
57         if (fr.getDecimalSeparator() != en.getDecimalSeparator()) {
58             errln("ERROR: get/set DecimalSeparator failed");
59         }
60     
61         char perMill = en.getPerMill();
62         fr.setPerMill(perMill);
63         if (fr.getPerMill() != en.getPerMill()) {
64             errln("ERROR: get/set PerMill failed");
65         }
66     
67         char percent = en.getPercent();
68         fr.setPercent(percent);
69         if (fr.getPercent() != en.getPercent()) {
70             errln("ERROR: get/set Percent failed");
71         }
72     
73         char digit = en.getDigit();
74         fr.setDigit(digit);
75         if (fr.getPercent() != en.getPercent()) {
76             errln("ERROR: get/set Percent failed");
77         }
78     
79         char patternSeparator = en.getPatternSeparator();
80         fr.setPatternSeparator(patternSeparator);
81         if (fr.getPatternSeparator() != en.getPatternSeparator()) {
82             errln("ERROR: get/set PatternSeparator failed");
83         }
84     
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");
90         }
91     
92         String nan = en.getNaN();
93         fr.setNaN(nan);
94         String nan2 = fr.getNaN();
95         if (!nan.equals(nan2)) {
96             errln("ERROR: get/set NaN failed");
97         }
98     
99         char minusSign = en.getMinusSign();
100         fr.setMinusSign(minusSign);
101         if (fr.getMinusSign() != en.getMinusSign()) {
102             errln("ERROR: get/set MinusSign failed");
103         }
104     
105         //        char exponential = en.getExponentialSymbol();
106         //        fr.setExponentialSymbol(exponential);
107         //        if(fr.getExponentialSymbol() != en.getExponentialSymbol()) {
108         //            errln("ERROR: get/set Exponential failed");
109         //        }
110     
111         //DecimalFormatSymbols foo = new DecimalFormatSymbols(); //The variable is never used
112     
113         en = (DecimalFormatSymbols) fr.clone();
114     
115         if (!en.equals(fr)) {
116             errln("ERROR: Clone failed");
117         }
118         
119         DecimalFormatSymbols sym = new DecimalFormatSymbols(Locale.US);
120     
121         verify(34.5, "00.00", sym, "34.50");
122         sym.setDecimalSeparator('S');
123         verify(34.5, "00.00", sym, "34S50");
124         sym.setPercent('P');
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");
130     }
131     
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);
141         }
142     }
143 }