1 /*
   2  * Copyright (c) 2003, 2013, 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  */
  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 6476425 5063507 6469160 6476168
  29  *      8059175
  30  *
  31  * @modules java.base/sun.misc
  32  * @run shell/timeout=240 Basic.sh
  33  */
  34 
  35 import static java.lang.System.out;
  36 
  37 public class Basic {
  38 
  39     private static int fail = 0;
  40     private static int pass = 0;
  41 
  42     private static Throwable first;
  43 
  44     static void pass() {
  45         pass++;
  46     }
  47 
  48     static void fail(String fs, Class ex) {
  49         String s = "'" + fs + "': " + ex.getName() + " not thrown";
  50         if (first == null)
  51             setFirst(s);
  52         System.err.println("FAILED: " + s);
  53         fail++;
  54     }
  55 
  56     static void fail(String fs, String exp, String got) {
  57         String s = "'" + fs + "': Expected '" + exp + "', got '" + got + "'";
  58         if (first == null)
  59             setFirst(s);
  60         System.err.println("FAILED: " + s);
  61         fail++;
  62     }
  63 
  64     private static void setFirst(String s) {
  65         try {
  66             throw new RuntimeException(s);
  67         } catch (RuntimeException x) {
  68             first = x;
  69         }
  70     }
  71 
  72     static void ck(String fs, String exp, String got) {
  73         if (!exp.equals(got))
  74             fail(fs, exp, got);
  75         else
  76             pass();
  77     }
  78 
  79     public static void main(String[] args) {
  80         BasicBoolean.test();
  81         BasicBooleanObject.test();
  82         BasicByte.test();
  83         BasicByteObject.test();
  84         BasicChar.test();
  85         BasicCharObject.test();
  86         BasicShort.test();
  87         BasicShortObject.test();
  88         BasicInt.test();
  89         BasicIntObject.test();
  90         BasicLong.test();
  91         BasicLongObject.test();
  92         BasicBigInteger.test();
  93         BasicFloat.test();
  94         BasicFloatObject.test();
  95         BasicDouble.test();
  96         BasicDoubleObject.test();
  97         BasicBigDecimal.test();
  98 
  99         BasicDateTime.test();
 100 
 101         if (fail != 0)
 102             throw new RuntimeException((fail + pass) + " tests: "
 103                                        + fail + " failure(s), first", first);
 104         else
 105             out.println("all " + (fail + pass) + " tests passed");
 106     }
 107 }