| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 define([ | 5 define([ |
| 6 "gin/test/expect", | 6 "gin/test/expect", |
| 7 "mojo/public/js/bindings/codec", | 7 "mojo/public/js/bindings/codec", |
| 8 "mojo/public/interfaces/bindings/tests/sample_service.mojom", | 8 "mojo/public/interfaces/bindings/tests/sample_service.mojom", |
| 9 ], function(expect, codec, sample) { | 9 ], function(expect, codec, sample) { |
| 10 testBar(); | 10 testBar(); |
| 11 testFoo(); | 11 testFoo(); |
| 12 testTypes(); |
| 12 testAlign(); | 13 testAlign(); |
| 13 testUtf8(); | 14 testUtf8(); |
| 14 this.result = "PASS"; | 15 this.result = "PASS"; |
| 15 | 16 |
| 16 function testBar() { | 17 function testBar() { |
| 17 var bar = new sample.Bar(); | 18 var bar = new sample.Bar(); |
| 18 bar.alpha = 1; | 19 bar.alpha = 1; |
| 19 bar.beta = 2; | 20 bar.beta = 2; |
| 20 bar.gamma = 3; | 21 bar.gamma = 3; |
| 21 bar.type = 0x08070605; | 22 bar.type = 0x08070605; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 expect(foo2.c).toBe(foo.c & 1 ? true : false); | 127 expect(foo2.c).toBe(foo.c & 1 ? true : false); |
| 127 | 128 |
| 128 expect(foo2.bar).toEqual(foo.bar); | 129 expect(foo2.bar).toEqual(foo.bar); |
| 129 expect(foo2.data).toEqual(foo.data); | 130 expect(foo2.data).toEqual(foo.data); |
| 130 | 131 |
| 131 expect(foo2.extra_bars).toEqual(foo.extra_bars); | 132 expect(foo2.extra_bars).toEqual(foo.extra_bars); |
| 132 expect(foo2.name).toBe(foo.name); | 133 expect(foo2.name).toBe(foo.name); |
| 133 expect(foo2.source).toEqual(foo.source); | 134 expect(foo2.source).toEqual(foo.source); |
| 134 } | 135 } |
| 135 | 136 |
| 137 function testTypes() { |
| 138 function encodeDecode(cls, input, expectedResult, encodedSize) { |
| 139 var messageName = 42; |
| 140 var payloadSize = encodedSize || cls.encodedSize; |
| 141 |
| 142 var builder = new codec.MessageBuilder(messageName, payloadSize); |
| 143 builder.encodeStruct(cls, input) |
| 144 var message = builder.finish(); |
| 145 |
| 146 var reader = new codec.MessageReader(message); |
| 147 expect(reader.payloadSize).toBe(payloadSize); |
| 148 expect(reader.messageName).toBe(messageName); |
| 149 var result = reader.decodeStruct(cls); |
| 150 expect(result).toEqual(expectedResult); |
| 151 } |
| 152 encodeDecode(codec.String, "banana", "banana", 24); |
| 153 encodeDecode(codec.Int8, -1, -1); |
| 154 encodeDecode(codec.Int8, 0xff, -1); |
| 155 encodeDecode(codec.Int16, -1, -1); |
| 156 encodeDecode(codec.Int16, 0xff, 0xff); |
| 157 encodeDecode(codec.Int16, 0xffff, -1); |
| 158 encodeDecode(codec.Int32, -1, -1); |
| 159 encodeDecode(codec.Int32, 0xffff, 0xffff); |
| 160 encodeDecode(codec.Int32, 0xffffffff, -1); |
| 161 encodeDecode(codec.Float, 1.0, 1.0); |
| 162 encodeDecode(codec.Double, 1.0, 1.0); |
| 163 } |
| 164 |
| 136 function testAlign() { | 165 function testAlign() { |
| 137 var aligned = [ | 166 var aligned = [ |
| 138 0, // 0 | 167 0, // 0 |
| 139 8, // 1 | 168 8, // 1 |
| 140 8, // 2 | 169 8, // 2 |
| 141 8, // 3 | 170 8, // 3 |
| 142 8, // 4 | 171 8, // 4 |
| 143 8, // 5 | 172 8, // 5 |
| 144 8, // 6 | 173 8, // 6 |
| 145 8, // 7 | 174 8, // 7 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 expect(actualMemory.length).toEqual(expectedMemory.length); | 210 expect(actualMemory.length).toEqual(expectedMemory.length); |
| 182 expect(actualMemory).toEqual(expectedMemory); | 211 expect(actualMemory).toEqual(expectedMemory); |
| 183 | 212 |
| 184 var reader = new codec.MessageReader(message); | 213 var reader = new codec.MessageReader(message); |
| 185 expect(reader.payloadSize).toBe(payloadSize); | 214 expect(reader.payloadSize).toBe(payloadSize); |
| 186 expect(reader.messageName).toBe(messageName); | 215 expect(reader.messageName).toBe(messageName); |
| 187 var str2 = reader.decoder.decodeStringPointer(); | 216 var str2 = reader.decoder.decodeStringPointer(); |
| 188 expect(str2).toEqual(str); | 217 expect(str2).toEqual(str); |
| 189 } | 218 } |
| 190 }); | 219 }); |
| OLD | NEW |