1 /* 2 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* @test 25 @bug 4614121 4809375 6437591 26 @summary Basic test for deleteOnExit method 27 @author kladko 28 */ 29 30 31 import java.io.File; 32 33 public class DeleteOnExit { 34 35 static String tmpdir = System.getProperty("java.io.tmpdir"); 36 static String java = System.getProperty("java.home") + File.separator + 37 "bin" + File.separator + "java"; 38 static File file1 = new File(tmpdir + "deletedOnExit1"); 39 static File file2 = new File(tmpdir + "deletedOnExit2"); 40 static File file3 = new File(tmpdir + "deletedOnExit3"); 41 42 // used to verify deletion order 43 static File dir = new File(tmpdir + "deletedOnExitDir"); 44 static File file4 = new File(dir + File.separator + "deletedOnExit4"); 45 static File file5 = new File(dir + File.separator + "dxnsdnguidfgejngognrogn"); 46 static File file6 = new File(dir + File.separator + "mmmmmmsdmfgmdsmfgmdsfgm"); 47 static File file7 = new File(dir + File.separator + "12345566777"); 48 49 public static void main (String args[]) throws Exception{ 50 if (args.length == 0) { 51 String cmd = java + " -classpath " + System.getProperty("test.classes") 52 + " DeleteOnExit -test"; 53 Runtime.getRuntime().exec(cmd).waitFor(); 54 if (file1.exists() || file2.exists() || file3.exists() || 55 dir.exists() || file4.exists() || file5.exists() || 56 file6.exists() || file7.exists()) { 57 58 System.out.println(file1 + ", exists = " + file1.exists()); 59 System.out.println(file2 + ", exists = " + file2.exists()); 60 System.out.println(file3 + ", exists = " + file3.exists()); 61 System.out.println(dir + ", exists = " + dir.exists()); 62 System.out.println(file4 + ", exists = " + file4.exists()); 63 System.out.println(file5 + ", exists = " + file5.exists()); 64 System.out.println(file6 + ", exists = " + file6.exists()); 65 System.out.println(file7 + ", exists = " + file7.exists()); 66 67 // cleanup undeleted dir if test fails 68 dir.delete(); 69 70 throw new Exception("File exists"); 71 } 72 } else { 73 file1.createNewFile(); 74 file2.createNewFile(); 75 file3.createNewFile(); 76 file1.deleteOnExit(); 77 file2.deleteOnExit(); 78 file3.deleteOnExit(); 79 80 // verify that deleting a File marked deleteOnExit will not cause a problem 81 // during shutdown. 82 file3.delete(); 83 84 // verify that calling deleteOnExit multiple times on a File does not cause 85 // a problem during shutdown. 86 file2.deleteOnExit(); 87 file2.deleteOnExit(); 88 file2.deleteOnExit(); 89 90 // Verify DeleteOnExit Internal implementation deletion order. 91 if (dir.mkdir()) { 92 dir.deleteOnExit(); 93 94 file4.createNewFile(); 95 file5.createNewFile(); 96 file6.createNewFile(); 97 file7.createNewFile(); 98 99 file4.deleteOnExit(); 100 file5.deleteOnExit(); 101 file6.deleteOnExit(); 102 file7.deleteOnExit(); 103 } 104 } 105 } 106 }