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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/*************************************************************************
2
/* DataInputOutputTest.java -- Tests Data{Input,Output}Stream'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
// Write some data using DataOutput and read it using DataInput.
25
 
26
public class DataInputOutputTest
27
{
28
 
29
public static void
30
runReadTest(String filename, int seq, String testname)
31
{
32
  try
33
    {
34
      System.out.println("Test " + seq + ": " + testname);
35
 
36
      FileInputStream fis = new FileInputStream(filename);
37
      DataInputStream dis = new DataInputStream(fis);
38
 
39
      boolean passed = true;
40
 
41
      boolean b = dis.readBoolean();
42
      if (b != true)
43
        {
44
          passed = false;
45
          System.out.println("Failed to read boolean. Expected true and got false");
46
        }
47
      b = dis.readBoolean();
48
      if (b != false)
49
        {
50
          passed = false;
51
          System.out.println("Failed to read boolean. Expected false and got true");
52
        }
53
      byte bt = dis.readByte();
54
      if (bt != 8)
55
        {
56
          passed = false;
57
          System.out.println("Failed to read byte. Expected 8 and got "+ bt);
58
        }
59
      bt = dis.readByte();
60
      if (bt != -122)
61
        {
62
          passed = false;
63
          System.out.println("Failed to read byte. Expected -122 and got "+ bt);
64
        }
65
      char c = dis.readChar();
66
      if (c != 'a')
67
        {
68
          passed = false;
69
          System.out.println("Failed to read char. Expected a and got " + c);
70
        }
71
      c = dis.readChar();
72
      if (c != '\uE2D2')
73
        {
74
          passed = false;
75
          System.out.println("Failed to read char. Expected \\uE2D2 and got " + c);
76
        }
77
      short s = dis.readShort();
78
      if (s != 32000)
79
        {
80
          passed = false;
81
          System.out.println("Failed to read short. Expected 32000 and got " + s);
82
        }
83
      int i = dis.readInt();
84
      if (i != 8675309)
85
        {
86
          passed = false;
87
          System.out.println("Failed to read int. Expected 8675309 and got " + i);
88
        }
89
      long l = dis.readLong();
90
      if (l != 696969696969L)
91
        {
92
          passed = false;
93
          System.out.println("Failed to read long. Expected 696969696969 and got " + l);
94
        }
95
      float f = dis.readFloat();
96
      if (!Float.toString(f).equals("3.1415"))
97
        {
98
          passed = false;
99
          System.out.println("Failed to read float. Expected 3.1415 and got " + f);
100
        }
101
      double d = dis.readDouble();
102
      if (d != 999999999.999)
103
        {
104
          passed = false;
105
          System.out.println("Failed to read double.  Expected 999999999.999 and got " + d);
106
        }
107
      String str = dis.readUTF();
108
      if (!str.equals("Testing code is such a boring activity but it must be done"))
109
        {
110
          passed = false;
111
          System.out.println("Read unexpected String: " + str);
112
        }
113
      str = dis.readUTF();
114
      if (!str.equals("a-->\u01FF\uA000\u6666\u0200RRR"))
115
        {
116
          passed = false;
117
          System.out.println("Read unexpected String: " + str);
118
        }
119
 
120
      if (passed)
121
        System.out.println("PASSED: " + testname + " read test");
122
      else
123
        System.out.println("FAILED: " + testname + " read test");
124
    }
125
  catch (IOException e)
126
    {
127
      System.out.println("FAILED: " + testname + " read test: " + e);
128
    }
129
 
130
}
131
 
132
public static void
133
main(String[] argv)
134
{
135
  System.out.println("Started test of DataInputStream and DataOutputStream");
136
 
137
  try
138
    {
139
      System.out.println("Test 1: DataOutputStream write test");
140
 
141
      FileOutputStream fos = new FileOutputStream("dataoutput.out");
142
      DataOutputStream dos = new DataOutputStream(fos);
143
 
144
      dos.writeBoolean(true);
145
      dos.writeBoolean(false);
146
      dos.writeByte((byte)8);
147
      dos.writeByte((byte)-122);
148
      dos.writeChar((char)'a');
149
      dos.writeChar((char)'\uE2D2');
150
      dos.writeShort((short)32000);
151
      dos.writeInt((int)8675309);
152
      dos.writeLong(696969696969L);
153
      dos.writeFloat((float)3.1415);
154
      dos.writeDouble((double)999999999.999);
155
      dos.writeUTF("Testing code is such a boring activity but it must be done");
156
      dos.writeUTF("a-->\u01FF\uA000\u6666\u0200RRR");
157
      dos.close();
158
 
159
      // We'll find out if this was really right later, but conditionally
160
      // report success for now
161
      System.out.println("PASSED: DataOutputStream write test");
162
    }
163
  catch(IOException e)
164
    {
165
      System.out.println("FAILED: DataOutputStream write test: " + e);
166
    }
167
 
168
  runReadTest("dataoutput.out", 2, "Read of JCL written data file");
169
  runReadTest("dataoutput-jdk.out", 3, "Read of JDK written data file");
170
 
171
} // main
172
 
173
} // class DataInputOutputTest
174
 

powered by: WebSVN 2.1.0

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