001: /*
002: *******************************************************************************
003: * Copyright (C) 2001-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007:
008: /**
009: * Port From: ICU4C v1.8.1 : format : IntlTestDecimalFormatSymbols
010: * Source File: $ICU4CRoot/source/test/intltest/tsdcfmsy.cpp
011: **/package com.ibm.icu.dev.test.format;
012:
013: import java.text.FieldPosition;
014: import java.util.Locale;
015: import com.ibm.icu.text.*;
016:
017: /**
018: * Tests for DecimalFormatSymbols
019: **/
020: public class IntlTestDecimalFormatSymbolsC extends
021: com.ibm.icu.dev.test.TestFmwk {
022:
023: public static void main(String[] args) throws Exception {
024: new IntlTestDecimalFormatSymbolsC().run(args);
025: }
026:
027: /**
028: * Test the API of DecimalFormatSymbols; primarily a simple get/set set.
029: */
030: public void TestSymbols() {
031: DecimalFormatSymbols fr = new DecimalFormatSymbols(
032: Locale.FRENCH);
033: DecimalFormatSymbols en = new DecimalFormatSymbols(
034: Locale.ENGLISH);
035:
036: if (en.equals(fr)) {
037: errln("ERROR: English DecimalFormatSymbols equal to French");
038: }
039:
040: // just do some VERY basic tests to make sure that get/set work
041:
042: char zero = en.getZeroDigit();
043: fr.setZeroDigit(zero);
044: if (fr.getZeroDigit() != en.getZeroDigit()) {
045: errln("ERROR: get/set ZeroDigit failed");
046: }
047:
048: char group = en.getGroupingSeparator();
049: fr.setGroupingSeparator(group);
050: if (fr.getGroupingSeparator() != en.getGroupingSeparator()) {
051: errln("ERROR: get/set GroupingSeparator failed");
052: }
053:
054: char decimal = en.getDecimalSeparator();
055: fr.setDecimalSeparator(decimal);
056: if (fr.getDecimalSeparator() != en.getDecimalSeparator()) {
057: errln("ERROR: get/set DecimalSeparator failed");
058: }
059:
060: char perMill = en.getPerMill();
061: fr.setPerMill(perMill);
062: if (fr.getPerMill() != en.getPerMill()) {
063: errln("ERROR: get/set PerMill failed");
064: }
065:
066: char percent = en.getPercent();
067: fr.setPercent(percent);
068: if (fr.getPercent() != en.getPercent()) {
069: errln("ERROR: get/set Percent failed");
070: }
071:
072: char digit = en.getDigit();
073: fr.setDigit(digit);
074: if (fr.getPercent() != en.getPercent()) {
075: errln("ERROR: get/set Percent failed");
076: }
077:
078: char patternSeparator = en.getPatternSeparator();
079: fr.setPatternSeparator(patternSeparator);
080: if (fr.getPatternSeparator() != en.getPatternSeparator()) {
081: errln("ERROR: get/set PatternSeparator failed");
082: }
083:
084: String infinity = en.getInfinity();
085: fr.setInfinity(infinity);
086: String infinity2 = fr.getInfinity();
087: if (!infinity.equals(infinity2)) {
088: errln("ERROR: get/set Infinity failed");
089: }
090:
091: String nan = en.getNaN();
092: fr.setNaN(nan);
093: String nan2 = fr.getNaN();
094: if (!nan.equals(nan2)) {
095: errln("ERROR: get/set NaN failed");
096: }
097:
098: char minusSign = en.getMinusSign();
099: fr.setMinusSign(minusSign);
100: if (fr.getMinusSign() != en.getMinusSign()) {
101: errln("ERROR: get/set MinusSign failed");
102: }
103:
104: // char exponential = en.getExponentialSymbol();
105: // fr.setExponentialSymbol(exponential);
106: // if(fr.getExponentialSymbol() != en.getExponentialSymbol()) {
107: // errln("ERROR: get/set Exponential failed");
108: // }
109:
110: //DecimalFormatSymbols foo = new DecimalFormatSymbols(); //The variable is never used
111:
112: en = (DecimalFormatSymbols) fr.clone();
113:
114: if (!en.equals(fr)) {
115: errln("ERROR: Clone failed");
116: }
117:
118: DecimalFormatSymbols sym = new DecimalFormatSymbols(Locale.US);
119:
120: verify(34.5, "00.00", sym, "34.50");
121: sym.setDecimalSeparator('S');
122: verify(34.5, "00.00", sym, "34S50");
123: sym.setPercent('P');
124: verify(34.5, "00 %", sym, "3450 P");
125: sym.setCurrencySymbol("D");
126: verify(34.5, "\u00a4##.##", sym, "D34.5");
127: sym.setGroupingSeparator('|');
128: verify(3456.5, "0,000.##", sym, "3|456S5");
129: }
130:
131: /** helper functions**/
132: public void verify(double value, String pattern,
133: 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: }
|