1 /*
2 * Copyright (c) 1998, 1999, 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 /*
25 * @test
26 * @bug 1267039 1267043 4193729
27 * @summary Check for correct handling of parameters to
28 * XXXXOutputStream.write(b, off, len).
29 *
30 */
31
32 import java.io.*;
33 import java.util.zip.DeflaterOutputStream;
34
35 public class WriteParams {
36
37 /* check for correct handling of different values of off and len */
38 public static void doTest(OutputStream out) throws Exception {
39
40 int off[] = {-1, -1, 0, 0, 33, 33, 0, 32, 32, 4, 1, 0, -1,
41 Integer.MAX_VALUE, 1, Integer.MIN_VALUE,
42 Integer.MIN_VALUE, 1};
43 int len[] = {-1, 0, -1, 33, 0, 4, 32, 0, 4, 16, 31, 0,
44 Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE,
45 1, -1, Integer.MIN_VALUE};
46 boolean results[] = { false, false, false, false, false, false,
135 doTest1(baos);
136 baos.close();
137
138 DataOutputStream dos = new DataOutputStream(new MyOutputStream());
139 doTest(dos);
140 doTest1(dos);
141 dos.close();
142
143 PipedInputStream pis = new PipedInputStream();
144 PipedOutputStream pos = new PipedOutputStream();
145 pos.connect(pis);
146 doTest(pos);
147 doTest1(pos);
148 pos.close();
149
150 DeflaterOutputStream dfos = new DeflaterOutputStream(new MyOutputStream());
151 doTest(dfos);
152 doTest1(dfos);
153 dfos.close();
154
155 /* cleanup */
156 fn.delete();
157
158 }
159 }
160
161 /* An OutputStream class used in the above tests */
162 class MyOutputStream extends OutputStream {
163
164 public MyOutputStream() {
165 }
166
167 public void write(int b) throws IOException {
168 }
169 }
|
1 /*
2 * Copyright (c) 1998, 2017, 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 /*
25 * @test
26 * @bug 1267039 1267043 4193729 4358774
27 * @summary Check for correct handling of parameters to
28 * XXXXOutputStream.write(b, off, len).
29 *
30 */
31
32 import java.io.*;
33 import java.util.zip.DeflaterOutputStream;
34
35 public class WriteParams {
36
37 /* check for correct handling of different values of off and len */
38 public static void doTest(OutputStream out) throws Exception {
39
40 int off[] = {-1, -1, 0, 0, 33, 33, 0, 32, 32, 4, 1, 0, -1,
41 Integer.MAX_VALUE, 1, Integer.MIN_VALUE,
42 Integer.MIN_VALUE, 1};
43 int len[] = {-1, 0, -1, 33, 0, 4, 32, 0, 4, 16, 31, 0,
44 Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE,
45 1, -1, Integer.MIN_VALUE};
46 boolean results[] = { false, false, false, false, false, false,
135 doTest1(baos);
136 baos.close();
137
138 DataOutputStream dos = new DataOutputStream(new MyOutputStream());
139 doTest(dos);
140 doTest1(dos);
141 dos.close();
142
143 PipedInputStream pis = new PipedInputStream();
144 PipedOutputStream pos = new PipedOutputStream();
145 pos.connect(pis);
146 doTest(pos);
147 doTest1(pos);
148 pos.close();
149
150 DeflaterOutputStream dfos = new DeflaterOutputStream(new MyOutputStream());
151 doTest(dfos);
152 doTest1(dfos);
153 dfos.close();
154
155 OutputStream nos = OutputStream.nullStream();
156 doTest(nos);
157 doTest1(nos);
158 nos.close();
159
160 /* cleanup */
161 fn.delete();
162
163 }
164 }
165
166 /* An OutputStream class used in the above tests */
167 class MyOutputStream extends OutputStream {
168
169 public MyOutputStream() {
170 }
171
172 public void write(int b) throws IOException {
173 }
174 }
|