diff options
author | Urs Grob <> | 2009-04-22 10:08:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-22 10:08:00 -0700 |
commit | cfa4d0b6e3295190bafce48e6807ab7110302351 (patch) | |
tree | 6d244b916f752b90d5062186b97035404713b87e /luni | |
parent | b90da8218274400c8710211d467ed28f23bc28ba (diff) | |
download | libcore-cfa4d0b6e3295190bafce48e6807ab7110302351.zip libcore-cfa4d0b6e3295190bafce48e6807ab7110302351.tar.gz libcore-cfa4d0b6e3295190bafce48e6807ab7110302351.tar.bz2 |
AI 147388: am: CL 147386 am: CL 147384 Fixes from the review of 'Bringing luni down to 15 broken tests.
Not perfect, but an improvement.' that Joerg didn't fix yet.
Original author: ursg
Merged from: //branches/cupcake/...
Original author: android-build
Automated import of CL 147388
Diffstat (limited to 'luni')
3 files changed, 92 insertions, 133 deletions
diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest0.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest0.java index c200dee..a91817c 100644 --- a/luni/src/test/java/tests/api/java/io/SerializationStressTest0.java +++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest0.java @@ -922,17 +922,12 @@ public class SerializationStressTest0 extends SerializationStressTest { method = "!Serialization", args = {} ) - public void test_2_writeReplace_01() { + public void test_2_writeReplace_01() throws IOException { try { - boolean exception = false; - try { - oos.writeObject(new WriteReplaceTestF(0, -1)); - } catch (ObjectStreamException e) { - exception = true; - } - assertTrue("Should throw ObjectStreamException", exception); - } catch (IOException e) { - fail("IOException serializing data : " + e.getMessage()); + oos.writeObject(new WriteReplaceTestF(0, -1)); + fail("Should throw ObjectStreamException"); + } catch (ObjectStreamException e) { + // expected } } @@ -942,17 +937,12 @@ public class SerializationStressTest0 extends SerializationStressTest { method = "!Serialization", args = {} ) - public void test_2_writeReplace_02() { + public void test_2_writeReplace_02() throws IOException { try { - boolean exception = false; - try { - oos.writeObject(new WriteReplaceTestF(1, -1)); - } catch (RuntimeException e) { - exception = true; - } - assertTrue("Should throw RuntimeException", exception); - } catch (IOException e) { - fail("IOException serializing data : " + e.getMessage()); + oos.writeObject(new WriteReplaceTestF(1, -1)); + fail("Should throw RuntimeException"); + } catch (RuntimeException e) { + // expected } } @@ -962,17 +952,12 @@ public class SerializationStressTest0 extends SerializationStressTest { method = "!Serialization", args = {} ) - public void test_2_writeReplace_03() { + public void test_2_writeReplace_03() throws IOException { try { - boolean exception = false; - try { - oos.writeObject(new WriteReplaceTestF(2, -1)); - } catch (Error e) { - exception = true; - } - assertTrue("Should throw Error", exception); - } catch (IOException e) { - fail("IOException serializing data : " + e.getMessage()); + oos.writeObject(new WriteReplaceTestF(2, -1)); + fail("Should throw Error"); + } catch (Error e) { + // expected } } @@ -982,54 +967,46 @@ public class SerializationStressTest0 extends SerializationStressTest { method = "!Serialization", args = {} ) - public void test_2_writeReplace_04() { + public void test_2_writeReplace_04() throws IOException, + ClassNotFoundException { + oos.writeObject(new WriteReplaceTestF(3, 0)); + oos.writeObject(new WriteReplaceTestF(3, 1)); + oos.writeObject(new WriteReplaceTestF(3, 2)); + WriteReplaceTestF test = new WriteReplaceTestF(3, 3); + oos.writeObject(test); + oos.writeObject(test); + WriteReplaceTestF test2 = new WriteReplaceTestF(3, 4); + oos.writeObject(test2); + oos.writeObject(test2); + oos.close(); + ois = new ObjectInputStream(loadStream()); try { - boolean exception = false; - - oos.writeObject(new WriteReplaceTestF(3, 0)); - oos.writeObject(new WriteReplaceTestF(3, 1)); - oos.writeObject(new WriteReplaceTestF(3, 2)); - WriteReplaceTestF test = new WriteReplaceTestF(3, 3); - oos.writeObject(test); - oos.writeObject(test); - WriteReplaceTestF test2 = new WriteReplaceTestF(3, 4); - oos.writeObject(test2); - oos.writeObject(test2); - oos.close(); - ois = new ObjectInputStream(loadStream()); - try { - ois.readObject(); - } catch (InvalidObjectException e) { - exception = true; - } - assertTrue("Expected InvalidObjectException", exception); + ois.readObject(); + fail("Expected InvalidObjectException"); + } catch (InvalidObjectException e) { + // expected + } - exception = false; - try { - ois.readObject(); - } catch (RuntimeException e) { - exception = true; - } - assertTrue("Expected RuntimeException", exception); - exception = false; - try { - ois.readObject(); - } catch (Error e) { - exception = true; - } - assertTrue("Expected Error", exception); - - Object readE1 = ois.readObject(); - Object readE2 = ois.readObject(); - assertTrue("Replaced objects should be identical", readE1 == readE2); - Object readF1 = ois.readObject(); - Object readF2 = ois.readObject(); - assertTrue("Replaced resolved objects should be identical: " - + readF1 + " " + readF2, readF1 == readF2); - } catch (IOException e) { - fail("IOException serializing data : " + e.getMessage()); - } catch (ClassNotFoundException e) { - fail("ClassNotFoundException serializing data : " + e.getMessage()); + try { + ois.readObject(); + fail("Expected RuntimeException"); + } catch (RuntimeException e) { + // expected } + + try { + ois.readObject(); + fail("Expected Error"); + } catch (Error e) { + // expected + } + + Object readE1 = ois.readObject(); + Object readE2 = ois.readObject(); + assertTrue("Replaced objects should be identical", readE1 == readE2); + Object readF1 = ois.readObject(); + Object readF2 = ois.readObject(); + assertTrue("Replaced resolved objects should be identical: " + + readF1 + " " + readF2, readF1 == readF2); } } diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest1.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest1.java index 2f5c265..a8621a1 100644 --- a/luni/src/test/java/tests/api/java/io/SerializationStressTest1.java +++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest1.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.NotSerializableException; import java.io.Serializable; import java.util.Arrays; +import java.util.Hashtable; import java.util.Vector; @SuppressWarnings("serial") @@ -1246,7 +1247,7 @@ public class SerializationStressTest1 extends SerializationStressTest { Object objLoaded; try { - java.util.Vector<String> vector = new java.util.Vector<String>(1); + Vector<String> vector = new Vector<String>(1); vector.add(FOO); objToSave = vector; if (DEBUG) @@ -1254,7 +1255,7 @@ public class SerializationStressTest1 extends SerializationStressTest { objLoaded = dumpAndReload(objToSave); // Has to have the string there @SuppressWarnings("unchecked") - java.util.Vector<String> obj = (Vector<String>)objLoaded; + Vector<String> obj = (Vector<String>) objLoaded; assertTrue(MSG_TEST_FAILED + objToSave, FOO .equals(obj.elementAt(0))); @@ -1284,14 +1285,14 @@ public class SerializationStressTest1 extends SerializationStressTest { Object objLoaded; try { - java.util.Hashtable<String, String> hashTable = new java.util.Hashtable<String, String>(5); + Hashtable<String, String> hashTable = new Hashtable<String, String>(5); hashTable.put(FOO, FOO); objToSave = hashTable; if (DEBUG) System.out.println("Obj = " + objToSave); objLoaded = dumpAndReload(objToSave); @SuppressWarnings("unchecked") - java.util.Hashtable<String, String> loadedHashTable = (java.util.Hashtable<String, String>) objLoaded; + Hashtable<String, String> loadedHashTable = (Hashtable<String, String>) objLoaded; // Has to have the key/value there (FOO -> FOO) assertTrue(MSG_TEST_FAILED + objToSave, FOO.equals(loadedHashTable .get(FOO))); diff --git a/luni/src/test/java/tests/api/java/io/SerializationStressTest4.java b/luni/src/test/java/tests/api/java/io/SerializationStressTest4.java index 3669a1b..ef73192 100644 --- a/luni/src/test/java/tests/api/java/io/SerializationStressTest4.java +++ b/luni/src/test/java/tests/api/java/io/SerializationStressTest4.java @@ -1193,59 +1193,40 @@ public class SerializationStressTest4 extends SerializationStressTest { // // } - /* - * serializing java.util.Collections.UnmodifiableMap.UnmodifiableEntrySet tries to serialize - * java.util.HashMap.EntrySet which is not serializable - */ - // @TestTargetNew( - // level = TestLevel.COMPLETE, - // notes = "Verifies serialization.", - // method = "!Serialization", - // args = {} - // ) - // @BrokenTest("Needs investigation. Fails on RI and on Android with the same IOException.") - // public void - // test_writeObject_Collections_UnmodifiableMap_UnmodifiableEntrySet() { - // // Test for method void - // // - // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableMap.UnmodifiableEntrySet) - // - // Object objToSave = null; - // Object objLoaded = null; - // - // try { - // objToSave = java.util.Collections.unmodifiableMap(MAP).entrySet(); - // if (DEBUG) - // System.out.println("Obj = " + objToSave); - // objLoaded = dumpAndReload(objToSave); - // - // // Has to have worked - // boolean equals; - // equals = ((java.util.Collection) objToSave).size() == - // ((java.util.Collection) objLoaded) - // .size(); - // if (equals) { - // java.util.Iterator iter1 = ((java.util.Collection) objToSave) - // .iterator(), iter2 = ((java.util.Collection) objLoaded) - // .iterator(); - // while (iter1.hasNext()) - // equals = equals && iter1.next().equals(iter2.next()); - // } - // assertTrue(MSG_TEST_FAILED + objToSave, equals); - // } catch (IOException e) { - // e.printStackTrace(); - // fail("IOException serializing " + objToSave + " : " - // + e.getMessage()); - // } catch (ClassNotFoundException e) { - // fail("ClassNotFoundException reading Object type : " - // + e.getMessage()); - // } catch (Error err) { - // System.out.println("Error when obj = " + objToSave); - // // err.printStackTrace(); - // throw err; - // } - // - // } + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "Verifies serialization.", + method = "!Serialization", + args = {} + ) + public void test_writeObject_Collections_UnmodifiableMap() { + // Test for method void + // java.io.ObjectOutputStream.writeObject(java.util.Collections.UnmodifiableMap) + + Object objToSave = null; + Object objLoaded = null; + + try { + objToSave = java.util.Collections.unmodifiableMap(MAP); + if (DEBUG) System.out.println("Obj = " + objToSave); + objLoaded = dumpAndReload(objToSave); + + // Has to have worked + assertEquals(MSG_TEST_FAILED, objToSave, objLoaded); + } catch (IOException e) { + e.printStackTrace(); + fail("IOException serializing " + objToSave + " : " + + e.getMessage()); + } catch (ClassNotFoundException e) { + fail("ClassNotFoundException reading Object type : " + + e.getMessage()); + } catch (Error err) { + System.out.println("Error when obj = " + objToSave); + // err.printStackTrace(); + throw err; + } + + } @TestTargetNew( level = TestLevel.COMPLETE, |