blob: c92f3f9c0482d32bbc8d3f0ed33dffb14263f0cc [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1997 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 @bug 4017196
26 @summary Test for correct implementation of PushbackInputStream.skip
27 */
28
29import java.io.*;
30
31public class Skip {
32
33 private static void dotest(PushbackInputStream in, int expected)
34 throws Exception
35 {
36 int one, two, last, got;
37
38 in.unread(4);
39 in.unread(5);
40 in.unread(6);
41 in.skip(2);
42 if (in.read() != 4) {
43 throw new Exception("Failed the n < pushed back bytes case");
44 }
45 System.err.println("Passed the n < pushed back bytes case");
46 one = in.read();
47 two = in.read();
48
49 if (two == 7) {
50 in.unread(two);
51 two = 0;
52 }
53 in.skip(2);
54 last = in.read();
55 got = (one + two + last);
56 System.err.println("Expected " + expected + " got " + got);
57 if (expected != got) {
58 throw new Exception("Expected " + expected + " got " + got);
59 }
60 }
61
62
63 public static void main(String args[]) throws Exception {
64 byte[] data1 = {1, 7, 1, 0, 4};
65 byte[] data2 = {1, 1, 1, 1, 5};
66 byte[] data3 = {1, 7, 1, 3, 6};
67 PushbackInputStream in;
68
69 in = new PushbackInputStream(new ByteArrayInputStream(data1), 3);
70 dotest(in, 1);
71 in = new PushbackInputStream(new ByteArrayInputStream(data2), 3);
72 dotest(in, 7);
73 in = new PushbackInputStream(new ByteArrayInputStream(data3), 3);
74 dotest(in, 4);
75 }
76
77}