1 /*************************************************************************
2 /* StringBufferInputStreamTest.java -- Test StringBufferInputStream's of course
4 /* Copyright (c) 1998 Free Software Foundation, Inc.
5 /* Written by Aaron M. Renn (arenn@urbanophile.com)
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 /*************************************************************************/
24 public class StringBufferInputStreamTest
extends StringBufferInputStream
28 StringBufferInputStreamTest(String b
)
36 System
.out
.println("Starting test of StringBufferInputStream.");
39 String str
= "Between my freshman and sophomore years of high school\n" +
40 "we moved into a brand new building. The old high school was turned\n" +
41 "into an elementary school.\n";
43 System
.out
.println("Test 1: Protected Variables");
45 StringBufferInputStreamTest sbis
= new StringBufferInputStreamTest(str
);
46 byte[] read_buf
= new byte[12];
53 boolean passed
= true;
56 if (sbis
.pos
!= (read_buf
.length
* 2))
59 System
.out
.println("The pos variable is wrong. Expected 24 and got " +
62 if (sbis
.count
!= str
.length())
65 System
.out
.println("The count variable is wrong. Expected " +
66 str
.length() + " and got " + sbis
.pos
);
68 if (sbis
.buffer
!= str
)
71 System
.out
.println("The buf variable is not correct");
75 System
.out
.println("PASSED: Protected Variables Test");
77 System
.out
.println("FAILED: Protected Variables Test");
81 System
.out
.println("FAILED: Protected Variables Test: " + e
);
84 System
.out
.println("Test 2: Simple Read Test");
86 sbis
= new StringBufferInputStreamTest(str
);
90 int bytes_read
, total_read
= 0;
91 while ((bytes_read
= sbis
.read(read_buf
, 0, read_buf
.length
)) != -1)
93 System
.out
.print(new String(read_buf
, 0, bytes_read
));
94 total_read
+= bytes_read
;
98 if (total_read
== str
.length())
99 System
.out
.println("PASSED: Simple Read Test");
101 System
.out
.println("FAILED: Simple Read Test");
103 catch (IOException e
)
105 System
.out
.println("FAILED: Simple Read Test: " + e
);
108 System
.out
.println("Test 3: mark/reset/available/skip test");
109 sbis
= new StringBufferInputStreamTest(str
);
113 boolean passed
= true;
116 if (sbis
.available() != (str
.length() - read_buf
.length
))
119 System
.out
.println("available() reported " + sbis
.available() +
120 " and " + (str
.length() - read_buf
.length
) +
124 if (sbis
.skip(5) != 5)
127 System
.out
.println("skip() didn't work");
129 if (sbis
.available() != (str
.length() - (read_buf
.length
+ 5)))
132 System
.out
.println("skip() lied");
135 if (sbis
.markSupported())
138 System
.out
.println("markSupported() should have returned false but returned true");
141 int availsave
= sbis
.available();
146 System
.out
.println("mark/reset failed to work");
150 System
.out
.println("PASSED: mark/reset/available/skip test");
152 System
.out
.println("FAILED: mark/reset/available/skip test");
156 System
.out
.println("FAILED: mark/reset/available/skip test: " + e
);
159 System
.out
.println("Finished StringBufferInputStream test");