jdk/test/java/util/Formatter/Basic.java
changeset 2 90ce3da70b43
child 1823 23d42a96635e
equal deleted inserted replaced
0:fd16c54261b3 2:90ce3da70b43
       
     1 /*
       
     2  * Copyright 2003-2007 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  */
       
    23 
       
    24 /* @test
       
    25  * @summary Unit test for formatter
       
    26  * @bug 4906370 4962433 4973103 4989961 5005818 5031150 4970931 4989491 5002937
       
    27  *      5005104 5007745 5061412 5055180 5066788 5088703 6317248 6318369 6320122
       
    28  *      6344623 6369500 6534606 6282094 6286592
       
    29  *
       
    30  * @run shell/timeout=240 Basic.sh
       
    31  */
       
    32 
       
    33 import static java.lang.System.out;
       
    34 
       
    35 public class Basic {
       
    36 
       
    37     private static int fail = 0;
       
    38     private static int pass = 0;
       
    39 
       
    40     private static Throwable first;
       
    41 
       
    42     static void pass() {
       
    43         pass++;
       
    44     }
       
    45 
       
    46     static void fail(String fs, Class ex) {
       
    47         String s = "'" + fs + "': " + ex.getName() + " not thrown";
       
    48         if (first == null)
       
    49             setFirst(s);
       
    50         System.err.println("FAILED: " + s);
       
    51         fail++;
       
    52     }
       
    53 
       
    54     static void fail(String fs, String exp, String got) {
       
    55         String s = "'" + fs + "': Expected '" + exp + "', got '" + got + "'";
       
    56         if (first == null)
       
    57             setFirst(s);
       
    58         System.err.println("FAILED: " + s);
       
    59         fail++;
       
    60     }
       
    61 
       
    62     private static void setFirst(String s) {
       
    63         try {
       
    64             throw new RuntimeException(s);
       
    65         } catch (RuntimeException x) {
       
    66             first = x;
       
    67         }
       
    68     }
       
    69 
       
    70     static void ck(String fs, String exp, String got) {
       
    71         if (!exp.equals(got))
       
    72             fail(fs, exp, got);
       
    73         else
       
    74             pass();
       
    75     }
       
    76 
       
    77     public static void main(String[] args) {
       
    78         BasicBoolean.test();
       
    79         BasicBooleanObject.test();
       
    80         BasicByte.test();
       
    81         BasicByteObject.test();
       
    82         BasicChar.test();
       
    83         BasicCharObject.test();
       
    84         BasicShort.test();
       
    85         BasicShortObject.test();
       
    86         BasicInt.test();
       
    87         BasicIntObject.test();
       
    88         BasicLong.test();
       
    89         BasicLongObject.test();
       
    90         BasicBigInteger.test();
       
    91         BasicFloat.test();
       
    92         BasicFloatObject.test();
       
    93         BasicDouble.test();
       
    94         BasicDoubleObject.test();
       
    95         BasicBigDecimal.test();
       
    96 
       
    97         BasicDateTime.test();
       
    98 
       
    99         if (fail != 0)
       
   100             throw new RuntimeException((fail + pass) + " tests: "
       
   101                                        + fail + " failure(s), first", first);
       
   102         else
       
   103             out.println("all " + (fail + pass) + " tests passed");
       
   104     }
       
   105 }