aboutsummaryrefslogtreecommitdiff
path: root/js/binary/proto_test.js
diff options
context:
space:
mode:
authorAdam Cozzette <acozzette@gmail.com>2016-11-23 11:26:31 -0800
committerGitHub <noreply@github.com>2016-11-23 11:26:31 -0800
commit39f9b43219bc5718b659ed72a2130a7b2ce66108 (patch)
treee48fe16afc2e1d868408e9453fff521d6ddcd4ae /js/binary/proto_test.js
parentc9504715634948c9f8f306330449f296d926b74e (diff)
parent65479cb7b1f99ab957da68abce17feb68a9e1cf0 (diff)
downloadprotobuf-39f9b43219bc5718b659ed72a2130a7b2ce66108.tar.gz
protobuf-39f9b43219bc5718b659ed72a2130a7b2ce66108.tar.bz2
protobuf-39f9b43219bc5718b659ed72a2130a7b2ce66108.zip
Merge pull request #2403 from google/down-integrate-with-msvc-fix
Integrated internal changes from Google
Diffstat (limited to 'js/binary/proto_test.js')
-rw-r--r--js/binary/proto_test.js41
1 files changed, 39 insertions, 2 deletions
diff --git a/js/binary/proto_test.js b/js/binary/proto_test.js
index 26e1d30f..f86dc645 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: ../node_modules/google-protobuf/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);
+ });
});