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/] [StringBufferInputStreamTest.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
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.
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 StringBufferInputStreamTest extends StringBufferInputStream
25
{
26
 
27
public
28
StringBufferInputStreamTest(String b)
29
{
30
  super(b);
31
}
32
 
33
public static void
34
main(String[] argv)
35
{
36
  System.out.println("Starting test of StringBufferInputStream.");
37
  System.out.flush();
38
 
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";
42
 
43
  System.out.println("Test 1: Protected Variables");
44
 
45
  StringBufferInputStreamTest sbis = new StringBufferInputStreamTest(str);
46
  byte[] read_buf = new byte[12];
47
 
48
  try
49
    {
50
      sbis.read(read_buf);
51
      sbis.mark(0);
52
 
53
      boolean passed = true;
54
 
55
      sbis.read(read_buf);
56
      if (sbis.pos != (read_buf.length * 2))
57
        {
58
          passed = false;
59
          System.out.println("The pos variable is wrong.  Expected 24 and got " +
60
                             sbis.pos);
61
        }
62
      if (sbis.count != str.length())
63
        {
64
          passed = false;
65
          System.out.println("The count variable is wrong.  Expected " +
66
                             str.length() + " and got " + sbis.pos);
67
        }
68
      if (sbis.buffer != str)
69
        {
70
          passed = false;
71
          System.out.println("The buf variable is not correct");
72
        }
73
 
74
      if (passed)
75
        System.out.println("PASSED: Protected Variables Test");
76
      else
77
        System.out.println("FAILED: Protected Variables Test");
78
    }
79
  catch (IOException e)
80
    {
81
      System.out.println("FAILED: Protected Variables Test: " + e);
82
    }
83
 
84
  System.out.println("Test 2: Simple Read Test");
85
 
86
  sbis = new StringBufferInputStreamTest(str);
87
 
88
  try
89
    {
90
      int bytes_read, total_read = 0;
91
      while ((bytes_read = sbis.read(read_buf, 0, read_buf.length)) != -1)
92
        {
93
          System.out.print(new String(read_buf, 0, bytes_read));
94
          total_read += bytes_read;
95
        }
96
 
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");
102
    }
103
  catch (IOException e)
104
    {
105
      System.out.println("FAILED: Simple Read Test: " + e);
106
    }
107
 
108
  System.out.println("Test 3: mark/reset/available/skip test");
109
  sbis = new StringBufferInputStreamTest(str);
110
 
111
  try
112
    {
113
      boolean passed = true;
114
 
115
      sbis.read(read_buf);
116
      if (sbis.available() != (str.length() - read_buf.length))
117
        {
118
          passed = false;
119
          System.out.println("available() reported " + sbis.available() +
120
                             " and " + (str.length() - read_buf.length) +
121
                             " was expected");
122
        }
123
 
124
      if (sbis.skip(5) != 5)
125
        {
126
          passed = false;
127
          System.out.println("skip() didn't work");
128
        }
129
      if (sbis.available() != (str.length() - (read_buf.length + 5)))
130
        {
131
          passed = false;
132
          System.out.println("skip() lied");
133
        }
134
 
135
      if (sbis.markSupported())
136
        {
137
          passed = false;
138
          System.out.println("markSupported() should have returned false but returned true");
139
        }
140
 
141
      int availsave = sbis.available();
142
      sbis.reset();
143
      if (sbis.pos != 0)
144
        {
145
          passed = false;
146
          System.out.println("mark/reset failed to work");
147
        }
148
 
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");
153
    }
154
  catch(IOException e)
155
    {
156
      System.out.println("FAILED: mark/reset/available/skip test: " + e);
157
    }
158
 
159
  System.out.println("Finished StringBufferInputStream test");
160
}
161
 
162
}
163
 

powered by: WebSVN 2.1.0

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