1 /************************************************************************* |
|
2 /* MarkReset.java -- ByteArrayInputStream mark/reset test |
|
3 /* |
|
4 /* Copyright (c) 1998, 1999 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.0 |
|
23 |
|
24 package gnu.testlet.java.io.ByteArrayInputStream; |
|
25 |
|
26 import gnu.testlet.Testlet; |
|
27 import gnu.testlet.TestHarness; |
|
28 import java.io.*; |
|
29 |
|
30 public class MarkReset implements Testlet |
|
31 { |
|
32 |
|
33 public void |
|
34 test(TestHarness harness) |
|
35 { |
|
36 String str = "My sophomore year of college I moved out of the dorms. I\n" + |
|
37 "moved in with three friends into a brand new townhouse in east\n" + |
|
38 "Bloomington at 771 Woodbridge Drive. To this day that was the\n" + |
|
39 "nicest place I've ever lived.\n"; |
|
40 |
|
41 byte[] str_bytes = str.getBytes(); |
|
42 ByteArrayInputStream bais = new ByteArrayInputStream(str_bytes); |
|
43 byte[] read_buf = new byte[12]; |
|
44 |
|
45 try |
|
46 { |
|
47 bais.read(read_buf); |
|
48 |
|
49 harness.check(bais.available(), (str_bytes.length - read_buf.length), |
|
50 "available() 1"); |
|
51 harness.check(bais.skip(5), 5, "skip()"); |
|
52 // System.out.println("skip() didn't work"); |
|
53 harness.check(bais.available(), (str_bytes.length - |
|
54 (read_buf.length + 5)), "available() 2"); |
|
55 harness.check(bais.markSupported(), "markSupported()"); |
|
56 |
|
57 bais.mark(0); |
|
58 int availsave = bais.available(); |
|
59 bais.read(); |
|
60 bais.reset(); |
|
61 harness.check(bais.available(), availsave, "reset"); |
|
62 } |
|
63 catch(IOException e) |
|
64 { |
|
65 harness.debug(e); |
|
66 harness.check(false); |
|
67 } |
|
68 } |
|
69 |
|
70 } // MarkReset |
|
71 |
|