DeleteOnExit.java revision 2362
0N/A/*
2362N/A * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/* @test
0N/A @bug 4614121 4809375 6437591
0N/A @summary Basic test for deleteOnExit method
0N/A @author kladko
0N/A */
0N/A
0N/A
0N/Aimport java.io.File;
0N/A
0N/Apublic class DeleteOnExit {
0N/A
0N/A static String tmpdir = System.getProperty("java.io.tmpdir");
0N/A static String java = System.getProperty("java.home") + File.separator +
0N/A "bin" + File.separator + "java";
0N/A static File file1 = new File(tmpdir + "deletedOnExit1");
0N/A static File file2 = new File(tmpdir + "deletedOnExit2");
0N/A static File file3 = new File(tmpdir + "deletedOnExit3");
0N/A
0N/A // used to verify deletion order
0N/A static File dir = new File(tmpdir + "deletedOnExitDir");
0N/A static File file4 = new File(dir + File.separator + "deletedOnExit4");
0N/A static File file5 = new File(dir + File.separator + "dxnsdnguidfgejngognrogn");
0N/A static File file6 = new File(dir + File.separator + "mmmmmmsdmfgmdsmfgmdsfgm");
0N/A static File file7 = new File(dir + File.separator + "12345566777");
0N/A
0N/A public static void main (String args[]) throws Exception{
0N/A if (args.length == 0) {
0N/A Runtime.getRuntime().exec(java + " DeleteOnExit -test").waitFor();
0N/A if (file1.exists() || file2.exists() || file3.exists() ||
0N/A dir.exists() || file4.exists() || file5.exists() ||
0N/A file6.exists() || file7.exists()) {
0N/A
0N/A System.out.println(file1 + ", exists = " + file1.exists());
0N/A System.out.println(file2 + ", exists = " + file2.exists());
0N/A System.out.println(file3 + ", exists = " + file3.exists());
0N/A System.out.println(dir + ", exists = " + dir.exists());
0N/A System.out.println(file4 + ", exists = " + file4.exists());
0N/A System.out.println(file5 + ", exists = " + file5.exists());
0N/A System.out.println(file6 + ", exists = " + file6.exists());
0N/A System.out.println(file7 + ", exists = " + file7.exists());
0N/A
0N/A // cleanup undeleted dir if test fails
0N/A dir.delete();
0N/A
0N/A throw new Exception("File exists");
0N/A }
0N/A } else {
0N/A file1.createNewFile();
0N/A file2.createNewFile();
0N/A file3.createNewFile();
0N/A file1.deleteOnExit();
0N/A file2.deleteOnExit();
0N/A file3.deleteOnExit();
0N/A
0N/A // verify that deleting a File marked deleteOnExit will not cause a problem
0N/A // during shutdown.
0N/A file3.delete();
0N/A
0N/A // verify that calling deleteOnExit multiple times on a File does not cause
0N/A // a problem during shutdown.
0N/A file2.deleteOnExit();
0N/A file2.deleteOnExit();
0N/A file2.deleteOnExit();
0N/A
0N/A // Verify DeleteOnExit Internal implementation deletion order.
0N/A if (dir.mkdir()) {
0N/A dir.deleteOnExit();
0N/A
0N/A file4.createNewFile();
0N/A file5.createNewFile();
0N/A file6.createNewFile();
0N/A file7.createNewFile();
0N/A
0N/A file4.deleteOnExit();
0N/A file5.deleteOnExit();
0N/A file6.deleteOnExit();
0N/A file7.deleteOnExit();
0N/A }
0N/A }
0N/A }
0N/A}