Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/FilePermission/FilePermissionTest.java
41149 views
1
/*
2
* Copyright (c) 2016, 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
import java.io.File;
25
import java.io.FilePermission;
26
import java.util.Arrays;
27
import java.util.List;
28
29
/*
30
* @test
31
* @bug 8156054
32
* @summary Test some of FilePermission methods when canonicalization property
33
* set and un-set.
34
* @run main/othervm -Djdk.io.permissionsUseCanonicalPath=true
35
* FilePermissionTest truetruetruetruetruetrue
36
* @run main/othervm -Djdk.io.permissionsUseCanonicalPath=false
37
* FilePermissionTest falsefalsefalsefalsefalsefalse
38
* @run main FilePermissionTest falsefalsefalsefalsefalsefalse
39
*/
40
public class FilePermissionTest {
41
42
public static void main(String[] args) throws Exception {
43
44
final File realFile = new File("exist.file");
45
try {
46
if (!realFile.createNewFile()) {
47
throw new RuntimeException("Unable to create a file.");
48
}
49
check(Arrays.asList(realFile.getName(), "notexist.file"), args[0]);
50
} finally {
51
if (realFile.exists()) {
52
realFile.delete();
53
}
54
}
55
}
56
57
private static void check(List<String> files, String expected) {
58
59
StringBuilder actual = new StringBuilder();
60
files.forEach(f -> {
61
StringBuilder result = new StringBuilder();
62
FilePermission fp1 = new FilePermission(f, "read");
63
FilePermission fp2 = new FilePermission(
64
new File(f).getAbsolutePath(), "read");
65
result.append(fp1.equals(fp2));
66
result.append(fp1.implies(fp2));
67
result.append(fp1.hashCode() == fp2.hashCode());
68
System.out.println(fp1 + " Vs. " + fp2 + " : Result: " + result);
69
actual.append(result);
70
});
71
if (!expected.equals(actual.toString())) {
72
throw new RuntimeException("Failed: " + expected + "/" + actual);
73
}
74
}
75
}
76
77