< prev index next >

test/java/text/Format/DateFormat/Bug4823811.java

Print this page


   1 /*
   2  * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 667 
 668                 System.err.print("      Month 0: ");
 669                 System.err.println(sdf.getDateFormatSymbols().getMonths()[0]);
 670             }
 671         }
 672     }
 673 
 674 
 675     //
 676     // NumberFormat test
 677     //
 678     private static void testNumberFormat() {
 679         NumberFormat nfEG = NumberFormat.getInstance(localeEG);
 680         NumberFormat nfUS = NumberFormat.getInstance(localeUS);
 681 
 682         System.out.println("*** DecimalFormat.format test in ar_EG");
 683         testNumberFormatFormatting(nfEG, -123456789, "123,456,789-", "ar_EG");
 684         testNumberFormatFormatting(nfEG, -456, "456-", "ar_EG");
 685 
 686         System.out.println("*** DecimalFormat.parse test in ar_EG");
 687         testNumberFormatParsing(nfEG, "123-", new Long(-123), "ar_EG");
 688         testNumberFormatParsing(nfEG, "123--", new Long(-123), "ar_EG");
 689         testNumberFormatParsingCheckException(nfEG, "-123", 0, "ar_EG");
 690 
 691         System.out.println("*** DecimalFormat.format test in en_US");
 692         testNumberFormatFormatting(nfUS, -123456789, "-123,456,789", "en_US");
 693         testNumberFormatFormatting(nfUS, -456, "-456", "en_US");
 694 
 695         System.out.println("*** DecimalFormat.parse test in en_US");
 696         testNumberFormatParsing(nfUS, "123-", new Long(123), "en_US");
 697         testNumberFormatParsing(nfUS, "-123", new Long(-123), "en_US");
 698         testNumberFormatParsingCheckException(nfUS, "--123", 0, "en_US");
 699     }
 700 
 701     private static void testNumberFormatFormatting(NumberFormat nf,
 702                                                    int given,
 703                                                    String expected,
 704                                                    String locale) {
 705         String str = nf.format(given);
 706         if (expected.equals(str)) {
 707             if (verbose) {
 708                 System.out.print("  Passed: NumberFormat(" + locale);
 709                 System.out.println(").format(" + given + ")");
 710 
 711                 System.out.println("      ---> \"" + str + "\"");
 712             }
 713         } else {
 714             err = true;
 715             System.err.print("  Failed: Unexpected NumberFormat(" + locale);
 716             System.err.println(").format(" + given + ") result.");
 717 


   1 /*
   2  * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 667 
 668                 System.err.print("      Month 0: ");
 669                 System.err.println(sdf.getDateFormatSymbols().getMonths()[0]);
 670             }
 671         }
 672     }
 673 
 674 
 675     //
 676     // NumberFormat test
 677     //
 678     private static void testNumberFormat() {
 679         NumberFormat nfEG = NumberFormat.getInstance(localeEG);
 680         NumberFormat nfUS = NumberFormat.getInstance(localeUS);
 681 
 682         System.out.println("*** DecimalFormat.format test in ar_EG");
 683         testNumberFormatFormatting(nfEG, -123456789, "123,456,789-", "ar_EG");
 684         testNumberFormatFormatting(nfEG, -456, "456-", "ar_EG");
 685 
 686         System.out.println("*** DecimalFormat.parse test in ar_EG");
 687         testNumberFormatParsing(nfEG, "123-", -123L, "ar_EG");
 688         testNumberFormatParsing(nfEG, "123--",-123L, "ar_EG");
 689         testNumberFormatParsingCheckException(nfEG, "-123", 0, "ar_EG");
 690 
 691         System.out.println("*** DecimalFormat.format test in en_US");
 692         testNumberFormatFormatting(nfUS, -123456789, "-123,456,789", "en_US");
 693         testNumberFormatFormatting(nfUS, -456, "-456", "en_US");
 694 
 695         System.out.println("*** DecimalFormat.parse test in en_US");
 696         testNumberFormatParsing(nfUS, "123-", 123L, "en_US");
 697         testNumberFormatParsing(nfUS, "-123",-123L, "en_US");
 698         testNumberFormatParsingCheckException(nfUS, "--123", 0, "en_US");
 699     }
 700 
 701     private static void testNumberFormatFormatting(NumberFormat nf,
 702                                                    int given,
 703                                                    String expected,
 704                                                    String locale) {
 705         String str = nf.format(given);
 706         if (expected.equals(str)) {
 707             if (verbose) {
 708                 System.out.print("  Passed: NumberFormat(" + locale);
 709                 System.out.println(").format(" + given + ")");
 710 
 711                 System.out.println("      ---> \"" + str + "\"");
 712             }
 713         } else {
 714             err = true;
 715             System.err.print("  Failed: Unexpected NumberFormat(" + locale);
 716             System.err.println(").format(" + given + ") result.");
 717 


< prev index next >