PR target/27599
[official-gcc.git] / libjava / classpath / test / java.io / FileWriterTest.java
blob3602c045c2ca4f0291947c9b088b7ff2ce5b6a28
1 /*************************************************************************
2 /* FileWriterTest.java -- Test of FileWriter and OutputStreamWriter classes
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 public class FileWriterTest
27 public static void
28 main(String[] argv)
30 System.out.println("Starting test of FileWriter and OutputStreamWriter");
32 System.out.println("Test 1: File Write Test");
33 try
35 String s1 = "Ok, what are some of the great flame wars that we have " +
36 "had lately. Let us see, there was emacs vs. xemacs, " +
37 "KDE vs. Gnome, and Tcl vs. Guile";
39 String s2 = "Operating systems I have known include: solaris, sco, " +
40 "hp-ux, linux, freebsd, winblows, os400, mvs, tpf, its, multics";
42 //File f = File.createTempFile("fostest", new File("/tmp"));
43 File f = new File("/tmp/000001");
44 FileWriter fw = new FileWriter(f.getPath());
46 char buf[] = new char[s1.length()];
47 s1.getChars(0, s1.length(), buf, 0);
48 fw.write(buf, 0, 32);
49 fw.write(buf, 32, s1.getBytes().length - 32);
50 fw.close();
52 fw = new FileWriter(f.getPath(), true);
53 buf = new char[s2.length()];
54 s2.getChars(0, s2.length(), buf, 0);
55 fw.write(buf);
56 fw.close();
58 if (f.length() != (s1.length() + s2.length()))
59 throw new IOException("Incorrect number of chars written");
61 f.delete();
63 System.out.println("PASSED: File Write Test");
65 catch(IOException e)
67 System.out.println("FAILED: File Write Test: " + e);
70 System.out.println("Test 2: Permission Denied Test");
71 try
73 FileWriter fw = new FileWriter("/etc/newtempfile");
74 System.out.println("FAILED: Permission Denied Test");
76 catch (IOException e)
78 System.out.println("PASSED: Permission Denied Test: " + e);
81 System.out.println("Finished test of FileWriter");
84 } // class FileWriter