Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/tools/native2ascii/Permission.java
38840 views
1
/*
2
* Copyright (c) 2012, 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
/**
25
* @test
26
* @bug 7177216
27
* @summary resulting file of native2ascii should have normal permission
28
*/
29
30
import java.io.*;
31
import java.nio.file.*;
32
import java.nio.file.attribute.*;
33
import sun.tools.native2ascii.Main;
34
35
public class Permission {
36
37
private static void cleanup(String... fnames) throws Throwable {
38
for (String fname : fnames) {
39
Files.deleteIfExists(Paths.get(fname));
40
}
41
}
42
43
public static void realMain(String[] args) throws Throwable {
44
if (!System.getProperty("os.name").startsWith("Windows")) {
45
String src = "native2ascii_permtest_src";
46
String dst = "native2ascii_permtest_dst";
47
48
cleanup(src, dst);
49
try {
50
try (FileOutputStream fos = new FileOutputStream(src)) {
51
fos.write('a'); fos.write('b'); fos.write('c');
52
}
53
String[] n2aArgs = new String[] {"-encoding", "utf8", src, dst};
54
if (!new Main().convert(n2aArgs)) {
55
fail("n2a failed.");
56
}
57
equal(Files.getPosixFilePermissions(Paths.get(src)),
58
Files.getPosixFilePermissions(Paths.get(dst)));
59
String[] a2nArgs = new String[] {"-reverse", "-encoding", "utf8", dst, src};
60
if (!new Main().convert(a2nArgs)) {
61
fail("a2n failed.");
62
}
63
equal(Files.getPosixFilePermissions(Paths.get(src)),
64
Files.getPosixFilePermissions(Paths.get(dst)));
65
} finally {
66
cleanup(src, dst);
67
}
68
}
69
}
70
71
//--------------------- Infrastructure ---------------------------
72
static volatile int passed = 0, failed = 0;
73
static void pass() {passed++;}
74
static void fail() {failed++; Thread.dumpStack();}
75
static void fail(String msg) {System.out.println(msg); fail();}
76
static void unexpected(Throwable t) {failed++; t.printStackTrace();}
77
static void check(boolean cond) {if (cond) pass(); else fail();}
78
static void equal(Object x, Object y) {
79
if (x == null ? y == null : x.equals(y)) pass();
80
else fail(x + " not equal to " + y);}
81
public static void main(String[] args) throws Throwable {
82
try {realMain(args);} catch (Throwable t) {unexpected(t);}
83
System.out.println("\nPassed = " + passed + " failed = " + failed);
84
if (failed > 0) throw new AssertionError("Some tests failed");}
85
}
86
87