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

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

Issue 1983203003: Update third_party/protobuf to protobuf-v3.0.0-beta-3 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: owners Created 4 years, 6 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
« no previous file with comments | « third_party/protobuf/js/binary/reader.js ('k') | third_party/protobuf/js/binary/utils.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Protocol Buffers - Google's data interchange format 1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved. 2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/ 3 // https://developers.google.com/protocol-buffers/
4 // 4 //
5 // Redistribution and use in source and binary forms, with or without 5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are 6 // modification, are permitted provided that the following conditions are
7 // met: 7 // met:
8 // 8 //
9 // * Redistributions of source code must retain the above copyright 9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer. 10 // notice, this list of conditions and the following disclaimer.
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 }); 359 });
360 360
361 361
362 /** 362 /**
363 * Tests 64-bit fields that are handled as strings. 363 * Tests 64-bit fields that are handled as strings.
364 */ 364 */
365 it('testStringInt64Fields', function() { 365 it('testStringInt64Fields', function() {
366 var writer = new jspb.BinaryWriter(); 366 var writer = new jspb.BinaryWriter();
367 367
368 var testSignedData = [ 368 var testSignedData = [
369 '2730538252207801776', 369 '2730538252207801776',
370 '-2688470994844604560', 370 '-2688470994844604560',
371 '3398529779486536359', 371 '3398529779486536359',
372 '3568577411627971000', 372 '3568577411627971000',
373 '272477188847484900', 373 '272477188847484900',
374 '-6649058714086158188', 374 '-6649058714086158188',
375 '-7695254765712060806', 375 '-7695254765712060806',
376 '-4525541438037104029', 376 '-4525541438037104029',
377 '-4993706538836508568', 377 '-4993706538836508568',
378 '4990160321893729138' 378 '4990160321893729138'
379 ]; 379 ];
380 var testUnsignedData = [ 380 var testUnsignedData = [
381 '7822732630241694882', 381 '7822732630241694882',
382 '6753602971916687352', 382 '6753602971916687352',
383 '2399935075244442116', 383 '2399935075244442116',
384 '8724292567325338867', 384 '8724292567325338867',
385 '16948784802625696584', 385 '16948784802625696584',
386 '4136275908516066934', 386 '4136275908516066934',
387 '3575388346793700364', 387 '3575388346793700364',
388 '5167142028379259461', 388 '5167142028379259461',
389 '1557573948689737699', 389 '1557573948689737699',
390 '17100725280812548567' 390 '17100725280812548567'
391 ]; 391 ];
392 392
393 for (var i = 0; i < testSignedData.length; i++) { 393 for (var i = 0; i < testSignedData.length; i++) {
394 writer.writeInt64String(2 * i + 1, testSignedData[i]); 394 writer.writeInt64String(2 * i + 1, testSignedData[i]);
395 writer.writeUint64String(2 * i + 2, testUnsignedData[i]); 395 writer.writeUint64String(2 * i + 2, testUnsignedData[i]);
396 } 396 }
397 397
398 var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); 398 var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
399 399
400 for (var i = 0; i < testSignedData.length; i++) { 400 for (var i = 0; i < testSignedData.length; i++) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 } 528 }
529 } 529 }
530 }); 530 });
531 531
532 532
533 /** 533 /**
534 * Tests nested messages. 534 * Tests nested messages.
535 */ 535 */
536 it('testNesting', function() { 536 it('testNesting', function() {
537 var writer = new jspb.BinaryWriter(); 537 var writer = new jspb.BinaryWriter();
538 var dummyMessage = /** @type {!jspb.BinaryMessage} */({}); 538 var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
539 539
540 writer.writeInt32(1, 100); 540 writer.writeInt32(1, 100);
541 541
542 // Add one message with 3 int fields. 542 // Add one message with 3 int fields.
543 writer.writeMessage(2, dummyMessage, function() { 543 writer.writeMessage(2, dummyMessage, function() {
544 writer.writeInt32(3, 300); 544 writer.writeInt32(3, 300);
545 writer.writeInt32(4, 400); 545 writer.writeInt32(4, 400);
546 writer.writeInt32(5, 500); 546 writer.writeInt32(5, 500);
547 }); 547 });
548 548
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 writer.writeInt32(3, sentinel); 619 writer.writeInt32(3, sentinel);
620 writer.writeFloat(3, 1); 620 writer.writeFloat(3, 1);
621 writer.writeFixed32(3, 1); 621 writer.writeFixed32(3, 1);
622 writer.writeSfixed32(3, 1); 622 writer.writeSfixed32(3, 1);
623 623
624 // Write delimited fields. 624 // Write delimited fields.
625 writer.writeInt32(4, sentinel); 625 writer.writeInt32(4, sentinel);
626 writer.writeBytes(4, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 626 writer.writeBytes(4, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
627 writer.writeString(4, 'The quick brown fox jumps over the lazy dog'); 627 writer.writeString(4, 'The quick brown fox jumps over the lazy dog');
628 628
629 // Write a group with a nested group inside. We use the internal 629 // Write a group with a nested group inside.
630 // .rawWriteVarint() to ensure the tested wire data is what we want,
631 // independently of any serialization logic.
632 writer.writeInt32(5, sentinel); 630 writer.writeInt32(5, sentinel);
633 // Start group, field 5. 631 var dummyMessage = /** @type {!jspb.BinaryMessage} */({});
634 writer.rawWriteVarint( 632 writer.writeGroup(5, dummyMessage, function() {
635 (5 << 3) + jspb.BinaryConstants.WireType.START_GROUP); 633 writer.writeInt64(42, 42);
636 // Varint, field 42. 634 writer.writeGroup(6, dummyMessage, function() {
637 writer.rawWriteVarint( 635 writer.writeInt64(84, 42);
638 (42 << 3) + jspb.BinaryConstants.WireType.VARINT); 636 });
639 // Varint data. 637 });
640 writer.rawWriteVarint(42);
641 // Start group, field 6.
642 writer.rawWriteVarint(
643 (6 << 3) + jspb.BinaryConstants.WireType.START_GROUP);
644 // Varint, field 84.
645 writer.rawWriteVarint(
646 (84 << 3) + jspb.BinaryConstants.WireType.VARINT);
647 writer.rawWriteVarint(42);
648 // End group, field 6.
649 writer.rawWriteVarint(
650 (6 << 3) + jspb.BinaryConstants.WireType.END_GROUP);
651 // End group, field 5.
652 writer.rawWriteVarint(
653 (5 << 3) + jspb.BinaryConstants.WireType.END_GROUP);
654 638
655 // Write final sentinel. 639 // Write final sentinel.
656 writer.writeInt32(6, sentinel); 640 writer.writeInt32(6, sentinel);
657 641
658 var reader = jspb.BinaryReader.alloc(writer.getResultBuffer()); 642 var reader = jspb.BinaryReader.alloc(writer.getResultBuffer());
659 643
660 function skip(field, count) { 644 function skip(field, count) {
661 for (var i = 0; i < count; i++) { 645 for (var i = 0; i < count; i++) {
662 reader.nextField(); 646 reader.nextField();
663 if (field != reader.getFieldNumber()) throw 'fail!'; 647 if (field != reader.getFieldNumber()) throw 'fail!';
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 reader.runReadCallback('readCallback'); 864 reader.runReadCallback('readCallback');
881 }); 865 });
882 866
883 reader.nextField(); 867 reader.nextField();
884 assertEquals(7, reader.getFieldNumber()); 868 assertEquals(7, reader.getFieldNumber());
885 assertEquals(700, reader.readInt32()); 869 assertEquals(700, reader.readInt32());
886 870
887 assertEquals(false, reader.nextField()); 871 assertEquals(false, reader.nextField());
888 }); 872 });
889 }); 873 });
OLDNEW
« no previous file with comments | « third_party/protobuf/js/binary/reader.js ('k') | third_party/protobuf/js/binary/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698