diff options
author | Adam Cozzette <acozzette@google.com> | 2016-11-17 16:48:38 -0800 |
---|---|---|
committer | Adam Cozzette <acozzette@google.com> | 2016-11-17 16:59:59 -0800 |
commit | 5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74 (patch) | |
tree | 0276f81f8848a05d84cd7e287b43d665e30f04e3 /js/binary/proto_test.js | |
parent | e28286fa05d8327fd6c5aa70cfb3be558f0932b8 (diff) | |
download | protobuf-5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74.tar.gz protobuf-5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74.tar.bz2 protobuf-5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74.zip |
Integrated internal changes from Google
Diffstat (limited to 'js/binary/proto_test.js')
-rw-r--r-- | js/binary/proto_test.js | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/js/binary/proto_test.js b/js/binary/proto_test.js index 26e1d30f..ae50a703 100644 --- a/js/binary/proto_test.js +++ b/js/binary/proto_test.js @@ -32,6 +32,7 @@ goog.require('goog.crypt.base64'); goog.require('goog.testing.asserts'); +goog.require('jspb.BinaryWriter'); goog.require('jspb.Message'); // CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test @@ -87,6 +88,9 @@ goog.require('proto.jspb.test.extendRepeatedStringList'); goog.require('proto.jspb.test.extendRepeatedUint32List'); goog.require('proto.jspb.test.extendRepeatedUint64List'); +// CommonJS-LoadFromFile: google/protobuf/any_pb proto.google.protobuf +goog.require('proto.google.protobuf.Any'); + var suite = {}; @@ -194,8 +198,6 @@ function bytesCompare(arr, expected) { * @param {proto.jspb.test.TestAllTypes} copy */ function checkAllFields(original, copy) { - assertTrue(jspb.Message.equals(original, copy)); - assertEquals(copy.getOptionalInt32(), -42); assertEquals(copy.getOptionalInt64(), -0x7fffffff00000000); assertEquals(copy.getOptionalUint32(), 0x80000000); @@ -270,6 +272,9 @@ function checkAllFields(original, copy) { assertElementsEquals(copy.getPackedRepeatedFloatList(), [1.5]); assertElementsEquals(copy.getPackedRepeatedDoubleList(), [-1.5]); + + // Check last so we get more granular errors first. + assertTrue(jspb.Message.equals(original, copy)); } @@ -625,4 +630,36 @@ describe('protoBinaryTest', function() { var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); checkExtensions(decoded); }); + + /** + * Tests that unknown extensions don't cause deserialization failure. + */ + it('testUnknownExtension', function() { + var msg = new proto.jspb.test.TestExtendable(); + fillExtensions(msg); + var writer = new jspb.BinaryWriter(); + writer.writeBool((1 << 29) - 1, true); + proto.jspb.test.TestExtendable.serializeBinaryToWriter(msg, writer); + var encoded = writer.getResultBuffer(); + var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); + checkExtensions(decoded); + }); + + it('testAnyWellKnownType', function() { + var any = new proto.google.protobuf.Any(); + var msg = new proto.jspb.test.TestAllTypes(); + + fillAllFields(msg); + + any.pack(msg.serializeBinary(), 'jspb.test.TestAllTypes'); + + assertEquals('type.googleapis.com/jspb.test.TestAllTypes', + any.getTypeUrl()); + + var msg2 = any.unpack( + proto.jspb.test.TestAllTypes.deserializeBinary, + 'jspb.test.TestAllTypes'); + + checkAllFields(msg, msg2); + }); }); |