diff options
author | Brian Carlstrom <bdc@google.com> | 2011-04-29 21:29:36 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2011-04-29 21:45:36 -0700 |
commit | d7a21ec11a89594497f35f731b42d98af72e1235 (patch) | |
tree | c45d8893a9e7ceb477c935d5966ea234bc841c9e /support | |
parent | 0c814baa7aff1b0845b2ad36c62dc791700732e1 (diff) | |
parent | 7195b3b965df5c3288435d94e8d13bd256e33890 (diff) | |
download | libcore-d7a21ec11a89594497f35f731b42d98af72e1235.zip libcore-d7a21ec11a89594497f35f731b42d98af72e1235.tar.gz libcore-d7a21ec11a89594497f35f731b42d98af72e1235.tar.bz2 |
resolved conflicts for merge of 7195b3b9 to dalvik-dev
Change-Id: Ie1f2d796466f1799929b010d67585fd551b6f840
Diffstat (limited to 'support')
-rw-r--r-- | support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java | 63 | ||||
-rw-r--r-- | support/src/test/java/tests/support/resource/Support_Resources.java | 18 |
2 files changed, 21 insertions, 60 deletions
diff --git a/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java b/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java index 958d471..8d0c3a4 100644 --- a/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java +++ b/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java @@ -38,9 +38,7 @@ import java.security.PermissionCollection; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import junit.framework.Assert; import junit.framework.TestCase; -import libcore.util.Objects; /** * Framework for serialization testing. Subclasses only need to override @@ -64,22 +62,6 @@ import libcore.util.Objects; public abstract class SerializationTest extends TestCase { /** - * Property name for the testing mode. - */ - public static final String MODE_KEY = "test.mode"; - - - /** - * Testing mode. - */ - public static String mode = System.getProperty(MODE_KEY); - - /** - * Reference files generation mode switch. - */ - public static final String SERIAL_REFERENCE_MODE = "serial.reference"; - - /** * Key to a system property defining root location of golden files. */ public static final String GOLDEN_PATH = "RESOURCE_DIR"; @@ -88,33 +70,6 @@ public abstract class SerializationTest extends TestCase { "src/test/resources/serialization"); /** - * Parameterized c-tor inherited from superclass. - */ - public SerializationTest(String name) { - super(name); - } - - /** - * Default c-tor inherited from superclass. - */ - public SerializationTest() { - super(); - } - - /** - * Depending on testing mode, produces golden files or performs testing. - */ - @Override - public void runBare() throws Throwable { - - if (Objects.equal(mode, SERIAL_REFERENCE_MODE)) { - produceGoldenFiles(); - } else { - super.runBare(); - } - } - - /** * This is the main working method of this framework. Subclasses must * override it to provide actual objects for testing. * @@ -314,6 +269,7 @@ public abstract class SerializationTest extends TestCase { */ public static SerializableAssert defineComparator(TestCase test, Object object) throws Exception { + if (test instanceof SerializableAssert) { return (SerializableAssert) test; } @@ -329,7 +285,7 @@ public abstract class SerializationTest extends TestCase { // instead of 'instanceof' for the first element if (object instanceof Throwable) { return THROWABLE_COMPARATOR; - } + } if (object instanceof PermissionCollection) { return PERMISSION_COLLECTION_COMPARATOR; } @@ -345,8 +301,7 @@ public abstract class SerializationTest extends TestCase { * @param test - test case * @param object - to be compared */ - public static void verifyGolden(TestCase test, Object object) - throws Exception { + public static void verifyGolden(TestCase test, Object object) throws Exception { verifyGolden(test, object, defineComparator(test, object)); } @@ -379,8 +334,7 @@ public abstract class SerializationTest extends TestCase { * @param test - test case * @param objects - array of objects to be compared */ - public static void verifyGolden(TestCase test, Object[] objects) - throws Exception { + public static void verifyGolden(TestCase test, Object[] objects) throws Exception { assertFalse("Empty array", objects.length == 0); verifyGolden(test, objects, defineComparator(test, objects[0])); } @@ -417,8 +371,7 @@ public abstract class SerializationTest extends TestCase { * * @param object - to be serialized/deserialized */ - public static void verifySelf(Object object) - throws Exception { + public static void verifySelf(Object object) throws Exception { verifySelf(object, defineComparator(null, object)); } @@ -431,8 +384,7 @@ public abstract class SerializationTest extends TestCase { * @param object - object to be serialized/deserialized * @param comparator - for comparing serialized/deserialized object with initial object */ - public static void verifySelf(Object object, SerializableAssert comparator) - throws Exception { + public static void verifySelf(Object object, SerializableAssert comparator) throws Exception { Serializable initial = (Serializable) object; comparator.assertDeserialized(initial, copySerializable(initial)); } @@ -469,8 +421,7 @@ public abstract class SerializationTest extends TestCase { } } - private static Serializable getObject(TestCase test, String toAppend) - throws Exception { + private static Serializable getObject(TestCase test, String toAppend) throws Exception { StringBuilder path = new StringBuilder("/serialization"); path.append(File.separatorChar); path.append(test.getClass().getName().replace('.', File.separatorChar)); diff --git a/support/src/test/java/tests/support/resource/Support_Resources.java b/support/src/test/java/tests/support/resource/Support_Resources.java index c1594d4..80a53fb 100644 --- a/support/src/test/java/tests/support/resource/Support_Resources.java +++ b/support/src/test/java/tests/support/resource/Support_Resources.java @@ -17,16 +17,15 @@ package tests.support.resource; -import libcore.io.Streams; -import tests.support.Support_Configuration; - import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URL; +import tests.support.Support_Configuration; public class Support_Resources { @@ -118,13 +117,24 @@ public class Support_Resources { public static void copyLocalFileto(File dest, InputStream in) throws IOException { if (!dest.exists()) { FileOutputStream out = new FileOutputStream(dest); - Streams.copy(in, out); + copy(in, out); out.close(); dest.deleteOnExit(); } in.close(); } + private static int copy(InputStream in, OutputStream out) throws IOException { + int total = 0; + byte[] buffer = new byte[8192]; + int c; + while ((c = in.read(buffer)) != -1) { + total += c; + out.write(buffer, 0, c); + } + return total; + } + public static File getExternalLocalFile(String url) throws IOException { File resources = createTempFolder(); InputStream in = new URL(url).openStream(); |