This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: setting Double.MAX_VALUE as Double into double primitive setter through Method.invoke


2006-01-18  Olivier Jolly  <olivier.jolly@pcedev.com>
    * gnu/testlet/java/lang/Double/DoubleTest.java: Added tests which
make sure that unwrapping of new Double(Double.MAX_VALUE) in
Method.invoke works correctly

Index: DoubleTest.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/lang/Double/DoubleTest.java,v
retrieving revision 1.7
diff -u -r1.7 DoubleTest.java
--- DoubleTest.java	21 Feb 2005 15:52:46 -0000	1.7
+++ DoubleTest.java	18 Jan 2006 19:12:37 -0000
@@ -21,6 +21,9 @@
 // Tags: JDK1.0
 
 package gnu.testlet.java.lang.Double;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 import gnu.testlet.Testlet;
 import gnu.testlet.TestHarness;
 
@@ -605,6 +608,59 @@
 		harness.fail("Error: test_neg failed - 6");
 	    }
 	}
+	
+  /**
+   * Tests the conversion of behaviour of max values when converting from double into Double
+   */
+  public void test_max()
+  {
+	// Check directly the MAX_VALUE against NaN 
+	harness.check(!Double.isNaN(Double.MAX_VALUE), "Error: test_max return wrong results");
+	harness.check(!Double.isNaN(new Double(Double.MAX_VALUE).doubleValue()));
+	
+	// Check the MAX_VALUE against NaN via a direct method setter
+	DoubleHolder doubleHolder = new DoubleHolder();
+	doubleHolder.setValue(Double.MAX_VALUE);
+	harness.check(Double.MAX_VALUE, doubleHolder.getValue());
+
+	// Check the MAX_VALUE against NaN via a setter called by reflection
+	DoubleHolder doubleHolder2 = new DoubleHolder();	
+	try
+	{
+	  Method setMethod = DoubleHolder.class.getDeclaredMethod("setValue", new Class[] {double.class});
+	  setMethod.invoke(doubleHolder2, new Object[] {new Double(Double.MAX_VALUE)});
+	} catch (NoSuchMethodException e) {
+	  harness.fail("no method setValue");
+	} catch (IllegalAccessException e) {
+	  harness.fail("illegal access");
+	} catch (InvocationTargetException e) {
+	  harness.fail("invocation failed");
+	}
+	
+	harness.check(!Double.isNaN(doubleHolder2.getValue()));
+	
+  }
+
+
+  /**
+   * Simple holder used to test various way of setting and getting primitive double
+   */
+  private static class DoubleHolder
+  {
+    private double value;
+
+	public double getValue()
+	{
+	  return value;
+	}
+
+	public void setValue(double value)
+	{
+	  this.value = value;
+	}
+  
+  }
+	  
 	public void testall()
 	{
 		test_Basics();
@@ -623,6 +679,7 @@
 		test_doubleToLongBits();
 		test_longBitsToDouble();
 		test_neg();
+		test_max();
 	}
 
   public void test (TestHarness the_harness)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]