Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame^] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
| 3 | // https://developers.google.com/protocol-buffers/ |
| 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
| 8 | // |
| 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | // Test suite is written using Jasmine -- see http://jasmine.github.io/ |
| 32 | |
| 33 | goog.require('goog.testing.asserts'); |
| 34 | goog.require('proto.jspb.test.ExtendsWithMessage'); |
| 35 | goog.require('proto.jspb.test.ForeignEnum'); |
| 36 | goog.require('proto.jspb.test.ForeignMessage'); |
| 37 | goog.require('proto.jspb.test.TestAllTypes'); |
| 38 | goog.require('proto.jspb.test.TestExtendable'); |
| 39 | |
| 40 | var suite = {}; |
| 41 | |
| 42 | /** |
| 43 | * Helper: fill all fields on a TestAllTypes message. |
| 44 | * @param {proto.jspb.test.TestAllTypes} msg |
| 45 | */ |
| 46 | function fillAllFields(msg) { |
| 47 | msg.setOptionalInt32(-42); |
| 48 | // can be exactly represented by JS number (64-bit double, i.e., 52-bit |
| 49 | // mantissa). |
| 50 | msg.setOptionalInt64(-0x7fffffff00000000); |
| 51 | msg.setOptionalUint32(0x80000000); |
| 52 | msg.setOptionalUint64(0xf000000000000000); |
| 53 | msg.setOptionalSint32(-100); |
| 54 | msg.setOptionalSint64(-0x8000000000000000); |
| 55 | msg.setOptionalFixed32(1234); |
| 56 | msg.setOptionalFixed64(0x1234567800000000); |
| 57 | msg.setOptionalSfixed32(-1234); |
| 58 | msg.setOptionalSfixed64(-0x1234567800000000); |
| 59 | msg.setOptionalFloat(1.5); |
| 60 | msg.setOptionalDouble(-1.5); |
| 61 | msg.setOptionalBool(true); |
| 62 | msg.setOptionalString('hello world'); |
| 63 | msg.setOptionalBytes('bytes'); |
| 64 | msg.setOptionalGroup(new proto.jspb.test.TestAllTypes.OptionalGroup()); |
| 65 | msg.getOptionalGroup().setA(100); |
| 66 | var submsg = new proto.jspb.test.ForeignMessage(); |
| 67 | submsg.setC(16); |
| 68 | msg.setOptionalForeignMessage(submsg); |
| 69 | msg.setOptionalForeignEnum(proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
| 70 | msg.setOneofString('oneof'); |
| 71 | |
| 72 | msg.setRepeatedInt32List([-42]); |
| 73 | msg.setRepeatedInt64List([-0x7fffffff00000000]); |
| 74 | msg.setRepeatedUint32List([0x80000000]); |
| 75 | msg.setRepeatedUint64List([0xf000000000000000]); |
| 76 | msg.setRepeatedSint32List([-100]); |
| 77 | msg.setRepeatedSint64List([-0x8000000000000000]); |
| 78 | msg.setRepeatedFixed32List([1234]); |
| 79 | msg.setRepeatedFixed64List([0x1234567800000000]); |
| 80 | msg.setRepeatedSfixed32List([-1234]); |
| 81 | msg.setRepeatedSfixed64List([-0x1234567800000000]); |
| 82 | msg.setRepeatedFloatList([1.5]); |
| 83 | msg.setRepeatedDoubleList([-1.5]); |
| 84 | msg.setRepeatedBoolList([true]); |
| 85 | msg.setRepeatedStringList(['hello world']); |
| 86 | msg.setRepeatedBytesList(['bytes']); |
| 87 | msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]); |
| 88 | msg.getRepeatedGroupList()[0].setA(100); |
| 89 | submsg = new proto.jspb.test.ForeignMessage(); |
| 90 | submsg.setC(1000); |
| 91 | msg.setRepeatedForeignMessageList([submsg]); |
| 92 | msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 93 | |
| 94 | msg.setPackedRepeatedInt32List([-42]); |
| 95 | msg.setPackedRepeatedInt64List([-0x7fffffff00000000]); |
| 96 | msg.setPackedRepeatedUint32List([0x80000000]); |
| 97 | msg.setPackedRepeatedUint64List([0xf000000000000000]); |
| 98 | msg.setPackedRepeatedSint32List([-100]); |
| 99 | msg.setPackedRepeatedSint64List([-0x8000000000000000]); |
| 100 | msg.setPackedRepeatedFixed32List([1234]); |
| 101 | msg.setPackedRepeatedFixed64List([0x1234567800000000]); |
| 102 | msg.setPackedRepeatedSfixed32List([-1234]); |
| 103 | msg.setPackedRepeatedSfixed64List([-0x1234567800000000]); |
| 104 | msg.setPackedRepeatedFloatList([1.5]); |
| 105 | msg.setPackedRepeatedDoubleList([-1.5]); |
| 106 | msg.setPackedRepeatedBoolList([true]); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | /** |
| 111 | * Helper: compare a bytes field to a string with codepoints 0--255. |
| 112 | * @param {Uint8Array|string} arr |
| 113 | * @param {string} str |
| 114 | * @return {boolean} |
| 115 | */ |
| 116 | function bytesCompare(arr, str) { |
| 117 | if (arr.length != str.length) { |
| 118 | return false; |
| 119 | } |
| 120 | if (typeof arr == 'string') { |
| 121 | for (var i = 0; i < arr.length; i++) { |
| 122 | if (arr.charCodeAt(i) != str.charCodeAt(i)) { |
| 123 | return false; |
| 124 | } |
| 125 | } |
| 126 | return true; |
| 127 | } else { |
| 128 | for (var i = 0; i < arr.length; i++) { |
| 129 | if (arr[i] != str.charCodeAt(i)) { |
| 130 | return false; |
| 131 | } |
| 132 | } |
| 133 | return true; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | |
| 138 | /** |
| 139 | * Helper: verify contents of given TestAllTypes message as set by |
| 140 | * fillAllFields(). |
| 141 | * @param {proto.jspb.test.TestAllTypes} msg |
| 142 | */ |
| 143 | function checkAllFields(msg) { |
| 144 | assertEquals(msg.getOptionalInt32(), -42); |
| 145 | assertEquals(msg.getOptionalInt64(), -0x7fffffff00000000); |
| 146 | assertEquals(msg.getOptionalUint32(), 0x80000000); |
| 147 | assertEquals(msg.getOptionalUint64(), 0xf000000000000000); |
| 148 | assertEquals(msg.getOptionalSint32(), -100); |
| 149 | assertEquals(msg.getOptionalSint64(), -0x8000000000000000); |
| 150 | assertEquals(msg.getOptionalFixed32(), 1234); |
| 151 | assertEquals(msg.getOptionalFixed64(), 0x1234567800000000); |
| 152 | assertEquals(msg.getOptionalSfixed32(), -1234); |
| 153 | assertEquals(msg.getOptionalSfixed64(), -0x1234567800000000); |
| 154 | assertEquals(msg.getOptionalFloat(), 1.5); |
| 155 | assertEquals(msg.getOptionalDouble(), -1.5); |
| 156 | assertEquals(msg.getOptionalBool(), true); |
| 157 | assertEquals(msg.getOptionalString(), 'hello world'); |
| 158 | assertEquals(true, bytesCompare(msg.getOptionalBytes(), 'bytes')); |
| 159 | assertEquals(msg.getOptionalGroup().getA(), 100); |
| 160 | assertEquals(msg.getOptionalForeignMessage().getC(), 16); |
| 161 | assertEquals(msg.getOptionalForeignEnum(), |
| 162 | proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
| 163 | assertEquals(msg.getOneofString(), 'oneof'); |
| 164 | assertEquals(msg.getOneofFieldCase(), |
| 165 | proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING); |
| 166 | |
| 167 | assertElementsEquals(msg.getRepeatedInt32List(), [-42]); |
| 168 | assertElementsEquals(msg.getRepeatedInt64List(), [-0x7fffffff00000000]); |
| 169 | assertElementsEquals(msg.getRepeatedUint32List(), [0x80000000]); |
| 170 | assertElementsEquals(msg.getRepeatedUint64List(), [0xf000000000000000]); |
| 171 | assertElementsEquals(msg.getRepeatedSint32List(), [-100]); |
| 172 | assertElementsEquals(msg.getRepeatedSint64List(), [-0x8000000000000000]); |
| 173 | assertElementsEquals(msg.getRepeatedFixed32List(), [1234]); |
| 174 | assertElementsEquals(msg.getRepeatedFixed64List(), [0x1234567800000000]); |
| 175 | assertElementsEquals(msg.getRepeatedSfixed32List(), [-1234]); |
| 176 | assertElementsEquals(msg.getRepeatedSfixed64List(), [-0x1234567800000000]); |
| 177 | assertElementsEquals(msg.getRepeatedFloatList(), [1.5]); |
| 178 | assertElementsEquals(msg.getRepeatedDoubleList(), [-1.5]); |
| 179 | assertElementsEquals(msg.getRepeatedBoolList(), [true]); |
| 180 | assertElementsEquals(msg.getRepeatedStringList(), ['hello world']); |
| 181 | assertEquals(msg.getRepeatedBytesList().length, 1); |
| 182 | assertEquals(true, bytesCompare(msg.getRepeatedBytesList()[0], 'bytes')); |
| 183 | assertEquals(msg.getRepeatedGroupList().length, 1); |
| 184 | assertEquals(msg.getRepeatedGroupList()[0].getA(), 100); |
| 185 | assertEquals(msg.getRepeatedForeignMessageList().length, 1); |
| 186 | assertEquals(msg.getRepeatedForeignMessageList()[0].getC(), 1000); |
| 187 | assertElementsEquals(msg.getRepeatedForeignEnumList(), |
| 188 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 189 | |
| 190 | assertElementsEquals(msg.getPackedRepeatedInt32List(), [-42]); |
| 191 | assertElementsEquals(msg.getPackedRepeatedInt64List(), |
| 192 | [-0x7fffffff00000000]); |
| 193 | assertElementsEquals(msg.getPackedRepeatedUint32List(), [0x80000000]); |
| 194 | assertElementsEquals(msg.getPackedRepeatedUint64List(), [0xf000000000000000]); |
| 195 | assertElementsEquals(msg.getPackedRepeatedSint32List(), [-100]); |
| 196 | assertElementsEquals(msg.getPackedRepeatedSint64List(), |
| 197 | [-0x8000000000000000]); |
| 198 | assertElementsEquals(msg.getPackedRepeatedFixed32List(), [1234]); |
| 199 | assertElementsEquals(msg.getPackedRepeatedFixed64List(), |
| 200 | [0x1234567800000000]); |
| 201 | assertElementsEquals(msg.getPackedRepeatedSfixed32List(), [-1234]); |
| 202 | assertElementsEquals(msg.getPackedRepeatedSfixed64List(), |
| 203 | [-0x1234567800000000]); |
| 204 | assertElementsEquals(msg.getPackedRepeatedFloatList(), [1.5]); |
| 205 | assertElementsEquals(msg.getPackedRepeatedDoubleList(), [-1.5]); |
| 206 | assertElementsEquals(msg.getPackedRepeatedBoolList(), [true]); |
| 207 | } |
| 208 | |
| 209 | |
| 210 | /** |
| 211 | * Helper: verify that all expected extensions are present. |
| 212 | * @param {!proto.jspb.test.TestExtendable} msg |
| 213 | */ |
| 214 | function checkExtensions(msg) { |
| 215 | assertEquals(-42, |
| 216 | msg.getExtension(proto.jspb.test.extendOptionalInt32)); |
| 217 | assertEquals(-0x7fffffff00000000, |
| 218 | msg.getExtension(proto.jspb.test.extendOptionalInt64)); |
| 219 | assertEquals(0x80000000, |
| 220 | msg.getExtension(proto.jspb.test.extendOptionalUint32)); |
| 221 | assertEquals(0xf000000000000000, |
| 222 | msg.getExtension(proto.jspb.test.extendOptionalUint64)); |
| 223 | assertEquals(-100, |
| 224 | msg.getExtension(proto.jspb.test.extendOptionalSint32)); |
| 225 | assertEquals(-0x8000000000000000, |
| 226 | msg.getExtension(proto.jspb.test.extendOptionalSint64)); |
| 227 | assertEquals(1234, |
| 228 | msg.getExtension(proto.jspb.test.extendOptionalFixed32)); |
| 229 | assertEquals(0x1234567800000000, |
| 230 | msg.getExtension(proto.jspb.test.extendOptionalFixed64)); |
| 231 | assertEquals(-1234, |
| 232 | msg.getExtension(proto.jspb.test.extendOptionalSfixed32)); |
| 233 | assertEquals(-0x1234567800000000, |
| 234 | msg.getExtension(proto.jspb.test.extendOptionalSfixed64)); |
| 235 | assertEquals(1.5, |
| 236 | msg.getExtension(proto.jspb.test.extendOptionalFloat)); |
| 237 | assertEquals(-1.5, |
| 238 | msg.getExtension(proto.jspb.test.extendOptionalDouble)); |
| 239 | assertEquals(true, |
| 240 | msg.getExtension(proto.jspb.test.extendOptionalBool)); |
| 241 | assertEquals('hello world', |
| 242 | msg.getExtension(proto.jspb.test.extendOptionalString)); |
| 243 | assertEquals(true, |
| 244 | bytesCompare(msg.getExtension(proto.jspb.test.extendOptionalBytes), |
| 245 | 'bytes')); |
| 246 | assertEquals(16, |
| 247 | msg.getExtension( |
| 248 | proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo()); |
| 249 | assertEquals(proto.jspb.test.ForeignEnum.FOREIGN_FOO, |
| 250 | msg.getExtension(proto.jspb.test.extendOptionalForeignEnum)); |
| 251 | |
| 252 | assertElementsEquals( |
| 253 | msg.getExtension(proto.jspb.test.extendRepeatedInt32List), |
| 254 | [-42]); |
| 255 | assertElementsEquals( |
| 256 | msg.getExtension(proto.jspb.test.extendRepeatedInt64List), |
| 257 | [-0x7fffffff00000000]); |
| 258 | assertElementsEquals( |
| 259 | msg.getExtension(proto.jspb.test.extendRepeatedUint32List), |
| 260 | [0x80000000]); |
| 261 | assertElementsEquals( |
| 262 | msg.getExtension(proto.jspb.test.extendRepeatedUint64List), |
| 263 | [0xf000000000000000]); |
| 264 | assertElementsEquals( |
| 265 | msg.getExtension(proto.jspb.test.extendRepeatedSint32List), |
| 266 | [-100]); |
| 267 | assertElementsEquals( |
| 268 | msg.getExtension(proto.jspb.test.extendRepeatedSint64List), |
| 269 | [-0x8000000000000000]); |
| 270 | assertElementsEquals( |
| 271 | msg.getExtension(proto.jspb.test.extendRepeatedFixed32List), |
| 272 | [1234]); |
| 273 | assertElementsEquals( |
| 274 | msg.getExtension(proto.jspb.test.extendRepeatedFixed64List), |
| 275 | [0x1234567800000000]); |
| 276 | assertElementsEquals( |
| 277 | msg.getExtension(proto.jspb.test.extendRepeatedSfixed32List), |
| 278 | [-1234]); |
| 279 | assertElementsEquals( |
| 280 | msg.getExtension(proto.jspb.test.extendRepeatedSfixed64List), |
| 281 | [-0x1234567800000000]); |
| 282 | assertElementsEquals( |
| 283 | msg.getExtension(proto.jspb.test.extendRepeatedFloatList), |
| 284 | [1.5]); |
| 285 | assertElementsEquals( |
| 286 | msg.getExtension(proto.jspb.test.extendRepeatedDoubleList), |
| 287 | [-1.5]); |
| 288 | assertElementsEquals( |
| 289 | msg.getExtension(proto.jspb.test.extendRepeatedBoolList), |
| 290 | [true]); |
| 291 | assertElementsEquals( |
| 292 | msg.getExtension(proto.jspb.test.extendRepeatedStringList), |
| 293 | ['hello world']); |
| 294 | assertEquals(true, |
| 295 | bytesCompare( |
| 296 | msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0], |
| 297 | 'bytes')); |
| 298 | assertEquals(1000, |
| 299 | msg.getExtension( |
| 300 | proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0] |
| 301 | .getFoo()); |
| 302 | assertElementsEquals( |
| 303 | msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList), |
| 304 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 305 | |
| 306 | assertElementsEquals( |
| 307 | msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List), |
| 308 | [-42]); |
| 309 | assertElementsEquals( |
| 310 | msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List), |
| 311 | [-0x7fffffff00000000]); |
| 312 | assertElementsEquals( |
| 313 | msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List), |
| 314 | [0x80000000]); |
| 315 | assertElementsEquals( |
| 316 | msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64List), |
| 317 | [0xf000000000000000]); |
| 318 | assertElementsEquals( |
| 319 | msg.getExtension(proto.jspb.test.extendPackedRepeatedSint32List), |
| 320 | [-100]); |
| 321 | assertElementsEquals( |
| 322 | msg.getExtension(proto.jspb.test.extendPackedRepeatedSint64List), |
| 323 | [-0x8000000000000000]); |
| 324 | assertElementsEquals( |
| 325 | msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed32List), |
| 326 | [1234]); |
| 327 | assertElementsEquals( |
| 328 | msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed64List), |
| 329 | [0x1234567800000000]); |
| 330 | assertElementsEquals( |
| 331 | msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed32List), |
| 332 | [-1234]); |
| 333 | assertElementsEquals( |
| 334 | msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed64List), |
| 335 | [-0x1234567800000000]); |
| 336 | assertElementsEquals( |
| 337 | msg.getExtension(proto.jspb.test.extendPackedRepeatedFloatList), |
| 338 | [1.5]); |
| 339 | assertElementsEquals( |
| 340 | msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList), |
| 341 | [-1.5]); |
| 342 | assertElementsEquals( |
| 343 | msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList), |
| 344 | [true]); |
| 345 | assertElementsEquals( |
| 346 | msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList), |
| 347 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | describe('protoBinaryTest', function() { |
| 352 | /** |
| 353 | * Tests a basic serialization-deserializaton round-trip with all supported |
| 354 | * field types (on the TestAllTypes message type). |
| 355 | */ |
| 356 | it('testRoundTrip', function() { |
| 357 | var msg = new proto.jspb.test.TestAllTypes(); |
| 358 | fillAllFields(msg); |
| 359 | var encoded = msg.serializeBinary(); |
| 360 | var decoded = proto.jspb.test.TestAllTypes.deserializeBinary(encoded); |
| 361 | checkAllFields(decoded); |
| 362 | }); |
| 363 | |
| 364 | |
| 365 | /** |
| 366 | * Helper: fill all extension values. |
| 367 | * @param {proto.jspb.test.TestExtendable} msg |
| 368 | */ |
| 369 | function fillExtensions(msg) { |
| 370 | msg.setExtension( |
| 371 | proto.jspb.test.extendOptionalInt32, -42); |
| 372 | msg.setExtension( |
| 373 | proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000); |
| 374 | msg.setExtension( |
| 375 | proto.jspb.test.extendOptionalUint32, 0x80000000); |
| 376 | msg.setExtension( |
| 377 | proto.jspb.test.extendOptionalUint64, 0xf000000000000000); |
| 378 | msg.setExtension( |
| 379 | proto.jspb.test.extendOptionalSint32, -100); |
| 380 | msg.setExtension( |
| 381 | proto.jspb.test.extendOptionalSint64, -0x8000000000000000); |
| 382 | msg.setExtension( |
| 383 | proto.jspb.test.extendOptionalFixed32, 1234); |
| 384 | msg.setExtension( |
| 385 | proto.jspb.test.extendOptionalFixed64, 0x1234567800000000); |
| 386 | msg.setExtension( |
| 387 | proto.jspb.test.extendOptionalSfixed32, -1234); |
| 388 | msg.setExtension( |
| 389 | proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000); |
| 390 | msg.setExtension( |
| 391 | proto.jspb.test.extendOptionalFloat, 1.5); |
| 392 | msg.setExtension( |
| 393 | proto.jspb.test.extendOptionalDouble, -1.5); |
| 394 | msg.setExtension( |
| 395 | proto.jspb.test.extendOptionalBool, true); |
| 396 | msg.setExtension( |
| 397 | proto.jspb.test.extendOptionalString, 'hello world'); |
| 398 | msg.setExtension( |
| 399 | proto.jspb.test.extendOptionalBytes, 'bytes'); |
| 400 | var submsg = new proto.jspb.test.ExtendsWithMessage(); |
| 401 | submsg.setFoo(16); |
| 402 | msg.setExtension( |
| 403 | proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg); |
| 404 | msg.setExtension( |
| 405 | proto.jspb.test.extendOptionalForeignEnum, |
| 406 | proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
| 407 | |
| 408 | msg.setExtension( |
| 409 | proto.jspb.test.extendRepeatedInt32List, [-42]); |
| 410 | msg.setExtension( |
| 411 | proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]); |
| 412 | msg.setExtension( |
| 413 | proto.jspb.test.extendRepeatedUint32List, [0x80000000]); |
| 414 | msg.setExtension( |
| 415 | proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]); |
| 416 | msg.setExtension( |
| 417 | proto.jspb.test.extendRepeatedSint32List, [-100]); |
| 418 | msg.setExtension( |
| 419 | proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]); |
| 420 | msg.setExtension( |
| 421 | proto.jspb.test.extendRepeatedFixed32List, [1234]); |
| 422 | msg.setExtension( |
| 423 | proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]); |
| 424 | msg.setExtension( |
| 425 | proto.jspb.test.extendRepeatedSfixed32List, [-1234]); |
| 426 | msg.setExtension( |
| 427 | proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]); |
| 428 | msg.setExtension( |
| 429 | proto.jspb.test.extendRepeatedFloatList, [1.5]); |
| 430 | msg.setExtension( |
| 431 | proto.jspb.test.extendRepeatedDoubleList, [-1.5]); |
| 432 | msg.setExtension( |
| 433 | proto.jspb.test.extendRepeatedBoolList, [true]); |
| 434 | msg.setExtension( |
| 435 | proto.jspb.test.extendRepeatedStringList, ['hello world']); |
| 436 | msg.setExtension( |
| 437 | proto.jspb.test.extendRepeatedBytesList, ['bytes']); |
| 438 | submsg = new proto.jspb.test.ExtendsWithMessage(); |
| 439 | submsg.setFoo(1000); |
| 440 | msg.setExtension( |
| 441 | proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]); |
| 442 | msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList, |
| 443 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 444 | |
| 445 | msg.setExtension( |
| 446 | proto.jspb.test.extendPackedRepeatedInt32List, [-42]); |
| 447 | msg.setExtension( |
| 448 | proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]); |
| 449 | msg.setExtension( |
| 450 | proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]); |
| 451 | msg.setExtension( |
| 452 | proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]); |
| 453 | msg.setExtension( |
| 454 | proto.jspb.test.extendPackedRepeatedSint32List, [-100]); |
| 455 | msg.setExtension( |
| 456 | proto.jspb.test.extendPackedRepeatedSint64List, [-0x8000000000000000]); |
| 457 | msg.setExtension( |
| 458 | proto.jspb.test.extendPackedRepeatedFixed32List, [1234]); |
| 459 | msg.setExtension( |
| 460 | proto.jspb.test.extendPackedRepeatedFixed64List, [0x1234567800000000]); |
| 461 | msg.setExtension( |
| 462 | proto.jspb.test.extendPackedRepeatedSfixed32List, [-1234]); |
| 463 | msg.setExtension( |
| 464 | proto.jspb.test.extendPackedRepeatedSfixed64List, |
| 465 | [-0x1234567800000000]); |
| 466 | msg.setExtension( |
| 467 | proto.jspb.test.extendPackedRepeatedFloatList, [1.5]); |
| 468 | msg.setExtension( |
| 469 | proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]); |
| 470 | msg.setExtension( |
| 471 | proto.jspb.test.extendPackedRepeatedBoolList, [true]); |
| 472 | msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList, |
| 473 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 474 | } |
| 475 | |
| 476 | |
| 477 | /** |
| 478 | * Tests extension serialization and deserialization. |
| 479 | */ |
| 480 | it('testExtensions', function() { |
| 481 | var msg = new proto.jspb.test.TestExtendable(); |
| 482 | fillExtensions(msg); |
| 483 | var encoded = msg.serializeBinary(); |
| 484 | var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); |
| 485 | checkExtensions(decoded); |
| 486 | }); |
| 487 | }); |