Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/nio/charset/CharsetDecoder/AverageMax.java
38828 views
/*1* Copyright (c) 2010, 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 485335025* @summary Ensure that averages do not exceed maxima26*27* @build AverageMax28* @run main AverageMax29* @run main/othervm -Dsun.nio.cs.bugLevel=1.4 AverageMax30*/3132import java.nio.*;33import java.nio.charset.*;343536public class AverageMax {3738static boolean compat;3940static abstract class Test {4142public abstract void go() throws Exception;4344Test() throws Exception {45try {46go();47} catch (Exception x) {48if (compat) {49throw new Exception("Exception thrown", x);50}51if (x instanceof IllegalArgumentException) {52System.err.println("Thrown as expected: " + x);53return;54}55throw new Exception("Incorrect exception: "56+ x.getClass().getName(),57x);58}59if (!compat)60throw new Exception("No exception thrown");61}6263}6465public static void main(String[] args) throws Exception {6667// If sun.nio.cs.bugLevel == 1.4 then we want the 1.4 behavior68String bl = System.getProperty("sun.nio.cs.bugLevel");69compat = (bl != null && bl.equals("1.4"));70final Charset ascii = Charset.forName("US-ASCII");7172new Test() {73public void go() throws Exception {74new CharsetDecoder(ascii, 3.9f, 1.2f) {75protected CoderResult decodeLoop(ByteBuffer in,76CharBuffer out)77{78return null;79}80};81}};8283new Test() {84public void go() throws Exception {85new CharsetEncoder(ascii, 3.9f, 1.2f) {86protected CoderResult encodeLoop(CharBuffer in,87ByteBuffer out)88{89return null;90}91};92}};93}9495}969798