harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r429959 [2/3] - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java: org/apache/harmony/luni/tests/java/lang/ tests/api/java/lang/
Date Wed, 09 Aug 2006 04:42:00 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java?rev=429959&r1=429958&r2=429959&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java Tue Aug  8 21:41:59 2006
@@ -15,115 +15,651 @@
 
 package org.apache.harmony.luni.tests.java.lang;
 
+import java.util.Vector;
+
 import junit.framework.TestCase;
 
 public class FloatTest extends TestCase {
 
-	/**
-	 * @tests java.lang.Float#compareTo(java.lang.Float)
-	 * @tests java.lang.Float#compare(float, float)
-	 */
-	public void test_compareToLjava_lang_Float() {
-		// A selection of float values in ascending order.
-		float[] values = new float[] { Float.NEGATIVE_INFINITY,
-				-Float.MAX_VALUE, -2f, -Float.MIN_VALUE, -0f, 0f,
-				Float.MIN_VALUE, 2f, Float.MAX_VALUE, Float.POSITIVE_INFINITY,
-				Float.NaN };
-
-		for (int i = 0; i < values.length; i++) {
-			float f1 = values[i];
-
-			// Test that each value compares equal to itself; and each object is equal to another object
-			// like itself
-			assertTrue("Assert 0: compare() should be equal: " + f1, Float
-					.compare(f1, f1) == 0);
-			Float objFloat = new Float(f1);
-			assertTrue("Assert 1: compareTo() should be equal: " + objFloat,
-					objFloat.compareTo(objFloat) == 0);
-
-			// Test that the Float-defined order is respected
-			for (int j = i + 1; j < values.length; j++) {
-				float f2 = values[j];
-				assertTrue("Assert 2: compare() " + f1 + " should be less " + f2,
-						Float.compare(f1, f2) == -1);
-				assertTrue("Assert 3: compare() " + f2 + " should be greater " + f1,
-						Float.compare(f2, f1) == 1);
-
-				Float F2 = new Float(f2);
-				assertTrue("Assert 4: compareTo() " + f1 + " should be less " + f2,
-						objFloat.compareTo(F2) == -1);
-				assertTrue("Assert 5: compareTo() " + f2 + " should be greater " + f1,
-						F2.compareTo(objFloat) == 1);
-			}
-		}
-	}
-
-	/**
-	 * @tests java.lang.Float#equals(java.lang.Object)
-	 */
-	public void test_equalsLjava_lang_Object() {
-		Float f1 = new Float(8765.4321f);
-		Float f2 = new Float(8765.4321f);
-		Float f3 = new Float(-1.0f);
-		assertTrue("Assert 0: Equality test failed", f1.equals(f2)
-				&& !(f1.equals(f3)));
-
-		assertTrue("Assert 1: NaN should not be == Nan",
-				Float.NaN != Float.NaN);
-		assertTrue("Assert 2: NaN should not be == Nan",
-				new Float(Float.NaN).equals(new Float(Float.NaN)));
-		assertTrue("Assert 3: -0f should be == 0f",
-				0f == -0f);
-		assertTrue("Assert 4: -0f should not be equals() 0f",
-				!new Float(0f).equals(new Float(-0f)));
-	}
-	    
-	/**
-	 * @tests java.lang.Float#toHexString(float)
-	 */
-	public void test_toHexStringF() 
-	{
-		//the follow values comes from the Float Javadoc/Spec
-		assertEquals("0x0.0p0", Float.toHexString(0.0F));
-		assertEquals("-0x0.0p0", Float.toHexString(-0.0F));
-		assertEquals("0x1.0p0", Float.toHexString(1.0F));
-		assertEquals("-0x1.0p0", Float.toHexString(-1.0F));
-		assertEquals("0x1.0p1", Float.toHexString(2.0F));
-		assertEquals("0x1.8p1", Float.toHexString(3.0F));
-		assertEquals("0x1.0p-1", Float.toHexString(0.5F));
-		assertEquals("0x1.0p-2", Float.toHexString(0.25F));
-		assertEquals("0x1.fffffep127", Float.toHexString(Float.MAX_VALUE));
-		assertEquals("0x0.000002p-126", Float.toHexString(Float.MIN_VALUE));
-        
-		//test edge cases
-		assertEquals("NaN", Float.toHexString(Float.NaN));
-		assertEquals("-Infinity", Float.toHexString(Float.NEGATIVE_INFINITY));
-		assertEquals("Infinity", Float.toHexString(Float.POSITIVE_INFINITY));
-        
-		//test various numbers
-		assertEquals("-0x1.da8p6", Float.toHexString(-118.625F));
-		assertEquals("0x1.295788p23", Float.toHexString(9743299.65F));
-		assertEquals("0x1.295788p23", Float.toHexString(9743299.65000F));
-		assertEquals("0x1.295788p23", Float.toHexString(9743299.650001234F));
-		assertEquals("0x1.700d1p33", Float.toHexString(12349743299.65000F));
-	}
-    
-	/**
-	 * @tests java.lang.Float#valueOf(float)
-	 */
-	public void test_valueOfF() 
-	{
-		assertEquals(new Float(Float.MIN_VALUE), Float.valueOf(Float.MIN_VALUE));
-		assertEquals(new Float(Float.MAX_VALUE), Float.valueOf(Float.MAX_VALUE));
-		assertEquals(new Float(0), Float.valueOf(0));
-
-		int s = -128;
-		while (s < 128) 
-		{
-			assertEquals(new Float(s), Float.valueOf(s));
-			assertEquals(new Float(s + 0.1F), Float.valueOf(s + 0.1F));
-			assertEquals(Float.valueOf(s + 0.1F), Float.valueOf(s + 0.1F));
-			s++;
-		}
-	}
+    private Vector compareResults;
+
+    private static int rawBitsFor3_4eN38To38[] = { 0x1394470, 0x2e7958c, 0x490bd77, 0x634ecd5,
+            0x7e2280b, 0x98d5907, 0xb30af48, 0xcdcdb1a, 0xe8a08f0, 0x102c8b2d, 0x11d7adf8,
+            0x1386ccbb, 0x15287fe9, 0x16d29fe4, 0x1883a3ee, 0x1a248cea, 0x1bcdb025, 0x1d808e17,
+            0x1f20b19d, 0x20c8de04, 0x227b1585, 0x241ced73, 0x25c428d0, 0x27753303, 0x29193fe2,
+            0x2abf8fdb, 0x2c6f73d1, 0x2e15a863, 0x2fbb127c, 0x3169d71a, 0x33122671, 0x34b6b00d,
+            0x36645c10, 0x380eb98a, 0x39b267ec, 0x3b5f01e8, 0x3d0b6131, 0x3eae397d, 0x4059c7dc,
+            0x42081cea, 0x43aa2424, 0x4554ad2d, 0x4704ec3c, 0x48a6274b, 0x4a4fb11e, 0x4c01ceb3,
+            0x4da2425f, 0x4f4ad2f7, 0x50fd87b5, 0x529e74d1, 0x54461205, 0x55f79687, 0x579abe14,
+            0x59416d99, 0x5af1c900, 0x5c971da0, 0x5e3ce508, 0x5fec1e4a, 0x619392ee, 0x633877a9,
+            0x64e69594, 0x66901d7c, 0x683424dc, 0x69e12e12, 0x6b8cbccb, 0x6d2febfe, 0x6edbe6fe,
+            0x7089705f, 0x722bcc76, 0x73d6bf94, 0x758637bc, 0x7727c5ac, 0x78d1b717, 0x7a83126e,
+            0x7c23d70a, 0x7dcccccc, 0x7f7fffff };
+
+    private static String expectedStringFor3_4eN38To38[] = { "3.4028235E-38", "3.4028235E-37",
+            "3.4028233E-36", "3.4028234E-35", "3.4028236E-34", "3.4028236E-33",
+            "3.4028234E-32", "3.4028234E-31", "3.4028233E-30", "3.4028236E-29",
+            "3.4028235E-28", "3.4028235E-27", "3.4028233E-26", "3.4028235E-25",
+            "3.4028233E-24", "3.4028235E-23", "3.4028236E-22", "3.4028235E-21",
+            "3.4028236E-20", "3.4028236E-19", "3.4028236E-18", "3.4028235E-17",
+            "3.4028236E-16", "3.4028234E-15", "3.4028234E-14", "3.4028235E-13",
+            "3.4028234E-12", "3.4028235E-11", "3.4028236E-10", "3.4028234E-9", "3.4028236E-8",
+            "3.4028236E-7", "3.4028235E-6", "3.4028235E-5", "3.4028233E-4", "0.0034028236",
+            "0.034028236", "0.34028235", "3.4028234", "34.028236", "340.28235", "3402.8235",
+            "34028.234", "340282.34", "3402823.5", "3.4028236E7", "3.40282336E8",
+            "3.40282342E9", "3.40282348E10", "3.40282343E11", "3.40282337E12", "3.40282353E13",
+            "3.4028234E14", "3.4028234E15", "3.40282356E16", "3.40282356E17", "3.40282356E18",
+            "3.4028236E19", "3.4028235E20", "3.4028233E21", "3.4028235E22", "3.4028233E23",
+            "3.4028236E24", "3.4028234E25", "3.4028233E26", "3.4028234E27", "3.4028235E28",
+            "3.4028236E29", "3.4028233E30", "3.4028235E31", "3.4028233E32", "3.4028236E33",
+            "3.4028236E34", "3.4028234E35", "3.4028236E36", "3.4028235E37", "3.4028235E38" };
+
+    private static int rawBitsFor1_17eN38To38[] = { 0x80800000, 0x82200000, 0x83c80000,
+            0x857a0000, 0x871c4000, 0x88c35000, 0x8a742400, 0x8c189680, 0x8dbebc20, 0x8f6e6b28,
+            0x911502f9, 0x92ba43b7, 0x9468d4a5, 0x961184e7, 0x97b5e621, 0x99635fa9, 0x9b0e1bca,
+            0x9cb1a2bc, 0x9e5e0b6b, 0xa00ac723, 0xa1ad78ec, 0xa358d727, 0xa5078678, 0xa6a96816,
+            0xa853c21c, 0xaa045951, 0xaba56fa6, 0xad4ecb8f, 0xaf013f39, 0xb0a18f08, 0xb249f2ca,
+            0xb3fc6f7c, 0xb59dc5ae, 0xb7453719, 0xb8f684df, 0xba9a130c, 0xbc4097ce, 0xbdf0bdc2,
+            0xbf967699, 0xc13c1440, 0xc2eb1950, 0xc492efd2, 0xc637abc6, 0xc7e596b8, 0xc98f7e33,
+            0xcb335dc0, 0xcce0352f, 0xce8c213e, 0xd02f298d, 0xd1daf3f0, 0xd388d876, 0xd52b0e94,
+            0xd6d5d239, 0xd885a363, 0xda270c3c, 0xdbd0cf4b, 0xdd82818f, 0xdf2321f3, 0xe0cbea70,
+            0xe27ee50b, 0xe41f4f27, 0xe5c722f1, 0xe778ebad, 0xe91b934c, 0xeac2781f, 0xec731627,
+            0xee17edd8, 0xefbde94f, 0xf16d63a2, 0xf3145e45, 0xf4b975d7, 0xf667d34c, 0xf810e410,
+            0xf9b51d14, 0xfb626459, 0xfd0d7eb7, 0xfeb0de65 };
+
+    private static String expectedStringFor1_17eN38To38[] = { "-1.17549435E-38",
+            "-1.1754944E-37", "-1.17549435E-36", "-1.17549435E-35", "-1.1754944E-34",
+            "-1.17549435E-33", "-1.17549435E-32", "-1.1754944E-31", "-1.17549435E-30",
+            "-1.17549435E-29", "-1.1754944E-28", "-1.1754943E-27", "-1.17549435E-26",
+            "-1.1754943E-25", "-1.1754944E-24", "-1.1754943E-23", "-1.1754944E-22",
+            "-1.1754943E-21", "-1.1754943E-20", "-1.1754943E-19", "-1.1754944E-18",
+            "-1.1754944E-17", "-1.1754943E-16", "-1.1754943E-15", "-1.1754944E-14",
+            "-1.1754943E-13", "-1.1754944E-12", "-1.1754943E-11", "-1.1754943E-10",
+            "-1.1754944E-9", "-1.1754944E-8", "-1.1754943E-7", "-1.1754944E-6",
+            "-1.1754943E-5", "-1.1754943E-4", "-0.0011754944", "-0.011754943", "-0.117549434",
+            "-1.1754943", "-11.754944", "-117.54944", "-1175.4944", "-11754.943", "-117549.44",
+            "-1175494.4", "-1.1754944E7", "-1.17549432E8", "-1.1754944E9", "-1.17549435E10",
+            "-1.17549433E11", "-1.17549433E12", "-1.17549438E13", "-1.17549438E14",
+            "-1.1754943E15", "-1.17549432E16", "-1.17549432E17", "-1.17549434E18",
+            "-1.1754944E19", "-1.1754944E20", "-1.1754943E21", "-1.1754943E22",
+            "-1.1754944E23", "-1.17549434E24", "-1.1754943E25", "-1.1754943E26",
+            "-1.17549434E27", "-1.1754943E28", "-1.1754944E29", "-1.1754943E30",
+            "-1.1754943E31", "-1.1754944E32", "-1.1754943E33", "-1.1754944E34",
+            "-1.1754944E35", "-1.1754944E36", "-1.1754943E37", "-1.1754943E38" };
+
+    private static String toHex(int i) {
+        return Integer.toHexString(i);
+    }
+
+    private void doTestCompareRawBits(String originalFloatString, int expectedRawBits,
+            String expectedString) {
+        int rawBits;
+        String convertedString;
+        float result = Float.parseFloat(originalFloatString);
+        rawBits = Float.floatToIntBits(result);
+        convertedString = Float.toString(result);
+        if (expectedRawBits != rawBits) {
+            if (compareResults == null) {
+                compareResults = new Vector();
+            }
+            compareResults.addElement("Original float(" + originalFloatString
+                    + ") Converted float(" + result + ") Expecting:" + toHex(expectedRawBits)
+                    + " Got: " + toHex(rawBits));
+        }
+    }
+
+    /**
+     * @tests java.lang.Float#Float(float)
+     */
+    public void test_ConstructorF() {
+        // Test for method java.lang.Float(float)
+
+        Float f = new Float(900.89f);
+        assertTrue("Created incorrect float", f.floatValue() == 900.89f);
+    }
+
+    /**
+     * @tests java.lang.Float#Float(java.lang.String)
+     */
+    public void test_ConstructorLjava_lang_String() {
+        // Test for method java.lang.Float(java.lang.String)
+
+        Float f = new Float("900.89");
+        assertTrue("Created incorrect Float", f.floatValue() == 900.89f);
+    }
+
+    /**
+     * @tests java.lang.Float#byteValue()
+     */
+    public void test_byteValue() {
+        // Test for method byte java.lang.Float.byteValue()
+        Float f = new Float(0.46874f);
+        Float f2 = new Float(90.8f);
+        assertTrue("Returned incorrect byte value", f.byteValue() == 0 && f2.byteValue() == 90);
+    }
+
+    /**
+     * @tests java.lang.Float#compareTo(java.lang.Float)
+     * @tests java.lang.Float#compare(float, float)
+     */
+    public void test_compare() {
+        float[] values = new float[] { Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, -2f,
+                -Float.MIN_VALUE, -0f, 0f, Float.MIN_VALUE, 2f, Float.MAX_VALUE,
+                Float.POSITIVE_INFINITY, Float.NaN };
+        for (int i = 0; i < values.length; i++) {
+            float f1 = values[i];
+            assertTrue("compare() should be equal: " + f1, Float.compare(f1, f1) == 0);
+            Float F1 = new Float(f1);
+            assertTrue("compareTo() should be equal: " + f1, F1.compareTo(F1) == 0);
+            for (int j = i + 1; j < values.length; j++) {
+                float f2 = values[j];
+                assertTrue("compare() " + f1 + " should be less " + f2,
+                        Float.compare(f1, f2) == -1);
+                assertTrue("compare() " + f2 + " should be greater " + f1, Float
+                        .compare(f2, f1) == 1);
+                Float F2 = new Float(f2);
+                assertTrue("compareTo() " + f1 + " should be less " + f2,
+                        F1.compareTo(F2) == -1);
+                assertTrue("compareTo() " + f2 + " should be greater " + f1,
+                        F2.compareTo(F1) == 1);
+            }
+        }
+
+        try {
+            new Float(0.0F).compareTo(null);
+            fail("No NPE");
+        } catch (NullPointerException e) {
+        }
+    }
+
+    /**
+     * @tests java.lang.Float#doubleValue()
+     */
+    public void test_doubleValue() {
+        // Test for method double java.lang.Float.doubleValue()
+        assertTrue("Incorrect double value returned", Math.abs(new Float(999999.999f)
+                .doubleValue() - 999999.999d) < 1);
+    }
+
+    /**
+     * @tests java.lang.Float#floatToIntBits(float)
+     */
+    public void test_floatToIntBitsF() {
+        // Test for method int java.lang.Float.floatToIntBits(float)
+        // TODO : Enhance test ??
+        float f = 9876.2345f;
+        int bits = Float.floatToIntBits(f);
+        float r = Float.intBitsToFloat(bits);
+        assertTrue("Incorrect intBits returned", f == r);
+    }
+
+    /**
+     * @tests java.lang.Float#floatToRawIntBits(float)
+     */
+    public void test_floatToRawIntBitsF() {
+        int i = 0x7fc004d2;
+        float f = Float.intBitsToFloat(i);
+        assertTrue("Wrong raw bits", Float.floatToRawIntBits(f) == i);
+    }
+
+    /**
+     * @tests java.lang.Float#floatValue()
+     */
+    public void test_floatValue() {
+        // Test for method float java.lang.Float.floatValue()
+        Float f = new Float(87.657f);
+        Float f2 = new Float(-0.876f);
+        assertTrue("Returned incorrect floatValue", f.floatValue() == 87.657f
+                && (f2.floatValue() == -0.876f));
+
+    }
+
+    /**
+     * @tests java.lang.Float#hashCode()
+     */
+    public void test_hashCode() {
+        // Test for method int java.lang.Float.hashCode()
+        Float f = new Float(1908.8786f);
+        assertTrue("Returned invalid hash code for 1908.8786f", f.hashCode() == Float
+                .floatToIntBits(1908.8786f));
+
+        f = new Float(-1.112f);
+        assertTrue("Returned invalid hash code for -1.112", f.hashCode() == Float
+                .floatToIntBits(-1.112f));
+
+        f = new Float(0f);
+        assertTrue("Returned invalid hash code for 0", f.hashCode() == Float.floatToIntBits(0f));
+
+    }
+
+    /**
+     * @tests java.lang.Float#intBitsToFloat(int)
+     */
+    public void test_intBitsToFloatI() {
+        // Test for method float java.lang.Float.intBitsToFloat(int)
+        // TODO : Enhance test ??
+        float f = 9876.2345f;
+        int bits = Float.floatToIntBits(f);
+        float r = Float.intBitsToFloat(bits);
+        assertTrue("Incorrect intBits returned", f == r);
+    }
+
+    /**
+     * @tests java.lang.Float#intValue()
+     */
+    public void test_intValue() {
+        // Test for method int java.lang.Float.intValue()
+        Float f = new Float(0.46874f);
+        Float f2 = new Float(90.8f);
+        assertTrue("Returned incorrect int value", f.intValue() == 0 && f2.intValue() == 90);
+    }
+
+    /**
+     * @tests java.lang.Float#isInfinite()
+     */
+    public void test_isInfinite() {
+        // Test for method boolean java.lang.Float.isInfinite()
+        assertTrue("Ininifty check failed",
+                (new Float(Float.POSITIVE_INFINITY).isInfinite() && new Float(
+                        Float.NEGATIVE_INFINITY).isInfinite())
+                        && !(new Float(0.13131414f).isInfinite()));
+    }
+
+    /**
+     * @tests java.lang.Float#isInfinite(float)
+     */
+    public void test_isInfiniteF() {
+        // Test for method boolean java.lang.Float.isInfinite(float)
+
+        assertTrue("Infinity check failed", Float.isInfinite(Float.POSITIVE_INFINITY)
+                && (Float.isInfinite(Float.NEGATIVE_INFINITY)) && !(Float.isInfinite(1.0f)));
+    }
+
+    /**
+     * @tests java.lang.Float#isNaN()
+     */
+    public void test_isNaN() {
+        // Test for method boolean java.lang.Float.isNaN()
+        assertTrue("NAN check failed", new Float(Float.NaN).isNaN()
+                && !(new Float(1.0f).isNaN()));
+    }
+
+    /**
+     * @tests java.lang.Float#isNaN(float)
+     */
+    public void test_isNaNF() {
+        // Test for method boolean java.lang.Float.isNaN(float)
+        assertTrue("NaN check failed", Float.isNaN(Float.NaN) && !(Float.isNaN(12.09f)));
+    }
+
+    /**
+     * @tests java.lang.Float#longValue()
+     */
+    public void test_longValue() {
+        // Test for method long java.lang.Float.longValue()
+        Float f = new Float(0.46874f);
+        Float f2 = new Float(90.8f);
+        assertTrue("Returned incorrect long value", f.longValue() == 0 && f2.longValue() == 90);
+    }
+
+    /**
+     * @tests java.lang.Float#parseFloat(java.lang.String)
+     */
+    public void test_parseFloatLjava_lang_String() {
+        assertEquals("Incorrect float returned, expected zero.", 0.0, Float
+                .parseFloat("7.0064923216240853546186479164495e-46"), 0.0);
+        assertEquals("Incorrect float returned, expected minimum float.", Float.MIN_VALUE,
+                Float.parseFloat("7.0064923216240853546186479164496e-46"), 0.0);
+
+        doTestCompareRawBits(
+                "0.000000000000000000000000000000000000011754942807573642917278829910357665133228589927589904276829631184250030649651730385585324256680905818939208984375",
+                0x800000, "1.17549435E-38");
+        doTestCompareRawBits(
+                "0.00000000000000000000000000000000000001175494280757364291727882991035766513322858992758990427682963118425003064965173038558532425668090581893920898437499999f",
+                0x7fffff, "1.1754942E-38");
+
+        /* Test a set of regular floats with exponents from -38 to +38 */
+        for (int i = 38; i > 3; i--) {
+            String testString, expectedString;
+            testString = expectedString = "3.4028234663852886e-" + i;
+            doTestCompareRawBits(testString, rawBitsFor3_4eN38To38[38 - i],
+                    expectedStringFor3_4eN38To38[38 - i]);
+        }
+        doTestCompareRawBits("3.4028234663852886e-3", rawBitsFor3_4eN38To38[38 - 3],
+                expectedStringFor3_4eN38To38[38 - 3]);
+        doTestCompareRawBits("3.4028234663852886e-2", rawBitsFor3_4eN38To38[38 - 2],
+                expectedStringFor3_4eN38To38[38 - 2]);
+        doTestCompareRawBits("3.4028234663852886e-1", rawBitsFor3_4eN38To38[38 - 1],
+                expectedStringFor3_4eN38To38[38 - 1]);
+        doTestCompareRawBits("3.4028234663852886e-0", rawBitsFor3_4eN38To38[38 - 0],
+                expectedStringFor3_4eN38To38[38 - 0]);
+        doTestCompareRawBits("3.4028234663852886e+1", rawBitsFor3_4eN38To38[38 + 1],
+                expectedStringFor3_4eN38To38[38 + 1]);
+        doTestCompareRawBits("3.4028234663852886e+2", rawBitsFor3_4eN38To38[38 + 2],
+                expectedStringFor3_4eN38To38[38 + 2]);
+        doTestCompareRawBits("3.4028234663852886e+3", rawBitsFor3_4eN38To38[38 + 3],
+                expectedStringFor3_4eN38To38[38 + 3]);
+        doTestCompareRawBits("3.4028234663852886e+4", rawBitsFor3_4eN38To38[38 + 4],
+                expectedStringFor3_4eN38To38[38 + 4]);
+        doTestCompareRawBits("3.4028234663852886e+5", rawBitsFor3_4eN38To38[38 + 5],
+                expectedStringFor3_4eN38To38[38 + 5]);
+        doTestCompareRawBits("3.4028234663852886e+6", rawBitsFor3_4eN38To38[38 + 6],
+                expectedStringFor3_4eN38To38[38 + 6]);
+
+        for (int i = 7; i < 39; i++) {
+            String testString, expectedString;
+            testString = expectedString = "3.4028234663852886e+" + i;
+            doTestCompareRawBits(testString, rawBitsFor3_4eN38To38[38 + i],
+                    expectedStringFor3_4eN38To38[38 + i]);
+        }
+
+        /* Test another set of regular floats with exponents from -38 to +38 */
+        for (int i = 38; i > 3; i--) {
+            String testString, expectedString;
+            testString = expectedString = "-1.1754943508222875e-" + i;
+            doTestCompareRawBits(testString, rawBitsFor1_17eN38To38[38 - i],
+                    expectedStringFor1_17eN38To38[38 - i]);
+        }
+        doTestCompareRawBits("-1.1754943508222875e-3", rawBitsFor1_17eN38To38[38 - 3],
+                expectedStringFor1_17eN38To38[38 - 3]);
+        doTestCompareRawBits("-1.1754943508222875e-2", rawBitsFor1_17eN38To38[38 - 2],
+                expectedStringFor1_17eN38To38[38 - 2]);
+        doTestCompareRawBits("-1.1754943508222875e-1", rawBitsFor1_17eN38To38[38 - 1],
+                expectedStringFor1_17eN38To38[38 - 1]);
+        doTestCompareRawBits("-1.1754943508222875e-0", rawBitsFor1_17eN38To38[38 - 0],
+                expectedStringFor1_17eN38To38[38 - 0]);
+        doTestCompareRawBits("-1.1754943508222875e+1", rawBitsFor1_17eN38To38[38 + 1],
+                expectedStringFor1_17eN38To38[38 + 1]);
+        doTestCompareRawBits("-1.1754943508222875e+2", rawBitsFor1_17eN38To38[38 + 2],
+                expectedStringFor1_17eN38To38[38 + 2]);
+        doTestCompareRawBits("-1.1754943508222875e+3", rawBitsFor1_17eN38To38[38 + 3],
+                expectedStringFor1_17eN38To38[38 + 3]);
+        doTestCompareRawBits("-1.1754943508222875e+4", rawBitsFor1_17eN38To38[38 + 4],
+                expectedStringFor1_17eN38To38[38 + 4]);
+        doTestCompareRawBits("-1.1754943508222875e+5", rawBitsFor1_17eN38To38[38 + 5],
+                expectedStringFor1_17eN38To38[38 + 5]);
+        doTestCompareRawBits("-1.1754943508222875e+6", rawBitsFor1_17eN38To38[38 + 6],
+                expectedStringFor1_17eN38To38[38 + 6]);
+
+        for (int i = 7; i < 39; i++) {
+            String testString, expectedString;
+            testString = expectedString = "-1.1754943508222875e+" + i;
+            doTestCompareRawBits(testString, rawBitsFor1_17eN38To38[38 + i],
+                    expectedStringFor1_17eN38To38[38 + i]);
+        }
+
+        /* Test denormalized floats (floats with exponents <= -38 */
+        doTestCompareRawBits("1.1012984643248170E-45", 1, "1.4E-45");
+        doTestCompareRawBits("-1.1012984643248170E-45", 0x80000001, "-1.4E-45");
+        doTestCompareRawBits("1.0E-45", 1, "1.4E-45");
+        doTestCompareRawBits("-1.0E-45", 0x80000001, "-1.4E-45");
+        doTestCompareRawBits("0.9E-45", 1, "1.4E-45");
+        doTestCompareRawBits("-0.9E-45", 0x80000001, "-1.4E-45");
+        doTestCompareRawBits("4.203895392974451e-45", 3, "4.2E-45");
+        doTestCompareRawBits("-4.203895392974451e-45", 0x80000003, "-4.2E-45");
+        doTestCompareRawBits("0.004E-45", 0, "0.0");
+        doTestCompareRawBits("-0.004E-45", 0x80000000, "-0.0");
+
+        /*
+         * Test for large floats close to and greater than 3.4028235E38 and
+         * -3.4028235E38
+         */
+        doTestCompareRawBits("1.2E+38", 0x7eb48e52, "1.2E38");
+        doTestCompareRawBits("-1.2E+38", 0xfeb48e52, "-1.2E38");
+        doTestCompareRawBits("3.2E+38", 0x7f70bdc2, "3.2E38");
+        doTestCompareRawBits("-3.2E+38", 0xff70bdc2, "-3.2E38");
+        doTestCompareRawBits("3.4E+38", 0x7f7fc99e, "3.4E38");
+        doTestCompareRawBits("-3.4E+38", 0xff7fc99e, "-3.4E38");
+        doTestCompareRawBits("3.4028234663852886E+38", 0x7f7fffff, "3.4028235E38");
+        doTestCompareRawBits("-3.4028234663852886E+38", 0xff7fffff, "-3.4028235E38");
+        doTestCompareRawBits("3.405E+38", 0x7f800000, "Infinity");
+        doTestCompareRawBits("-3.405E+38", 0xff800000, "-Infinity");
+        doTestCompareRawBits("3.41E+38", 0x7f800000, "Infinity");
+        doTestCompareRawBits("-3.41E+38", 0xff800000, "-Infinity");
+        doTestCompareRawBits("3.42E+38", 0x7f800000, "Infinity");
+        doTestCompareRawBits("-3.42E+38", 0xff800000, "-Infinity");
+        doTestCompareRawBits("1.0E+39", 0x7f800000, "Infinity");
+        doTestCompareRawBits("-1.0E+39", 0xff800000, "-Infinity");
+
+        if (compareResults != null) {
+            StringBuffer failString = new StringBuffer();
+            for (int i = 0; i < compareResults.size(); i++) {
+                failString.append(compareResults.elementAt(i));
+                failString.append("\n");
+            }
+            fail(failString.toString());
+        }
+    }
+
+    /**
+     * @tests java.lang.Float#shortValue()
+     */
+    public void test_shortValue() {
+        // Test for method short java.lang.Float.shortValue()
+        Float f = new Float(0.46874f);
+        Float f2 = new Float(90.8f);
+        assertTrue("Returned incorrect short value", f.shortValue() == 0
+                && f2.shortValue() == 90);
+    }
+
+    /**
+     * @tests java.lang.Float#toString()
+     */
+    public void test_toString() {
+        // Test for method java.lang.String java.lang.Float.toString()
+
+        test_toString(12.90898f, "12.90898");
+
+        test_toString(1.7014118346046924e+38F, "1.7014118E38");
+    }
+
+    /**
+     * @tests java.lang.Float#toString(float)
+     */
+    public void test_toStringF() {
+        // Test for method java.lang.String java.lang.Float.toString(float)
+
+        float ff;
+        String answer;
+
+        ff = 12.90898f;
+        answer = "12.90898";
+        assertTrue("Incorrect String representation want " + answer + ", got "
+                + Float.toString(ff), Float.toString(ff).equals(answer));
+
+        ff = Float.MAX_VALUE;
+        answer = "3.4028235E38";
+        assertTrue("Incorrect String representation want " + answer + ", got "
+                + Float.toString(ff), Float.toString(ff).equals(answer));
+        // TODO : There is a known problem with floating point printing. So
+        // this is not included
+    }
+
+    /**
+     * @tests java.lang.Float#valueOf(java.lang.String)
+     */
+    public void test_valueOfLjava_lang_String() {
+        // Test for method java.lang.Float
+        // java.lang.Float.valueOf(java.lang.String)
+
+        Float wanted = new Float(432.1235f);
+        Float got = Float.valueOf("432.1235");
+        assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
+                .equals(wanted));
+
+        wanted = new Float(0f);
+        got = Float.valueOf("0");
+        assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
+                .equals(wanted));
+
+        wanted = new Float(-1212.3232f);
+        got = Float.valueOf("-1212.3232");
+        assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
+                .equals(wanted));
+
+        try {
+            Float.valueOf(null);
+            fail("Expected Float.valueOf(null) to throw NPE.");
+        } catch (NullPointerException ex) {
+            // expected
+        } catch (Exception ex) {
+            fail("Expected Float.valueOf(null) to throw NPE not " + ex.getClass().getName());
+        }
+
+        try {
+            Float.valueOf("");
+            fail("Expected Float.valueOf(\"\") to throw NFE");
+        } catch (NumberFormatException e) {
+            // expected
+        }
+
+        Float posZero = Float.valueOf("+0.0");
+        Float negZero = Float.valueOf("-0.0");
+        assertFalse("Floattest0", posZero.equals(negZero));
+        assertTrue("Floattest1", 0.0f == -0.0f);
+
+        // Tests for float values by name.
+        Float expectedNaN = new Float(Float.NaN);
+
+        Float posNaN = Float.valueOf("NaN");
+        assertTrue("Floattest2", posNaN.equals(expectedNaN));
+
+        Float posNaNSigned = Float.valueOf("+NaN");
+        assertTrue("Floattest3", posNaNSigned.equals(expectedNaN));
+
+        Float negNaNSigned = Float.valueOf("-NaN");
+        assertTrue("Floattest4", negNaNSigned.equals(expectedNaN));
+
+        Float posInfinite = Float.valueOf("Infinity");
+        assertTrue("Floattest5", posInfinite.equals(new Float(Float.POSITIVE_INFINITY)));
+
+        Float posInfiniteSigned = Float.valueOf("+Infinity");
+        assertTrue("Floattest6", posInfiniteSigned.equals(new Float(Float.POSITIVE_INFINITY)));
+
+        Float negInfiniteSigned = Float.valueOf("-Infinity");
+        assertTrue("Floattest7", negInfiniteSigned.equals(new Float(Float.NEGATIVE_INFINITY)));
+    }
+
+    private void test_toString(float ff, String answer) {
+        // Test for method java.lang.String java.lang.Double.toString(double)
+        assertTrue("Incorrect String representation want " + answer + ", got ("
+                + Float.toString(ff) + ")", Float.toString(ff).equals(answer));
+        Float f = new Float(ff);
+        assertTrue("Incorrect String representation want " + answer + ", got ("
+                + Float.toString(f.floatValue()) + ")", Float.toString(f.floatValue()).equals(
+                answer));
+        assertTrue("Incorrect String representation want " + answer + ", got (" + f.toString()
+                + ")", f.toString().equals(answer));
+    }
+
+    /**
+     * @tests java.lang.Float#compareTo(java.lang.Float)
+     * @tests java.lang.Float#compare(float, float)
+     */
+    public void test_compareToLjava_lang_Float() {
+        // A selection of float values in ascending order.
+        float[] values = new float[] { Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, -2f,
+                -Float.MIN_VALUE, -0f, 0f, Float.MIN_VALUE, 2f, Float.MAX_VALUE,
+                Float.POSITIVE_INFINITY, Float.NaN };
+
+        for (int i = 0; i < values.length; i++) {
+            float f1 = values[i];
+
+            // Test that each value compares equal to itself; and each object is equal to another object
+            // like itself
+            assertTrue("Assert 0: compare() should be equal: " + f1, Float.compare(f1, f1) == 0);
+            Float objFloat = new Float(f1);
+            assertTrue("Assert 1: compareTo() should be equal: " + objFloat, objFloat
+                    .compareTo(objFloat) == 0);
+
+            // Test that the Float-defined order is respected
+            for (int j = i + 1; j < values.length; j++) {
+                float f2 = values[j];
+                assertTrue("Assert 2: compare() " + f1 + " should be less " + f2, Float
+                        .compare(f1, f2) == -1);
+                assertTrue("Assert 3: compare() " + f2 + " should be greater " + f1, Float
+                        .compare(f2, f1) == 1);
+
+                Float F2 = new Float(f2);
+                assertTrue("Assert 4: compareTo() " + f1 + " should be less " + f2, objFloat
+                        .compareTo(F2) == -1);
+                assertTrue("Assert 5: compareTo() " + f2 + " should be greater " + f1, F2
+                        .compareTo(objFloat) == 1);
+            }
+        }
+    }
+
+    /**
+     * @tests java.lang.Float#equals(java.lang.Object)
+     */
+    public void test_equalsLjava_lang_Object() {
+        Float f1 = new Float(8765.4321f);
+        Float f2 = new Float(8765.4321f);
+        Float f3 = new Float(-1.0f);
+        assertTrue("Assert 0: Equality test failed", f1.equals(f2) && !(f1.equals(f3)));
+
+        assertTrue("Assert 1: NaN should not be == Nan", Float.NaN != Float.NaN);
+        assertTrue("Assert 2: NaN should not be == Nan", new Float(Float.NaN).equals(new Float(
+                Float.NaN)));
+        assertTrue("Assert 3: -0f should be == 0f", 0f == -0f);
+        assertTrue("Assert 4: -0f should not be equals() 0f", !new Float(0f).equals(new Float(
+                -0f)));
+
+        f1 = new Float(1098.576f);
+        f2 = new Float(1098.576f);
+        f3 = new Float(1.0f);
+        assertTrue("Equality test failed", f1.equals(f2) && !(f1.equals(f3)));
+
+        assertTrue("NaN should not be == Nan", Float.NaN != Float.NaN);
+        assertTrue("NaN should not be == Nan", new Float(Float.NaN)
+                .equals(new Float(Float.NaN)));
+        assertTrue("-0f should be == 0f", 0f == -0f);
+        assertTrue("-0f should not be equals() 0f", !new Float(0f).equals(new Float(-0f)));
+    }
+
+    /**
+     * @tests java.lang.Float#toHexString(float)
+     */
+    public void test_toHexStringF() {
+        //the follow values comes from the Float Javadoc/Spec
+        assertEquals("0x0.0p0", Float.toHexString(0.0F));
+        assertEquals("-0x0.0p0", Float.toHexString(-0.0F));
+        assertEquals("0x1.0p0", Float.toHexString(1.0F));
+        assertEquals("-0x1.0p0", Float.toHexString(-1.0F));
+        assertEquals("0x1.0p1", Float.toHexString(2.0F));
+        assertEquals("0x1.8p1", Float.toHexString(3.0F));
+        assertEquals("0x1.0p-1", Float.toHexString(0.5F));
+        assertEquals("0x1.0p-2", Float.toHexString(0.25F));
+        assertEquals("0x1.fffffep127", Float.toHexString(Float.MAX_VALUE));
+        assertEquals("0x0.000002p-126", Float.toHexString(Float.MIN_VALUE));
+
+        //test edge cases
+        assertEquals("NaN", Float.toHexString(Float.NaN));
+        assertEquals("-Infinity", Float.toHexString(Float.NEGATIVE_INFINITY));
+        assertEquals("Infinity", Float.toHexString(Float.POSITIVE_INFINITY));
+
+        //test various numbers
+        assertEquals("-0x1.da8p6", Float.toHexString(-118.625F));
+        assertEquals("0x1.295788p23", Float.toHexString(9743299.65F));
+        assertEquals("0x1.295788p23", Float.toHexString(9743299.65000F));
+        assertEquals("0x1.295788p23", Float.toHexString(9743299.650001234F));
+        assertEquals("0x1.700d1p33", Float.toHexString(12349743299.65000F));
+    }
+
+    /**
+     * @tests java.lang.Float#valueOf(float)
+     */
+    public void test_valueOfF() {
+        assertEquals(new Float(Float.MIN_VALUE), Float.valueOf(Float.MIN_VALUE));
+        assertEquals(new Float(Float.MAX_VALUE), Float.valueOf(Float.MAX_VALUE));
+        assertEquals(new Float(0), Float.valueOf(0));
+
+        int s = -128;
+        while (s < 128) {
+            assertEquals(new Float(s), Float.valueOf(s));
+            assertEquals(new Float(s + 0.1F), Float.valueOf(s + 0.1F));
+            assertEquals(Float.valueOf(s + 0.1F), Float.valueOf(s + 0.1F));
+            s++;
+        }
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IntegerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IntegerTest.java?rev=429959&r1=429958&r2=429959&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IntegerTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IntegerTest.java Tue Aug  8 21:41:59 2006
@@ -15,10 +15,597 @@
 
 package org.apache.harmony.luni.tests.java.lang;
 
+import java.util.Properties;
+
 import junit.framework.TestCase;
 
 public class IntegerTest extends TestCase {
+    private Properties orgProps;
+    
+    protected void setUp() {
+        orgProps = System.getProperties();
+    }
+
+    protected void tearDown() {
+        System.setProperties(orgProps);
+    }
+
+    /**
+     * @tests java.lang.Integer#byteValue()
+     */
+    public void test_byteValue() {
+        // Test for method byte java.lang.Integer.byteValue()
+        assertEquals("Returned incorrect byte value", -1, new Integer(65535)
+                .byteValue());
+        assertEquals("Returned incorrect byte value", 127, new Integer(127)
+                .byteValue());
+    }
+
+    /**
+     * @tests java.lang.Integer#compareTo(java.lang.Integer)
+     */
+    public void test_compareToLjava_lang_Integer() {
+        // Test for method int java.lang.Integer.compareTo(java.lang.Integer)
+        assertTrue("-2 compared to 1 gave non-negative answer", new Integer(-2)
+                .compareTo(new Integer(1)) < 0);
+        assertEquals("-2 compared to -2 gave non-zero answer", 0, new Integer(-2)
+                .compareTo(new Integer(-2)));
+        assertTrue("3 compared to 2 gave non-positive answer", new Integer(3)
+                .compareTo(new Integer(2)) > 0);
+        
+        try {
+            new Integer(0).compareTo(null);
+            fail("No NPE");
+        } catch (NullPointerException e) {
+        }
+    }
+
+    /**
+     * @tests java.lang.Integer#decode(java.lang.String)
+     */
+    public void test_decodeLjava_lang_String2() {
+        // Test for method java.lang.Integer
+        // java.lang.Integer.decode(java.lang.String)
+        assertEquals("Failed for 132233",
+                132233, Integer.decode("132233").intValue());
+        assertEquals("Failed for 07654321",
+                07654321, Integer.decode("07654321").intValue());
+        assertTrue("Failed for #1234567",
+                Integer.decode("#1234567").intValue() == 0x1234567);
+        assertTrue("Failed for 0xdAd",
+                Integer.decode("0xdAd").intValue() == 0xdad);
+        assertEquals("Failed for -23", -23, Integer.decode("-23").intValue());
+        assertEquals("Returned incorrect value for 0 decimal", 0, Integer
+                .decode("0").intValue());
+        assertEquals("Returned incorrect value for 0 hex", 0, Integer.decode("0x0")
+                .intValue());
+        assertTrue("Returned incorrect value for most negative value decimal",
+                Integer.decode("-2147483648").intValue() == 0x80000000);
+        assertTrue("Returned incorrect value for most negative value hex",
+                Integer.decode("-0x80000000").intValue() == 0x80000000);
+        assertTrue("Returned incorrect value for most positive value decimal",
+                Integer.decode("2147483647").intValue() == 0x7fffffff);
+        assertTrue("Returned incorrect value for most positive value hex",
+                Integer.decode("0x7fffffff").intValue() == 0x7fffffff);
+
+        boolean exception = false;
+        try {
+            Integer.decode("0a");
+        } catch (NumberFormatException e) {
+            // correct
+            exception = true;
+        }
+        assertTrue("Failed to throw NumberFormatException for \"Oa\"",
+                exception);
 
+        exception = false;
+        try {
+            Integer.decode("2147483648");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Integer.decode("-2147483649");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+
+        exception = false;
+        try {
+            Integer.decode("0x80000000");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Integer.decode("-0x80000001");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
+
+        exception = false;
+        try {
+            Integer.decode("9999999999");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for 9999999999", exception);
+    }
+
+    /**
+     * @tests java.lang.Integer#doubleValue()
+     */
+    public void test_doubleValue2() {
+        // Test for method double java.lang.Integer.doubleValue()
+        assertEquals("Returned incorrect double value", 2147483647.0, new Integer(2147483647)
+                .doubleValue(), 0.0D);
+        assertEquals("Returned incorrect double value", -2147483647.0, new Integer(-2147483647)
+                .doubleValue(), 0.0D);
+    }
+
+    /**
+     * @tests java.lang.Integer#equals(java.lang.Object)
+     */
+    public void test_equalsLjava_lang_Object2() {
+        // Test for method boolean java.lang.Integer.equals(java.lang.Object)
+        Integer i1 = new Integer(1000);
+        Integer i2 = new Integer(1000);
+        Integer i3 = new Integer(-1000);
+        assertTrue("Equality test failed", i1.equals(i2) && !(i1.equals(i3)));
+    }
+
+    /**
+     * @tests java.lang.Integer#floatValue()
+     */
+    public void test_floatValue2() {
+        // Test for method float java.lang.Integer.floatValue()
+        assertTrue("Returned incorrect float value", new Integer(65535)
+                .floatValue() == 65535.0f);
+        assertTrue("Returned incorrect float value", new Integer(-65535)
+                .floatValue() == -65535.0f);
+    }
+
+    /**
+     * @tests java.lang.Integer#getInteger(java.lang.String)
+     */
+    public void test_getIntegerLjava_lang_String() {
+        // Test for method java.lang.Integer
+        // java.lang.Integer.getInteger(java.lang.String)
+        Properties tProps = new Properties();
+        tProps.put("testInt", "99");
+        System.setProperties(tProps);
+        assertTrue("returned incorrect Integer", Integer.getInteger("testInt")
+                .equals(new Integer(99)));
+        assertNull("returned incorrect default Integer", Integer
+                .getInteger("ff"));
+    }
+
+    /**
+     * @tests java.lang.Integer#getInteger(java.lang.String, int)
+     */
+    public void test_getIntegerLjava_lang_StringI() {
+        // Test for method java.lang.Integer
+        // java.lang.Integer.getInteger(java.lang.String, int)
+        Properties tProps = new Properties();
+        tProps.put("testInt", "99");
+        System.setProperties(tProps);
+        assertTrue("returned incorrect Integer", Integer.getInteger("testInt",
+                4).equals(new Integer(99)));
+        assertTrue("returned incorrect default Integer", Integer.getInteger(
+                "ff", 4).equals(new Integer(4)));
+    }
+
+    /**
+     * @tests java.lang.Integer#getInteger(java.lang.String, java.lang.Integer)
+     */
+    public void test_getIntegerLjava_lang_StringLjava_lang_Integer() {
+        // Test for method java.lang.Integer
+        // java.lang.Integer.getInteger(java.lang.String, java.lang.Integer)
+        Properties tProps = new Properties();
+        tProps.put("testInt", "99");
+        System.setProperties(tProps);
+        assertTrue("returned incorrect Integer", Integer.getInteger("testInt",
+                new Integer(4)).equals(new Integer(99)));
+        assertTrue("returned incorrect default Integer", Integer.getInteger(
+                "ff", new Integer(4)).equals(new Integer(4)));
+    }
+
+    /**
+     * @tests java.lang.Integer#hashCode()
+     */
+    public void test_hashCode2() {
+        // Test for method int java.lang.Integer.hashCode()
+
+        Integer i1 = new Integer(1000);
+        Integer i2 = new Integer(-1000);
+        assertTrue("Returned incorrect hashcode", i1.hashCode() == 1000
+                && (i2.hashCode() == -1000));
+    }
+
+    /**
+     * @tests java.lang.Integer#intValue()
+     */
+    public void test_intValue2() {
+        // Test for method int java.lang.Integer.intValue()
+
+        Integer i = new Integer(8900);
+        assertEquals("Returned incorrect int value", 8900, i.intValue());
+    }
+
+    /**
+     * @tests java.lang.Integer#longValue()
+     */
+    public void test_longValue2() {
+        // Test for method long java.lang.Integer.longValue()
+        Integer i = new Integer(8900);
+        assertEquals("Returned incorrect long value", 8900L, i.longValue());
+    }
+
+    /**
+     * @tests java.lang.Integer#parseInt(java.lang.String)
+     */
+    public void test_parseIntLjava_lang_String2() {
+        // Test for method int java.lang.Integer.parseInt(java.lang.String)
+
+        int i = Integer.parseInt("-8900");
+        assertEquals("Returned incorrect int", -8900, i);
+        assertEquals("Returned incorrect value for 0", 0, Integer.parseInt("0"));
+        assertTrue("Returned incorrect value for most negative value", Integer
+                .parseInt("-2147483648") == 0x80000000);
+        assertTrue("Returned incorrect value for most positive value", Integer
+                .parseInt("2147483647") == 0x7fffffff);
+
+        boolean exception = false;
+        try {
+            Integer.parseInt("999999999999");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for value > int", exception);
+
+        exception = false;
+        try {
+            Integer.parseInt("2147483648");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Integer.parseInt("-2147483649");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+    }
+
+    /**
+     * @tests java.lang.Integer#parseInt(java.lang.String, int)
+     */
+    public void test_parseIntLjava_lang_StringI2() {
+        // Test for method int java.lang.Integer.parseInt(java.lang.String, int)
+        assertEquals("Parsed dec val incorrectly",
+                -8000, Integer.parseInt("-8000", 10));
+        assertEquals("Parsed hex val incorrectly",
+                255, Integer.parseInt("FF", 16));
+        assertEquals("Parsed oct val incorrectly",
+                16, Integer.parseInt("20", 8));
+        assertEquals("Returned incorrect value for 0 hex", 0, Integer.parseInt("0",
+                16));
+        assertTrue("Returned incorrect value for most negative value hex",
+                Integer.parseInt("-80000000", 16) == 0x80000000);
+        assertTrue("Returned incorrect value for most positive value hex",
+                Integer.parseInt("7fffffff", 16) == 0x7fffffff);
+        assertEquals("Returned incorrect value for 0 decimal", 0, Integer.parseInt(
+                "0", 10));
+        assertTrue("Returned incorrect value for most negative value decimal",
+                Integer.parseInt("-2147483648", 10) == 0x80000000);
+        assertTrue("Returned incorrect value for most positive value decimal",
+                Integer.parseInt("2147483647", 10) == 0x7fffffff);
+
+        boolean exception = false;
+        try {
+            Integer.parseInt("FFFF", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue(
+                "Failed to throw exception when passes hex string and dec parm",
+                exception);
+
+        exception = false;
+        try {
+            Integer.parseInt("2147483648", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Integer.parseInt("-2147483649", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+
+        exception = false;
+        try {
+            Integer.parseInt("80000000", 16);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Integer.parseInt("-80000001", 16);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Integer.parseInt("9999999999", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for 9999999999", exception);
+    }
+
+    /**
+     * @tests java.lang.Integer#shortValue()
+     */
+    public void test_shortValue2() {
+        // Test for method short java.lang.Integer.shortValue()
+        Integer i = new Integer(2147450880);
+        assertEquals("Returned incorrect long value", -32768, i.shortValue());
+    }
+
+    /**
+     * @tests java.lang.Integer#toBinaryString(int)
+     */
+    public void test_toBinaryStringI() {
+        // Test for method java.lang.String
+        // java.lang.Integer.toBinaryString(int)
+        assertEquals("Incorrect string returned", "1111111111111111111111111111111", Integer.toBinaryString(
+                Integer.MAX_VALUE));
+        assertEquals("Incorrect string returned", "10000000000000000000000000000000", Integer.toBinaryString(
+                Integer.MIN_VALUE));
+    }
+
+    /**
+     * @tests java.lang.Integer#toHexString(int)
+     */
+    public void test_toHexStringI() {
+        // Test for method java.lang.String java.lang.Integer.toHexString(int)
+
+        String[] hexvals = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+                "a", "b", "c", "d", "e", "f" };
+
+        for (int i = 0; i < 16; i++) {
+            assertTrue("Incorrect string returned " + hexvals[i], Integer
+                    .toHexString(i).equals(hexvals[i]));
+        }
+
+        assertTrue("Returned incorrect hex string: "
+                + Integer.toHexString(Integer.MAX_VALUE), Integer.toHexString(
+                Integer.MAX_VALUE).equals("7fffffff"));
+        assertTrue("Returned incorrect hex string: "
+                + Integer.toHexString(Integer.MIN_VALUE), Integer.toHexString(
+                Integer.MIN_VALUE).equals("80000000"));
+    }
+
+    /**
+     * @tests java.lang.Integer#toOctalString(int)
+     */
+    public void test_toOctalStringI() {
+        // Test for method java.lang.String java.lang.Integer.toOctalString(int)
+        // Spec states that the int arg is treated as unsigned
+        assertEquals("Returned incorrect octal string", "17777777777", Integer.toOctalString(
+                Integer.MAX_VALUE));
+        assertEquals("Returned incorrect octal string", "20000000000", Integer.toOctalString(
+                Integer.MIN_VALUE));
+    }
+
+    /**
+     * @tests java.lang.Integer#toString()
+     */
+    public void test_toString2() {
+        // Test for method java.lang.String java.lang.Integer.toString()
+
+        Integer i = new Integer(-80001);
+
+        assertEquals("Returned incorrect String", "-80001", i.toString());
+    }
+
+    /**
+     * @tests java.lang.Integer#toString(int)
+     */
+    public void test_toStringI2() {
+        // Test for method java.lang.String java.lang.Integer.toString(int)
+
+        assertEquals("Returned incorrect String", "-80765", Integer.toString(-80765)
+                );
+        assertEquals("Returned incorrect octal string", "2147483647", Integer.toString(
+                Integer.MAX_VALUE));
+        assertEquals("Returned incorrect octal string", "-2147483647", Integer.toString(
+                -Integer.MAX_VALUE));
+        assertEquals("Returned incorrect octal string", "-2147483648", Integer.toString(
+                Integer.MIN_VALUE));
+    }
+
+    /**
+     * @tests java.lang.Integer#toString(int, int)
+     */
+    public void test_toStringII() {
+        // Test for method java.lang.String java.lang.Integer.toString(int, int)
+        assertEquals("Returned incorrect octal string", "17777777777", Integer.toString(
+                2147483647, 8));
+        assertTrue("Returned incorrect hex string--wanted 7fffffff but got: "
+                + Integer.toString(2147483647, 16), Integer.toString(
+                2147483647, 16).equals("7fffffff"));
+        assertEquals("Incorrect string returned", "1111111111111111111111111111111", Integer.toString(2147483647, 2)
+                );
+        assertEquals("Incorrect string returned", "2147483647", Integer
+                .toString(2147483647, 10));
+
+        assertEquals("Returned incorrect octal string", "-17777777777", Integer.toString(
+                -2147483647, 8));
+        assertTrue("Returned incorrect hex string--wanted -7fffffff but got: "
+                + Integer.toString(-2147483647, 16), Integer.toString(
+                -2147483647, 16).equals("-7fffffff"));
+        assertEquals("Incorrect string returned", 
+                        "-1111111111111111111111111111111", Integer
+                .toString(-2147483647, 2));
+        assertEquals("Incorrect string returned", "-2147483647", Integer.toString(-2147483647,
+                10));
+
+        assertEquals("Returned incorrect octal string", "-20000000000", Integer.toString(
+                -2147483648, 8));
+        assertTrue("Returned incorrect hex string--wanted -80000000 but got: "
+                + Integer.toString(-2147483648, 16), Integer.toString(
+                -2147483648, 16).equals("-80000000"));
+        assertEquals("Incorrect string returned", 
+                        "-10000000000000000000000000000000", Integer
+                .toString(-2147483648, 2));
+        assertEquals("Incorrect string returned", "-2147483648", Integer.toString(-2147483648,
+                10));
+    }
+
+    /**
+     * @tests java.lang.Integer#valueOf(java.lang.String)
+     */
+    public void test_valueOfLjava_lang_String2() {
+        // Test for method java.lang.Integer
+        // java.lang.Integer.valueOf(java.lang.String)
+        assertEquals("Returned incorrect int", 8888888, Integer.valueOf("8888888")
+                .intValue());
+        assertTrue("Returned incorrect int", Integer.valueOf("2147483647")
+                .intValue() == Integer.MAX_VALUE);
+        assertTrue("Returned incorrect int", Integer.valueOf("-2147483648")
+                .intValue() == Integer.MIN_VALUE);
+
+        boolean exception = false;
+        try {
+            Integer.valueOf("2147483648");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception with MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Integer.valueOf("-2147483649");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception with MIN_VALUE - 1", exception);
+    }
+
+    /**
+     * @tests java.lang.Integer#valueOf(java.lang.String, int)
+     */
+    public void test_valueOfLjava_lang_StringI2() {
+        // Test for method java.lang.Integer
+        // java.lang.Integer.valueOf(java.lang.String, int)
+        assertEquals("Returned incorrect int for hex string", 255, Integer.valueOf(
+                "FF", 16).intValue());
+        assertEquals("Returned incorrect int for oct string", 16, Integer.valueOf(
+                "20", 8).intValue());
+        assertEquals("Returned incorrect int for bin string", 4, Integer.valueOf(
+                "100", 2).intValue());
+
+        assertEquals("Returned incorrect int for - hex string", -255, Integer.valueOf(
+                "-FF", 16).intValue());
+        assertEquals("Returned incorrect int for - oct string", -16, Integer.valueOf(
+                "-20", 8).intValue());
+        assertEquals("Returned incorrect int for - bin string", -4, Integer.valueOf(
+                "-100", 2).intValue());
+        assertTrue("Returned incorrect int", Integer.valueOf("2147483647", 10)
+                .intValue() == Integer.MAX_VALUE);
+        assertTrue("Returned incorrect int", Integer.valueOf("-2147483648", 10)
+                .intValue() == Integer.MIN_VALUE);
+        assertTrue("Returned incorrect int", Integer.valueOf("7fffffff", 16)
+                .intValue() == Integer.MAX_VALUE);
+        assertTrue("Returned incorrect int", Integer.valueOf("-80000000", 16)
+                .intValue() == Integer.MIN_VALUE);
+
+        boolean exception = false;
+        try {
+            Integer.valueOf("FF", 2);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue(
+                "Failed to throw exception with hex string and base 2 radix",
+                exception);
+
+        exception = false;
+        try {
+            Integer.valueOf("2147483648", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception with MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Integer.valueOf("-2147483649", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception with MIN_VALUE - 1", exception);
+
+        exception = false;
+        try {
+            Integer.valueOf("80000000", 16);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception with hex MAX_VALUE + 1",
+                exception);
+
+        exception = false;
+        try {
+            Integer.valueOf("-80000001", 16);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception with hex MIN_VALUE - 1",
+                exception);
+    }
+    
 	/**
 	 * @tests java.lang.Integer#valueOf(byte)
 	 */
@@ -82,6 +669,9 @@
         assertEquals(2, new Integer(2).intValue());
         assertEquals(0, new Integer(0).intValue());
         assertEquals(-1, new Integer(-1).intValue());
+        
+        Integer i = new Integer(-89000);
+        assertEquals("Incorrect Integer created", -89000, i.intValue());
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LongTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LongTest.java?rev=429959&r1=429958&r2=429959&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LongTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LongTest.java Tue Aug  8 21:41:59 2006
@@ -15,10 +15,493 @@
 
 package org.apache.harmony.luni.tests.java.lang;
 
+import java.util.Properties;
+
 import junit.framework.TestCase;
 
 public class LongTest extends TestCase {
+    private Properties orgProps;
+    
+    protected void setUp() {
+        orgProps = System.getProperties();
+    }
+
+    protected void tearDown() {
+        System.setProperties(orgProps);
+    }
+
+    /**
+     * @tests java.lang.Long#byteValue()
+     */
+    public void test_byteValue() {
+        // Test for method byte java.lang.Long.byteValue()
+        Long l = new Long(127);
+        assertEquals("Returned incorrect byte value", 127, l.byteValue());
+        assertEquals("Returned incorrect byte value", -1, new Long(Long.MAX_VALUE)
+                .byteValue());
+    }
+
+    /**
+     * @tests java.lang.Long#compareTo(java.lang.Long)
+     */
+    public void test_compareToLjava_lang_Long() {
+        // Test for method int java.lang.Long.compareTo(java.lang.Long)
+        assertTrue("-2 compared to 1 gave non-negative answer", new Long(-2L)
+                .compareTo(new Long(1L)) < 0);
+        assertEquals("-2 compared to -2 gave non-zero answer", 0, new Long(-2L)
+                .compareTo(new Long(-2L)));
+        assertTrue("3 compared to 2 gave non-positive answer", new Long(3L)
+                .compareTo(new Long(2L)) > 0);
+        
+        try {
+            new Long(0).compareTo(null);
+            fail("No NPE");
+        } catch (NullPointerException e) {
+        }
+    }
+
+    /**
+     * @tests java.lang.Long#decode(java.lang.String)
+     */
+    public void test_decodeLjava_lang_String2() {
+        // Test for method java.lang.Long
+        // java.lang.Long.decode(java.lang.String)
+        assertEquals("Returned incorrect value for hex string", 255L, Long.decode(
+                "0xFF").longValue());
+        assertEquals("Returned incorrect value for dec string", -89000L, Long.decode(
+                "-89000").longValue());
+        assertEquals("Returned incorrect value for 0 decimal", 0, Long.decode("0")
+                .longValue());
+        assertEquals("Returned incorrect value for 0 hex", 0, Long.decode("0x0")
+                .longValue());
+        assertTrue(
+                "Returned incorrect value for most negative value decimal",
+                Long.decode("-9223372036854775808").longValue() == 0x8000000000000000L);
+        assertTrue(
+                "Returned incorrect value for most negative value hex",
+                Long.decode("-0x8000000000000000").longValue() == 0x8000000000000000L);
+        assertTrue(
+                "Returned incorrect value for most positive value decimal",
+                Long.decode("9223372036854775807").longValue() == 0x7fffffffffffffffL);
+        assertTrue(
+                "Returned incorrect value for most positive value hex",
+                Long.decode("0x7fffffffffffffff").longValue() == 0x7fffffffffffffffL);
+        assertTrue("Failed for 07654321765432", Long.decode("07654321765432")
+                .longValue() == 07654321765432l);
+
+        boolean exception = false;
+        try {
+            Long
+                    .decode("999999999999999999999999999999999999999999999999999999");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for value > ilong", exception);
+
+        exception = false;
+        try {
+            Long.decode("9223372036854775808");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Long.decode("-9223372036854775809");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+
+        exception = false;
+        try {
+            Long.decode("0x8000000000000000");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Long.decode("-0x8000000000000001");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
+
+        exception = false;
+        try {
+            Long.decode("42325917317067571199");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for 42325917317067571199",
+                exception);
+    }
+
+     /**
+     * @tests java.lang.Long#getLong(java.lang.String)
+     */
+    public void test_getLongLjava_lang_String() {
+        // Test for method java.lang.Long
+        // java.lang.Long.getLong(java.lang.String)
+        Properties tProps = new Properties();
+        tProps.put("testLong", "99");
+        System.setProperties(tProps);
+        assertTrue("returned incorrect Long", Long.getLong("testLong").equals(
+                new Long(99)));
+        assertNull("returned incorrect default Long",
+                Long.getLong("ff"));
+    }
+
+    /**
+     * @tests java.lang.Long#getLong(java.lang.String, long)
+     */
+    public void test_getLongLjava_lang_StringJ() {
+        // Test for method java.lang.Long
+        // java.lang.Long.getLong(java.lang.String, long)
+        Properties tProps = new Properties();
+        tProps.put("testLong", "99");
+        System.setProperties(tProps);
+        assertTrue("returned incorrect Long", Long.getLong("testLong", 4L)
+                .equals(new Long(99)));
+        assertTrue("returned incorrect default Long", Long.getLong("ff", 4L)
+                .equals(new Long(4)));
+    }
+
+    /**
+     * @tests java.lang.Long#getLong(java.lang.String, java.lang.Long)
+     */
+    public void test_getLongLjava_lang_StringLjava_lang_Long() {
+        // Test for method java.lang.Long
+        // java.lang.Long.getLong(java.lang.String, java.lang.Long)
+        Properties tProps = new Properties();
+        tProps.put("testLong", "99");
+        System.setProperties(tProps);
+        assertTrue("returned incorrect Long", Long.getLong("testLong",
+                new Long(4)).equals(new Long(99)));
+        assertTrue("returned incorrect default Long", Long.getLong("ff",
+                new Long(4)).equals(new Long(4)));
+    }
+
+    /**
+     * @tests java.lang.Long#parseLong(java.lang.String)
+     */
+    public void test_parseLongLjava_lang_String2() {
+        // Test for method long java.lang.Long.parseLong(java.lang.String)
+
+        long l = Long.parseLong("89000000005");
+        assertEquals("Parsed to incorrect long value", 89000000005L, l);
+        assertEquals("Returned incorrect value for 0", 0, Long.parseLong("0"));
+        assertTrue("Returned incorrect value for most negative value", Long
+                .parseLong("-9223372036854775808") == 0x8000000000000000L);
+        assertTrue("Returned incorrect value for most positive value", Long
+                .parseLong("9223372036854775807") == 0x7fffffffffffffffL);
+
+        boolean exception = false;
+        try {
+            Long.parseLong("9223372036854775808");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Long.parseLong("-9223372036854775809");
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+    }
+
+    /**
+     * @tests java.lang.Long#parseLong(java.lang.String, int)
+     */
+    public void test_parseLongLjava_lang_StringI() {
+        // Test for method long java.lang.Long.parseLong(java.lang.String, int)
+        assertEquals("Returned incorrect value",
+                100000000L, Long.parseLong("100000000", 10));
+        assertEquals("Returned incorrect value from hex string", 68719476735L, Long.parseLong(
+                "FFFFFFFFF", 16));
+        assertTrue("Returned incorrect value from octal string: "
+                + Long.parseLong("77777777777"), Long.parseLong("77777777777",
+                8) == 8589934591L);
+        assertEquals("Returned incorrect value for 0 hex", 0, Long
+                .parseLong("0", 16));
+        assertTrue("Returned incorrect value for most negative value hex", Long
+                .parseLong("-8000000000000000", 16) == 0x8000000000000000L);
+        assertTrue("Returned incorrect value for most positive value hex", Long
+                .parseLong("7fffffffffffffff", 16) == 0x7fffffffffffffffL);
+        assertEquals("Returned incorrect value for 0 decimal", 0, Long.parseLong(
+                "0", 10));
+        assertTrue(
+                "Returned incorrect value for most negative value decimal",
+                Long.parseLong("-9223372036854775808", 10) == 0x8000000000000000L);
+        assertTrue(
+                "Returned incorrect value for most positive value decimal",
+                Long.parseLong("9223372036854775807", 10) == 0x7fffffffffffffffL);
+
+        boolean exception = false;
+        try {
+            Long.parseLong("999999999999", 8);
+        } catch (NumberFormatException e) {
+            // correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception when passed invalid string",
+                exception);
+
+        exception = false;
+        try {
+            Long.parseLong("9223372036854775808", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Long.parseLong("-9223372036854775809", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+
+        exception = false;
+        try {
+            Long.parseLong("8000000000000000", 16);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Long.parseLong("-8000000000000001", 16);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
+
+        exception = false;
+        try {
+            Long.parseLong("42325917317067571199", 10);
+        } catch (NumberFormatException e) {
+            // Correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception for 42325917317067571199",
+                exception);
+    }
+
+    /**
+     * @tests java.lang.Long#toBinaryString(long)
+     */
+    public void test_toBinaryStringJ() {
+        // Test for method java.lang.String java.lang.Long.toBinaryString(long)
+        assertEquals("Incorrect binary string returned", "11011001010010010000", Long.toBinaryString(
+                890000L));
+        assertEquals("Incorrect binary string returned",
+                
+                                "1000000000000000000000000000000000000000000000000000000000000000", Long
+                        .toBinaryString(Long.MIN_VALUE)
+                        );
+        assertEquals("Incorrect binary string returned",
+                
+                                "111111111111111111111111111111111111111111111111111111111111111", Long
+                        .toBinaryString(Long.MAX_VALUE)
+                        );
+    }
+
+    /**
+     * @tests java.lang.Long#toHexString(long)
+     */
+    public void test_toHexStringJ() {
+        // Test for method java.lang.String java.lang.Long.toHexString(long)
+        assertEquals("Incorrect hex string returned", "54e0845", Long.toHexString(89000005L)
+                );
+        assertEquals("Incorrect hex string returned", "8000000000000000", Long.toHexString(
+                Long.MIN_VALUE));
+        assertEquals("Incorrect hex string returned", "7fffffffffffffff", Long.toHexString(
+                Long.MAX_VALUE));
+    }
+
+    /**
+     * @tests java.lang.Long#toOctalString(long)
+     */
+    public void test_toOctalStringJ() {
+        // Test for method java.lang.String java.lang.Long.toOctalString(long)
+        assertEquals("Returned incorrect oct string", "77777777777", Long.toOctalString(
+                8589934591L));
+        assertEquals("Returned incorrect oct string", "1000000000000000000000", Long.toOctalString(
+                Long.MIN_VALUE));
+        assertEquals("Returned incorrect oct string", "777777777777777777777", Long.toOctalString(
+                Long.MAX_VALUE));
+    }
+
+    /**
+     * @tests java.lang.Long#toString()
+     */
+    public void test_toString2() {
+        // Test for method java.lang.String java.lang.Long.toString()
+        Long l = new Long(89000000005L);
+        assertEquals("Returned incorrect String", 
+                "89000000005", l.toString());
+        assertEquals("Returned incorrect String", "-9223372036854775808", new Long(Long.MIN_VALUE)
+                .toString());
+        assertEquals("Returned incorrect String", "9223372036854775807", new Long(Long.MAX_VALUE)
+                .toString());
+    }
+
+    /**
+     * @tests java.lang.Long#toString(long)
+     */
+    public void test_toStringJ2() {
+        // Test for method java.lang.String java.lang.Long.toString(long)
+
+        assertEquals("Returned incorrect String", "89000000005", Long.toString(89000000005L)
+                );
+        assertEquals("Returned incorrect String", "-9223372036854775808", Long.toString(Long.MIN_VALUE)
+                );
+        assertEquals("Returned incorrect String", "9223372036854775807", Long.toString(Long.MAX_VALUE)
+                );
+    }
+
+    /**
+     * @tests java.lang.Long#toString(long, int)
+     */
+    public void test_toStringJI() {
+        // Test for method java.lang.String java.lang.Long.toString(long, int)
+        assertEquals("Returned incorrect dec string", "100000000", Long.toString(100000000L,
+                10));
+        assertEquals("Returned incorrect hex string", "fffffffff", Long.toString(68719476735L,
+                16));
+        assertEquals("Returned incorrect oct string", "77777777777", Long.toString(8589934591L,
+                8));
+        assertEquals("Returned incorrect bin string", 
+                "1111111111111111111111111111111111111111111", Long.toString(
+                8796093022207L, 2));
+        assertEquals("Returned incorrect min string", "-9223372036854775808", Long.toString(
+                0x8000000000000000L, 10));
+        assertEquals("Returned incorrect max string", "9223372036854775807", Long.toString(
+                0x7fffffffffffffffL, 10));
+        assertEquals("Returned incorrect min string", "-8000000000000000", Long.toString(
+                0x8000000000000000L, 16));
+        assertEquals("Returned incorrect max string", "7fffffffffffffff", Long.toString(
+                0x7fffffffffffffffL, 16));
+    }
+
+    /**
+     * @tests java.lang.Long#valueOf(java.lang.String)
+     */
+    public void test_valueOfLjava_lang_String2() {
+        // Test for method java.lang.Long
+        // java.lang.Long.valueOf(java.lang.String)
+        assertEquals("Returned incorrect value", 100000000L, Long.valueOf("100000000")
+                .longValue());
+        assertTrue("Returned incorrect value", Long.valueOf(
+                "9223372036854775807").longValue() == Long.MAX_VALUE);
+        assertTrue("Returned incorrect value", Long.valueOf(
+                "-9223372036854775808").longValue() == Long.MIN_VALUE);
+
+        boolean exception = false;
+        try {
+            Long
+                    .valueOf("999999999999999999999999999999999999999999999999999999999999");
+        } catch (NumberFormatException e) {
+            // correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception when passed invalid string",
+                exception);
+
+        exception = false;
+        try {
+            Long.valueOf("9223372036854775808");
+        } catch (NumberFormatException e) {
+            // correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception when passed invalid string",
+                exception);
+
+        exception = false;
+        try {
+            Long.valueOf("-9223372036854775809");
+        } catch (NumberFormatException e) {
+            // correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception when passed invalid string",
+                exception);
+    }
+
+    /**
+     * @tests java.lang.Long#valueOf(java.lang.String, int)
+     */
+    public void test_valueOfLjava_lang_StringI() {
+        // Test for method java.lang.Long
+        // java.lang.Long.valueOf(java.lang.String, int)
+        assertEquals("Returned incorrect value", 100000000L, Long.valueOf("100000000", 10)
+                .longValue());
+        assertEquals("Returned incorrect value from hex string", 68719476735L, Long.valueOf(
+                "FFFFFFFFF", 16).longValue());
+        assertTrue("Returned incorrect value from octal string: "
+                + Long.valueOf("77777777777", 8).toString(), Long.valueOf(
+                "77777777777", 8).longValue() == 8589934591L);
+        assertTrue("Returned incorrect value", Long.valueOf(
+                "9223372036854775807", 10).longValue() == Long.MAX_VALUE);
+        assertTrue("Returned incorrect value", Long.valueOf(
+                "-9223372036854775808", 10).longValue() == Long.MIN_VALUE);
+        assertTrue("Returned incorrect value", Long.valueOf("7fffffffffffffff",
+                16).longValue() == Long.MAX_VALUE);
+        assertTrue("Returned incorrect value", Long.valueOf(
+                "-8000000000000000", 16).longValue() == Long.MIN_VALUE);
+
+        boolean exception = false;
+        try {
+            Long.valueOf("999999999999", 8);
+        } catch (NumberFormatException e) {
+            // correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception when passed invalid string",
+                exception);
+
+        exception = false;
+        try {
+            Long.valueOf("9223372036854775808", 10);
+        } catch (NumberFormatException e) {
+            // correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception when passed invalid string",
+                exception);
 
+        exception = false;
+        try {
+            Long.valueOf("-9223372036854775809", 10);
+        } catch (NumberFormatException e) {
+            // correct
+            exception = true;
+        }
+        assertTrue("Failed to throw exception when passed invalid string",
+                exception);
+    }
     /**
      * @tests java.lang.Long#valueOf(long)
      */

Copied: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberTest.java (from r429950, incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberTest.java)
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberTest.java?p2=incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberTest.java&p1=incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberTest.java&r1=429950&r2=429959&rev=429959&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/lang/NumberTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberTest.java Tue Aug  8 21:41:59 2006
@@ -13,7 +13,7 @@
  * limitations under the License.
  */
 
-package tests.api.java.lang;
+package org.apache.harmony.luni.tests.java.lang;
 
 public class NumberTest extends junit.framework.TestCase {
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java?rev=429959&r1=429958&r2=429959&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java Tue Aug  8 21:41:59 2006
@@ -18,18 +18,59 @@
 import junit.framework.TestCase;
 
 public class SecurityManagerTest extends TestCase {
+    
+    /**
+     * @tests java.lang.SecurityManager#checkMemberAccess(java.lang.Class, int)
+     */
+    public void test_checkMemberAccessLjava_lang_ClassI() {
+        System.setSecurityManager(new SecurityManager());
+        try {
+            try {
+                getClass().getDeclaredFields();
+            } catch (SecurityException e) {
+                fail("This should not throw a security exception");
+            }
 
-	/**
-	 * @tests java.lang.SecurityManager#checkAccess(java.lang.Thread)
-	 */
-	public void test_checkAccessLjava_lang_Thread() throws InterruptedException {
-		// Regression for HARMONY-66
-		Thread t = new Thread() {
-			public void run() {
-			};
-		};
-		t.start();
-		t.join();
-		new SecurityManager().checkAccess(t);
-	}
+            try {
+                Object.class.getDeclaredFields();
+                fail("This should throw a SecurityException.");
+            } catch (SecurityException e) {
+            }
+
+        } finally {
+            System.setSecurityManager(null);
+        }
+    }
+
+    /**
+     * @tests java.lang.SecurityManager#checkPermission(java.security.Permission)
+     */
+    public void test_checkPermissionLjava_security_Permission() {
+        System.setSecurityManager(new SecurityManager());
+        try {
+            try {
+                System.getSecurityManager().checkPermission(
+                        new RuntimePermission("createClassLoader"));
+                fail("This should throw a SecurityException");
+            } catch (SecurityException e) {
+            }
+        } finally {
+            System.setSecurityManager(null);
+        }
+    }
+
+    /**
+     * @tests java.lang.SecurityManager#checkAccess(java.lang.Thread)
+     */
+    public void test_checkAccessLjava_lang_Thread() throws InterruptedException {
+        // Regression for HARMONY-66
+        Thread t = new Thread() {
+            @Override
+            public void run() {
+            };
+        };
+        t.start();
+        t.join();
+        new SecurityManager().checkAccess(t);
+    }
 }



Mime
View raw message