Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / test / java.io / DataInputOutputTest.java
blobdd03fb0cd215c4827a36e330110f61dc978a9f33
1 /*************************************************************************
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.
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 // Write some data using DataOutput and read it using DataInput.
26 public class DataInputOutputTest
29 public static void
30 runReadTest(String filename, int seq, String testname)
32 try
34 System.out.println("Test " + seq + ": " + testname);
36 FileInputStream fis = new FileInputStream(filename);
37 DataInputStream dis = new DataInputStream(fis);
39 boolean passed = true;
41 boolean b = dis.readBoolean();
42 if (b != true)
44 passed = false;
45 System.out.println("Failed to read boolean. Expected true and got false");
47 b = dis.readBoolean();
48 if (b != false)
50 passed = false;
51 System.out.println("Failed to read boolean. Expected false and got true");
53 byte bt = dis.readByte();
54 if (bt != 8)
56 passed = false;
57 System.out.println("Failed to read byte. Expected 8 and got "+ bt);
59 bt = dis.readByte();
60 if (bt != -122)
62 passed = false;
63 System.out.println("Failed to read byte. Expected -122 and got "+ bt);
65 char c = dis.readChar();
66 if (c != 'a')
68 passed = false;
69 System.out.println("Failed to read char. Expected a and got " + c);
71 c = dis.readChar();
72 if (c != '\uE2D2')
74 passed = false;
75 System.out.println("Failed to read char. Expected \\uE2D2 and got " + c);
77 short s = dis.readShort();
78 if (s != 32000)
80 passed = false;
81 System.out.println("Failed to read short. Expected 32000 and got " + s);
83 int i = dis.readInt();
84 if (i != 8675309)
86 passed = false;
87 System.out.println("Failed to read int. Expected 8675309 and got " + i);
89 long l = dis.readLong();
90 if (l != 696969696969L)
92 passed = false;
93 System.out.println("Failed to read long. Expected 696969696969 and got " + l);
95 float f = dis.readFloat();
96 if (!Float.toString(f).equals("3.1415"))
98 passed = false;
99 System.out.println("Failed to read float. Expected 3.1415 and got " + f);
101 double d = dis.readDouble();
102 if (d != 999999999.999)
104 passed = false;
105 System.out.println("Failed to read double. Expected 999999999.999 and got " + d);
107 String str = dis.readUTF();
108 if (!str.equals("Testing code is such a boring activity but it must be done"))
110 passed = false;
111 System.out.println("Read unexpected String: " + str);
113 str = dis.readUTF();
114 if (!str.equals("a-->\u01FF\uA000\u6666\u0200RRR"))
116 passed = false;
117 System.out.println("Read unexpected String: " + str);
120 if (passed)
121 System.out.println("PASSED: " + testname + " read test");
122 else
123 System.out.println("FAILED: " + testname + " read test");
125 catch (IOException e)
127 System.out.println("FAILED: " + testname + " read test: " + e);
132 public static void
133 main(String[] argv)
135 System.out.println("Started test of DataInputStream and DataOutputStream");
139 System.out.println("Test 1: DataOutputStream write test");
141 FileOutputStream fos = new FileOutputStream("dataoutput.out");
142 DataOutputStream dos = new DataOutputStream(fos);
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();
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");
163 catch(IOException e)
165 System.out.println("FAILED: DataOutputStream write test: " + e);
168 runReadTest("dataoutput.out", 2, "Read of JCL written data file");
169 runReadTest("dataoutput-jdk.out", 3, "Read of JDK written data file");
171 } // main
173 } // class DataInputOutputTest