OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [test/] [java.io/] [BufferedInputStreamTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* BufferedInputStreamTest.java -- Tests BufferedInputStream's
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20
/*************************************************************************/
21
 
22
import java.io.*;
23
 
24
public class BufferedInputStreamTest extends BufferedInputStream
25
{
26
 
27
public
28
BufferedInputStreamTest(InputStream in, int size)
29
{
30
  super(in, size);
31
}
32
 
33
public static int
34
marktest(InputStream ins) throws IOException
35
{
36
  BufferedInputStream bis = new BufferedInputStream(ins, 15);
37
 
38
  int bytes_read;
39
  int total_read = 0;
40
  byte[] buf = new byte[12];
41
 
42
  bytes_read = bis.read(buf);
43
  total_read += bytes_read;
44
  System.out.print(new String(buf, 0, bytes_read));
45
 
46
  bytes_read = bis.read(buf);
47
  total_read += bytes_read;
48
  System.out.print(new String(buf, 0, bytes_read));
49
 
50
  bis.mark(75);
51
  bis.read();
52
  bis.read(buf);
53
  bis.read(buf);
54
  bis.read(buf);
55
  bis.reset();
56
 
57
  bytes_read = bis.read(buf);
58
  total_read += bytes_read;
59
  System.out.print(new String(buf, 0, bytes_read));
60
 
61
  bis.mark(555);
62
 
63
  bytes_read = bis.read(buf);
64
  total_read += bytes_read;
65
  System.out.print(new String(buf, 0, bytes_read));
66
 
67
  bis.reset();
68
 
69
  bis.read(buf);
70
  bytes_read = bis.read(buf);
71
  total_read += bytes_read;
72
  System.out.print(new String(buf, 0, bytes_read));
73
 
74
  bytes_read = bis.read(buf);
75
  total_read += bytes_read;
76
  System.out.print(new String(buf, 0, bytes_read));
77
 
78
  bis.mark(14);
79
 
80
  bis.read(buf);
81
 
82
  bis.reset();
83
 
84
  bytes_read = bis.read(buf);
85
  total_read += bytes_read;
86
  System.out.print(new String(buf, 0, bytes_read));
87
 
88
  while ((bytes_read = bis.read(buf)) != -1)
89
    {
90
      System.out.print(new String(buf, 0, bytes_read));
91
      total_read += bytes_read;
92
    }
93
 
94
  return(total_read);
95
}
96
 
97
public static void
98
main(String[] argv)
99
{
100
  System.out.println("Started test of BufferedInputStream");
101
 
102
  try
103
    {
104
      System.out.println("Test 1: Protected Variables Test");
105
 
106
      String str = "This is a test line of text for this pass";
107
 
108
      StringBufferInputStream sbis = new StringBufferInputStream(str);
109
      BufferedInputStreamTest bist = new BufferedInputStreamTest(sbis, 12);
110
 
111
      bist.read();
112
      bist.mark(5);
113
 
114
      boolean passed = true;
115
 
116
      if (bist.buf.length != 12)
117
        {
118
          passed = false;
119
          System.out.println("buf.length is wrong.  Expected 12, but got " +
120
                             bist.buf.length);
121
        }
122
      if (bist.count != 12)
123
        {
124
          passed = false;
125
          System.out.println("count is wrong.  Expected 12, but got " +
126
                             bist.count);
127
        }
128
      if (bist.marklimit != 5)
129
        {
130
          passed = false;
131
          System.out.println("marklimit is wrong.  Expected 5, but got " +
132
                             bist.marklimit);
133
        }
134
      if (bist.markpos != 1)
135
        {
136
          passed = false;
137
          System.out.println("markpos is wrong.  Expected 5, but got " +
138
                             bist.markpos);
139
        }
140
      if (bist.pos != 1)
141
        {
142
          passed = false;
143
          System.out.println("pos is wrong.  Expected 1, but got " +
144
                             bist.pos);
145
        }
146
 
147
      if (passed)
148
        System.out.println("PASSED: Protected Variables Test");
149
      else
150
        System.out.println("FAILED: Protected Variables Test");
151
    }
152
  catch(IOException e)
153
    {
154
      System.out.println("FAILED: Protected Variables Test: " + e);
155
    }
156
 
157
  try
158
    {
159
      System.out.println("Test 2: Simple Read Test");
160
 
161
      String str = "One of my 8th grade teachers was Mr. Russell.\n" +
162
         "He used to start each year off by telling the class that the\n" +
163
         "earth was flat.  He did it to teach people to question\n" +
164
         "things they are told.  But everybody knew that he did it\n" +
165
         "so it lost its effect.\n";
166
 
167
      StringBufferInputStream sbis = new StringBufferInputStream(str);
168
      BufferedInputStream bis = new BufferedInputStream(sbis, 15);
169
 
170
      byte[] buf = new byte[12];
171
      int bytes_read;
172
      while((bytes_read = bis.read(buf)) != -1)
173
        System.out.print(new String(buf, 0, bytes_read));
174
 
175
      bis.close();
176
      System.out.println("PASSED: Simple Read Test");
177
    }
178
  catch (IOException e)
179
    {
180
      System.out.println("FAILED: Simple Read Test: " + e);
181
    }
182
 
183
  try
184
    {
185
      System.out.println("Test 3: First mark/reset Test");
186
 
187
      String str = "My 6th grade teacher was named Mrs. Hostetler.\n" +
188
        "She had a whole list of rules that you were supposed to follow\n" +
189
        "in class and if you broke a rule she would make you write the\n" +
190
        "rules out several times.  The number varied depending on what\n" +
191
        "rule you broke.  Since I knew I would get in trouble, I would\n" +
192
        "just go ahead and write out a few sets on the long school bus\n" +
193
        "ride home so that if had to stay in during recess and write\n" +
194
        "rules, five minutes later I could just tell the teacher I was\n" +
195
        "done so I could go outside and play kickball.\n";
196
 
197
      StringBufferInputStream sbis = new StringBufferInputStream(str);
198
 
199
      int total_read = marktest(sbis);
200
 
201
      if (total_read == str.length())
202
        System.out.println("PASSED: First mark/reset Test");
203
      else
204
        System.out.println("FAILED: First mark/reset Test");
205
    }
206
  catch (IOException e)
207
    {
208
      System.out.println("FAILED: First mark/reset Test: " + e);
209
    }
210
 
211
  try
212
    {
213
      System.out.println("Test 4: Second mark/reset Test");
214
 
215
      String str = "My first day of college was fun.  A bunch of us\n" +
216
         "got pretty drunk, then this guy named Rick Flake (I'm not\n" +
217
         "making that name up) took a piss in the bed of a Physical\n" +
218
         "Plant dept pickup truck.  Later on we were walking across\n" +
219
         "campus, saw a cop, and took off running for no reason.\n" +
220
         "When we got back to the dorm we found an even drunker guy\n" +
221
         "passed out in a shopping cart outside.\n";
222
 
223
      ByteArrayInputStream sbis = new ByteArrayInputStream(str.getBytes());
224
 
225
      int total_read = marktest(sbis);
226
 
227
      if (total_read == str.length())
228
        System.out.println("PASSED: Second mark/reset Test");
229
      else
230
        System.out.println("FAILED: Second mark/reset Test");
231
    }
232
  catch (IOException e)
233
    {
234
      System.out.println("FAILED: Second mark/reset Test: " + e);
235
    }
236
 
237
  System.out.println("Finished test of BufferedInputStream");
238
} // main
239
 
240
} // class BufferedInputStreamTest
241
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.