|
@@ -30,8 +30,14 @@
|
|
|
|
|
|
package com.google.protobuf;
|
|
package com.google.protobuf;
|
|
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.ObjectInputStream;
|
|
|
|
+import java.io.ObjectOutputStream;
|
|
import java.io.UnsupportedEncodingException;
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* This class tests {@link BoundedByteString}, which extends {@link LiteralByteString},
|
|
* This class tests {@link BoundedByteString}, which extends {@link LiteralByteString},
|
|
* by inheriting the tests from {@link LiteralByteStringTest}. The only method which
|
|
* by inheriting the tests from {@link LiteralByteStringTest}. The only method which
|
|
@@ -65,4 +71,17 @@ public class BoundedByteStringTest extends LiteralByteStringTest {
|
|
assertEquals(classUnderTest + " unicode bytes must match",
|
|
assertEquals(classUnderTest + " unicode bytes must match",
|
|
testString.substring(2, testString.length() - 6), roundTripString);
|
|
testString.substring(2, testString.length() - 6), roundTripString);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void testJavaSerialization() throws Exception {
|
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
+ ObjectOutputStream oos = new ObjectOutputStream(out);
|
|
|
|
+ oos.writeObject(stringUnderTest);
|
|
|
|
+ oos.close();
|
|
|
|
+ byte[] pickled = out.toByteArray();
|
|
|
|
+ InputStream in = new ByteArrayInputStream(pickled);
|
|
|
|
+ ObjectInputStream ois = new ObjectInputStream(in);
|
|
|
|
+ Object o = ois.readObject();
|
|
|
|
+ assertTrue("Didn't get a ByteString back", o instanceof ByteString);
|
|
|
|
+ assertEquals("Should get an equal ByteString back", stringUnderTest, o);
|
|
|
|
+ }
|
|
}
|
|
}
|