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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* CharArrayReaderTest.java -- Test CharArrayReaders'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 CharArrayReaderTest extends CharArrayReader
25
{
26
 
27
public
28
CharArrayReaderTest(char[] b)
29
{
30
  super(b);
31
}
32
 
33
public static void
34
main(String[] argv)
35
{
36
  System.out.println("Starting test of CharArrayReader.");
37
  System.out.flush();
38
 
39
  String str = "In junior high, I did a lot writing.  I wrote a science\n" +
40
     "fiction novel length story that was called 'The Destruction of\n" +
41
     "Planet Earth'.  All the characters in the story were my friends \n" +
42
     "from school because I couldn't think up any cool names.";
43
 
44
  char[] str_chars = new char[str.length()];
45
  str.getChars(0, str.length(), str_chars, 0);
46
 
47
  System.out.println("Test 1: Protected Variables");
48
 
49
  CharArrayReaderTest car = new CharArrayReaderTest(str_chars);
50
  char[] read_buf = new char[12];
51
 
52
  try
53
    {
54
      car.read(read_buf);
55
      car.mark(0);
56
 
57
      boolean passed = true;
58
 
59
      if (car.markedPos != read_buf.length)
60
        {
61
          passed = false;
62
          System.out.println("The mark variable is wrong.  Expected " +
63
                             read_buf.length + " and got " + car.markedPos);
64
        }
65
      car.read(read_buf);
66
      if (car.pos != (read_buf.length * 2))
67
        {
68
          passed = false;
69
          System.out.println("The pos variable is wrong.  Expected 24 and got " +
70
                             car.pos);
71
        }
72
      if (car.count != str_chars.length)
73
        {
74
          passed = false;
75
          System.out.println("The count variable is wrong.  Expected " +
76
                             str_chars.length + " and got " + car.pos);
77
        }
78
      if (car.buf != str_chars)
79
        {
80
          passed = false;
81
          System.out.println("The buf variable is not correct");
82
        }
83
 
84
      if (passed)
85
        System.out.println("PASSED: Protected Variables Test");
86
      else
87
        System.out.println("FAILED: Protected Variables Test");
88
    }
89
  catch (IOException e)
90
    {
91
      System.out.println("FAILED: Protected Variables Test: " + e);
92
    }
93
 
94
  System.out.println("Test 2: Simple Read Test");
95
 
96
  car = new CharArrayReaderTest(str_chars);
97
 
98
  try
99
    {
100
      int chars_read, total_read = 0;
101
      while ((chars_read = car.read(read_buf, 0, read_buf.length)) != -1)
102
        {
103
          System.out.print(new String(read_buf, 0, chars_read));
104
          total_read += chars_read;
105
        }
106
 
107
      car.close();
108
      if (total_read == str.length())
109
        System.out.println("PASSED: Simple Read Test");
110
      else
111
        System.out.println("FAILED: Simple Read Test");
112
    }
113
  catch (IOException e)
114
    {
115
      System.out.println("FAILED: Simple Read Test: " + e);
116
    }
117
 
118
  System.out.println("Test 3: mark/reset/available/skip test");
119
  car = new CharArrayReaderTest(str_chars);
120
 
121
  try
122
    {
123
      boolean passed = true;
124
 
125
      car.read(read_buf);
126
      if (!car.ready())
127
        {
128
          passed = false;
129
          System.out.println("ready() reported false and should have " +
130
                             "reported true.");
131
        }
132
 
133
      if (car.skip(5) != 5)
134
        {
135
          passed = false;
136
          System.out.println("skip() didn't work");
137
        }
138
 
139
      if (!car.markSupported())
140
        {
141
          passed = false;
142
          System.out.println("markSupported() should have returned true but returned false");
143
        }
144
 
145
      car.mark(0);
146
      int pos_save = car.pos;
147
      car.read();
148
      car.reset();
149
      if (car.pos != pos_save)
150
        {
151
          passed = false;
152
          System.out.println("mark/reset failed to work");
153
        }
154
 
155
      if (passed)
156
        System.out.println("PASSED: mark/reset/available/skip test");
157
      else
158
        System.out.println("FAILED: mark/reset/available/skip test");
159
    }
160
  catch(IOException e)
161
    {
162
      System.out.println("FAILED: mark/reset/available/skip test: " + e);
163
    }
164
 
165
  System.out.println("Finished CharArrayReader test");
166
}
167
 
168
}
169
 

powered by: WebSVN 2.1.0

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