AverageMax.java revision 2362
2115N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2115N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2115N/A *
2115N/A * This code is free software; you can redistribute it and/or modify it
2115N/A * under the terms of the GNU General Public License version 2 only, as
2115N/A * published by the Free Software Foundation.
2115N/A *
2115N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2115N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2115N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2115N/A * version 2 for more details (a copy is included in the LICENSE file that
2115N/A * accompanied this code).
2115N/A *
2115N/A * You should have received a copy of the GNU General Public License version
2115N/A * 2 along with this work; if not, write to the Free Software Foundation,
2115N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2115N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2115N/A */
2115N/A
2115N/A/* @test
2115N/A * @bug 4853350
2115N/A * @summary Ensure that averages do not exceed maxima
2115N/A *
2115N/A * @build AverageMax
2115N/A * @run main AverageMax
2115N/A * @run main/othervm -Dsun.nio.cs.bugLevel=1.4 AverageMax
2115N/A */
2115N/A
2115N/Aimport java.nio.*;
2115N/Aimport java.nio.charset.*;
2115N/A
2115N/A
2115N/Apublic class AverageMax {
2115N/A
2115N/A static boolean compat;
2115N/A
2115N/A static abstract class Test {
2115N/A
2115N/A public abstract void go() throws Exception;
2115N/A
2115N/A Test() throws Exception {
2115N/A try {
2115N/A go();
2115N/A } catch (Exception x) {
2115N/A if (compat) {
2115N/A throw new Exception("Exception thrown", x);
2115N/A }
2115N/A if (x instanceof IllegalArgumentException) {
2115N/A System.err.println("Thrown as expected: " + x);
2115N/A return;
2115N/A }
2115N/A throw new Exception("Incorrect exception: "
2115N/A + x.getClass().getName(),
2115N/A x);
2115N/A }
2115N/A if (!compat)
2115N/A throw new Exception("No exception thrown");
2115N/A }
2115N/A
2115N/A }
2115N/A
2115N/A public static void main(String[] args) throws Exception {
2115N/A
2115N/A // If sun.nio.cs.bugLevel == 1.4 then we want the 1.4 behavior
2115N/A String bl = System.getProperty("sun.nio.cs.bugLevel");
2115N/A compat = (bl != null && bl.equals("1.4"));
2115N/A final Charset ascii = Charset.forName("US-ASCII");
2115N/A
2115N/A new Test() {
2115N/A public void go() throws Exception {
2115N/A new CharsetDecoder(ascii, 3.9f, 1.2f) {
2115N/A protected CoderResult decodeLoop(ByteBuffer in,
2115N/A CharBuffer out)
2115N/A {
2115N/A return null;
2115N/A }
2115N/A };
2115N/A }};
2115N/A
2115N/A new Test() {
2115N/A public void go() throws Exception {
2115N/A new CharsetEncoder(ascii, 3.9f, 1.2f) {
2115N/A protected CoderResult encodeLoop(CharBuffer in,
2115N/A ByteBuffer out)
2115N/A {
2115N/A return null;
2115N/A }
2115N/A };
2115N/A }};
2115N/A }
2115N/A
2115N/A}