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

Side by Side Diff: third_party/protobuf/js/binary/proto_test.js

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
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.setOptionalInt32String('-12345');
71 msg.setOptionalUint32String('12345');
72 msg.setOptionalInt64String('-123456789012345');
73 msg.setOptionalUint64String('987654321098765');
74 msg.setOneofString('oneof');
75
76 msg.setRepeatedInt32List([-42]);
77 msg.setRepeatedInt64List([-0x7fffffff00000000]);
78 msg.setRepeatedUint32List([0x80000000]);
79 msg.setRepeatedUint64List([0xf000000000000000]);
80 msg.setRepeatedSint32List([-100]);
81 msg.setRepeatedSint64List([-0x8000000000000000]);
82 msg.setRepeatedFixed32List([1234]);
83 msg.setRepeatedFixed64List([0x1234567800000000]);
84 msg.setRepeatedSfixed32List([-1234]);
85 msg.setRepeatedSfixed64List([-0x1234567800000000]);
86 msg.setRepeatedFloatList([1.5]);
87 msg.setRepeatedDoubleList([-1.5]);
88 msg.setRepeatedBoolList([true]);
89 msg.setRepeatedStringList(['hello world']);
90 msg.setRepeatedBytesList(['bytes']);
91 msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]);
92 msg.getRepeatedGroupList()[0].setA(100);
93 submsg = new proto.jspb.test.ForeignMessage();
94 submsg.setC(1000);
95 msg.setRepeatedForeignMessageList([submsg]);
96 msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
97
98 msg.setPackedRepeatedInt32List([-42]);
99 msg.setPackedRepeatedInt64List([-0x7fffffff00000000]);
100 msg.setPackedRepeatedUint32List([0x80000000]);
101 msg.setPackedRepeatedUint64List([0xf000000000000000]);
102 msg.setPackedRepeatedSint32List([-100]);
103 msg.setPackedRepeatedSint64List([-0x8000000000000000]);
104 msg.setPackedRepeatedFixed32List([1234]);
105 msg.setPackedRepeatedFixed64List([0x1234567800000000]);
106 msg.setPackedRepeatedSfixed32List([-1234]);
107 msg.setPackedRepeatedSfixed64List([-0x1234567800000000]);
108 msg.setPackedRepeatedFloatList([1.5]);
109 msg.setPackedRepeatedDoubleList([-1.5]);
110 msg.setPackedRepeatedBoolList([true]);
111
112 msg.setRepeatedInt32StringList(['-12345']);
113 msg.setRepeatedUint32StringList(['12345']);
114 msg.setRepeatedInt64StringList(['-123456789012345']);
115 msg.setRepeatedUint64StringList(['987654321098765']);
116 msg.setPackedRepeatedInt32StringList(['-12345']);
117 msg.setPackedRepeatedUint32StringList(['12345']);
118 msg.setPackedRepeatedInt64StringList(['-123456789012345']);
119 msg.setPackedRepeatedUint64StringList(['987654321098765']);
120 }
121
122
123 /**
124 * Helper: compare a bytes field to a string with codepoints 0--255.
125 * @param {Uint8Array|string} arr
126 * @param {string} str
127 * @return {boolean}
128 */
129 function bytesCompare(arr, str) {
130 if (arr.length != str.length) {
131 return false;
132 }
133 if (typeof arr == 'string') {
134 for (var i = 0; i < arr.length; i++) {
135 if (arr.charCodeAt(i) != str.charCodeAt(i)) {
136 return false;
137 }
138 }
139 return true;
140 } else {
141 for (var i = 0; i < arr.length; i++) {
142 if (arr[i] != str.charCodeAt(i)) {
143 return false;
144 }
145 }
146 return true;
147 }
148 }
149
150
151 /**
152 * Helper: verify contents of given TestAllTypes message as set by
153 * fillAllFields().
154 * @param {proto.jspb.test.TestAllTypes} msg
155 */
156 function checkAllFields(msg) {
157 assertEquals(msg.getOptionalInt32(), -42);
158 assertEquals(msg.getOptionalInt64(), -0x7fffffff00000000);
159 assertEquals(msg.getOptionalUint32(), 0x80000000);
160 assertEquals(msg.getOptionalUint64(), 0xf000000000000000);
161 assertEquals(msg.getOptionalSint32(), -100);
162 assertEquals(msg.getOptionalSint64(), -0x8000000000000000);
163 assertEquals(msg.getOptionalFixed32(), 1234);
164 assertEquals(msg.getOptionalFixed64(), 0x1234567800000000);
165 assertEquals(msg.getOptionalSfixed32(), -1234);
166 assertEquals(msg.getOptionalSfixed64(), -0x1234567800000000);
167 assertEquals(msg.getOptionalFloat(), 1.5);
168 assertEquals(msg.getOptionalDouble(), -1.5);
169 assertEquals(msg.getOptionalBool(), true);
170 assertEquals(msg.getOptionalString(), 'hello world');
171 assertEquals(true, bytesCompare(msg.getOptionalBytes(), 'bytes'));
172 assertEquals(msg.getOptionalGroup().getA(), 100);
173 assertEquals(msg.getOptionalForeignMessage().getC(), 16);
174 assertEquals(msg.getOptionalForeignEnum(),
175 proto.jspb.test.ForeignEnum.FOREIGN_FOO);
176 assertEquals(msg.getOptionalInt32String(), '-12345');
177 assertEquals(msg.getOptionalUint32String(), '12345');
178 assertEquals(msg.getOptionalInt64String(), '-123456789012345');
179 assertEquals(msg.getOptionalUint64String(), '987654321098765');
180 assertEquals(msg.getOneofString(), 'oneof');
181 assertEquals(msg.getOneofFieldCase(),
182 proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING);
183
184 assertElementsEquals(msg.getRepeatedInt32List(), [-42]);
185 assertElementsEquals(msg.getRepeatedInt64List(), [-0x7fffffff00000000]);
186 assertElementsEquals(msg.getRepeatedUint32List(), [0x80000000]);
187 assertElementsEquals(msg.getRepeatedUint64List(), [0xf000000000000000]);
188 assertElementsEquals(msg.getRepeatedSint32List(), [-100]);
189 assertElementsEquals(msg.getRepeatedSint64List(), [-0x8000000000000000]);
190 assertElementsEquals(msg.getRepeatedFixed32List(), [1234]);
191 assertElementsEquals(msg.getRepeatedFixed64List(), [0x1234567800000000]);
192 assertElementsEquals(msg.getRepeatedSfixed32List(), [-1234]);
193 assertElementsEquals(msg.getRepeatedSfixed64List(), [-0x1234567800000000]);
194 assertElementsEquals(msg.getRepeatedFloatList(), [1.5]);
195 assertElementsEquals(msg.getRepeatedDoubleList(), [-1.5]);
196 assertElementsEquals(msg.getRepeatedBoolList(), [true]);
197 assertElementsEquals(msg.getRepeatedStringList(), ['hello world']);
198 assertEquals(msg.getRepeatedBytesList().length, 1);
199 assertEquals(true, bytesCompare(msg.getRepeatedBytesList()[0], 'bytes'));
200 assertEquals(msg.getRepeatedGroupList().length, 1);
201 assertEquals(msg.getRepeatedGroupList()[0].getA(), 100);
202 assertEquals(msg.getRepeatedForeignMessageList().length, 1);
203 assertEquals(msg.getRepeatedForeignMessageList()[0].getC(), 1000);
204 assertElementsEquals(msg.getRepeatedForeignEnumList(),
205 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
206
207 assertElementsEquals(msg.getPackedRepeatedInt32List(), [-42]);
208 assertElementsEquals(msg.getPackedRepeatedInt64List(),
209 [-0x7fffffff00000000]);
210 assertElementsEquals(msg.getPackedRepeatedUint32List(), [0x80000000]);
211 assertElementsEquals(msg.getPackedRepeatedUint64List(), [0xf000000000000000]);
212 assertElementsEquals(msg.getPackedRepeatedSint32List(), [-100]);
213 assertElementsEquals(msg.getPackedRepeatedSint64List(),
214 [-0x8000000000000000]);
215 assertElementsEquals(msg.getPackedRepeatedFixed32List(), [1234]);
216 assertElementsEquals(msg.getPackedRepeatedFixed64List(),
217 [0x1234567800000000]);
218 assertElementsEquals(msg.getPackedRepeatedSfixed32List(), [-1234]);
219 assertElementsEquals(msg.getPackedRepeatedSfixed64List(),
220 [-0x1234567800000000]);
221 assertElementsEquals(msg.getPackedRepeatedFloatList(), [1.5]);
222 assertElementsEquals(msg.getPackedRepeatedDoubleList(), [-1.5]);
223 assertElementsEquals(msg.getPackedRepeatedBoolList(), [true]);
224
225 assertEquals(msg.getRepeatedInt32StringList().length, 1);
226 assertElementsEquals(msg.getRepeatedInt32StringList(), ['-12345']);
227 assertEquals(msg.getRepeatedUint32StringList().length, 1);
228 assertElementsEquals(msg.getRepeatedUint32StringList(), ['12345']);
229 assertEquals(msg.getRepeatedInt64StringList().length, 1);
230 assertElementsEquals(msg.getRepeatedInt64StringList(), ['-123456789012345']);
231 assertEquals(msg.getRepeatedUint64StringList().length, 1);
232 assertElementsEquals(msg.getRepeatedUint64StringList(), ['987654321098765']);
233
234 assertEquals(msg.getPackedRepeatedInt32StringList().length, 1);
235 assertElementsEquals(msg.getPackedRepeatedInt32StringList(), ['-12345']);
236 assertEquals(msg.getPackedRepeatedUint32StringList().length, 1);
237 assertElementsEquals(msg.getPackedRepeatedUint32StringList(), ['12345']);
238 assertEquals(msg.getPackedRepeatedInt64StringList().length, 1);
239 assertElementsEquals(msg.getPackedRepeatedInt64StringList(),
240 ['-123456789012345']);
241 assertEquals(msg.getPackedRepeatedUint64StringList().length, 1);
242 assertElementsEquals(msg.getPackedRepeatedUint64StringList(),
243 ['987654321098765']);
244 }
245
246
247 /**
248 * Helper: verify that all expected extensions are present.
249 * @param {!proto.jspb.test.TestExtendable} msg
250 */
251 function checkExtensions(msg) {
252 assertEquals(-42,
253 msg.getExtension(proto.jspb.test.extendOptionalInt32));
254 assertEquals(-0x7fffffff00000000,
255 msg.getExtension(proto.jspb.test.extendOptionalInt64));
256 assertEquals(0x80000000,
257 msg.getExtension(proto.jspb.test.extendOptionalUint32));
258 assertEquals(0xf000000000000000,
259 msg.getExtension(proto.jspb.test.extendOptionalUint64));
260 assertEquals(-100,
261 msg.getExtension(proto.jspb.test.extendOptionalSint32));
262 assertEquals(-0x8000000000000000,
263 msg.getExtension(proto.jspb.test.extendOptionalSint64));
264 assertEquals(1234,
265 msg.getExtension(proto.jspb.test.extendOptionalFixed32));
266 assertEquals(0x1234567800000000,
267 msg.getExtension(proto.jspb.test.extendOptionalFixed64));
268 assertEquals(-1234,
269 msg.getExtension(proto.jspb.test.extendOptionalSfixed32));
270 assertEquals(-0x1234567800000000,
271 msg.getExtension(proto.jspb.test.extendOptionalSfixed64));
272 assertEquals(1.5,
273 msg.getExtension(proto.jspb.test.extendOptionalFloat));
274 assertEquals(-1.5,
275 msg.getExtension(proto.jspb.test.extendOptionalDouble));
276 assertEquals(true,
277 msg.getExtension(proto.jspb.test.extendOptionalBool));
278 assertEquals('hello world',
279 msg.getExtension(proto.jspb.test.extendOptionalString));
280 assertEquals(true,
281 bytesCompare(msg.getExtension(proto.jspb.test.extendOptionalBytes),
282 'bytes'));
283 assertEquals(16,
284 msg.getExtension(
285 proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo());
286 assertEquals(proto.jspb.test.ForeignEnum.FOREIGN_FOO,
287 msg.getExtension(proto.jspb.test.extendOptionalForeignEnum));
288 assertEquals('-12345',
289 msg.getExtension(proto.jspb.test.extendOptionalInt32String));
290 assertEquals('12345',
291 msg.getExtension(proto.jspb.test.extendOptionalUint32String));
292 assertEquals('-123456789012345',
293 msg.getExtension(proto.jspb.test.extendOptionalInt64String));
294 assertEquals('987654321098765',
295 msg.getExtension(proto.jspb.test.extendOptionalUint64String));
296
297 assertElementsEquals(
298 msg.getExtension(proto.jspb.test.extendRepeatedInt32List),
299 [-42]);
300 assertElementsEquals(
301 msg.getExtension(proto.jspb.test.extendRepeatedInt64List),
302 [-0x7fffffff00000000]);
303 assertElementsEquals(
304 msg.getExtension(proto.jspb.test.extendRepeatedUint32List),
305 [0x80000000]);
306 assertElementsEquals(
307 msg.getExtension(proto.jspb.test.extendRepeatedUint64List),
308 [0xf000000000000000]);
309 assertElementsEquals(
310 msg.getExtension(proto.jspb.test.extendRepeatedSint32List),
311 [-100]);
312 assertElementsEquals(
313 msg.getExtension(proto.jspb.test.extendRepeatedSint64List),
314 [-0x8000000000000000]);
315 assertElementsEquals(
316 msg.getExtension(proto.jspb.test.extendRepeatedFixed32List),
317 [1234]);
318 assertElementsEquals(
319 msg.getExtension(proto.jspb.test.extendRepeatedFixed64List),
320 [0x1234567800000000]);
321 assertElementsEquals(
322 msg.getExtension(proto.jspb.test.extendRepeatedSfixed32List),
323 [-1234]);
324 assertElementsEquals(
325 msg.getExtension(proto.jspb.test.extendRepeatedSfixed64List),
326 [-0x1234567800000000]);
327 assertElementsEquals(
328 msg.getExtension(proto.jspb.test.extendRepeatedFloatList),
329 [1.5]);
330 assertElementsEquals(
331 msg.getExtension(proto.jspb.test.extendRepeatedDoubleList),
332 [-1.5]);
333 assertElementsEquals(
334 msg.getExtension(proto.jspb.test.extendRepeatedBoolList),
335 [true]);
336 assertElementsEquals(
337 msg.getExtension(proto.jspb.test.extendRepeatedStringList),
338 ['hello world']);
339 assertEquals(true,
340 bytesCompare(
341 msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0],
342 'bytes'));
343 assertEquals(1000,
344 msg.getExtension(
345 proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0]
346 .getFoo());
347 assertElementsEquals(
348 msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList),
349 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
350
351 assertElementsEquals(
352 msg.getExtension(proto.jspb.test.extendRepeatedInt32StringList),
353 ['-12345']);
354 assertElementsEquals(
355 msg.getExtension(proto.jspb.test.extendRepeatedUint32StringList),
356 ['12345']);
357 assertElementsEquals(
358 msg.getExtension(proto.jspb.test.extendRepeatedInt64StringList),
359 ['-123456789012345']);
360 assertElementsEquals(
361 msg.getExtension(proto.jspb.test.extendRepeatedUint64StringList),
362 ['987654321098765']);
363
364 assertElementsEquals(
365 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List),
366 [-42]);
367 assertElementsEquals(
368 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List),
369 [-0x7fffffff00000000]);
370 assertElementsEquals(
371 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List),
372 [0x80000000]);
373 assertElementsEquals(
374 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64List),
375 [0xf000000000000000]);
376 assertElementsEquals(
377 msg.getExtension(proto.jspb.test.extendPackedRepeatedSint32List),
378 [-100]);
379 assertElementsEquals(
380 msg.getExtension(proto.jspb.test.extendPackedRepeatedSint64List),
381 [-0x8000000000000000]);
382 assertElementsEquals(
383 msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed32List),
384 [1234]);
385 assertElementsEquals(
386 msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed64List),
387 [0x1234567800000000]);
388 assertElementsEquals(
389 msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed32List),
390 [-1234]);
391 assertElementsEquals(
392 msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed64List),
393 [-0x1234567800000000]);
394 assertElementsEquals(
395 msg.getExtension(proto.jspb.test.extendPackedRepeatedFloatList),
396 [1.5]);
397 assertElementsEquals(
398 msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList),
399 [-1.5]);
400 assertElementsEquals(
401 msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList),
402 [true]);
403 assertElementsEquals(
404 msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList),
405 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
406
407 assertElementsEquals(
408 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32StringList),
409 ['-12345']);
410 assertElementsEquals(
411 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32StringList),
412 ['12345']);
413 assertElementsEquals(
414 msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64StringList),
415 ['-123456789012345']);
416 assertElementsEquals(
417 msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64StringList),
418 ['987654321098765']);
419 }
420
421
422 describe('protoBinaryTest', function() {
423 /**
424 * Tests a basic serialization-deserializaton round-trip with all supported
425 * field types (on the TestAllTypes message type).
426 */
427 it('testRoundTrip', function() {
428 var msg = new proto.jspb.test.TestAllTypes();
429 fillAllFields(msg);
430 var encoded = msg.serializeBinary();
431 var decoded = proto.jspb.test.TestAllTypes.deserializeBinary(encoded);
432 checkAllFields(decoded);
433 });
434
435
436 /**
437 * Helper: fill all extension values.
438 * @param {proto.jspb.test.TestExtendable} msg
439 */
440 function fillExtensions(msg) {
441 msg.setExtension(
442 proto.jspb.test.extendOptionalInt32, -42);
443 msg.setExtension(
444 proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000);
445 msg.setExtension(
446 proto.jspb.test.extendOptionalUint32, 0x80000000);
447 msg.setExtension(
448 proto.jspb.test.extendOptionalUint64, 0xf000000000000000);
449 msg.setExtension(
450 proto.jspb.test.extendOptionalSint32, -100);
451 msg.setExtension(
452 proto.jspb.test.extendOptionalSint64, -0x8000000000000000);
453 msg.setExtension(
454 proto.jspb.test.extendOptionalFixed32, 1234);
455 msg.setExtension(
456 proto.jspb.test.extendOptionalFixed64, 0x1234567800000000);
457 msg.setExtension(
458 proto.jspb.test.extendOptionalSfixed32, -1234);
459 msg.setExtension(
460 proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000);
461 msg.setExtension(
462 proto.jspb.test.extendOptionalFloat, 1.5);
463 msg.setExtension(
464 proto.jspb.test.extendOptionalDouble, -1.5);
465 msg.setExtension(
466 proto.jspb.test.extendOptionalBool, true);
467 msg.setExtension(
468 proto.jspb.test.extendOptionalString, 'hello world');
469 msg.setExtension(
470 proto.jspb.test.extendOptionalBytes, 'bytes');
471 var submsg = new proto.jspb.test.ExtendsWithMessage();
472 submsg.setFoo(16);
473 msg.setExtension(
474 proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg);
475 msg.setExtension(
476 proto.jspb.test.extendOptionalForeignEnum,
477 proto.jspb.test.ForeignEnum.FOREIGN_FOO);
478 msg.setExtension(
479 proto.jspb.test.extendOptionalInt32String, '-12345');
480 msg.setExtension(
481 proto.jspb.test.extendOptionalUint32String, '12345');
482 msg.setExtension(
483 proto.jspb.test.extendOptionalInt64String, '-123456789012345');
484 msg.setExtension(
485 proto.jspb.test.extendOptionalUint64String, '987654321098765');
486
487 msg.setExtension(
488 proto.jspb.test.extendRepeatedInt32List, [-42]);
489 msg.setExtension(
490 proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]);
491 msg.setExtension(
492 proto.jspb.test.extendRepeatedUint32List, [0x80000000]);
493 msg.setExtension(
494 proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]);
495 msg.setExtension(
496 proto.jspb.test.extendRepeatedSint32List, [-100]);
497 msg.setExtension(
498 proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]);
499 msg.setExtension(
500 proto.jspb.test.extendRepeatedFixed32List, [1234]);
501 msg.setExtension(
502 proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]);
503 msg.setExtension(
504 proto.jspb.test.extendRepeatedSfixed32List, [-1234]);
505 msg.setExtension(
506 proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]);
507 msg.setExtension(
508 proto.jspb.test.extendRepeatedFloatList, [1.5]);
509 msg.setExtension(
510 proto.jspb.test.extendRepeatedDoubleList, [-1.5]);
511 msg.setExtension(
512 proto.jspb.test.extendRepeatedBoolList, [true]);
513 msg.setExtension(
514 proto.jspb.test.extendRepeatedStringList, ['hello world']);
515 msg.setExtension(
516 proto.jspb.test.extendRepeatedBytesList, ['bytes']);
517 submsg = new proto.jspb.test.ExtendsWithMessage();
518 submsg.setFoo(1000);
519 msg.setExtension(
520 proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]);
521 msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList,
522 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
523
524 msg.setExtension(
525 proto.jspb.test.extendRepeatedInt32StringList, ['-12345']);
526 msg.setExtension(
527 proto.jspb.test.extendRepeatedUint32StringList, ['12345']);
528 msg.setExtension(
529 proto.jspb.test.extendRepeatedInt64StringList, ['-123456789012345']);
530 msg.setExtension(
531 proto.jspb.test.extendRepeatedUint64StringList, ['987654321098765']);
532
533 msg.setExtension(
534 proto.jspb.test.extendPackedRepeatedInt32List, [-42]);
535 msg.setExtension(
536 proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]);
537 msg.setExtension(
538 proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]);
539 msg.setExtension(
540 proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]);
541 msg.setExtension(
542 proto.jspb.test.extendPackedRepeatedSint32List, [-100]);
543 msg.setExtension(
544 proto.jspb.test.extendPackedRepeatedSint64List, [-0x8000000000000000]);
545 msg.setExtension(
546 proto.jspb.test.extendPackedRepeatedFixed32List, [1234]);
547 msg.setExtension(
548 proto.jspb.test.extendPackedRepeatedFixed64List, [0x1234567800000000]);
549 msg.setExtension(
550 proto.jspb.test.extendPackedRepeatedSfixed32List, [-1234]);
551 msg.setExtension(
552 proto.jspb.test.extendPackedRepeatedSfixed64List,
553 [-0x1234567800000000]);
554 msg.setExtension(
555 proto.jspb.test.extendPackedRepeatedFloatList, [1.5]);
556 msg.setExtension(
557 proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]);
558 msg.setExtension(
559 proto.jspb.test.extendPackedRepeatedBoolList, [true]);
560 msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList,
561 [proto.jspb.test.ForeignEnum.FOREIGN_FOO]);
562
563 msg.setExtension(
564 proto.jspb.test.extendPackedRepeatedInt32StringList,
565 ['-12345']);
566 msg.setExtension(
567 proto.jspb.test.extendPackedRepeatedUint32StringList,
568 ['12345']);
569 msg.setExtension(
570 proto.jspb.test.extendPackedRepeatedInt64StringList,
571 ['-123456789012345']);
572 msg.setExtension(
573 proto.jspb.test.extendPackedRepeatedUint64StringList,
574 ['987654321098765']);
575 }
576
577
578 /**
579 * Tests extension serialization and deserialization.
580 */
581 it('testExtensions', function() {
582 var msg = new proto.jspb.test.TestExtendable();
583 fillExtensions(msg);
584 var encoded = msg.serializeBinary();
585 var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded);
586 checkExtensions(decoded);
587 });
588 });
OLDNEW
« no previous file with comments | « third_party/protobuf/js/binary/decoder_test.js ('k') | third_party/protobuf/js/binary/reader.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698