jdk/test/sun/tools/native2ascii/Permission.java
author stefank
Mon, 25 Aug 2014 09:10:13 +0200
changeset 26314 f8bc1966fb30
parent 13154 9e8a04d28ded
permissions -rw-r--r--
8055416: Several vm/gc/heap/summary "After GC" events emitted for the same GC ID Reviewed-by: brutisso, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13154
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     1
/*
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     4
 *
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     8
 *
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    13
 * accompanied this code).
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    14
 *
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    18
 *
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    21
 * questions.
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    22
 */
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    23
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    24
/**
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    25
 * @test
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    26
 * @bug 7177216
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    27
 * @summary resulting file of native2ascii should have normal permission
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    28
 */
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    29
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    30
import java.io.*;
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    31
import java.nio.file.*;
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    32
import java.nio.file.attribute.*;
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    33
import sun.tools.native2ascii.Main;
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    34
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    35
public class Permission {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    36
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    37
    private static void cleanup(String... fnames) throws Throwable {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    38
        for (String fname : fnames) {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    39
            Files.deleteIfExists(Paths.get(fname));
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    40
        }
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    41
    }
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    42
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    43
    public static void realMain(String[] args) throws Throwable {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    44
        if (!System.getProperty("os.name").startsWith("Windows")) {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    45
            String src = "native2ascii_permtest_src";
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    46
            String dst = "native2ascii_permtest_dst";
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    47
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    48
            cleanup(src, dst);
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    49
            try {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    50
                try (FileOutputStream fos = new FileOutputStream(src)) {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    51
                    fos.write('a'); fos.write('b'); fos.write('c');
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    52
                }
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    53
                String[] n2aArgs = new String[] {"-encoding", "utf8", src, dst};
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    54
                if (!new Main().convert(n2aArgs)) {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    55
                    fail("n2a failed.");
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    56
                }
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    57
                equal(Files.getPosixFilePermissions(Paths.get(src)),
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    58
                      Files.getPosixFilePermissions(Paths.get(dst)));
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    59
                String[] a2nArgs = new String[] {"-reverse", "-encoding", "utf8", dst, src};
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    60
                if (!new Main().convert(a2nArgs)) {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    61
                    fail("a2n failed.");
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    62
                }
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    63
                equal(Files.getPosixFilePermissions(Paths.get(src)),
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    64
                      Files.getPosixFilePermissions(Paths.get(dst)));
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    65
            } finally {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    66
                cleanup(src, dst);
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    67
            }
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    68
        }
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    69
    }
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    70
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    71
    //--------------------- Infrastructure ---------------------------
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    72
    static volatile int passed = 0, failed = 0;
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    73
    static void pass() {passed++;}
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    74
    static void fail() {failed++; Thread.dumpStack();}
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    75
    static void fail(String msg) {System.out.println(msg); fail();}
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    76
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    77
    static void check(boolean cond) {if (cond) pass(); else fail();}
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    78
    static void equal(Object x, Object y) {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    79
        if (x == null ? y == null : x.equals(y)) pass();
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    80
        else fail(x + " not equal to " + y);}
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    81
    public static void main(String[] args) throws Throwable {
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    82
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    83
        System.out.println("\nPassed = " + passed + " failed = " + failed);
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    84
        if (failed > 0) throw new AssertionError("Some tests failed");}
9e8a04d28ded 7175845: jar uf changes file permissions unexpectedly
sherman
parents:
diff changeset
    85
}