5121N/A/*
5121N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
5121N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5121N/A *
5121N/A * This code is free software; you can redistribute it and/or modify it
5121N/A * under the terms of the GNU General Public License version 2 only, as
5121N/A * published by the Free Software Foundation.
5121N/A *
5121N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5121N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5121N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5121N/A * version 2 for more details (a copy is included in the LICENSE file that
5121N/A * accompanied this code).
5121N/A *
5121N/A * You should have received a copy of the GNU General Public License version
5121N/A * 2 along with this work; if not, write to the Free Software Foundation,
5121N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5121N/A *
5121N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5121N/A * or visit www.oracle.com if you need additional information or have any
5121N/A * questions.
5121N/A */
5121N/A
5121N/A/**
5121N/A * @test
5121N/A * @bug 7177216
5121N/A * @summary resulting file of native2ascii should have normal permission
5121N/A */
5121N/A
5121N/Aimport java.io.*;
5121N/Aimport java.nio.file.*;
5121N/Aimport java.nio.file.attribute.*;
5121N/Aimport sun.tools.native2ascii.Main;
5121N/A
5121N/Apublic class Permission {
5121N/A
5121N/A private static void cleanup(String... fnames) throws Throwable {
5121N/A for (String fname : fnames) {
5121N/A Files.deleteIfExists(Paths.get(fname));
5121N/A }
5121N/A }
5121N/A
5121N/A public static void realMain(String[] args) throws Throwable {
5121N/A if (!System.getProperty("os.name").startsWith("Windows")) {
5121N/A String src = "native2ascii_permtest_src";
5121N/A String dst = "native2ascii_permtest_dst";
5121N/A
5121N/A cleanup(src, dst);
5121N/A try {
5121N/A try (FileOutputStream fos = new FileOutputStream(src)) {
5121N/A fos.write('a'); fos.write('b'); fos.write('c');
5121N/A }
5121N/A String[] n2aArgs = new String[] {"-encoding", "utf8", src, dst};
5121N/A if (!new Main().convert(n2aArgs)) {
5121N/A fail("n2a failed.");
5121N/A }
5121N/A equal(Files.getPosixFilePermissions(Paths.get(src)),
5121N/A Files.getPosixFilePermissions(Paths.get(dst)));
5121N/A String[] a2nArgs = new String[] {"-reverse", "-encoding", "utf8", dst, src};
5121N/A if (!new Main().convert(a2nArgs)) {
5121N/A fail("a2n failed.");
5121N/A }
5121N/A equal(Files.getPosixFilePermissions(Paths.get(src)),
5121N/A Files.getPosixFilePermissions(Paths.get(dst)));
5121N/A } finally {
5121N/A cleanup(src, dst);
5121N/A }
5121N/A }
5121N/A }
5121N/A
5121N/A //--------------------- Infrastructure ---------------------------
5121N/A static volatile int passed = 0, failed = 0;
5121N/A static void pass() {passed++;}
5121N/A static void fail() {failed++; Thread.dumpStack();}
5121N/A static void fail(String msg) {System.out.println(msg); fail();}
5121N/A static void unexpected(Throwable t) {failed++; t.printStackTrace();}
5121N/A static void check(boolean cond) {if (cond) pass(); else fail();}
5121N/A static void equal(Object x, Object y) {
5121N/A if (x == null ? y == null : x.equals(y)) pass();
5121N/A else fail(x + " not equal to " + y);}
5121N/A public static void main(String[] args) throws Throwable {
5121N/A try {realMain(args);} catch (Throwable t) {unexpected(t);}
5121N/A System.out.println("\nPassed = " + passed + " failed = " + failed);
5121N/A if (failed > 0) throw new AssertionError("Some tests failed");}
5121N/A}