author | dholmes |
Wed, 06 Nov 2019 21:18:42 -0500 | |
changeset 58956 | 9a0a5e70eeb2 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
41378
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
1 |
/* |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
4 |
* |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
8 |
* |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
13 |
* accompanied this code). |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
14 |
* |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
18 |
* |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
21 |
* questions. |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
22 |
*/ |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
23 |
|
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
24 |
import java.io.File; |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
25 |
import java.io.FilePermission; |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
26 |
import java.util.Arrays; |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
27 |
import java.util.List; |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
28 |
|
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
29 |
/* |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
30 |
* @test |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
31 |
* @bug 8156054 |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
32 |
* @summary Test some of FilePermission methods when canonicalization property |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
33 |
* set and un-set. |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
34 |
* @run main/othervm -Djdk.io.permissionsUseCanonicalPath=true |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
35 |
* FilePermissionTest truetruetruetruetruetrue |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
36 |
* @run main/othervm -Djdk.io.permissionsUseCanonicalPath=false |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
37 |
* FilePermissionTest falsefalsefalsefalsefalsefalse |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
38 |
* @run main FilePermissionTest falsefalsefalsefalsefalsefalse |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
39 |
*/ |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
40 |
public class FilePermissionTest { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
41 |
|
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
42 |
public static void main(String[] args) throws Exception { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
43 |
|
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
44 |
final File realFile = new File("exist.file"); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
45 |
try { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
46 |
if (!realFile.createNewFile()) { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
47 |
throw new RuntimeException("Unable to create a file."); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
48 |
} |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
49 |
check(Arrays.asList(realFile.getName(), "notexist.file"), args[0]); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
50 |
} finally { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
51 |
if (realFile.exists()) { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
52 |
realFile.delete(); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
53 |
} |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
54 |
} |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
55 |
} |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
56 |
|
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
57 |
private static void check(List<String> files, String expected) { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
58 |
|
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
59 |
StringBuilder actual = new StringBuilder(); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
60 |
files.forEach(f -> { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
61 |
StringBuilder result = new StringBuilder(); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
62 |
FilePermission fp1 = new FilePermission(f, "read"); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
63 |
FilePermission fp2 = new FilePermission( |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
64 |
new File(f).getAbsolutePath(), "read"); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
65 |
result.append(fp1.equals(fp2)); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
66 |
result.append(fp1.implies(fp2)); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
67 |
result.append(fp1.hashCode() == fp2.hashCode()); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
68 |
System.out.println(fp1 + " Vs. " + fp2 + " : Result: " + result); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
69 |
actual.append(result); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
70 |
}); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
71 |
if (!expected.equals(actual.toString())) { |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
72 |
throw new RuntimeException("Failed: " + expected + "/" + actual); |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
73 |
} |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
74 |
} |
62969f0fb9c5
8156054: Test Task: Develop new tests for JEP C155: Remove FilePermission Pathname Canonicalization
ssahoo
parents:
diff
changeset
|
75 |
} |