This is the mail archive of the
mauve-discuss@sourceware.org
mailing list for the Mauve project.
Re: Fix for test gnu/testlet/java/lang/Integer/parseInt.java
Dr Andrew John Hughes wrote:
> As the old behaviour is specific to versions of Sun/Oracle's JDK implementation,
> it should check that this implementation is being used as well, rather than just
> the version.
Hi Andrew,
I've tried to add check for JDK/JRE implementation as you suggested. Patch for
parseInt Mauve test is stored in an attachment.
Cheers,
Pavel
--- gnu/testlet/java/lang/Integer/parseInt.java 2008-05-12 23:35:49.000000000 +0200
+++ gnu/testlet/java/lang/Integer/parseInt.java 2011-08-17 17:17:16.000000000 +0200
@@ -27,6 +27,26 @@
public class parseInt implements Testlet
{
+ /**
+ * Returns true if tested JRE conformns to JDK 1.7 specification.
+ */
+ private static boolean conformToJDK17()
+ {
+ String[] javaVersion = System.getProperty("java.version").split("\\.");
+ String vendorID = System.getProperty("java.vendor");
+ // GNU CLASSPATH conform to JDK1.7, at least in case of Integer.parseInt() method
+ if ("Free Software Foundation, Inc.".equals(vendorID))
+ {
+ return true;
+ }
+ // test of OpenJDK
+ if ("Sun Microsystems Inc.".equals(vendorID))
+ {
+ return Integer.parseInt(javaVersion[1]) >= 7;
+ }
+ return false; // questionable
+ }
+
public void test(TestHarness harness)
{
int i;
@@ -106,15 +126,30 @@
}
// In JDK1.7, '+' is considered a valid character.
- try
- {
- i = Integer.parseInt("+10");
- harness.check(true);
- harness.check(i, 10);
- }
- catch (NumberFormatException nfe)
- {
- harness.fail("Leading '+' does not throw NumberFormatException");
+ // it means that the following step should be divided
+ // for pre JDK1.7 case and >= JDK1.7
+ if (conformToJDK17()) {
+ try
+ {
+ i = Integer.parseInt("+10");
+ harness.check(true);
+ harness.check(i, 10);
+ }
+ catch (NumberFormatException nfe)
+ {
+ harness.fail("'+10' string is not parsed correctly as expected in JDK1.7");
+ }
+ }
+ else { // pre JDK1.7 branch
+ try
+ {
+ i = Integer.parseInt("+10");
+ harness.fail("'+10' must throw NumberFormatException");
+ }
+ catch (NumberFormatException nfe)
+ {
+ harness.check(true);
+ }
}
try