PR target/27599
[official-gcc.git] / libjava / classpath / test / java.io / FileOutputStreamTest.java
blob1917f4e3b228186ed16bb0cf373aed41ea8a8575
1 /*************************************************************************
2 /* FileOutputStreamTest.java -- Test of FileOutputStream class
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 FileOutputStreamTest
27 public static void
28 main(String[] argv)
30 System.out.println("Starting test of FileOutputStream");
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/000000");
44 FileOutputStream fos = new FileOutputStream(f.getPath());
46 fos.write(s1.getBytes(), 0, 32);
47 fos.write(s1.getBytes(), 32, s1.getBytes().length - 32);
48 fos.close();
50 fos = new FileOutputStream(f.getPath(), true);
51 fos.write(s2.getBytes());
52 fos.close();
54 if (f.length() != (s1.length() + s2.length()))
55 throw new IOException("Incorrect number of bytes written");
57 f.delete();
59 System.out.println("PASSED: File Write Test");
61 catch(IOException e)
63 System.out.println("FAILED: File Write Test: " + e);
66 System.out.println("Test 2: Permission Denied Test");
67 try
69 FileOutputStream fos = new FileOutputStream("/etc/newtempfile");
70 System.out.println("FAILED: Permission Denied Test");
72 catch (IOException e)
74 System.out.println("PASSED: Permission Denied Test: " + e);
77 System.out.println("Finished test of FileOutputStream");
80 } // class FileOutputStreamTest