0N/A/*
2362N/A * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/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.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4679743
0N/A * @summary Test parts of DeflaterInputStream code that don't really do I/O.
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.util.zip.*;
0N/A
0N/Apublic class ConstructDeflaterInput {
0N/A
0N/A static class MyDeflater extends Deflater {
0N/A private boolean ended = false;
0N/A boolean getEnded() { return ended; }
0N/A public void end() {
0N/A fail("MyDeflater had end() called");
0N/A super.end();
0N/A }
0N/A }
0N/A
0N/A public static void realMain(String[] args) throws Throwable {
0N/A ByteArrayInputStream bais = new ByteArrayInputStream(
0N/A "hello, world".getBytes());
0N/A MyDeflater def = new MyDeflater();
0N/A DeflaterInputStream dis = null;
0N/A byte[] b = new byte[512];
0N/A
0N/A // Check construction
0N/A //
0N/A try {
0N/A dis = new DeflaterInputStream(null);
0N/A fail();
0N/A } catch (NullPointerException ex) {
0N/A pass();
0N/A }
0N/A
0N/A try {
0N/A dis = new DeflaterInputStream(bais, null);
0N/A fail();
0N/A } catch (NullPointerException ex) {
0N/A pass();
0N/A }
0N/A
0N/A try {
0N/A dis = new DeflaterInputStream(bais, def, 0);
0N/A fail();
0N/A } catch (IllegalArgumentException ex) {
0N/A pass();
0N/A }
0N/A
0N/A // Check sanity checks in read methods
0N/A //
0N/A dis = new DeflaterInputStream(bais, def);
0N/A
0N/A try {
0N/A dis.read(null, 5, 2);
0N/A fail();
0N/A } catch (NullPointerException ex) {
0N/A pass();
0N/A }
0N/A
0N/A try {
0N/A dis.read(b, -1, 0);
0N/A fail();
0N/A } catch (IndexOutOfBoundsException ex) {
0N/A pass();
0N/A }
0N/A
0N/A try {
0N/A dis.read(b, 0, -1);
0N/A fail();
0N/A } catch (IndexOutOfBoundsException ex) {
0N/A pass();
0N/A }
0N/A
0N/A try {
0N/A dis.read(b, 0, 600);
0N/A fail();
0N/A } catch (IndexOutOfBoundsException ex) {
0N/A pass();
0N/A }
0N/A
0N/A int len = 0;
0N/A try {
0N/A len = dis.read(b, 0, 0);
0N/A check(len == 0);
0N/A } catch (IndexOutOfBoundsException ex) {
0N/A fail("Read of length 0 should return 0, but returned " + len);
0N/A }
0N/A
0N/A try {
0N/A dis.skip(-1);
0N/A fail();
0N/A } catch (IllegalArgumentException ex) {
0N/A pass();
0N/A }
0N/A
0N/A // Check unsupported operations
0N/A //
0N/A check(!dis.markSupported());
0N/A check(dis.available() == 1);
0N/A check(!def.getEnded());
0N/A try {
0N/A dis.reset();
0N/A fail();
0N/A } catch (IOException ex) {
0N/A pass();
0N/A }
0N/A
0N/A // Check close
0N/A //
0N/A dis.close();
0N/A check(!def.getEnded());
0N/A
0N/A try {
0N/A dis.available();
0N/A fail();
0N/A } catch (IOException ex) {
0N/A pass();
0N/A }
0N/A
0N/A try {
0N/A int x = dis.read();
0N/A fail();
0N/A } catch (IOException ex) {
0N/A pass();
0N/A }
0N/A
0N/A try {
0N/A dis.skip(1);
0N/A fail();
0N/A } catch (IOException ex) {
0N/A pass();
0N/A }
0N/A
0N/A }
0N/A
0N/A //--------------------- Infrastructure ---------------------------
0N/A static volatile int passed = 0, failed = 0;
0N/A static void pass() {passed++;}
0N/A static void fail() {failed++; Thread.dumpStack();}
0N/A static void fail(String msg) {System.out.println(msg); fail();}
0N/A static void unexpected(Throwable t) {failed++; t.printStackTrace();}
0N/A static void check(boolean cond) {if (cond) pass(); else fail();}
0N/A static void equal(Object x, Object y) {
0N/A if (x == null ? y == null : x.equals(y)) pass();
0N/A else fail(x + " not equal to " + y);}
0N/A public static void main(String[] args) throws Throwable {
0N/A try {realMain(args);} catch (Throwable t) {unexpected(t);}
0N/A System.out.println("\nPassed = " + passed + " failed = " + failed);
0N/A if (failed > 0) throw new AssertionError("Some tests failed");}
0N/A}