1 /*************************************************************************
2 /* FileWriterTest.java -- Test of FileWriter and OutputStreamWriter classes
4 /* Copyright (c) 1998 Free Software Foundation, Inc.
5 /* Written by Aaron M. Renn (arenn@urbanophile.com)
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 /*************************************************************************/
24 public class FileWriterTest
30 System
.out
.println("Starting test of FileWriter and OutputStreamWriter");
32 System
.out
.println("Test 1: File Write Test");
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);
49 fw
.write(buf
, 32, s1
.getBytes().length
- 32);
52 fw
= new FileWriter(f
.getPath(), true);
53 buf
= new char[s2
.length()];
54 s2
.getChars(0, s2
.length(), buf
, 0);
58 if (f
.length() != (s1
.length() + s2
.length()))
59 throw new IOException("Incorrect number of chars written");
63 System
.out
.println("PASSED: File Write Test");
67 System
.out
.println("FAILED: File Write Test: " + e
);
70 System
.out
.println("Test 2: Permission Denied Test");
73 FileWriter fw
= new FileWriter("/etc/newtempfile");
74 System
.out
.println("FAILED: Permission Denied Test");
78 System
.out
.println("PASSED: Permission Denied Test: " + e
);
81 System
.out
.println("Finished test of FileWriter");