| 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..c1f707d8a0bd438c41759ffe1b406bab9f6076d6 100644
|
| --- a/mojo/public/js/bindings/struct_unittests.js
|
| +++ b/mojo/public/js/bindings/struct_unittests.js
|
| @@ -5,10 +5,14 @@
|
| 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",
|
| + "mojo/public/js/bindings/validator",
|
| ], function(expect,
|
| rect,
|
| - testStructs) {
|
| + testStructs,
|
| + codec,
|
| + validator) {
|
|
|
| function testConstructors() {
|
| var r = new rect.Rect();
|
| @@ -93,9 +97,67 @@ 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 message = builder.finish();
|
| +
|
| + var messageValidator = new validator.Validator(message);
|
| + var err = structClass.validate(messageValidator, codec.kMessageHeaderSize);
|
| + expect(err).toEqual(validator.validationError.NONE);
|
| +
|
| + var reader = new codec.MessageReader(message);
|
| + return reader.decodeStruct(structClass);
|
| + }
|
| +
|
| + function testMapKeyTypes() {
|
| + var mapFieldsStruct = new testStructs.MapKeyTypes({
|
| + 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([[0, 0], [1, 32767], [2, -32768]]), // map<int64, int64>
|
| + f8: new Map([[0, 0], [1, 32768], [2, 0xFFFF]]), // map<uint64, uint64>
|
| + f9: new Map([[1000.5, -50000], [100.5, 5000]]), // map<float, float>
|
| + f10: new Map([[-100.5, -50000], [0, 50000000]]), // map<double, double>
|
| + f11: 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);
|
| + expect(decodedStruct.f10).toEqual(mapFieldsStruct.f10);
|
| + expect(decodedStruct.f11).toEqual(mapFieldsStruct.f11);
|
| + }
|
| +
|
| + function testMapValueTypes() {
|
| + var mapFieldsStruct = new testStructs.MapValueTypes({
|
| + f0: new Map([["a", ["b", "c"]], ["d", ["e"]]]), // array<string>>
|
| + f1: new Map([["a", null], ["b", ["c", "d"]]]), // array<string>?>
|
| + f2: new Map([["a", [null]], ["b", [null, "d"]]]), // array<string?>>
|
| + });
|
| + var decodedStruct = structEncodeDecode(mapFieldsStruct);
|
| + expect(decodedStruct.f0).toEqual(mapFieldsStruct.f0);
|
| + expect(decodedStruct.f1).toEqual(mapFieldsStruct.f1);
|
| + expect(decodedStruct.f2).toEqual(mapFieldsStruct.f2);
|
| + }
|
| +
|
| testConstructors();
|
| testNoDefaultFieldValues();
|
| testDefaultFieldValues();
|
| testScopedConstants();
|
| + testMapKeyTypes();
|
| + testMapValueTypes();
|
| this.result = "PASS";
|
| -});
|
| +});
|
|
|