• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * 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 
17 package android.core;
18 
19 import junit.framework.TestCase;
20 
21 import java.io.BufferedInputStream;
22 import java.io.ByteArrayInputStream;
23 import android.test.suitebuilder.annotation.SmallTest;
24 
25 /**
26  * Tests to verify that simple functionality works for BufferedInputStreams.
27  */
28 public class BufferedInputStreamTest extends TestCase {
29 
30     @SmallTest
testBufferedInputStream()31     public void testBufferedInputStream() throws Exception {
32         String str = "AbCdEfGhIjKlM\nOpQrStUvWxYz";
33         ByteArrayInputStream aa = new ByteArrayInputStream(str.getBytes());
34         ByteArrayInputStream ba = new ByteArrayInputStream(str.getBytes());
35         ByteArrayInputStream ca = new ByteArrayInputStream(str.getBytes());
36         ByteArrayInputStream da = new ByteArrayInputStream(str.getBytes());
37         ByteArrayInputStream ea = new ByteArrayInputStream(str.getBytes());
38 
39         BufferedInputStream a = new BufferedInputStream(aa, 6);
40         try {
41             assertEquals(str, IOUtil.read(a));
42         } finally {
43             a.close();
44         }
45 
46         BufferedInputStream b = new BufferedInputStream(ba, 7);
47         try {
48             assertEquals("AbCdEfGhIj", IOUtil.read(b, 10));
49         } finally {
50             b.close();
51         }
52 
53         BufferedInputStream c = new BufferedInputStream(ca, 9);
54         try {
55             assertEquals("bdfhjl\nprtvxz", IOUtil.skipRead(c));
56         } finally {
57             c.close();
58         }
59 
60         BufferedInputStream d = new BufferedInputStream(da, 9);
61         try {
62             assertEquals('A', d.read());
63             d.mark(15);
64             assertEquals('b', d.read());
65             assertEquals('C', d.read());
66             d.reset();
67             assertEquals('b', d.read());
68         } finally {
69             d.close();
70         }
71 
72         BufferedInputStream e = new BufferedInputStream(ea, 11);
73         try {
74             // test that we can ask for more than is present, and that we'll get
75             // back only what is there.
76             assertEquals(str, IOUtil.read(e, 10000));
77         } finally {
78             e.close();
79         }
80     }
81 }
82