Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / test / java.io / StringBufferInputStreamTest.java
blobadafac6e5a990c2e6d08785fb0252728b9a3f720
1 /*************************************************************************
2 /* StringBufferInputStreamTest.java -- Test StringBufferInputStream's of course
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.
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 /*************************************************************************/
22 import java.io.*;
24 public class StringBufferInputStreamTest extends StringBufferInputStream
27 public
28 StringBufferInputStreamTest(String b)
30 super(b);
33 public static void
34 main(String[] argv)
36 System.out.println("Starting test of StringBufferInputStream.");
37 System.out.flush();
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];
48 try
50 sbis.read(read_buf);
51 sbis.mark(0);
53 boolean passed = true;
55 sbis.read(read_buf);
56 if (sbis.pos != (read_buf.length * 2))
58 passed = false;
59 System.out.println("The pos variable is wrong. Expected 24 and got " +
60 sbis.pos);
62 if (sbis.count != str.length())
64 passed = false;
65 System.out.println("The count variable is wrong. Expected " +
66 str.length() + " and got " + sbis.pos);
68 if (sbis.buffer != str)
70 passed = false;
71 System.out.println("The buf variable is not correct");
74 if (passed)
75 System.out.println("PASSED: Protected Variables Test");
76 else
77 System.out.println("FAILED: Protected Variables Test");
79 catch (IOException e)
81 System.out.println("FAILED: Protected Variables Test: " + e);
84 System.out.println("Test 2: Simple Read Test");
86 sbis = new StringBufferInputStreamTest(str);
88 try
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;
97 sbis.close();
98 if (total_read == str.length())
99 System.out.println("PASSED: Simple Read Test");
100 else
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;
115 sbis.read(read_buf);
116 if (sbis.available() != (str.length() - read_buf.length))
118 passed = false;
119 System.out.println("available() reported " + sbis.available() +
120 " and " + (str.length() - read_buf.length) +
121 " was expected");
124 if (sbis.skip(5) != 5)
126 passed = false;
127 System.out.println("skip() didn't work");
129 if (sbis.available() != (str.length() - (read_buf.length + 5)))
131 passed = false;
132 System.out.println("skip() lied");
135 if (sbis.markSupported())
137 passed = false;
138 System.out.println("markSupported() should have returned false but returned true");
141 int availsave = sbis.available();
142 sbis.reset();
143 if (sbis.pos != 0)
145 passed = false;
146 System.out.println("mark/reset failed to work");
149 if (passed)
150 System.out.println("PASSED: mark/reset/available/skip test");
151 else
152 System.out.println("FAILED: mark/reset/available/skip test");
154 catch(IOException e)
156 System.out.println("FAILED: mark/reset/available/skip test: " + e);
159 System.out.println("Finished StringBufferInputStream test");