jdk/test/sun/tools/native2ascii/NativeErrors.java
author malenkov
Fri, 16 May 2014 15:51:57 +0400
changeset 25088 8d4b058368f0
parent 22980 19675dcb8ec9
child 24707 f1225d0f947c
permissions -rw-r--r--
8043152: KSS: javax.swing.plaf.synth.SynthContext Reviewed-by: alexsch, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
     2
 * Copyright (c) 1998, 1999, 2014 Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4319
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4319
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4319
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4136352
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    27
 * @library /lib/testlibrary
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Test Native2ASCII error messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    32
import java.io.File;
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    33
import java.util.ResourceBundle;
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    34
import java.util.MissingResourceException;
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    35
import jdk.testlibrary.OutputAnalyzer;
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    36
import jdk.testlibrary.JDKToolLauncher;
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    37
import jdk.testlibrary.ProcessTools;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class NativeErrors {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private static ResourceBundle rsrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
            rsrc = ResourceBundle.getBundle(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                     "sun.tools.native2ascii.resources.MsgNative2ascii");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        } catch (MissingResourceException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            throw new Error("Missing message file.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    52
    public static void main(String args[]) throws Throwable {
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    53
        // Execute command in another vm. Verify stdout for expected err msg.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    55
        // Test with no input file given.
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    56
        checkResult(executeCmd("-encoding"), "err.bad.arg");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
4319
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    58
        File f0 = new File(System.getProperty("test.src", "."), "test123");
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    59
        String path0 = f0.getPath();
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    60
        if ( f0.exists() ) {
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    61
            throw new Error("Input file should not exist: " + path0);
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    62
        }
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    63
        checkResult(executeCmd(path0), "err.cannot.read");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        File f1 = new File(System.getProperty("test.src", "."), "test1");
4319
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    66
        File f2 = File.createTempFile("test2", ".tmp");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        String path1 = f1.getPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        String path2 = f2.getPath();
4319
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    69
        if ( !f1.exists() ) {
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    70
            throw new Error("Missing input file: " + path1);
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    71
        }
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    72
        if ( !f2.setWritable(false) ) {
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    73
            throw new Error("Output file cannot be made read only: " + path2);
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    74
        }
47bb128ae7b3 6902323: Fix testcase sun/tools/native2ascii/NativeErrors.java
ohair
parents: 2
diff changeset
    75
        f2.deleteOnExit();
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    76
        checkResult(executeCmd(path1, path2), "err.cannot.write");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    79
    private static String executeCmd(String... toolArgs) throws Throwable {
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    80
        JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    81
        for (String s : toolArgs) {
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    82
            cmd.addToolArg(s);
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    83
        }
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    84
        OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    85
        if (output == null || output.getStdout() == null) {
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    86
            throw new Exception("Output was null. Process did not finish correctly.");
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    87
        }
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    88
        if (output.getExitValue() == 0) {
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    89
            throw new Exception("Process exit code was 0, but error was expected.");
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    90
        }
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    91
        return output.getStdout();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    94
    private static void checkResult(
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    95
            String errorReceived, String errorKey) throws Exception {
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    96
        String errorExpected = rsrc.getString(errorKey);
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    97
        if (errorExpected == null) {
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
    98
            throw new Exception("No error message for key: " + errorKey);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
22980
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
   100
        // Remove template tag from error message.
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
   101
        errorExpected = errorExpected.replaceAll("\\{0\\}", "");
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
   102
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
   103
        System.out.println("received: " + errorReceived);
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
   104
        System.out.println("expected: " + errorExpected);
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
   105
        if (errorReceived.indexOf(errorExpected) < 0) {
19675dcb8ec9 6545422: [TESTBUG] NativeErrors.java uses wrong path name in exec
sla
parents: 5506
diff changeset
   106
            throw new RuntimeException("Native2ascii bad arg error broken.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
}