Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/text/Format/DecimalFormat/RoundingAndPropertyTest.java
46973 views
/*1* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 705052825* @summary Test java.text.DecimalFormat fast-path for format(double...)26* @author Olivier Lagneau27* @run main RoundingAndPropertyTest28*29*/3031/* -----------------------------------------------------------------------------32* Note :33* Since fast-path algorithm does not modify any feature of DecimalFormat,34* some tests or values in this program may have to be adapted/added/removed35* when any change has been done in the fast-path source code, because the36* conditions for exercising fast-path may change.37*38* This is specially true if the set of constraints to fall in the fast-path39* case is relaxed in any manner.40*41* Usage :42* - Run main without any argument to test against a set of golden values and43* associated results hard-coded in the source code. That will do the tests44* described below45* See below comment section named "Description".46*47* or48*49* - Run main with string argument "-gengold" to output source code of50* GoldenFormattedValues.java class file with the jdk version used while51* generating the code.52* See below comment section named : "Modifying Golden Values".53*54* In case of error while running the test, a Runtime exception is generated55* providing the numbers of errors detected (format of golden values checks and56* property changes checks), and the program exit.57*58* Description :59*60* This test first checks that localization of digits is done correctly when61* calling DecimalFormat.format() on the array of values DecimalLocalizationValues62* found in GoldenDoubleValues, using the locale FullLocalizationTestLocale63* (from GoldenDoubleValues) that implies localization of digits. it checks the64* the results against expected returned string. In case of formatting error,65* it provides a message informing which value was wrongly formatted.66*67* Then it checks the results of calling NumberFormat.format(double) on a set68* of predefined golden values and checks results against expected returned69* string. It does this both for the decimal case, with an instance returned70* NumberFormat.getInstance() call and for the currency case, with an instance71* returned by NumberFormat.getCurrencyInstance(). Almost all the tested double72* values satisfy the constraints assumed by the fast-path algorithm for73* format(double ...). Some are voluntarily outside the scope of fast-path to74* check that the algorithm correctly eliminate them. In case of formatting75* error a message provides information on the golden value raising the error76* (value, exact decimal value (using BidDecimal), expected result, formatted result).77*78* Last the test checks the status and behavior of a DecimalFormat instance79* when changing properties that make this instance satisfy/invalidate its80* fast-path status, depending on the predefined set of fast-path constraints.81*82* The golden results are predefined arrays of int[] containing the unicode83* ints of the chars in the expected formatted string, when using locale84* provided in GoldenDoubleValues class. The results are those obtained by85* using a reference jdk version (for example one that does not contains the86* DecimalFormat fast-path algorithm, like jdk80-b25).87*88* The double values from which we get golden results are stored inside two89* arrays of double values:90* - DecimalGoldenValues for testing NumberFormat.getInstance().91* - CurrencyGoldenValues for testing NumberFormat.getCurrencyInstance().92* These arrays are located in GoldenDoubleValues.java source file.93*94* For each double value in the arrays above, there is an associated golden95* result. These results are stored in arrays of int[]:96* - DecimalGoldenFormattedValues for expected decimal golden results.97* - CurrencyGoldenFormattedValues for expected currency golden results.98* - DecimalDigitsLocalizedFormattedValues for expected localized digit results.99*100* We store the results in int[] arrays containing the expected unicode values101* because the compiler that will compile the containing java file may use a102* different locale than the one registered in GoldenDoubleValues.java. These103* arrays are located in a separate GoldenFormattedValues.java source file104* that is generated by RoundingAndPropertyTest using "-gengold" parameter.105* See below "Modifying Golden Values".106*107* The golden value arrays can be expanded, modified ... to test additional108* or different double values. In that case, the source file of class109* GoldenFormattedValues must be regenerated to replace the existing one..110*111* Modifying Golden Values :112*113* In order to ease further modification of the list of double values checked114* and associated golden results, the test includes the method115* generatesGoldenFormattedValuesClass() that writes on standard output stream116* the source code for GoldenFormattedValues class that includes the expected117* results arrays.118*119* Here are the steps to follow for updating/modifying golden values and results:120* 1- Edit GoldenDoubleValues.java to add/remove/modify golden or localization121* values.122* 2- Run main with "-gengold" string argument with a target jdk.123* (at the creation of this test file, the target jdk used was jdk1.8.0-ea).124* 2- Copy this java code that has been writen on standard output and replace125* GoldenFormattedValues.java contents by the generated output.126* 3- Check that this updated code compiles.127* [4]- If needed replaces existing GoldenDoubleValues and GoldenFormattedValues128* files in jdk/test section, respectively by the one modified at step 1 and129* generated at step 2.130* -----------------------------------------------------------------------------131*/132133import java.util.*;134import java.text.NumberFormat;135import java.text.DecimalFormat;136import java.text.DecimalFormatSymbols;137import java.math.RoundingMode;138import java.math.BigDecimal;139140141public class RoundingAndPropertyTest {142143144// Prints on standard output stream the unicode values of chars as a145// comma-separated list of int values146private static void printUnicodeValuesArray(char[] chars) {147for (int i = 0; i < chars.length; i++) {148System.out.print((int) chars[i]);149if (i != (chars.length - 1))150System.out.print(", ");151}152}153154// Converts given array of unicode values as an array of chars.155// Returns this converted array.156private static char[] getCharsFromUnicodeArray(int[] unicodeValues) {157char[] chars = new char[unicodeValues.length];158159for (int i = 0; i < unicodeValues.length; i++) {160chars[i] = (char) unicodeValues[i];161}162return chars;163}164165/* Prints on standard output stream the java code of resulting166* GoldenFormattedValues class for the golden values found in167* class GoldenDoubleValues.168*/169private static void generatesGoldenFormattedValuesClass() {170171String fourWhiteSpaces = " ";172String eightWhiteSpaces = " ";173174// Prints header without Copyright header.175System.out.println("/* This is a machine generated file - Please DO NOT EDIT !");176System.out.println(" * Change RoundingAndPropertyTest instead,");177System.out.println(" * and run with \"-gengold\" argument to regenerate (without copyright header).");178System.out.println(" */");179System.out.println();180181System.out.println("/* This file contains the set of result Strings expected from calling inside");182System.out.println(" * RoundingAndPropertyTest the method NumberFormat.format() upon the set of");183System.out.println(" * double values provided in GoldenDoubleValues.java. It contains three arrays,");184System.out.println(" * each containing arrays of unicode values representing the expected string");185System.out.println(" * result when calling format() on the corresponding (i.e. same index) double");186System.out.println(" * value found in GoldenDoubleValues arrays :");187System.out.println(" * - DecimalDigitsLocalizedFormattedValues corresponds to DecimalLocalizationValues,");188System.out.println(" * when using FullLocalizationTestLocale to format.");189System.out.println(" * - DecimalGoldenFormattedValues corresponds to DecimalGoldenValues, when used");190System.out.println(" * in the decimal pattern case together with TestLocale.");191System.out.println(" * - CurrencyGoldenFormattedValues corresponds to CurrencyGoldenValues. when used");192System.out.println(" * in the currency pattern case together with TestLocale.");193System.out.println(" * Please see documentation in RoundingAndPropertyTest.java for more details.");194System.out.println(" *");195System.out.println(" * This file generated by running RoundingAndPropertyTest with \"-gengold\" argument.");196System.out.println(" */");197System.out.println();198199// Prints beginning of class GoldenFormattedValues.200System.out.println("class GoldenFormattedValues {");201System.out.println();202System.out.println(203fourWhiteSpaces +204"// The formatted values below were generated from golden values");205System.out.print(206fourWhiteSpaces +207"// listed in GoldenDoubleValues.java,");208System.out.println(" using the following jvm version :");209System.out.println(210fourWhiteSpaces + "// " +211System.getProperty("java.vendor") +212" " +213System.getProperty("java.vm.name") +214" " +215System.getProperty("java.version"));216System.out.println(217fourWhiteSpaces +218"// locale for golden double values : " + GoldenDoubleValues.TestLocale);219System.out.println(220fourWhiteSpaces +221"// locale for testing digit localization : " + GoldenDoubleValues.FullLocalizationTestLocale);222System.out.println();223224// Prints the expected results when digit localization happens225System.out.println(226fourWhiteSpaces +227"// The array of int[] unicode values storing the expected results");228System.out.print(229fourWhiteSpaces +230"// when experiencing full localization of digits");231System.out.println(" on DecimalLocalizationValues.");232System.out.println(233fourWhiteSpaces +234"static int[][] DecimalDigitsLocalizedFormattedValues = {");235NumberFormat df =236NumberFormat.getInstance(GoldenDoubleValues.FullLocalizationTestLocale);237for (int i = 0;238i < GoldenDoubleValues.DecimalLocalizationValues.length;239i++) {240double d = GoldenDoubleValues.DecimalLocalizationValues[i];241String formatted = df.format(d);242char[] decFmtChars = formatted.toCharArray();243244System.out.print(eightWhiteSpaces + "{ ");245printUnicodeValuesArray(decFmtChars);246System.out.println(" },");247}248System.out.println(fourWhiteSpaces + "};");249System.out.println();250251// Prints the golden expected results for the decimal pattern case252System.out.println(253fourWhiteSpaces +254"// The array of int[] unicode values storing the expected results");255System.out.print(256fourWhiteSpaces +257"// when calling Decimal.format(double)");258System.out.println(" on the decimal GoldenDoubleValues.");259System.out.println(260fourWhiteSpaces +261"static int[][] DecimalGoldenFormattedValues = {");262df = NumberFormat.getInstance(GoldenDoubleValues.TestLocale);263for (int i = 0;264i < GoldenDoubleValues.DecimalGoldenValues.length;265i++) {266double d = GoldenDoubleValues.DecimalGoldenValues[i];267String formatted = df.format(d);268char[] decFmtChars = formatted.toCharArray();269270System.out.print(eightWhiteSpaces + "{ ");271printUnicodeValuesArray(decFmtChars);272System.out.println(" },");273}274System.out.println(fourWhiteSpaces + "};");275System.out.println();276277// Prints the golden expected results for the currency pattern case278System.out.println(279fourWhiteSpaces +280"// The array of int[] unicode values storing the expected results");281System.out.print(282fourWhiteSpaces +283"// when calling Decimal.format(double)");284System.out.println(" on the currency GoldenDoubleValues.");285System.out.println(286fourWhiteSpaces +287"static int[][] CurrencyGoldenFormattedValues = {");288NumberFormat cf =289NumberFormat.getCurrencyInstance(GoldenDoubleValues.TestLocale);290for (int i = 0;291i < GoldenDoubleValues.CurrencyGoldenValues.length;292i++) {293double d = GoldenDoubleValues.CurrencyGoldenValues[i];294String formatted = cf.format(d);295char[] decFmtChars = formatted.toCharArray();296297System.out.print(eightWhiteSpaces + "{ ");298printUnicodeValuesArray(decFmtChars);299System.out.println(" },");300}301System.out.println(fourWhiteSpaces + "};");302System.out.println();303304// Prints end of GoldenFormattedValues class.305System.out.println("}");306}307308private static int testLocalizationValues() {309310DecimalFormat df = (DecimalFormat)311NumberFormat.getInstance(GoldenDoubleValues.FullLocalizationTestLocale);312313double[] localizationValues = GoldenDoubleValues.DecimalLocalizationValues;314int size = localizationValues.length;315int successCounter = 0;316int failureCounter = 0;317for (int i = 0; i < size; i++) {318319double d = localizationValues[i];320String formatted = df.format(d);321322char[] expectedUnicodeArray =323getCharsFromUnicodeArray(324GoldenFormattedValues.DecimalDigitsLocalizedFormattedValues[i]);325String expected = new String(expectedUnicodeArray);326327if (!formatted.equals(expected)) {328failureCounter++;329System.out.println(330"--- Localization error for value d = " + d +331". Exact value = " + new BigDecimal(d).toString() +332". Expected result = " + expected +333". Output result = " + formatted);334} else successCounter++;335}336System.out.println("Checked positively " + successCounter +337" golden decimal values out of " + size +338" tests. There were " + failureCounter +339" format failure");340341return failureCounter;342}343344private static int testGoldenValues(java.text.DecimalFormat df,345java.text.DecimalFormat cf) {346347double[] goldenDecimalValues = GoldenDoubleValues.DecimalGoldenValues;348int decimalSize = goldenDecimalValues.length;349int decimalSuccessCounter = 0;350int decimalFailureCounter = 0;351for (int i = 0; i < decimalSize; i++) {352353double d = goldenDecimalValues[i];354String formatted = df.format(d);355356char[] expectedUnicodeArray =357getCharsFromUnicodeArray(358GoldenFormattedValues.DecimalGoldenFormattedValues[i]);359String expected = new String(expectedUnicodeArray);360361if (!formatted.equals(expected)) {362decimalFailureCounter++;363System.out.println(364"--- Error for golden value d = " + d +365". Exact value = " + new BigDecimal(d).toString() +366". Expected result = " + expected +367". Output result = " + formatted);368} else decimalSuccessCounter++;369}370System.out.println("Checked positively " + decimalSuccessCounter +371" golden decimal values out of " + decimalSize +372" tests. There were " + decimalFailureCounter +373" format failure");374375double[] goldenCurrencyValues = GoldenDoubleValues.CurrencyGoldenValues;376int currencySize = goldenCurrencyValues.length;377int currencySuccessCounter = 0;378int currencyFailureCounter = 0;379for (int i = 0; i < currencySize; i++) {380double d = goldenCurrencyValues[i];381String formatted = cf.format(d);382383char[] expectedUnicodeArray =384getCharsFromUnicodeArray(385GoldenFormattedValues.CurrencyGoldenFormattedValues[i]);386String expected = new String(expectedUnicodeArray);387388if (!formatted.equals(expected)) {389currencyFailureCounter++;390System.out.println(391"--- Error for golden value d = " + d +392". Exact value = " + new BigDecimal(d).toString() +393". Expected result = " + expected +394". Output result = " + formatted);395} else currencySuccessCounter++;396}397System.out.println("Checked positively " + currencySuccessCounter +398" golden currency values out of " + currencySize +399" tests. There were " + currencyFailureCounter +400" format failure");401402return (decimalFailureCounter + currencyFailureCounter);403}404405// Checks that the two passed s1 and s2 string are equal, and prints406// out message in case of error.407private static boolean resultsEqual(String propertyName,408String s1,409String s2) {410411boolean equality = s1.equals(s2);412if (!equality)413System.out.println(414"\n*** Error while reverting to default " +415propertyName + " property.\n" +416" initial output = " + s1 +417". reverted output = " + s2 + ".");418else System.out.println(" Test passed.");419420return equality;421422}423424/* This methods checks the behaviour of the management of properties425* of a DecimalFormat instance that satisfies fast-path constraints.426*427* It does this by comparing the results of the format(double) output428* obtained from initial fast-path state with the output provided by429* the same instance that has been pushed and exercised outside430* fast-path rules and finally "reverted" to its initial fast-path state.431*432* The schema of actions is this :433* - Call format(double) on a known DecimalFormat fast-path instance,434* and store this result.435* - Record the current state of a given property.436* - Change the property to invalidate the fast-path state.437* - Call again format(double) on the instance.438* - Revert state of property to validate again fast-path context.439* - Call format(double) again.440* - Check that first and last call to format(double) provide same result441* - Record failure if any.442* - Do the same for another property with the same instance.443* So all the property changes are chained one after the other on only the444* same instance.445*446* Some properties that currently do not influence the fast-path state447* are also tested. This is not useful with current fast-path source448* but is here for testing the whole set of properties. This is the case449* for prefixes and suffixes, and parseBigDecimal properties.450*/451private static int testSettersAndFastPath(DecimalFormat df,452boolean isCurrency) {453454final double d1 = GoldenDoubleValues.PROPERTY_CHECK_POSITIVE_VALUE;455final double d2 = GoldenDoubleValues.PROPERTY_CHECK_NEGATIVE_VALUE;456457int errors = 0;458boolean testSucceeded = false;459String firstFormatResult;460String secondFormatResult;461String propertyName;462463// ---- positivePrefix property test ----464testSucceeded = false;465propertyName = "positivePrefix";466System.out.print("Checking " + propertyName + " property.");467String initialPrefix = df.getPositivePrefix();468firstFormatResult = df.format(d1);469df.setPositivePrefix("positivePrefix:");470df.format(d1);471df.setPositivePrefix(initialPrefix);472secondFormatResult = df.format(d1);473testSucceeded =474resultsEqual(propertyName, firstFormatResult, secondFormatResult);475if (!testSucceeded)476errors++;477478// ---- positiveSuffix property test ----479testSucceeded = false;480propertyName = "positiveSuffix";481System.out.print("Checking " + propertyName + " property.");482String initialSuffix = df.getPositiveSuffix();483firstFormatResult = df.format(d1);484df.setPositiveSuffix("positiveSuffix:");485df.format(d1);486df.setPositiveSuffix(initialSuffix);487secondFormatResult = df.format(d1);488testSucceeded =489resultsEqual(propertyName,firstFormatResult, secondFormatResult);490if (!testSucceeded)491errors++;492493// ---- negativePrefix property test ----494testSucceeded = false;495propertyName = "negativePrefix";496System.out.print("Checking " + propertyName + " property.");497initialPrefix = df.getNegativePrefix();498firstFormatResult = df.format(d1);499df.setNegativePrefix("negativePrefix:");500df.format(d1);501df.setNegativePrefix(initialPrefix);502secondFormatResult = df.format(d1);503testSucceeded =504resultsEqual(propertyName, firstFormatResult, secondFormatResult);505if (!testSucceeded)506errors++;507508// ---- negativeSuffix property test ----509testSucceeded = false;510propertyName = "negativeSuffix";511System.out.print("Checking " + propertyName + " property.");512initialSuffix = df.getNegativeSuffix();513firstFormatResult = df.format(d1);514df.setNegativeSuffix("negativeSuffix:");515df.format(d1);516df.setNegativeSuffix(initialSuffix);517secondFormatResult = df.format(d1);518testSucceeded =519resultsEqual(propertyName, firstFormatResult, secondFormatResult);520if (!testSucceeded)521errors++;522523// ---- multiplier property test ----524testSucceeded = false;525propertyName = "multiplier";526System.out.print("Checking " + propertyName + " property.");527int initialMultiplier = df.getMultiplier();528firstFormatResult = df.format(d1);529df.setMultiplier(10);530df.format(d1);531df.setMultiplier(initialMultiplier);532secondFormatResult = df.format(d1);533testSucceeded =534resultsEqual(propertyName, firstFormatResult, secondFormatResult);535if (!testSucceeded)536errors++;537538// ---- groupingUsed property test ----539testSucceeded = false;540propertyName = "groupingUsed";541System.out.print("Checking " + propertyName + " property.");542boolean initialGroupingUsed = df.isGroupingUsed();543firstFormatResult = df.format(d1);544df.setGroupingUsed(!initialGroupingUsed);545df.format(d1);546df.setGroupingUsed(initialGroupingUsed);547secondFormatResult = df.format(d1);548testSucceeded =549resultsEqual(propertyName, firstFormatResult, secondFormatResult);550if (!testSucceeded)551errors++;552553// ---- groupingSize property test ----554testSucceeded = false;555propertyName = "groupingSize";556System.out.print("Checking " + propertyName + " property.");557int initialGroupingSize = df.getGroupingSize();558firstFormatResult = df.format(d1);559df.setGroupingSize(initialGroupingSize + 1);560df.format(d1);561df.setGroupingSize(initialGroupingSize);562secondFormatResult = df.format(d1);563testSucceeded =564resultsEqual(propertyName, firstFormatResult, secondFormatResult);565if (!testSucceeded)566errors++;567568// ---- decimalSeparatorAlwaysShown property test ----569testSucceeded = false;570propertyName = "decimalSeparatorAlwaysShown";571System.out.print("Checking " + propertyName + " property.");572boolean initialDSShown = df.isDecimalSeparatorAlwaysShown();573firstFormatResult = df.format(d1);574df.setDecimalSeparatorAlwaysShown(!initialDSShown);575df.format(d1);576df.setDecimalSeparatorAlwaysShown(initialDSShown);577secondFormatResult = df.format(d1);578testSucceeded =579resultsEqual(propertyName, firstFormatResult, secondFormatResult);580if (!testSucceeded)581errors++;582583// ---- parseBigDecimal property test ----584testSucceeded = false;585propertyName = "parseBigDecimal";586System.out.print("Checking " + propertyName + " property.");587boolean initialParseBigdecimal = df.isParseBigDecimal();588firstFormatResult = df.format(d1);589df.setParseBigDecimal(!initialParseBigdecimal);590df.format(d1);591df.setParseBigDecimal(initialParseBigdecimal);592secondFormatResult = df.format(d1);593testSucceeded =594resultsEqual(propertyName, firstFormatResult, secondFormatResult);595if (!testSucceeded)596errors++;597598// ---- maximumIntegerDigits property test ----599testSucceeded = false;600propertyName = "maximumIntegerDigits";601System.out.print("Checking " + propertyName + " property.");602int initialMaxIDs = df.getMaximumIntegerDigits();603firstFormatResult = df.format(d1);604df.setMaximumIntegerDigits(8);605df.format(d1);606df.setMaximumIntegerDigits(initialMaxIDs);607secondFormatResult = df.format(d1);608testSucceeded =609resultsEqual(propertyName, firstFormatResult, secondFormatResult);610if (!testSucceeded)611errors++;612613// ---- minimumIntegerDigits property test ----614testSucceeded = false;615propertyName = "minimumIntegerDigits";616System.out.print("Checking " + propertyName + " property.");617int initialMinIDs = df.getMinimumIntegerDigits();618firstFormatResult = df.format(d1);619df.setMinimumIntegerDigits(2);620df.format(d1);621df.setMinimumIntegerDigits(initialMinIDs);622secondFormatResult = df.format(d1);623testSucceeded =624resultsEqual(propertyName, firstFormatResult, secondFormatResult);625if (!testSucceeded)626errors++;627628// ---- maximumFractionDigits property test ----629testSucceeded = false;630propertyName = "maximumFractionDigits";631System.out.print("Checking " + propertyName + " property.");632firstFormatResult = df.format(d1);633df.setMaximumFractionDigits(8);634df.format(d1);635if (isCurrency) {636df.setMinimumFractionDigits(2);637df.setMaximumFractionDigits(2);638} else {639df.setMinimumFractionDigits(0);640df.setMaximumFractionDigits(3);641}642secondFormatResult = df.format(d1);643testSucceeded =644resultsEqual(propertyName, firstFormatResult, secondFormatResult);645if (!testSucceeded)646errors++;647648// ---- minimumFractionDigits property test ----649testSucceeded = false;650propertyName = "minimumFractionDigits";651System.out.print("Checking " + propertyName + " property.");652firstFormatResult = df.format(d1);653df.setMinimumFractionDigits(1);654df.format(d1);655if (isCurrency) {656df.setMinimumFractionDigits(2);657df.setMaximumFractionDigits(2);658} else {659df.setMinimumFractionDigits(0);660df.setMaximumFractionDigits(3);661}662secondFormatResult = df.format(d1);663testSucceeded =664resultsEqual(propertyName, firstFormatResult, secondFormatResult);665if (!testSucceeded)666errors++;667668// ---- currency property test ----669testSucceeded = false;670propertyName = "currency";671System.out.print("Checking " + propertyName + " property.");672Currency initialCurrency = df.getCurrency();673Currency japanCur = java.util.Currency.getInstance(Locale.JAPAN);674firstFormatResult = df.format(d1);675df.setCurrency(japanCur);676df.format(d1);677df.setCurrency(initialCurrency);678secondFormatResult = df.format(d1);679testSucceeded =680resultsEqual(propertyName, firstFormatResult, secondFormatResult);681if (!testSucceeded)682errors++;683684// ---- roundingMode property test ----685testSucceeded = false;686propertyName = "roundingMode";687System.out.print("Checking " + propertyName + " property.");688RoundingMode initialRMode = df.getRoundingMode();689firstFormatResult = df.format(d1);690df.setRoundingMode(RoundingMode.HALF_UP);691df.format(d1);692df.setRoundingMode(RoundingMode.HALF_EVEN);693secondFormatResult = df.format(d1);694testSucceeded =695resultsEqual(propertyName, firstFormatResult, secondFormatResult);696if (!testSucceeded)697errors++;698699// ---- decimalFormatSymbols property test ----700testSucceeded = false;701propertyName = "decimalFormatSymbols";702System.out.print("Checking " + propertyName + " property.");703DecimalFormatSymbols initialDecimalFormatSymbols = df.getDecimalFormatSymbols();704firstFormatResult = df.format(d1);705Locale bizarreLocale = new Locale("fr", "FR");706DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(bizarreLocale);707unusualSymbols.setDecimalSeparator('@');708unusualSymbols.setGroupingSeparator('|');709df.setDecimalFormatSymbols(unusualSymbols);710df.format(d1);711df.setDecimalFormatSymbols(initialDecimalFormatSymbols);712secondFormatResult = df.format(d1);713testSucceeded =714resultsEqual(propertyName, firstFormatResult, secondFormatResult);715if (!testSucceeded)716errors++;717718testSucceeded = false;719System.out.print("Checking " + propertyName + " property.");720initialDecimalFormatSymbols = df.getDecimalFormatSymbols();721firstFormatResult = df.format(d1);722Locale japanLocale = Locale.JAPAN;723unusualSymbols = new DecimalFormatSymbols(japanLocale);724unusualSymbols.setDecimalSeparator('9');725unusualSymbols.setGroupingSeparator('0');726df.setDecimalFormatSymbols(unusualSymbols);727df.format(d1);728df.setDecimalFormatSymbols(initialDecimalFormatSymbols);729secondFormatResult = df.format(d1);730testSucceeded =731resultsEqual(propertyName, firstFormatResult, secondFormatResult);732if (!testSucceeded)733errors++;734735return errors;736}737738// Main for RoundingAndPropertyTest. We test first the golden values,739// and then the property setters and getters.740public static void main(String[] args) {741742if ((args.length >= 1) &&743(args[0].equals("-gengold")))744generatesGoldenFormattedValuesClass();745else {746System.out.println("\nChecking correctness of formatting with digit localization.");747System.out.println("=============================================================");748int localizationErrors = testLocalizationValues();749if (localizationErrors != 0)750System.out.println("*** Failure in localization tests : " +751localizationErrors + " errors detected ");752else System.out.println(" Tests for full localization of digits all passed.");753754DecimalFormat df = (DecimalFormat)755NumberFormat.getInstance(GoldenDoubleValues.TestLocale);756DecimalFormat cf = (DecimalFormat)757NumberFormat.getCurrencyInstance(GoldenDoubleValues.TestLocale);758759System.out.println("\nChecking correctness of formating for golden values.");760System.out.println("=============================================================");761int goldenValuesErrors = testGoldenValues(df,cf);762if (goldenValuesErrors != 0)763System.out.println("*** Failure in goldenValues tests : " +764goldenValuesErrors + " errors detected ");765else System.out.println(" Tests for golden values all passed.");766767System.out.println("\nChecking behavior of property changes for decimal case.");768System.out.println("=============================================================");769int decimalTestsErrors = testSettersAndFastPath(df, false);770if (decimalTestsErrors != 0)771System.out.println("*** Failure in decimal property changes tests : " +772decimalTestsErrors + " errors detected ");773else System.out.println(" Tests for decimal property changes all passed.");774775System.out.println("\nChecking behavior of property changes for currency case.");776System.out.println("=============================================================");777int currencyTestsErrors = testSettersAndFastPath(cf, true);778if (currencyTestsErrors != 0)779System.out.println("*** Failure in currency property changes tests : " +780currencyTestsErrors + " errors detected ");781else System.out.println(" Tests for currency property chamges all passed.");782783if ((localizationErrors > 0) ||784(goldenValuesErrors > 0) ||785(decimalTestsErrors > 0) ||786(currencyTestsErrors > 0))787throw new RuntimeException(788"Failed with " +789(localizationErrors + goldenValuesErrors +790decimalTestsErrors + currencyTestsErrors) +791" error(s).");792}793}794}795796797