提交 ceb1b2e1 编写于 作者: D dwanvik

Merge

......@@ -409,23 +409,26 @@ public class FileHandler extends StreamHandler {
// Try the next file.
continue;
}
boolean available;
try {
FileLock fl = fc.tryLock();
if (fl == null) {
// We failed to get the lock. Try next file.
continue;
}
available = fc.tryLock() != null;
// We got the lock OK.
} catch (IOException ix) {
// We got an IOException while trying to get the lock.
// This normally indicates that locking is not supported
// on the target directory. We have to proceed without
// getting a lock. Drop through.
available = true;
}
if (available) {
// We got the lock. Remember it.
locks.put(lockFileName, lockFileName);
break;
}
// We failed to get the lock. Try next file.
fc.close();
}
}
files = new File[count];
......
......@@ -288,12 +288,6 @@ javax/management/monitor/AttributeArbitraryDataTypeTest.java generic-all
# jdk_math
# Problems with rounding add failures on solaris-sparcv9 and -server
java/math/BigDecimal/AddTests.java solaris-sparcv9
# Should be samevm? But seems problematic with samevm on windows
java/math/BigInteger/ModPow65537.java generic-all
############################################################################
# jdk_misc
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -25,6 +25,8 @@
* @test
* @bug 6274390
* @summary Verify {float, double}Value methods work with condensed representation
* @run main FloatDoubleValueTests
* @run main/othervm -XX:+AggressiveOpts FloatDoubleValueTests
*/
import java.math.*;
......@@ -64,6 +66,7 @@ public class FloatDoubleValueTests {
static void checkDouble(BigDecimal bd, double d) {
double dbd = bd.doubleValue();
if (d != dbd ) {
String message = String.format("Bad conversion:"+
"got %g (%a)\texpected %g (%a)",
......@@ -156,9 +159,29 @@ public class FloatDoubleValueTests {
}
}
static void testFloatValue1() {
checkFloat(new BigDecimal("85070591730234615847396907784232501249"), 8.507059e+37f);
checkFloat(new BigDecimal("7784232501249e12"), 7.7842326e24f);
checkFloat(new BigDecimal("907784232501249e-12"),907.78424f);
checkFloat(new BigDecimal("7784e8"),7.7839997e11f);
checkFloat(new BigDecimal("9077e-8"),9.077e-5f);
}
static void testDoubleValue1() {
checkDouble(new BigDecimal("85070591730234615847396907784232501249"), 8.507059173023462e37);
checkDouble(new BigDecimal("7784232501249e12"), 7.784232501249e24);
checkDouble(new BigDecimal("907784232501249e-12"), 907.784232501249);
checkDouble(new BigDecimal("7784e8"), 7.784e11);
checkDouble(new BigDecimal("9077e-8"), 9.077e-5);
}
public static void main(String[] args) throws Exception {
testFloatDoubleValue();
testDoubleValue();
testFloatValue();
testFloatValue1();
testDoubleValue1();
}
}
/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7036582
* @summary Some new tests for the add method and constructor with MathContext.
* @run main RangeTests
* @run main/othervm -XX:+AggressiveOpts RangeTests
* @author Sergey V. Kuksenko
*/
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
public class RangeTests {
private static int addTest(BigDecimal arg1, BigDecimal arg2, BigDecimal expectedResult) {
int failures = 0;
BigDecimal result = arg1.add(arg2);
if (!result.equals(expectedResult)) {
System.out.println("Sum:" +
arg1 + " + " +
arg2 + " == " +
result + "; expected " +
expectedResult
);
failures++;
}
result = arg2.add(arg1);
if (!result.equals(expectedResult)) {
System.out.println("Sum:" +
arg2 + " + " +
arg1 + " == " +
result + "; expected " +
expectedResult
);
failures++;
}
return failures;
}
/*
* Test BigDecimal.add(BigDecimal) when values are withing different ranges:
* 1. within 32 bits
* 2. within 64 bits
* 3. outside 64 bits.
*/
private static int addBoundaryTest() {
int failures = 0;
failures += addTest(
new BigDecimal("85070591730234615847396907784232501249"),
BigDecimal.valueOf(0),
new BigDecimal("85070591730234615847396907784232501249") );
failures += addTest(
new BigDecimal("-85070591730234615847396907784232501249"),
BigDecimal.valueOf(0),
new BigDecimal("-85070591730234615847396907784232501249") );
failures += addTest(
new BigDecimal("85070591730234615847396907784232501249"),
BigDecimal.valueOf(1),
new BigDecimal("85070591730234615847396907784232501250") );
failures += addTest(
new BigDecimal("85070591730234615847396907784232501249"),
BigDecimal.valueOf(-1),
new BigDecimal("85070591730234615847396907784232501248") );
failures += addTest(
new BigDecimal("-85070591730234615847396907784232501250"),
BigDecimal.valueOf(-1),
new BigDecimal("-85070591730234615847396907784232501251") );
failures += addTest(
new BigDecimal("-85070591730234615847396907784232501249"),
BigDecimal.valueOf(1),
new BigDecimal("-85070591730234615847396907784232501248") );
failures += addTest(
new BigDecimal("147573952589676412927"),
BigDecimal.valueOf(Integer.MAX_VALUE),
new BigDecimal("147573952591823896574") );
failures += addTest(
new BigDecimal("-147573952589676412927"),
BigDecimal.valueOf(Integer.MAX_VALUE),
new BigDecimal("-147573952587528929280") );
failures += addTest(
new BigDecimal("79228162514264337593543950335"),
BigDecimal.valueOf(999),
new BigDecimal("79228162514264337593543951334") );
failures += addTest(
new BigDecimal("79228162514264337593543950335"),
BigDecimal.valueOf(Integer.MAX_VALUE/2),
new BigDecimal("79228162514264337594617692158") );
failures += addTest(
new BigDecimal("79228162514264337593543950335"),
BigDecimal.valueOf(Integer.MIN_VALUE/2),
new BigDecimal("79228162514264337592470208511") );
failures += addTest(
new BigDecimal("-79228162514264337593543950335"),
BigDecimal.valueOf(Integer.MAX_VALUE/2),
new BigDecimal("-79228162514264337592470208512") );
failures += addTest(
new BigDecimal("79228162514264337593543950335"),
BigDecimal.valueOf(-(Integer.MIN_VALUE/2)),
new BigDecimal("79228162514264337594617692159") );
failures += addTest(
new BigDecimal("79228162514264337593543950335"),
BigDecimal.valueOf(Long.MAX_VALUE/2),
new BigDecimal("79228162518876023611971338238") );
failures += addTest(
new BigDecimal("79228162514264337593543950335"),
BigDecimal.valueOf(Long.MIN_VALUE/2),
new BigDecimal("79228162509652651575116562431") );
failures += addTest(
new BigDecimal("-79228162514264337593543950335"),
BigDecimal.valueOf(Long.MAX_VALUE/2),
new BigDecimal("-79228162509652651575116562432") );
failures += addTest(
new BigDecimal("79228162514264337593543950335"),
BigDecimal.valueOf(-(Long.MIN_VALUE/2)),
new BigDecimal("79228162518876023611971338239") );
failures += addTest(
new BigDecimal("-9223372036854775808"),
BigDecimal.valueOf(1),
new BigDecimal("-9223372036854775807") );
failures += addTest(
new BigDecimal("-9223372036854775808"),
BigDecimal.valueOf(Long.MAX_VALUE/2),
new BigDecimal("-4611686018427387905") );
failures += addTest(
new BigDecimal("9223372036854775808"),
BigDecimal.valueOf(-1),
new BigDecimal("9223372036854775807") );
failures += addTest(
new BigDecimal("9223372036854775808"),
BigDecimal.valueOf(-Long.MAX_VALUE/2),
new BigDecimal("4611686018427387905") );
return failures;
}
private static int testRoundingFromBigInteger(BigInteger bi, int scale, MathContext mc) {
int failures = 0;
BigDecimal bd1 = new BigDecimal(bi,scale, mc);
BigDecimal bd2 = (new BigDecimal(bi,scale)).round(mc);
if (!bd1.equals(bd2)) {
System.out.println("new BigDecimal(BigInteger,int,MathContext):" +
"BigInteger == " +
bi + "; scale == " + scale + "; result == " +
bd1 + "; expected == " +
bd2
);
failures++;
}
return failures;
}
private static int roundingConstructorTest() {
int failures = 0;
failures += testRoundingFromBigInteger(
new BigInteger("85070591730234615847396907784232501249"),
7, MathContext.DECIMAL64);
failures += testRoundingFromBigInteger(
new BigInteger("85070591730234615847396907784232501249"),
0, MathContext.DECIMAL64);
failures += testRoundingFromBigInteger(
new BigInteger("85070591730234615847396907784232501249"),
-7, MathContext.DECIMAL64);
failures += testRoundingFromBigInteger(
new BigInteger("85070591730234615847396907784232501249"),
7, MathContext.DECIMAL128);
failures += testRoundingFromBigInteger(
new BigInteger("85070591730234615847396907784232501249"),
177, MathContext.DECIMAL128);
failures += testRoundingFromBigInteger(
new BigInteger("85070591730234615847396907784232501249"),
177, MathContext.DECIMAL32);
failures += testRoundingFromBigInteger(
new BigInteger("85070591730234615847396907784232501249"),
177, MathContext.UNLIMITED);
failures += testRoundingFromBigInteger(
new BigInteger("85070591730234615847396907784232501249"),
0, MathContext.UNLIMITED);
return failures;
}
private static int minLongConstructorTest(MathContext mc) {
int failures = 0;
BigDecimal bd1 = new BigDecimal(Long.MIN_VALUE,mc);
BigDecimal bd2 = new BigDecimal(Long.MIN_VALUE).round(mc);
if (!bd1.equals(bd2)) {
System.out.println("new BigDecimal(long,MathContext):" +
"long == " +
Long.MIN_VALUE + "; result == " +
bd1 + "; expected == " +
bd2
);
failures++;
}
return failures;
}
private static int minLongConstructorTest() {
int failures = 0;
failures+=minLongConstructorTest(MathContext.UNLIMITED);
failures+=minLongConstructorTest(MathContext.DECIMAL32);
failures+=minLongConstructorTest(MathContext.DECIMAL64);
failures+=minLongConstructorTest(MathContext.DECIMAL128);
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += addBoundaryTest();
failures += roundingConstructorTest();
failures += minLongConstructorTest();
if (failures > 0) {
throw new RuntimeException("Incurred " + failures +
" failures while testing.");
}
}
}
......@@ -25,6 +25,8 @@
* @test
* @bug 4108852
* @summary A few tests of stripTrailingZeros
* @run main StrippingZerosTest
* @run main/othervm -XX:+AggressiveOpts StrippingZerosTest
* @author Joseph D. Darcy
*/
......@@ -53,6 +55,11 @@ public class StrippingZerosTest {
{new BigDecimal("10000000e2"), new BigDecimal("1e9")},
{new BigDecimal("1000000e3"), new BigDecimal("1e9")},
{new BigDecimal("100000e4"), new BigDecimal("1e9")},
// BD value which larger than Long.MaxValue
{new BigDecimal("1.0000000000000000000000000000"), new BigDecimal("1")},
{new BigDecimal("-1.0000000000000000000000000000"), new BigDecimal("-1")},
{new BigDecimal("1.00000000000000000000000000001"), new BigDecimal("1.00000000000000000000000000001")},
{new BigDecimal("1000000000000000000000000000000e4"), new BigDecimal("1e34")},
};
for(int i = 0; i < testCases.length; i++) {
......
......@@ -25,6 +25,8 @@
* @test
* @bug 4984872
* @summary Basic tests of toPlainString method
* @run main ToPlainStringTests
* @run main/othervm -XX:+AggressiveOpts ToPlainStringTests
* @author Joseph D. Darcy
*/
......@@ -60,6 +62,11 @@ public class ToPlainStringTests {
{"8e-8", "0.00000008"},
{"9e-9", "0.000000009"},
{"9000e-12", "0.000000009000"},
{"9000e-22", "0.0000000000000000009000"},
{"12345678901234567890", "12345678901234567890"},
{"12345678901234567890e22", "123456789012345678900000000000000000000000"},
{"12345678901234567890e-22", "0.0012345678901234567890"},
};
int errors = 0;
......@@ -73,8 +80,8 @@ public class ToPlainStringTests {
s + "'' from BigDecimal " +
bd);
}
if (!(s=("-"+bd.toPlainString())).equals("-"+testCase[1])) {
bd = new BigDecimal("-"+testCase[0]);
if (bd.signum()!=0 && !(s=(bd.toPlainString())).equals("-"+testCase[1])) {
errors++;
System.err.println("Unexpected plain result ``" +
s + "'' from BigDecimal " +
......
......@@ -29,23 +29,36 @@
import java.security.*;
import java.io.*;
import java.lang.reflect.*;
public class ConfigShortPath {
private static final String[] configNames = { "csp.cfg", "cspPlus.cfg" };
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
Constructor cons = null;
try {
Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11");
cons = clazz.getConstructor(String.class);
} catch (Exception ex) {
System.out.println("Skipping test - no PKCS11 provider available");
return;
}
String testSrc = System.getProperty("test.src", ".");
for (int i = 0; i < configNames.length; i++) {
String configFile = testSrc + File.separator + configNames[i];
System.out.println("Testing against " + configFile);
try {
Provider p = new sun.security.pkcs11.SunPKCS11(configFile);
} catch (ProviderException pe) {
String cause = pe.getCause().getMessage();
if (cause.indexOf("Unexpected token") != -1) {
// re-throw to indicate test failure
throw pe;
Object obj = cons.newInstance(configFile);
} catch (InvocationTargetException ite) {
Throwable cause = ite.getCause();
if (cause instanceof ProviderException) {
String causeMsg = cause.getCause().getMessage();
// Indicate failure if due to parsing config
if (causeMsg.indexOf("Unexpected token") != -1) {
throw (ProviderException) cause;
}
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册