Path: blob/master/test/jdk/java/util/Formatter/Basic.java
41149 views
/*1* Copyright (c) 2003, 2021, 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* @summary Unit test for formatter25* @bug 4906370 4962433 4973103 4989961 5005818 5031150 4970931 4989491 500293726* 5005104 5007745 5061412 5055180 5066788 5088703 6317248 6318369 632012227* 6344623 6369500 6534606 6282094 6286592 6476425 5063507 6469160 647616828* 8059175 820422929*30* @run shell/timeout=240 Basic.sh31*/3233import static java.lang.System.out;3435public class Basic {3637private static int fail = 0;38private static int pass = 0;3940private static Throwable first;4142static void pass() {43pass++;44}4546static void fail(String fs, Class ex) {47String s = "'" + fs + "': " + ex.getName() + " not thrown";48if (first == null)49setFirst(s);50System.err.println("FAILED: " + s);51fail++;52}5354static void fail(String fs, String exp, String got) {55String s = "'" + fs + "': Expected '" + exp + "', got '" + got + "'";56if (first == null)57setFirst(s);58System.err.println("FAILED: " + s);59fail++;60}6162private static void setFirst(String s) {63try {64throw new RuntimeException(s);65} catch (RuntimeException x) {66first = x;67}68}6970static void ck(String fs, String exp, String got) {71if (!exp.equals(got))72fail(fs, exp, got);73else74pass();75}7677public static void main(String[] args) {78BasicBoolean.test();79BasicBooleanObject.test();80BasicByte.test();81BasicByteObject.test();82BasicChar.test();83BasicCharObject.test();84BasicShort.test();85BasicShortObject.test();86BasicInt.test();87BasicIntObject.test();88BasicLong.test();89BasicLongObject.test();90BasicBigInteger.test();91BasicFloat.test();92BasicFloatObject.test();93BasicDouble.test();94BasicDoubleObject.test();95BasicBigDecimal.test();9697BasicDateTime.test();9899if (fail != 0)100throw new RuntimeException((fail + pass) + " tests: "101+ fail + " failure(s), first", first);102else103out.println("all " + (fail + pass) + " tests passed");104}105}106107108