Home | History | Annotate | Download | only in format
      1 /* GENERATED SOURCE. DO NOT MODIFY. */
      2 //  2016 and later: Unicode, Inc. and others.
      3 // License & terms of use: http://www.unicode.org/copyright.html#License
      4 /*
      5  *******************************************************************************
      6  * Copyright (C) 2001-2010, International Business Machines Corporation and    *
      7  * others. All Rights Reserved.                                                *
      8  *******************************************************************************
      9  */
     10 
     11 /**
     12  * Port From:   ICU4C v1.8.1 : format : IntlTestDecimalFormatSymbols
     13  * Source File: $ICU4CRoot/source/test/intltest/tsdcfmsy.cpp
     14  **/
     15 
     16 package android.icu.dev.test.format;
     17 
     18 import java.text.FieldPosition;
     19 import java.util.Locale;
     20 
     21 import org.junit.Test;
     22 
     23 import android.icu.text.DecimalFormat;
     24 import android.icu.text.DecimalFormatSymbols;
     25 
     26 /**
     27  * Tests for DecimalFormatSymbols
     28  **/
     29 public class IntlTestDecimalFormatSymbolsC extends android.icu.dev.test.TestFmwk {
     30     /**
     31      * Test the API of DecimalFormatSymbols; primarily a simple get/set set.
     32      */
     33     @Test
     34     public void TestSymbols() {
     35         DecimalFormatSymbols fr = new DecimalFormatSymbols(Locale.FRENCH);
     36         DecimalFormatSymbols en = new DecimalFormatSymbols(Locale.ENGLISH);
     37 
     38         if (en.equals(fr)) {
     39             errln("ERROR: English DecimalFormatSymbols equal to French");
     40         }
     41 
     42         // just do some VERY basic tests to make sure that get/set work
     43 
     44         char zero = en.getZeroDigit();
     45         fr.setZeroDigit(zero);
     46         if (fr.getZeroDigit() != en.getZeroDigit()) {
     47             errln("ERROR: get/set ZeroDigit failed");
     48         }
     49 
     50         char group = en.getGroupingSeparator();
     51         fr.setGroupingSeparator(group);
     52         if (fr.getGroupingSeparator() != en.getGroupingSeparator()) {
     53             errln("ERROR: get/set GroupingSeparator failed");
     54         }
     55 
     56         char decimal = en.getDecimalSeparator();
     57         fr.setDecimalSeparator(decimal);
     58         if (fr.getDecimalSeparator() != en.getDecimalSeparator()) {
     59             errln("ERROR: get/set DecimalSeparator failed");
     60         }
     61 
     62         char perMill = en.getPerMill();
     63         fr.setPerMill(perMill);
     64         if (fr.getPerMill() != en.getPerMill()) {
     65             errln("ERROR: get/set PerMill failed");
     66         }
     67 
     68         char percent = en.getPercent();
     69         fr.setPercent(percent);
     70         if (fr.getPercent() != en.getPercent()) {
     71             errln("ERROR: get/set Percent failed");
     72         }
     73 
     74         char digit = en.getDigit();
     75         fr.setDigit(digit);
     76         if (fr.getPercent() != en.getPercent()) {
     77             errln("ERROR: get/set Percent failed");
     78         }
     79 
     80         char patternSeparator = en.getPatternSeparator();
     81         fr.setPatternSeparator(patternSeparator);
     82         if (fr.getPatternSeparator() != en.getPatternSeparator()) {
     83             errln("ERROR: get/set PatternSeparator failed");
     84         }
     85 
     86         String infinity = en.getInfinity();
     87         fr.setInfinity(infinity);
     88         String infinity2 = fr.getInfinity();
     89         if (!infinity.equals(infinity2)) {
     90             errln("ERROR: get/set Infinity failed");
     91         }
     92 
     93         String nan = en.getNaN();
     94         fr.setNaN(nan);
     95         String nan2 = fr.getNaN();
     96         if (!nan.equals(nan2)) {
     97             errln("ERROR: get/set NaN failed");
     98         }
     99 
    100         char minusSign = en.getMinusSign();
    101         fr.setMinusSign(minusSign);
    102         if (fr.getMinusSign() != en.getMinusSign()) {
    103             errln("ERROR: get/set MinusSign failed");
    104         }
    105 
    106         //        char exponential = en.getExponentialSymbol();
    107         //        fr.setExponentialSymbol(exponential);
    108         //        if(fr.getExponentialSymbol() != en.getExponentialSymbol()) {
    109         //            errln("ERROR: get/set Exponential failed");
    110         //        }
    111 
    112         //DecimalFormatSymbols foo = new DecimalFormatSymbols(); //The variable is never used
    113 
    114         en = (DecimalFormatSymbols) fr.clone();
    115 
    116         if (!en.equals(fr)) {
    117             errln("ERROR: Clone failed");
    118         }
    119 
    120         DecimalFormatSymbols sym = new DecimalFormatSymbols(Locale.US);
    121 
    122         verify(34.5, "00.00", sym, "34.50");
    123         sym.setDecimalSeparator('S');
    124         verify(34.5, "00.00", sym, "34S50");
    125         sym.setPercent('P');
    126         verify(34.5, "00 %", sym, "3450 P");
    127         sym.setCurrencySymbol("D");
    128         verify(34.5, "\u00a4##.##", sym, "D34.5");
    129         sym.setGroupingSeparator('|');
    130         verify(3456.5, "0,000.##", sym, "3|456S5");
    131     }
    132 
    133     /** helper functions**/
    134     public void verify(double value, String pattern, DecimalFormatSymbols sym, String expected) {
    135         DecimalFormat df = new DecimalFormat(pattern, sym);
    136         StringBuffer buffer = new StringBuffer("");
    137         FieldPosition pos = new FieldPosition(-1);
    138         buffer = df.format(value, buffer, pos);
    139         if(!buffer.toString().equals(expected)){
    140             errln("ERROR: format failed after setSymbols()\n Expected" +
    141                 expected + ", Got " + buffer);
    142         }
    143     }
    144 }