提交 6b169fd5 编写于 作者: A asaha

Merge

...@@ -307,6 +307,7 @@ d723d05cd17afd5c4dd4293bcba83fef44a3c0bb jdk8u20-b16 ...@@ -307,6 +307,7 @@ d723d05cd17afd5c4dd4293bcba83fef44a3c0bb jdk8u20-b16
38548d32c91cfa57b1d31eec0a5e79c936e86f11 jdk8u20-b19 38548d32c91cfa57b1d31eec0a5e79c936e86f11 jdk8u20-b19
5c0406ee9e820140b5322db006baed199c165b4f jdk8u20-b20 5c0406ee9e820140b5322db006baed199c165b4f jdk8u20-b20
693025bbc45d683676fa78bb76201b665e0d8f2d jdk8u20-b21 693025bbc45d683676fa78bb76201b665e0d8f2d jdk8u20-b21
0c2393744b29175de5204140d4dfbf12ca3d364f jdk8u20-b22
abca9f6f1a10e9f91b2538bbe7870f54f550d986 jdk8u25-b00 abca9f6f1a10e9f91b2538bbe7870f54f550d986 jdk8u25-b00
7d0627679c9fdeaaaa9fe15c7cc11af0763621ec jdk8u25-b01 7d0627679c9fdeaaaa9fe15c7cc11af0763621ec jdk8u25-b01
b0277ec994b751ebb761814675352506cd56bcd6 jdk8u25-b02 b0277ec994b751ebb761814675352506cd56bcd6 jdk8u25-b02
......
/* /*
* Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,12 +25,18 @@ ...@@ -25,12 +25,18 @@
* @test * @test
* @bug 4136352 * @bug 4136352
* @summary Test Native2ASCII error messages * @summary Test Native2ASCII error messages
* * @library /lib/testlibrary
* @build jdk.testlibrary.* NativeErrors
* @run main NativeErrors
*/ */
import java.io.*;
import sun.tools.native2ascii.*; import java.io.File;
import java.util.*; import java.util.ResourceBundle;
import java.util.MissingResourceException;
import jdk.testlibrary.OutputAnalyzer;
import jdk.testlibrary.JDKToolLauncher;
import jdk.testlibrary.ProcessTools;
public class NativeErrors { public class NativeErrors {
...@@ -45,30 +51,18 @@ public class NativeErrors { ...@@ -45,30 +51,18 @@ public class NativeErrors {
} }
} }
public static void main(String args[]) throws Exception { public static void main(String args[]) throws Throwable {
String[] command; // Execute command in another vm. Verify stdout for expected err msg.
Process p = null;
BufferedReader in = null;
// Construct a command that runs the test in other vm // Test with no input file given.
// Exec another vm to run test in checkResult(executeCmd("-encoding"), "err.bad.arg");
// Read the result to determine if test failed
command = getComString("-encoding");
p = Runtime.getRuntime().exec(command);
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
checkResult(in, "err.bad.arg");
File f0 = new File(System.getProperty("test.src", "."), "test123"); File f0 = new File(System.getProperty("test.src", "."), "test123");
String path0 = f0.getPath(); String path0 = f0.getPath();
if ( f0.exists() ) { if ( f0.exists() ) {
throw new Error("Input file should not exist: " + path0); throw new Error("Input file should not exist: " + path0);
} }
checkResult(executeCmd(path0), "err.cannot.read");
command = getComString(path0);
p = Runtime.getRuntime().exec(command);
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
checkResult(in, "err.cannot.read");
File f1 = new File(System.getProperty("test.src", "."), "test1"); File f1 = new File(System.getProperty("test.src", "."), "test1");
File f2 = File.createTempFile("test2", ".tmp"); File f2 = File.createTempFile("test2", ".tmp");
...@@ -81,71 +75,38 @@ public class NativeErrors { ...@@ -81,71 +75,38 @@ public class NativeErrors {
throw new Error("Output file cannot be made read only: " + path2); throw new Error("Output file cannot be made read only: " + path2);
} }
f2.deleteOnExit(); f2.deleteOnExit();
checkResult(executeCmd(path1, path2), "err.cannot.write");
command = getComString(path1, path2);
p = Runtime.getRuntime().exec(command);
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
checkResult(in, "err.cannot.write");
} }
private static String executeCmd(String... toolArgs) throws Throwable {
private static void checkResult(BufferedReader in, String errorExpected) JDKToolLauncher cmd = JDKToolLauncher.createUsingTestJDK("native2ascii");
throws Exception { for (String s : toolArgs) {
String errorReceived; cmd.addToolArg(s);
errorReceived = in.readLine();
assert errorReceived != null : "First readline cannot be null";
errorExpected = rsrc.getString(errorExpected);
assert errorExpected != null : "Expected message cannot be null";
StringBuffer error = new StringBuffer(errorExpected);
int start = errorExpected.indexOf("{0}");
if (start >= 0) {
error.delete(start, start+3);
errorExpected = error.toString();
} }
//System.out.println("received: " + errorReceived); OutputAnalyzer output = ProcessTools.executeProcess(cmd.getCommand());
//System.out.println("expected: " + errorExpected); if (output == null || output.getStdout() == null) {
if (!errorReceived.endsWith(errorExpected)) throw new Exception("Output was null. Process did not finish correctly.");
throw new RuntimeException("Native2ascii bad arg error broken.");
} }
if (output.getExitValue() == 0) {
private static String[] getComString(String arg2) { throw new Exception("Process exit code was 0, but error was expected.");
String[] coms = new String[2];
coms[0] = getPathString();
coms[1] = arg2;
return coms;
} }
return output.getStdout();
private static String[] getComString(String arg2, String arg3) {
String[] coms = new String[3];
coms[0] = getPathString();
coms[1] = arg2;
coms[2] = arg3;
return coms;
} }
/* private static void checkResult(
* Search for path to native2ascii String errorReceived, String errorKey) throws Exception {
*/ String errorExpected = rsrc.getString(errorKey);
private static String getPathString() { if (errorExpected == null) {
String path = System.getProperty("java.home") + File.separator + throw new Exception("No error message for key: " + errorKey);
"bin" + File.separator + "native2ascii";
if (File.separatorChar == '\\') {
path = path + ".exe";
} }
File f = new File(path); // Remove template tag from error message.
if (!f.exists()) { errorExpected = errorExpected.replaceAll("\\{0\\}", "");
System.out.println("Cannot find native2ascii at "+path);
path = System.getProperty("java.home") + File.separator + ".." + System.out.println("received: " + errorReceived);
File.separator + "bin" + File.separator + "native2ascii"; System.out.println("expected: " + errorExpected);
if (File.separatorChar == '\\') { if (errorReceived.indexOf(errorExpected) < 0) {
path = path + ".exe"; throw new RuntimeException("Native2ascii bad arg error broken.");
}
f = new File(path);
if (!f.exists())
throw new RuntimeException("Cannot find native2ascii at "+path);
System.out.println("Using native2ascii at "+path);
} }
return path;
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册