author | malenkov |
Fri, 16 May 2014 15:51:57 +0400 | |
changeset 25088 | 8d4b058368f0 |
parent 22980 | 19675dcb8ec9 |
child 24707 | f1225d0f947c |
permissions | -rw-r--r-- |
2 | 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 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
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 | 28 |
* @summary Test Native2ASCII error messages |
29 |
* |
|
30 |
*/ |
|
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 | 38 |
|
39 |
public class NativeErrors { |
|
40 |
||
41 |
private static ResourceBundle rsrc; |
|
42 |
||
43 |
static { |
|
44 |
try { |
|
45 |
rsrc = ResourceBundle.getBundle( |
|
46 |
"sun.tools.native2ascii.resources.MsgNative2ascii"); |
|
47 |
} catch (MissingResourceException e) { |
|
48 |
throw new Error("Missing message file."); |
|
49 |
} |
|
50 |
} |
|
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 | 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 | 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 | 64 |
|
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 | 67 |
String path1 = f1.getPath(); |
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 | 77 |
} |
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 | 92 |
} |
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 | 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 | 107 |
} |
108 |
} |
|
109 |
||
110 |
} |