Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Unified Diff: mojo/android/javatests/src/org/chromium/mojo/bindings/SerializationTest.java

Issue 2327103004: Mojo Java Bindings: expose public API for struct serialization. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/android/javatests/src/org/chromium/mojo/bindings/SerializationTest.java
diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/SerializationTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/SerializationTest.java
index a7e213cbdf746607d94ea6ab78d72394e048857d..1d150a1a2c24b5c3fdce608027f5ce9865c2ced0 100644
--- a/mojo/android/javatests/src/org/chromium/mojo/bindings/SerializationTest.java
+++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/SerializationTest.java
@@ -17,6 +17,8 @@ import org.chromium.mojo.bindings.test.mojom.mojo.Struct5;
import org.chromium.mojo.bindings.test.mojom.mojo.Struct6;
import org.chromium.mojo.bindings.test.mojom.mojo.StructOfNullables;
+import java.nio.ByteBuffer;
+
/**
* Tests for the serialization logic of the generated structs, using structs defined in
* mojo/public/interfaces/bindings/tests/serialization_test_structs.mojom .
@@ -128,4 +130,46 @@ public class SerializationTest extends TestCase {
assertNull(struct.str);
struct.serialize(null);
}
+
+ /**
+ * Verifies that a struct can be serialized to and deserialized from a ByteBuffer.
+ */
+ @SmallTest
+ public void testByteBufferSerialization() {
+ Struct1 input = new Struct1();
+ input.i = 0x7F;
+
+ ByteBuffer buf = input.serialize();
+
+ byte[] expected_raw_bytes = {16, 0, 0, 0, 0, 0, 0, 0, 0x7F, 0, 0, 0, 0, 0, 0, 0};
+ ByteBuffer expected_buf = ByteBuffer.wrap(expected_raw_bytes);
+ assertEquals(expected_buf, buf);
+
+ Struct1 output = Struct1.deserialize(buf);
+ assertEquals(0x7F, output.i);
+ }
+
+ /**
+ * Verifies that a struct with handles cannot be serialized to a ByteBuffer.
+ */
+ @SmallTest
+ public void testByteBufferSerializationWithHandles() {
+ StructOfNullables struct = new StructOfNullables();
+ assertFalse(struct.hdl.isValid());
+ assertNull(struct.struct1);
+ assertNull(struct.str);
+
+ // It is okay to serialize invalid handles.
+ struct.serialize();
+
+ struct.hdl = new HandleMock();
+
+ try {
+ struct.serialize();
+ fail("Serializing a struct with handles to a ByteBuffer should have thrown an "
+ + "exception.");
+ } catch (UnsupportedOperationException ex) {
+ // Expected.
+ }
+ }
}
« no previous file with comments | « no previous file | mojo/public/java/bindings/src/org/chromium/mojo/bindings/Struct.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698