Index: mojo/public/js/bindings/struct_unittests.js |
diff --git a/mojo/public/js/bindings/struct_unittests.js b/mojo/public/js/bindings/struct_unittests.js |
index 2d7abe513c253d8a760041a55efbb1d1ab2aefb6..b5d14bae26a9e3d7cf32c63eb441cce6317bf47c 100644 |
--- a/mojo/public/js/bindings/struct_unittests.js |
+++ b/mojo/public/js/bindings/struct_unittests.js |
@@ -5,10 +5,12 @@ |
define([ |
"gin/test/expect", |
"mojo/public/interfaces/bindings/tests/rect.mojom", |
- "mojo/public/interfaces/bindings/tests/test_structs.mojom" |
+ "mojo/public/interfaces/bindings/tests/test_structs.mojom", |
+ "mojo/public/js/bindings/codec", |
], function(expect, |
rect, |
- testStructs) { |
+ testStructs, |
+ codec) { |
function testConstructors() { |
var r = new rect.Rect(); |
@@ -93,9 +95,44 @@ define([ |
expect(s.f6).toEqual(10); |
} |
+ function structEncodeDecode(struct) { |
+ var structClass = struct.constructor; |
+ var builder = new codec.MessageBuilder(1234, structClass.encodedSize); |
+ builder.encodeStruct(structClass, struct); |
+ var reader = new codec.MessageReader(builder.finish()); |
+ return reader.decodeStruct(structClass); |
+ } |
+ |
+ function testMapFields() { |
+ var mapFieldsStruct = new testStructs.MapFields({ |
+ f0: new Map([[true, false], [false, true]]), // map<bool, bool> |
+ f1: new Map([[0, 0], [1, 127], [-1, -128]]), // map<int8, int8> |
+ f2: new Map([[0, 0], [1, 127], [2, 255]]), // map<uint8, uint8> |
+ f3: new Map([[0, 0], [1, 32767], [2, -32768]]), // map<int16, int16> |
+ f4: new Map([[0, 0], [1, 32768], [2, 0xFFFF]]), // map<uint16, uint16> |
+ f5: new Map([[0, 0], [1, 32767], [2, -32768]]), // map<int32, int32> |
+ f6: new Map([[0, 0], [1, 32768], [2, 0xFFFF]]), // map<uint32, uint32> |
+ f7: new Map([[1000.5, -50000], [100.5, 5000]]), // map<float, float> |
+ f8: new Map([[-100.5, -50000], [0, 50000000]]), // map<double, double> |
+ f9: new Map([["one", "two"], ["free", "four"]]), // map<string, string> |
+ }); |
+ var decodedStruct = structEncodeDecode(mapFieldsStruct); |
+ expect(decodedStruct.f0).toEqual(mapFieldsStruct.f0); |
+ expect(decodedStruct.f1).toEqual(mapFieldsStruct.f1); |
+ expect(decodedStruct.f2).toEqual(mapFieldsStruct.f2); |
+ expect(decodedStruct.f3).toEqual(mapFieldsStruct.f3); |
+ expect(decodedStruct.f4).toEqual(mapFieldsStruct.f4); |
+ expect(decodedStruct.f5).toEqual(mapFieldsStruct.f5); |
+ expect(decodedStruct.f6).toEqual(mapFieldsStruct.f6); |
+ expect(decodedStruct.f7).toEqual(mapFieldsStruct.f7); |
+ expect(decodedStruct.f8).toEqual(mapFieldsStruct.f8); |
+ expect(decodedStruct.f9).toEqual(mapFieldsStruct.f9); |
+ } |
+ |
testConstructors(); |
testNoDefaultFieldValues(); |
testDefaultFieldValues(); |
testScopedConstants(); |
+ testMapFields(); |
this.result = "PASS"; |
}); |