PushBackInputStreamTest.java revision cc05ad238516f1303687aba4a978e24e57c0c07a
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.apache.harmony.luni.tests.java.io;
18
19import java.io.ByteArrayInputStream;
20import java.io.IOException;
21import java.io.PushbackInputStream;
22
23import junit.framework.TestCase;
24import dalvik.annotation.TestLevel;
25import dalvik.annotation.TestTargetClass;
26import dalvik.annotation.TestTargetNew;
27@TestTargetClass(PushbackInputStream.class)
28public class PushBackInputStreamTest extends TestCase {
29
30    /*
31     * @tests java.io.PushBackInputStream(InputStream)
32     */
33    @TestTargetNew(
34        level = TestLevel.PARTIAL_COMPLETE,
35        notes = "Checks IOException.",
36        method = "read",
37        args = {}
38    )
39    public void test_read() {
40        PushbackInputStream str = new PushbackInputStream(null);
41        try {
42            str.read();
43            fail("Test 1: IOException expected.");
44        } catch (IOException e) {
45            // Expected.
46        }
47
48        str = new PushbackInputStream(null, 1);
49        try {
50            str.read();
51            fail("Test 2: IOException expected.");
52        } catch (IOException e) {
53            // Expected
54        }
55    }
56
57    /**
58     * @tests java.io.PushbackInputStream#unread(byte[], int, int)
59     */
60    @TestTargetNew(
61        level = TestLevel.PARTIAL_COMPLETE,
62        notes = "",
63        method = "unread",
64        args = {byte[].class, int.class, int.class}
65    )
66    public void test_unread$BII() {
67        // Regression for HARMONY-49
68        try {
69            PushbackInputStream pb = new PushbackInputStream(
70                    new ByteArrayInputStream(new byte[] { 0 }), 2);
71            pb.unread(new byte[1], 0, 5);
72            fail("Assert 0: should throw IOE");
73        } catch (IOException e) {
74            // expected
75        }
76    }
77    @TestTargetNew(
78        level = TestLevel.COMPLETE,
79        notes = "",
80        method = "reset",
81        args = {}
82    )
83    public void test_reset() {
84        PushbackInputStream pb = new PushbackInputStream(
85                new ByteArrayInputStream(new byte[] { 0 }), 2);
86        try {
87            pb.reset();
88            fail("Should throw IOException");
89        } catch (IOException e) {
90            // expected
91        }
92    }
93    @TestTargetNew(
94        level = TestLevel.COMPLETE,
95        notes = "",
96        method = "mark",
97        args = {int.class}
98    )
99    public void test_mark() {
100        PushbackInputStream pb = new PushbackInputStream(
101                new ByteArrayInputStream(new byte[] { 0 }), 2);
102        pb.mark(Integer.MAX_VALUE);
103        pb.mark(0);
104        pb.mark(-1);
105        pb.mark(Integer.MIN_VALUE);
106    }
107
108}
109