Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [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 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 33 | goog.require('goog.crypt.base64'); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 34 | goog.require('goog.testing.asserts'); |
Adam Cozzette | 5a76e63 | 2016-11-17 16:48:38 -0800 | [diff] [blame] | 35 | goog.require('jspb.BinaryWriter'); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 36 | goog.require('jspb.Message'); |
Josh Haberman | e9f31ee | 2016-02-04 10:29:27 -0800 | [diff] [blame] | 37 | |
murgatroid99 | a862b6b | 2016-02-24 13:44:57 -0800 | [diff] [blame] | 38 | // CommonJS-LoadFromFile: ../testbinary_pb proto.jspb.test |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 39 | goog.require('proto.jspb.test.ExtendsWithMessage'); |
| 40 | goog.require('proto.jspb.test.ForeignEnum'); |
| 41 | goog.require('proto.jspb.test.ForeignMessage'); |
| 42 | goog.require('proto.jspb.test.TestAllTypes'); |
| 43 | goog.require('proto.jspb.test.TestExtendable'); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 44 | goog.require('proto.jspb.test.extendOptionalBool'); |
| 45 | goog.require('proto.jspb.test.extendOptionalBytes'); |
| 46 | goog.require('proto.jspb.test.extendOptionalDouble'); |
| 47 | goog.require('proto.jspb.test.extendOptionalFixed32'); |
| 48 | goog.require('proto.jspb.test.extendOptionalFixed64'); |
| 49 | goog.require('proto.jspb.test.extendOptionalFloat'); |
| 50 | goog.require('proto.jspb.test.extendOptionalForeignEnum'); |
| 51 | goog.require('proto.jspb.test.extendOptionalInt32'); |
| 52 | goog.require('proto.jspb.test.extendOptionalInt64'); |
| 53 | goog.require('proto.jspb.test.extendOptionalSfixed32'); |
| 54 | goog.require('proto.jspb.test.extendOptionalSfixed64'); |
| 55 | goog.require('proto.jspb.test.extendOptionalSint32'); |
| 56 | goog.require('proto.jspb.test.extendOptionalSint64'); |
| 57 | goog.require('proto.jspb.test.extendOptionalString'); |
| 58 | goog.require('proto.jspb.test.extendOptionalUint32'); |
| 59 | goog.require('proto.jspb.test.extendOptionalUint64'); |
| 60 | goog.require('proto.jspb.test.extendPackedRepeatedBoolList'); |
| 61 | goog.require('proto.jspb.test.extendPackedRepeatedDoubleList'); |
| 62 | goog.require('proto.jspb.test.extendPackedRepeatedFixed32List'); |
| 63 | goog.require('proto.jspb.test.extendPackedRepeatedFixed64List'); |
| 64 | goog.require('proto.jspb.test.extendPackedRepeatedFloatList'); |
| 65 | goog.require('proto.jspb.test.extendPackedRepeatedForeignEnumList'); |
| 66 | goog.require('proto.jspb.test.extendPackedRepeatedInt32List'); |
| 67 | goog.require('proto.jspb.test.extendPackedRepeatedInt64List'); |
| 68 | goog.require('proto.jspb.test.extendPackedRepeatedSfixed32List'); |
| 69 | goog.require('proto.jspb.test.extendPackedRepeatedSfixed64List'); |
| 70 | goog.require('proto.jspb.test.extendPackedRepeatedSint32List'); |
| 71 | goog.require('proto.jspb.test.extendPackedRepeatedSint64List'); |
| 72 | goog.require('proto.jspb.test.extendPackedRepeatedUint32List'); |
| 73 | goog.require('proto.jspb.test.extendPackedRepeatedUint64List'); |
| 74 | goog.require('proto.jspb.test.extendRepeatedBoolList'); |
| 75 | goog.require('proto.jspb.test.extendRepeatedBytesList'); |
| 76 | goog.require('proto.jspb.test.extendRepeatedDoubleList'); |
| 77 | goog.require('proto.jspb.test.extendRepeatedFixed32List'); |
| 78 | goog.require('proto.jspb.test.extendRepeatedFixed64List'); |
| 79 | goog.require('proto.jspb.test.extendRepeatedFloatList'); |
| 80 | goog.require('proto.jspb.test.extendRepeatedForeignEnumList'); |
| 81 | goog.require('proto.jspb.test.extendRepeatedInt32List'); |
| 82 | goog.require('proto.jspb.test.extendRepeatedInt64List'); |
| 83 | goog.require('proto.jspb.test.extendRepeatedSfixed32List'); |
| 84 | goog.require('proto.jspb.test.extendRepeatedSfixed64List'); |
| 85 | goog.require('proto.jspb.test.extendRepeatedSint32List'); |
| 86 | goog.require('proto.jspb.test.extendRepeatedSint64List'); |
| 87 | goog.require('proto.jspb.test.extendRepeatedStringList'); |
| 88 | goog.require('proto.jspb.test.extendRepeatedUint32List'); |
| 89 | goog.require('proto.jspb.test.extendRepeatedUint64List'); |
| 90 | |
Adam Cozzette | 40f3586 | 2016-11-18 12:32:52 -0800 | [diff] [blame] | 91 | // CommonJS-LoadFromFile: ../node_modules/google-protobuf/google/protobuf/any_pb proto.google.protobuf |
Adam Cozzette | 5a76e63 | 2016-11-17 16:48:38 -0800 | [diff] [blame] | 92 | goog.require('proto.google.protobuf.Any'); |
| 93 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 94 | |
| 95 | var suite = {}; |
| 96 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 97 | var BYTES = new Uint8Array([1, 2, 8, 9]); |
| 98 | |
| 99 | var BYTES_B64 = goog.crypt.base64.encodeByteArray(BYTES); |
| 100 | |
| 101 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 102 | /** |
| 103 | * Helper: fill all fields on a TestAllTypes message. |
| 104 | * @param {proto.jspb.test.TestAllTypes} msg |
| 105 | */ |
| 106 | function fillAllFields(msg) { |
| 107 | msg.setOptionalInt32(-42); |
| 108 | // can be exactly represented by JS number (64-bit double, i.e., 52-bit |
| 109 | // mantissa). |
| 110 | msg.setOptionalInt64(-0x7fffffff00000000); |
| 111 | msg.setOptionalUint32(0x80000000); |
| 112 | msg.setOptionalUint64(0xf000000000000000); |
| 113 | msg.setOptionalSint32(-100); |
| 114 | msg.setOptionalSint64(-0x8000000000000000); |
| 115 | msg.setOptionalFixed32(1234); |
| 116 | msg.setOptionalFixed64(0x1234567800000000); |
| 117 | msg.setOptionalSfixed32(-1234); |
| 118 | msg.setOptionalSfixed64(-0x1234567800000000); |
| 119 | msg.setOptionalFloat(1.5); |
| 120 | msg.setOptionalDouble(-1.5); |
| 121 | msg.setOptionalBool(true); |
| 122 | msg.setOptionalString('hello world'); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 123 | msg.setOptionalBytes(BYTES); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 124 | msg.setOptionalGroup(new proto.jspb.test.TestAllTypes.OptionalGroup()); |
| 125 | msg.getOptionalGroup().setA(100); |
| 126 | var submsg = new proto.jspb.test.ForeignMessage(); |
| 127 | submsg.setC(16); |
| 128 | msg.setOptionalForeignMessage(submsg); |
| 129 | msg.setOptionalForeignEnum(proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 130 | msg.setOneofString('oneof'); |
| 131 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 132 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 133 | msg.setRepeatedInt32List([-42]); |
| 134 | msg.setRepeatedInt64List([-0x7fffffff00000000]); |
| 135 | msg.setRepeatedUint32List([0x80000000]); |
| 136 | msg.setRepeatedUint64List([0xf000000000000000]); |
| 137 | msg.setRepeatedSint32List([-100]); |
| 138 | msg.setRepeatedSint64List([-0x8000000000000000]); |
| 139 | msg.setRepeatedFixed32List([1234]); |
| 140 | msg.setRepeatedFixed64List([0x1234567800000000]); |
| 141 | msg.setRepeatedSfixed32List([-1234]); |
| 142 | msg.setRepeatedSfixed64List([-0x1234567800000000]); |
| 143 | msg.setRepeatedFloatList([1.5]); |
| 144 | msg.setRepeatedDoubleList([-1.5]); |
| 145 | msg.setRepeatedBoolList([true]); |
| 146 | msg.setRepeatedStringList(['hello world']); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 147 | msg.setRepeatedBytesList([BYTES, BYTES]); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 148 | msg.setRepeatedGroupList([new proto.jspb.test.TestAllTypes.RepeatedGroup()]); |
| 149 | msg.getRepeatedGroupList()[0].setA(100); |
| 150 | submsg = new proto.jspb.test.ForeignMessage(); |
| 151 | submsg.setC(1000); |
| 152 | msg.setRepeatedForeignMessageList([submsg]); |
| 153 | msg.setRepeatedForeignEnumList([proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 154 | |
| 155 | msg.setPackedRepeatedInt32List([-42]); |
| 156 | msg.setPackedRepeatedInt64List([-0x7fffffff00000000]); |
| 157 | msg.setPackedRepeatedUint32List([0x80000000]); |
| 158 | msg.setPackedRepeatedUint64List([0xf000000000000000]); |
| 159 | msg.setPackedRepeatedSint32List([-100]); |
| 160 | msg.setPackedRepeatedSint64List([-0x8000000000000000]); |
| 161 | msg.setPackedRepeatedFixed32List([1234]); |
| 162 | msg.setPackedRepeatedFixed64List([0x1234567800000000]); |
| 163 | msg.setPackedRepeatedSfixed32List([-1234]); |
| 164 | msg.setPackedRepeatedSfixed64List([-0x1234567800000000]); |
| 165 | msg.setPackedRepeatedFloatList([1.5]); |
| 166 | msg.setPackedRepeatedDoubleList([-1.5]); |
| 167 | msg.setPackedRepeatedBoolList([true]); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 168 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | |
| 172 | /** |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 173 | * Helper: compare a bytes field to an expected value |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 174 | * @param {Uint8Array|string} arr |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 175 | * @param {Uint8Array} expected |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 176 | * @return {boolean} |
| 177 | */ |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 178 | function bytesCompare(arr, expected) { |
Rafi Kamal | 58d4420 | 2019-11-11 17:06:56 -0800 | [diff] [blame] | 179 | if (typeof arr === 'string') { |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 180 | arr = goog.crypt.base64.decodeStringToUint8Array(arr); |
| 181 | } |
| 182 | if (arr.length != expected.length) { |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 183 | return false; |
| 184 | } |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 185 | for (var i = 0; i < arr.length; i++) { |
| 186 | if (arr[i] != expected[i]) { |
| 187 | return false; |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 188 | } |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 189 | } |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 190 | return true; |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | |
| 194 | /** |
| 195 | * Helper: verify contents of given TestAllTypes message as set by |
| 196 | * fillAllFields(). |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 197 | * @param {proto.jspb.test.TestAllTypes} original |
| 198 | * @param {proto.jspb.test.TestAllTypes} copy |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 199 | */ |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 200 | function checkAllFields(original, copy) { |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 201 | assertEquals(copy.getOptionalInt32(), -42); |
| 202 | assertEquals(copy.getOptionalInt64(), -0x7fffffff00000000); |
| 203 | assertEquals(copy.getOptionalUint32(), 0x80000000); |
| 204 | assertEquals(copy.getOptionalUint64(), 0xf000000000000000); |
| 205 | assertEquals(copy.getOptionalSint32(), -100); |
| 206 | assertEquals(copy.getOptionalSint64(), -0x8000000000000000); |
| 207 | assertEquals(copy.getOptionalFixed32(), 1234); |
| 208 | assertEquals(copy.getOptionalFixed64(), 0x1234567800000000); |
| 209 | assertEquals(copy.getOptionalSfixed32(), -1234); |
| 210 | assertEquals(copy.getOptionalSfixed64(), -0x1234567800000000); |
| 211 | assertEquals(copy.getOptionalFloat(), 1.5); |
| 212 | assertEquals(copy.getOptionalDouble(), -1.5); |
| 213 | assertEquals(copy.getOptionalBool(), true); |
| 214 | assertEquals(copy.getOptionalString(), 'hello world'); |
| 215 | assertEquals(true, bytesCompare(copy.getOptionalBytes(), BYTES)); |
| 216 | assertEquals(true, bytesCompare(copy.getOptionalBytes_asU8(), BYTES)); |
| 217 | assertEquals( |
| 218 | copy.getOptionalBytes_asB64(), goog.crypt.base64.encodeByteArray(BYTES)); |
| 219 | |
| 220 | assertEquals(copy.getOptionalGroup().getA(), 100); |
| 221 | assertEquals(copy.getOptionalForeignMessage().getC(), 16); |
| 222 | assertEquals(copy.getOptionalForeignEnum(), |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 223 | proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 224 | |
| 225 | |
| 226 | assertEquals(copy.getOneofString(), 'oneof'); |
| 227 | assertEquals(copy.getOneofFieldCase(), |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 228 | proto.jspb.test.TestAllTypes.OneofFieldCase.ONEOF_STRING); |
| 229 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 230 | assertElementsEquals(copy.getRepeatedInt32List(), [-42]); |
| 231 | assertElementsEquals(copy.getRepeatedInt64List(), [-0x7fffffff00000000]); |
| 232 | assertElementsEquals(copy.getRepeatedUint32List(), [0x80000000]); |
| 233 | assertElementsEquals(copy.getRepeatedUint64List(), [0xf000000000000000]); |
| 234 | assertElementsEquals(copy.getRepeatedSint32List(), [-100]); |
| 235 | assertElementsEquals(copy.getRepeatedSint64List(), [-0x8000000000000000]); |
| 236 | assertElementsEquals(copy.getRepeatedFixed32List(), [1234]); |
| 237 | assertElementsEquals(copy.getRepeatedFixed64List(), [0x1234567800000000]); |
| 238 | assertElementsEquals(copy.getRepeatedSfixed32List(), [-1234]); |
| 239 | assertElementsEquals(copy.getRepeatedSfixed64List(), [-0x1234567800000000]); |
| 240 | assertElementsEquals(copy.getRepeatedFloatList(), [1.5]); |
| 241 | assertElementsEquals(copy.getRepeatedDoubleList(), [-1.5]); |
| 242 | assertElementsEquals(copy.getRepeatedBoolList(), [true]); |
| 243 | assertElementsEquals(copy.getRepeatedStringList(), ['hello world']); |
| 244 | assertEquals(copy.getRepeatedBytesList().length, 2); |
| 245 | assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[0], BYTES)); |
| 246 | assertEquals(true, bytesCompare(copy.getRepeatedBytesList()[0], BYTES)); |
| 247 | assertEquals(true, bytesCompare(copy.getRepeatedBytesList_asU8()[1], BYTES)); |
| 248 | assertEquals(copy.getRepeatedBytesList_asB64()[0], BYTES_B64); |
| 249 | assertEquals(copy.getRepeatedBytesList_asB64()[1], BYTES_B64); |
| 250 | assertEquals(copy.getRepeatedGroupList().length, 1); |
| 251 | assertEquals(copy.getRepeatedGroupList()[0].getA(), 100); |
| 252 | assertEquals(copy.getRepeatedForeignMessageList().length, 1); |
| 253 | assertEquals(copy.getRepeatedForeignMessageList()[0].getC(), 1000); |
| 254 | assertElementsEquals(copy.getRepeatedForeignEnumList(), |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 255 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 256 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 257 | assertElementsEquals(copy.getPackedRepeatedInt32List(), [-42]); |
| 258 | assertElementsEquals(copy.getPackedRepeatedInt64List(), |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 259 | [-0x7fffffff00000000]); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 260 | assertElementsEquals(copy.getPackedRepeatedUint32List(), [0x80000000]); |
| 261 | assertElementsEquals(copy.getPackedRepeatedUint64List(), |
| 262 | [0xf000000000000000]); |
| 263 | assertElementsEquals(copy.getPackedRepeatedSint32List(), [-100]); |
| 264 | assertElementsEquals(copy.getPackedRepeatedSint64List(), |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 265 | [-0x8000000000000000]); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 266 | assertElementsEquals(copy.getPackedRepeatedFixed32List(), [1234]); |
| 267 | assertElementsEquals(copy.getPackedRepeatedFixed64List(), |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 268 | [0x1234567800000000]); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 269 | assertElementsEquals(copy.getPackedRepeatedSfixed32List(), [-1234]); |
| 270 | assertElementsEquals(copy.getPackedRepeatedSfixed64List(), |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 271 | [-0x1234567800000000]); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 272 | assertElementsEquals(copy.getPackedRepeatedFloatList(), [1.5]); |
| 273 | assertElementsEquals(copy.getPackedRepeatedDoubleList(), [-1.5]); |
| 274 | |
Adam Cozzette | 5a76e63 | 2016-11-17 16:48:38 -0800 | [diff] [blame] | 275 | |
| 276 | // Check last so we get more granular errors first. |
| 277 | assertTrue(jspb.Message.equals(original, copy)); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | |
| 281 | /** |
| 282 | * Helper: verify that all expected extensions are present. |
| 283 | * @param {!proto.jspb.test.TestExtendable} msg |
| 284 | */ |
| 285 | function checkExtensions(msg) { |
Adam Cozzette | 651ba62 | 2017-03-06 15:12:19 -0800 | [diff] [blame] | 286 | assertEquals(0, msg.getExtension(proto.jspb.test.extendOptionalInt32)); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 287 | assertEquals(-0x7fffffff00000000, |
| 288 | msg.getExtension(proto.jspb.test.extendOptionalInt64)); |
| 289 | assertEquals(0x80000000, |
| 290 | msg.getExtension(proto.jspb.test.extendOptionalUint32)); |
| 291 | assertEquals(0xf000000000000000, |
| 292 | msg.getExtension(proto.jspb.test.extendOptionalUint64)); |
| 293 | assertEquals(-100, |
| 294 | msg.getExtension(proto.jspb.test.extendOptionalSint32)); |
| 295 | assertEquals(-0x8000000000000000, |
| 296 | msg.getExtension(proto.jspb.test.extendOptionalSint64)); |
| 297 | assertEquals(1234, |
| 298 | msg.getExtension(proto.jspb.test.extendOptionalFixed32)); |
| 299 | assertEquals(0x1234567800000000, |
| 300 | msg.getExtension(proto.jspb.test.extendOptionalFixed64)); |
| 301 | assertEquals(-1234, |
| 302 | msg.getExtension(proto.jspb.test.extendOptionalSfixed32)); |
| 303 | assertEquals(-0x1234567800000000, |
| 304 | msg.getExtension(proto.jspb.test.extendOptionalSfixed64)); |
| 305 | assertEquals(1.5, |
| 306 | msg.getExtension(proto.jspb.test.extendOptionalFloat)); |
| 307 | assertEquals(-1.5, |
| 308 | msg.getExtension(proto.jspb.test.extendOptionalDouble)); |
| 309 | assertEquals(true, |
| 310 | msg.getExtension(proto.jspb.test.extendOptionalBool)); |
| 311 | assertEquals('hello world', |
| 312 | msg.getExtension(proto.jspb.test.extendOptionalString)); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 313 | assertEquals( |
| 314 | true, bytesCompare( |
| 315 | msg.getExtension(proto.jspb.test.extendOptionalBytes), BYTES)); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 316 | assertEquals(16, |
| 317 | msg.getExtension( |
| 318 | proto.jspb.test.ExtendsWithMessage.optionalExtension).getFoo()); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 319 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 320 | |
| 321 | assertElementsEquals( |
| 322 | msg.getExtension(proto.jspb.test.extendRepeatedInt32List), |
| 323 | [-42]); |
| 324 | assertElementsEquals( |
| 325 | msg.getExtension(proto.jspb.test.extendRepeatedInt64List), |
| 326 | [-0x7fffffff00000000]); |
| 327 | assertElementsEquals( |
| 328 | msg.getExtension(proto.jspb.test.extendRepeatedUint32List), |
| 329 | [0x80000000]); |
| 330 | assertElementsEquals( |
| 331 | msg.getExtension(proto.jspb.test.extendRepeatedUint64List), |
| 332 | [0xf000000000000000]); |
| 333 | assertElementsEquals( |
| 334 | msg.getExtension(proto.jspb.test.extendRepeatedSint32List), |
| 335 | [-100]); |
| 336 | assertElementsEquals( |
| 337 | msg.getExtension(proto.jspb.test.extendRepeatedSint64List), |
| 338 | [-0x8000000000000000]); |
| 339 | assertElementsEquals( |
| 340 | msg.getExtension(proto.jspb.test.extendRepeatedFixed32List), |
| 341 | [1234]); |
| 342 | assertElementsEquals( |
| 343 | msg.getExtension(proto.jspb.test.extendRepeatedFixed64List), |
| 344 | [0x1234567800000000]); |
| 345 | assertElementsEquals( |
| 346 | msg.getExtension(proto.jspb.test.extendRepeatedSfixed32List), |
| 347 | [-1234]); |
| 348 | assertElementsEquals( |
| 349 | msg.getExtension(proto.jspb.test.extendRepeatedSfixed64List), |
| 350 | [-0x1234567800000000]); |
| 351 | assertElementsEquals( |
| 352 | msg.getExtension(proto.jspb.test.extendRepeatedFloatList), |
| 353 | [1.5]); |
| 354 | assertElementsEquals( |
| 355 | msg.getExtension(proto.jspb.test.extendRepeatedDoubleList), |
| 356 | [-1.5]); |
| 357 | assertElementsEquals( |
| 358 | msg.getExtension(proto.jspb.test.extendRepeatedBoolList), |
| 359 | [true]); |
| 360 | assertElementsEquals( |
| 361 | msg.getExtension(proto.jspb.test.extendRepeatedStringList), |
| 362 | ['hello world']); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 363 | assertEquals( |
| 364 | true, |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 365 | bytesCompare( |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 366 | msg.getExtension(proto.jspb.test.extendRepeatedBytesList)[0], BYTES)); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 367 | assertEquals(1000, |
| 368 | msg.getExtension( |
| 369 | proto.jspb.test.ExtendsWithMessage.repeatedExtensionList)[0] |
| 370 | .getFoo()); |
| 371 | assertElementsEquals( |
| 372 | msg.getExtension(proto.jspb.test.extendRepeatedForeignEnumList), |
| 373 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 374 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 375 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 376 | assertElementsEquals( |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 377 | msg.getExtension(proto.jspb.test.extendPackedRepeatedInt32List), |
| 378 | [-42]); |
| 379 | assertElementsEquals( |
| 380 | msg.getExtension(proto.jspb.test.extendPackedRepeatedInt64List), |
| 381 | [-0x7fffffff00000000]); |
| 382 | assertElementsEquals( |
| 383 | msg.getExtension(proto.jspb.test.extendPackedRepeatedUint32List), |
| 384 | [0x80000000]); |
| 385 | assertElementsEquals( |
| 386 | msg.getExtension(proto.jspb.test.extendPackedRepeatedUint64List), |
| 387 | [0xf000000000000000]); |
| 388 | assertElementsEquals( |
| 389 | msg.getExtension(proto.jspb.test.extendPackedRepeatedSint32List), |
| 390 | [-100]); |
| 391 | assertElementsEquals( |
| 392 | msg.getExtension(proto.jspb.test.extendPackedRepeatedSint64List), |
| 393 | [-0x8000000000000000]); |
| 394 | assertElementsEquals( |
| 395 | msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed32List), |
| 396 | [1234]); |
| 397 | assertElementsEquals( |
| 398 | msg.getExtension(proto.jspb.test.extendPackedRepeatedFixed64List), |
| 399 | [0x1234567800000000]); |
| 400 | assertElementsEquals( |
| 401 | msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed32List), |
| 402 | [-1234]); |
| 403 | assertElementsEquals( |
| 404 | msg.getExtension(proto.jspb.test.extendPackedRepeatedSfixed64List), |
| 405 | [-0x1234567800000000]); |
| 406 | assertElementsEquals( |
| 407 | msg.getExtension(proto.jspb.test.extendPackedRepeatedFloatList), |
| 408 | [1.5]); |
| 409 | assertElementsEquals( |
| 410 | msg.getExtension(proto.jspb.test.extendPackedRepeatedDoubleList), |
| 411 | [-1.5]); |
| 412 | assertElementsEquals( |
| 413 | msg.getExtension(proto.jspb.test.extendPackedRepeatedBoolList), |
| 414 | [true]); |
| 415 | assertElementsEquals( |
| 416 | msg.getExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList), |
| 417 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 418 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 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); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 432 | checkAllFields(msg, decoded); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 433 | }); |
| 434 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 435 | /** |
| 436 | * Test that base64 string and Uint8Array are interchangeable in bytes fields. |
| 437 | */ |
| 438 | it('testBytesFieldsGettersInterop', function() { |
| 439 | var msg = new proto.jspb.test.TestAllTypes(); |
| 440 | // Set from a base64 string and check all the getters work. |
| 441 | msg.setOptionalBytes(BYTES_B64); |
| 442 | assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
| 443 | assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
| 444 | assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 445 | |
| 446 | // Test binary serialize round trip doesn't break it. |
| 447 | msg = proto.jspb.test.TestAllTypes.deserializeBinary(msg.serializeBinary()); |
| 448 | assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
| 449 | assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
| 450 | assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 451 | |
| 452 | msg = new proto.jspb.test.TestAllTypes(); |
| 453 | // Set from a Uint8Array and check all the getters work. |
| 454 | msg.setOptionalBytes(BYTES); |
| 455 | assertTrue(bytesCompare(msg.getOptionalBytes_asU8(), BYTES)); |
| 456 | assertTrue(bytesCompare(msg.getOptionalBytes_asB64(), BYTES)); |
| 457 | assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 458 | |
| 459 | }); |
| 460 | |
| 461 | /** |
| 462 | * Test that bytes setters will receive result of any of the getters. |
| 463 | */ |
| 464 | it('testBytesFieldsSettersInterop', function() { |
| 465 | var msg = new proto.jspb.test.TestAllTypes(); |
| 466 | msg.setOptionalBytes(BYTES); |
| 467 | assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 468 | |
| 469 | msg.setOptionalBytes(msg.getOptionalBytes()); |
| 470 | assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 471 | msg.setOptionalBytes(msg.getOptionalBytes_asB64()); |
| 472 | assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 473 | msg.setOptionalBytes(msg.getOptionalBytes_asU8()); |
| 474 | assertTrue(bytesCompare(msg.getOptionalBytes(), BYTES)); |
| 475 | }); |
| 476 | |
| 477 | /** |
| 478 | * Test that bytes setters will receive result of any of the getters. |
| 479 | */ |
| 480 | it('testRepeatedBytesGetters', function() { |
| 481 | var msg = new proto.jspb.test.TestAllTypes(); |
| 482 | |
| 483 | function assertGetters() { |
Rafi Kamal | 58d4420 | 2019-11-11 17:06:56 -0800 | [diff] [blame] | 484 | assertTrue(typeof msg.getRepeatedBytesList_asB64()[0] === 'string'); |
| 485 | assertTrue(typeof msg.getRepeatedBytesList_asB64()[1] === 'string'); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 486 | assertTrue(msg.getRepeatedBytesList_asU8()[0] instanceof Uint8Array); |
| 487 | assertTrue(msg.getRepeatedBytesList_asU8()[1] instanceof Uint8Array); |
| 488 | |
| 489 | assertTrue(bytesCompare(msg.getRepeatedBytesList()[0], BYTES)); |
| 490 | assertTrue(bytesCompare(msg.getRepeatedBytesList()[1], BYTES)); |
| 491 | assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[0], BYTES)); |
| 492 | assertTrue(bytesCompare(msg.getRepeatedBytesList_asB64()[1], BYTES)); |
| 493 | assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[0], BYTES)); |
| 494 | assertTrue(bytesCompare(msg.getRepeatedBytesList_asU8()[1], BYTES)); |
| 495 | } |
| 496 | |
| 497 | msg.setRepeatedBytesList([BYTES, BYTES]); |
| 498 | assertGetters(); |
| 499 | |
| 500 | msg.setRepeatedBytesList([BYTES_B64, BYTES_B64]); |
| 501 | assertGetters(); |
| 502 | |
Bo Yang | cc8ca5b | 2016-09-19 13:45:07 -0700 | [diff] [blame] | 503 | msg.setRepeatedBytesList([]); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 504 | assertEquals(0, msg.getRepeatedBytesList().length); |
| 505 | assertEquals(0, msg.getRepeatedBytesList_asB64().length); |
| 506 | assertEquals(0, msg.getRepeatedBytesList_asU8().length); |
| 507 | }); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 508 | |
| 509 | /** |
| 510 | * Helper: fill all extension values. |
| 511 | * @param {proto.jspb.test.TestExtendable} msg |
| 512 | */ |
| 513 | function fillExtensions(msg) { |
Adam Cozzette | 651ba62 | 2017-03-06 15:12:19 -0800 | [diff] [blame] | 514 | msg.setExtension(proto.jspb.test.extendOptionalInt32, 0); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 515 | msg.setExtension( |
| 516 | proto.jspb.test.extendOptionalInt64, -0x7fffffff00000000); |
| 517 | msg.setExtension( |
| 518 | proto.jspb.test.extendOptionalUint32, 0x80000000); |
| 519 | msg.setExtension( |
| 520 | proto.jspb.test.extendOptionalUint64, 0xf000000000000000); |
| 521 | msg.setExtension( |
| 522 | proto.jspb.test.extendOptionalSint32, -100); |
| 523 | msg.setExtension( |
| 524 | proto.jspb.test.extendOptionalSint64, -0x8000000000000000); |
| 525 | msg.setExtension( |
| 526 | proto.jspb.test.extendOptionalFixed32, 1234); |
| 527 | msg.setExtension( |
| 528 | proto.jspb.test.extendOptionalFixed64, 0x1234567800000000); |
| 529 | msg.setExtension( |
| 530 | proto.jspb.test.extendOptionalSfixed32, -1234); |
| 531 | msg.setExtension( |
| 532 | proto.jspb.test.extendOptionalSfixed64, -0x1234567800000000); |
| 533 | msg.setExtension( |
| 534 | proto.jspb.test.extendOptionalFloat, 1.5); |
| 535 | msg.setExtension( |
| 536 | proto.jspb.test.extendOptionalDouble, -1.5); |
| 537 | msg.setExtension( |
| 538 | proto.jspb.test.extendOptionalBool, true); |
| 539 | msg.setExtension( |
| 540 | proto.jspb.test.extendOptionalString, 'hello world'); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 541 | msg.setExtension(proto.jspb.test.extendOptionalBytes, BYTES); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 542 | var submsg = new proto.jspb.test.ExtendsWithMessage(); |
| 543 | submsg.setFoo(16); |
| 544 | msg.setExtension( |
| 545 | proto.jspb.test.ExtendsWithMessage.optionalExtension, submsg); |
| 546 | msg.setExtension( |
| 547 | proto.jspb.test.extendOptionalForeignEnum, |
| 548 | proto.jspb.test.ForeignEnum.FOREIGN_FOO); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 549 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 550 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 551 | msg.setExtension( |
| 552 | proto.jspb.test.extendRepeatedInt32List, [-42]); |
| 553 | msg.setExtension( |
| 554 | proto.jspb.test.extendRepeatedInt64List, [-0x7fffffff00000000]); |
| 555 | msg.setExtension( |
| 556 | proto.jspb.test.extendRepeatedUint32List, [0x80000000]); |
| 557 | msg.setExtension( |
| 558 | proto.jspb.test.extendRepeatedUint64List, [0xf000000000000000]); |
| 559 | msg.setExtension( |
| 560 | proto.jspb.test.extendRepeatedSint32List, [-100]); |
| 561 | msg.setExtension( |
| 562 | proto.jspb.test.extendRepeatedSint64List, [-0x8000000000000000]); |
| 563 | msg.setExtension( |
| 564 | proto.jspb.test.extendRepeatedFixed32List, [1234]); |
| 565 | msg.setExtension( |
| 566 | proto.jspb.test.extendRepeatedFixed64List, [0x1234567800000000]); |
| 567 | msg.setExtension( |
| 568 | proto.jspb.test.extendRepeatedSfixed32List, [-1234]); |
| 569 | msg.setExtension( |
| 570 | proto.jspb.test.extendRepeatedSfixed64List, [-0x1234567800000000]); |
| 571 | msg.setExtension( |
| 572 | proto.jspb.test.extendRepeatedFloatList, [1.5]); |
| 573 | msg.setExtension( |
| 574 | proto.jspb.test.extendRepeatedDoubleList, [-1.5]); |
| 575 | msg.setExtension( |
| 576 | proto.jspb.test.extendRepeatedBoolList, [true]); |
| 577 | msg.setExtension( |
| 578 | proto.jspb.test.extendRepeatedStringList, ['hello world']); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 579 | msg.setExtension(proto.jspb.test.extendRepeatedBytesList, [BYTES]); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 580 | submsg = new proto.jspb.test.ExtendsWithMessage(); |
| 581 | submsg.setFoo(1000); |
| 582 | msg.setExtension( |
| 583 | proto.jspb.test.ExtendsWithMessage.repeatedExtensionList, [submsg]); |
| 584 | msg.setExtension(proto.jspb.test.extendRepeatedForeignEnumList, |
| 585 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
| 586 | |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 587 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 588 | msg.setExtension( |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 589 | proto.jspb.test.extendPackedRepeatedInt32List, [-42]); |
| 590 | msg.setExtension( |
| 591 | proto.jspb.test.extendPackedRepeatedInt64List, [-0x7fffffff00000000]); |
| 592 | msg.setExtension( |
| 593 | proto.jspb.test.extendPackedRepeatedUint32List, [0x80000000]); |
| 594 | msg.setExtension( |
| 595 | proto.jspb.test.extendPackedRepeatedUint64List, [0xf000000000000000]); |
| 596 | msg.setExtension( |
| 597 | proto.jspb.test.extendPackedRepeatedSint32List, [-100]); |
| 598 | msg.setExtension( |
| 599 | proto.jspb.test.extendPackedRepeatedSint64List, [-0x8000000000000000]); |
| 600 | msg.setExtension( |
| 601 | proto.jspb.test.extendPackedRepeatedFixed32List, [1234]); |
| 602 | msg.setExtension( |
| 603 | proto.jspb.test.extendPackedRepeatedFixed64List, [0x1234567800000000]); |
| 604 | msg.setExtension( |
| 605 | proto.jspb.test.extendPackedRepeatedSfixed32List, [-1234]); |
| 606 | msg.setExtension( |
| 607 | proto.jspb.test.extendPackedRepeatedSfixed64List, |
| 608 | [-0x1234567800000000]); |
| 609 | msg.setExtension( |
| 610 | proto.jspb.test.extendPackedRepeatedFloatList, [1.5]); |
| 611 | msg.setExtension( |
| 612 | proto.jspb.test.extendPackedRepeatedDoubleList, [-1.5]); |
| 613 | msg.setExtension( |
| 614 | proto.jspb.test.extendPackedRepeatedBoolList, [true]); |
| 615 | msg.setExtension(proto.jspb.test.extendPackedRepeatedForeignEnumList, |
| 616 | [proto.jspb.test.ForeignEnum.FOREIGN_FOO]); |
Jisi Liu | 3b3c8ab | 2016-03-30 11:39:59 -0700 | [diff] [blame] | 617 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | |
| 621 | /** |
| 622 | * Tests extension serialization and deserialization. |
| 623 | */ |
| 624 | it('testExtensions', function() { |
| 625 | var msg = new proto.jspb.test.TestExtendable(); |
| 626 | fillExtensions(msg); |
| 627 | var encoded = msg.serializeBinary(); |
| 628 | var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); |
| 629 | checkExtensions(decoded); |
| 630 | }); |
Adam Cozzette | 5a76e63 | 2016-11-17 16:48:38 -0800 | [diff] [blame] | 631 | |
| 632 | /** |
| 633 | * Tests that unknown extensions don't cause deserialization failure. |
| 634 | */ |
| 635 | it('testUnknownExtension', function() { |
| 636 | var msg = new proto.jspb.test.TestExtendable(); |
| 637 | fillExtensions(msg); |
| 638 | var writer = new jspb.BinaryWriter(); |
| 639 | writer.writeBool((1 << 29) - 1, true); |
| 640 | proto.jspb.test.TestExtendable.serializeBinaryToWriter(msg, writer); |
| 641 | var encoded = writer.getResultBuffer(); |
| 642 | var decoded = proto.jspb.test.TestExtendable.deserializeBinary(encoded); |
| 643 | checkExtensions(decoded); |
| 644 | }); |
| 645 | |
| 646 | it('testAnyWellKnownType', function() { |
| 647 | var any = new proto.google.protobuf.Any(); |
| 648 | var msg = new proto.jspb.test.TestAllTypes(); |
| 649 | |
| 650 | fillAllFields(msg); |
| 651 | |
| 652 | any.pack(msg.serializeBinary(), 'jspb.test.TestAllTypes'); |
| 653 | |
| 654 | assertEquals('type.googleapis.com/jspb.test.TestAllTypes', |
| 655 | any.getTypeUrl()); |
| 656 | |
| 657 | var msg2 = any.unpack( |
| 658 | proto.jspb.test.TestAllTypes.deserializeBinary, |
| 659 | 'jspb.test.TestAllTypes'); |
| 660 | |
| 661 | checkAllFields(msg, msg2); |
Adam Cozzette | 0894e07 | 2018-11-09 11:28:22 -0800 | [diff] [blame] | 662 | |
Adam Cozzette | 5a76e63 | 2016-11-17 16:48:38 -0800 | [diff] [blame] | 663 | }); |
Yilun Chong | 0adb74c | 2019-01-08 15:06:30 -0800 | [diff] [blame] | 664 | |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 665 | }); |