1 /************************************************************************* |
|
2 /* Test.java -- Run tests of SequenceInputStream |
|
3 /* |
|
4 /* Copyright (c) 1998 Free Software Foundation, Inc. |
|
5 /* Written by Aaron M. Renn (arenn@urbanophile.com) |
|
6 /* |
|
7 /* This program is free software; you can redistribute it and/or modify |
|
8 /* it under the terms of the GNU General Public License as published |
|
9 /* by the Free Software Foundation, either version 2 of the License, or |
|
10 /* (at your option) any later version. |
|
11 /* |
|
12 /* This program is distributed in the hope that it will be useful, but |
|
13 /* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 /* GNU General Public License for more details. |
|
16 /* |
|
17 /* You should have received a copy of the GNU General Public License |
|
18 /* along with this program; if not, write to the Free Software Foundation |
|
19 /* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA |
|
20 /*************************************************************************/ |
|
21 |
|
22 // Tags: JDK1.1 |
|
23 |
|
24 package gnu.testlet.java.io.SequenceInputStream; |
|
25 |
|
26 import gnu.testlet.Testlet; |
|
27 import gnu.testlet.TestHarness; |
|
28 import java.io.*; |
|
29 |
|
30 public class Test implements Testlet |
|
31 { |
|
32 |
|
33 public void |
|
34 test(TestHarness harness) |
|
35 { |
|
36 String str1 = "I don't believe in going to chain restaurants. I think\n" + |
|
37 "they are evil. I can't believe all the suburban folks who go to \n"; |
|
38 |
|
39 String str2 = "places like the Olive Garden. Not only does the food make\n" + |
|
40 "me want to puke, none of these chains has the slightest bit of character.\n"; |
|
41 |
|
42 byte[] buf = new byte[10]; |
|
43 |
|
44 try |
|
45 { |
|
46 StringBufferInputStream is1 = new StringBufferInputStream(str1); |
|
47 ByteArrayInputStream is2 = new ByteArrayInputStream(str2.getBytes()); |
|
48 SequenceInputStream sis = new SequenceInputStream(is1, is2); |
|
49 |
|
50 int bytes_read; |
|
51 harness.check(str1.length(), sis.available(), "available()"); |
|
52 while((bytes_read = sis.read(buf)) != -1) |
|
53 { |
|
54 harness.debug(new String(buf,0,bytes_read), false); |
|
55 } |
|
56 |
|
57 sis.close(); |
|
58 harness.check(true); |
|
59 } |
|
60 catch(IOException e) |
|
61 { |
|
62 harness.debug(e); |
|
63 harness.check(false); |
|
64 } |
|
65 |
|
66 try |
|
67 { |
|
68 StringBufferInputStream is1 = new StringBufferInputStream(str1); |
|
69 ByteArrayInputStream is2 = new ByteArrayInputStream(str2.getBytes()); |
|
70 SequenceInputStream sis = new SequenceInputStream(is1, is2); |
|
71 |
|
72 sis.read(buf, 0, 5); |
|
73 harness.check(true, "read(buf, off, len)"); |
|
74 |
|
75 sis.close(); |
|
76 |
|
77 harness.check(sis.read(), -1, "close() test"); |
|
78 } |
|
79 catch(IOException e) |
|
80 { |
|
81 harness.debug(e); |
|
82 harness.check(false); |
|
83 } |
|
84 } |
|
85 |
|
86 } // class Test |
|
87 |
|