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 33goog.setTestOnly(); 34 35goog.require('goog.json'); 36goog.require('goog.testing.PropertyReplacer'); 37goog.require('goog.testing.asserts'); 38goog.require('goog.userAgent'); 39 40// CommonJS-LoadFromFile: google-protobuf jspb 41goog.require('jspb.Message'); 42 43// CommonJS-LoadFromFile: test15_pb proto.jspb.filenametest.package1 44goog.require('proto.jspb.filenametest.package1.b'); 45 46// CommonJS-LoadFromFile: test14_pb proto.jspb.filenametest.package2 47goog.require('proto.jspb.filenametest.package2.TestMessage'); 48 49// CommonJS-LoadFromFile: test13_pb proto.jspb.filenametest.package1 50goog.require('proto.jspb.filenametest.package1.a'); 51goog.require('proto.jspb.filenametest.package1.TestMessage'); 52 53// CommonJS-LoadFromFile: test12_pb proto.jspb.circulartest 54goog.require('proto.jspb.circulartest.ExtensionContainingType1'); 55goog.require('proto.jspb.circulartest.ExtensionContainingType2'); 56goog.require('proto.jspb.circulartest.ExtensionField1'); 57goog.require('proto.jspb.circulartest.ExtensionField2'); 58goog.require('proto.jspb.circulartest.ExtensionField3'); 59goog.require('proto.jspb.circulartest.MapField1'); 60goog.require('proto.jspb.circulartest.MapField2'); 61goog.require('proto.jspb.circulartest.MessageField1'); 62goog.require('proto.jspb.circulartest.MessageField2'); 63goog.require('proto.jspb.circulartest.NestedEnum1'); 64goog.require('proto.jspb.circulartest.NestedEnum2'); 65goog.require('proto.jspb.circulartest.NestedMessage1'); 66goog.require('proto.jspb.circulartest.NestedMessage2'); 67goog.require('proto.jspb.circulartest.RepeatedMessageField1'); 68goog.require('proto.jspb.circulartest.RepeatedMessageField2'); 69 70// CommonJS-LoadFromFile: test11_pb proto.jspb.exttest.reverse 71goog.require('proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1'); 72goog.require('proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage2'); 73goog.require('proto.jspb.exttest.reverse.c'); 74 75// CommonJS-LoadFromFile: test8_pb proto.jspb.exttest.nested 76goog.require('proto.jspb.exttest.nested.TestNestedExtensionsMessage'); 77goog.require('proto.jspb.exttest.nested.TestOuterMessage'); 78 79// CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta 80goog.require('proto.jspb.exttest.beta.floatingStrField'); 81 82// CommonJS-LoadFromFile: test3_pb proto.jspb.exttest 83goog.require('proto.jspb.exttest.floatingMsgField'); 84 85// CommonJS-LoadFromFile: test4_pb proto.jspb.exttest 86goog.require('proto.jspb.exttest.floatingMsgFieldTwo'); 87 88// CommonJS-LoadFromFile: test_pb proto.jspb.test 89goog.require('proto.jspb.test.BooleanFields'); 90goog.require('proto.jspb.test.CloneExtension'); 91goog.require('proto.jspb.test.Complex'); 92goog.require('proto.jspb.test.DefaultValues'); 93goog.require('proto.jspb.test.Empty'); 94goog.require('proto.jspb.test.EnumContainer'); 95goog.require('proto.jspb.test.floatingMsgField'); 96goog.require('proto.jspb.test.FloatingPointFields'); 97goog.require('proto.jspb.test.floatingStrField'); 98goog.require('proto.jspb.test.HasExtensions'); 99goog.require('proto.jspb.test.IndirectExtension'); 100goog.require('proto.jspb.test.IsExtension'); 101goog.require('proto.jspb.test.OptionalFields'); 102goog.require('proto.jspb.test.OuterEnum'); 103goog.require('proto.jspb.test.OuterMessage.Complex'); 104goog.require('proto.jspb.test.Simple1'); 105goog.require('proto.jspb.test.Simple2'); 106goog.require('proto.jspb.test.SpecialCases'); 107goog.require('proto.jspb.test.TestClone'); 108goog.require('proto.jspb.test.TestCloneExtension'); 109goog.require('proto.jspb.test.TestEndsWithBytes'); 110goog.require('proto.jspb.test.TestGroup'); 111goog.require('proto.jspb.test.TestGroup1'); 112goog.require('proto.jspb.test.TestLastFieldBeforePivot'); 113goog.require('proto.jspb.test.TestMessageWithOneof'); 114goog.require('proto.jspb.test.TestReservedNames'); 115goog.require('proto.jspb.test.TestReservedNamesExtension'); 116 117// CommonJS-LoadFromFile: test2_pb proto.jspb.test 118goog.require('proto.jspb.test.ExtensionMessage'); 119goog.require('proto.jspb.test.TestExtensionsMessage'); 120 121 122describe('Message test suite', function() { 123 var stubs = new goog.testing.PropertyReplacer(); 124 125 beforeEach(function() { 126 stubs.set(jspb.Message, 'SERIALIZE_EMPTY_TRAILING_FIELDS', false); 127 }); 128 129 afterEach(function() { 130 stubs.reset(); 131 }); 132 133 it('testEmptyProto', function() { 134 var empty1 = new proto.jspb.test.Empty([]); 135 var empty2 = new proto.jspb.test.Empty([]); 136 assertObjectEquals({}, empty1.toObject()); 137 assertObjectEquals('Message should not be corrupted:', empty2, empty1); 138 }); 139 140 it('testTopLevelEnum', function() { 141 var response = new proto.jspb.test.EnumContainer([]); 142 response.setOuterEnum(proto.jspb.test.OuterEnum.FOO); 143 assertEquals(proto.jspb.test.OuterEnum.FOO, response.getOuterEnum()); 144 }); 145 146 it('testByteStrings', function() { 147 var data = new proto.jspb.test.DefaultValues([]); 148 data.setBytesField('some_bytes'); 149 assertEquals('some_bytes', data.getBytesField()); 150 }); 151 152 it('testComplexConversion', function() { 153 var data1 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , 1]; 154 var data2 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , 1]; 155 var foo = new proto.jspb.test.Complex(data1); 156 var bar = new proto.jspb.test.Complex(data2); 157 var result = foo.toObject(); 158 assertObjectEquals( 159 { 160 aString: 'a', 161 anOutOfOrderBool: true, 162 aNestedMessage: {anInt: 11}, 163 aRepeatedMessageList: [{anInt: 22}, {anInt: 33}], 164 aRepeatedStringList: ['s1', 's2'], 165 aFloatingPointField: undefined, 166 }, 167 result); 168 169 // Now test with the jspb instances included. 170 result = foo.toObject(true /* opt_includeInstance */); 171 assertObjectEquals( 172 { 173 aString: 'a', 174 anOutOfOrderBool: true, 175 aNestedMessage: 176 {anInt: 11, $jspbMessageInstance: foo.getANestedMessage()}, 177 aRepeatedMessageList: [ 178 {anInt: 22, $jspbMessageInstance: foo.getARepeatedMessageList()[0]}, 179 {anInt: 33, $jspbMessageInstance: foo.getARepeatedMessageList()[1]} 180 ], 181 aRepeatedStringList: ['s1', 's2'], 182 aFloatingPointField: undefined, 183 $jspbMessageInstance: foo 184 }, 185 result); 186 187 }); 188 189 it('testMissingFields', function() { 190 var foo = new proto.jspb.test.Complex([ 191 undefined, undefined, undefined, [], undefined, undefined, undefined, 192 undefined 193 ]); 194 var bar = new proto.jspb.test.Complex([ 195 undefined, undefined, undefined, [], undefined, undefined, undefined, 196 undefined 197 ]); 198 var result = foo.toObject(); 199 assertObjectEquals( 200 { 201 aString: undefined, 202 anOutOfOrderBool: undefined, 203 aNestedMessage: {anInt: undefined}, 204 // Note: JsPb converts undefined repeated fields to empty arrays. 205 aRepeatedMessageList: [], 206 aRepeatedStringList: [], 207 aFloatingPointField: undefined, 208 }, 209 result); 210 211 }); 212 213 it('testNestedComplexMessage', function() { 214 // Instantiate the message and set a unique field, just to ensure that we 215 // are not getting jspb.test.Complex instead. 216 var msg = new proto.jspb.test.OuterMessage.Complex(); 217 msg.setInnerComplexField(5); 218 }); 219 220 it('testSpecialCases', function() { 221 // Note: Some property names are reserved in JavaScript. 222 // These names are converted to the Js property named pb_<reserved_name>. 223 var special = new proto.jspb.test.SpecialCases( 224 ['normal', 'default', 'function', 'var']); 225 var result = special.toObject(); 226 assertObjectEquals( 227 { 228 normal: 'normal', 229 pb_default: 'default', 230 pb_function: 'function', 231 pb_var: 'var' 232 }, 233 result); 234 }); 235 236 it('testDefaultValues', function() { 237 var defaultString = 'default<>\'"abc'; 238 var response = new proto.jspb.test.DefaultValues(); 239 240 // Test toObject 241 var expectedObject = { 242 stringField: defaultString, 243 boolField: true, 244 intField: 11, 245 enumField: 13, 246 emptyField: '', 247 bytesField: 'bW9v' 248 }; 249 assertObjectEquals(expectedObject, response.toObject()); 250 251 252 // Test getters 253 response = new proto.jspb.test.DefaultValues(); 254 assertEquals(defaultString, response.getStringField()); 255 assertEquals(true, response.getBoolField()); 256 assertEquals(11, response.getIntField()); 257 assertEquals(13, response.getEnumField()); 258 assertEquals('', response.getEmptyField()); 259 assertEquals('bW9v', response.getBytesField()); 260 261 function makeDefault(values) { 262 return new proto.jspb.test.DefaultValues(values); 263 } 264 265 // Test with undefined values, 266 // Use push to workaround IE treating undefined array elements as holes. 267 response = makeDefault([undefined, undefined, undefined, undefined]); 268 assertEquals(defaultString, response.getStringField()); 269 assertEquals(true, response.getBoolField()); 270 assertEquals(11, response.getIntField()); 271 assertEquals(13, response.getEnumField()); 272 assertFalse(response.hasStringField()); 273 assertFalse(response.hasBoolField()); 274 assertFalse(response.hasIntField()); 275 assertFalse(response.hasEnumField()); 276 277 // Test with null values, as would be returned by a JSON serializer. 278 response = makeDefault([null, null, null, null]); 279 assertEquals(defaultString, response.getStringField()); 280 assertEquals(true, response.getBoolField()); 281 assertEquals(11, response.getIntField()); 282 assertEquals(13, response.getEnumField()); 283 assertFalse(response.hasStringField()); 284 assertFalse(response.hasBoolField()); 285 assertFalse(response.hasIntField()); 286 assertFalse(response.hasEnumField()); 287 288 // Test with false-like values. 289 response = makeDefault(['', false, 0, 0]); 290 assertEquals('', response.getStringField()); 291 assertEquals(false, response.getBoolField()); 292 assertEquals(true, response.getIntField() == 0); 293 assertEquals(true, response.getEnumField() == 0); 294 assertTrue(response.hasStringField()); 295 assertTrue(response.hasBoolField()); 296 assertTrue(response.hasIntField()); 297 assertTrue(response.hasEnumField()); 298 299 // Test that clearing the values reverts them to the default state. 300 response = makeDefault(['blah', false, 111, 77]); 301 response.clearStringField(); 302 response.clearBoolField(); 303 response.clearIntField(); 304 response.clearEnumField(); 305 assertEquals(defaultString, response.getStringField()); 306 assertEquals(true, response.getBoolField()); 307 assertEquals(11, response.getIntField()); 308 assertEquals(13, response.getEnumField()); 309 assertFalse(response.hasStringField()); 310 assertFalse(response.hasBoolField()); 311 assertFalse(response.hasIntField()); 312 assertFalse(response.hasEnumField()); 313 314 // Test that setFoo(null) clears the values. 315 response = makeDefault(['blah', false, 111, 77]); 316 response.setStringField(null); 317 response.setBoolField(null); 318 response.setIntField(undefined); 319 response.setEnumField(undefined); 320 assertEquals(defaultString, response.getStringField()); 321 assertEquals(true, response.getBoolField()); 322 assertEquals(11, response.getIntField()); 323 assertEquals(13, response.getEnumField()); 324 assertFalse(response.hasStringField()); 325 assertFalse(response.hasBoolField()); 326 assertFalse(response.hasIntField()); 327 assertFalse(response.hasEnumField()); 328 }); 329 330 it('testEqualsSimple', function() { 331 var s1 = new proto.jspb.test.Simple1(['hi']); 332 assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi']))); 333 assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye']))); 334 var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]); 335 assertTrue(jspb.Message.equals( 336 s1b, new proto.jspb.test.Simple1(['hi', ['hello']]))); 337 assertTrue(jspb.Message.equals(s1b, new proto.jspb.test.Simple1([ 338 'hi', ['hello', undefined, undefined, undefined] 339 ]))); 340 assertFalse(jspb.Message.equals( 341 s1b, new proto.jspb.test.Simple1(['no', ['hello']]))); 342 // Test with messages of different types 343 var s2 = new proto.jspb.test.Simple2(['hi']); 344 assertFalse(jspb.Message.equals(s1, s2)); 345 }); 346 347 it('testEquals_softComparison', function() { 348 var s1 = new proto.jspb.test.Simple1(['hi', [], null]); 349 assertTrue( 350 jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi', []]))); 351 352 var s1b = new proto.jspb.test.Simple1(['hi', [], true]); 353 assertTrue( 354 jspb.Message.equals(s1b, new proto.jspb.test.Simple1(['hi', [], 1]))); 355 }); 356 357 it('testEqualsComplex', function() { 358 var data1 = ['a', , , [, 11], [[, 22], [, 33]], , ['s1', 's2'], , 1]; 359 var data2 = ['a', , , [, 11], [[, 22], [, 34]], , ['s1', 's2'], , 1]; 360 var data3 = ['a', , , [, 11], [[, 22]], , ['s1', 's2'], , 1]; 361 var data4 = ['hi']; 362 var c1a = new proto.jspb.test.Complex(data1); 363 var c1b = new proto.jspb.test.Complex(data1); 364 var c2 = new proto.jspb.test.Complex(data2); 365 var c3 = new proto.jspb.test.Complex(data3); 366 var s1 = new proto.jspb.test.Simple1(data4); 367 368 assertTrue(jspb.Message.equals(c1a, c1b)); 369 assertFalse(jspb.Message.equals(c1a, c2)); 370 assertFalse(jspb.Message.equals(c2, c3)); 371 assertFalse(jspb.Message.equals(c1a, s1)); 372 }); 373 374 it('testEqualsExtensionsConstructed', function() { 375 assertTrue(jspb.Message.equals( 376 new proto.jspb.test.HasExtensions([]), 377 new proto.jspb.test.HasExtensions([{}]))); 378 assertTrue(jspb.Message.equals( 379 new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), 380 new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]))); 381 assertFalse(jspb.Message.equals( 382 new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), 383 new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'b'}]}]))); 384 assertTrue(jspb.Message.equals( 385 new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]), 386 new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]))); 387 assertTrue(jspb.Message.equals( 388 new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]), 389 new proto.jspb.test.HasExtensions([, , , {100: [{200: 'a'}]}]))); 390 assertTrue(jspb.Message.equals( 391 new proto.jspb.test.HasExtensions([, , , {100: [{200: 'a'}]}]), 392 new proto.jspb.test.HasExtensions([{100: [{200: 'a'}]}]))); 393 assertTrue(jspb.Message.equals( 394 new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]), 395 new proto.jspb.test.HasExtensions(['hi', , , {100: [{200: 'a'}]}]))); 396 assertTrue(jspb.Message.equals( 397 new proto.jspb.test.HasExtensions(['hi', , , {100: [{200: 'a'}]}]), 398 new proto.jspb.test.HasExtensions(['hi', {100: [{200: 'a'}]}]))); 399 }); 400 401 it('testEqualsExtensionsUnconstructed', function() { 402 assertTrue(jspb.Message.compareFields([], [{}])); 403 assertTrue(jspb.Message.compareFields([, , , {}], [])); 404 assertTrue(jspb.Message.compareFields([, , , {}], [, , {}])); 405 assertTrue(jspb.Message.compareFields( 406 ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}])); 407 assertFalse(jspb.Message.compareFields( 408 ['hi', {100: [{200: 'a'}]}], ['hi', {100: [{200: 'b'}]}])); 409 assertTrue(jspb.Message.compareFields( 410 [{100: [{200: 'a'}]}], [{100: [{200: 'a'}]}])); 411 assertTrue(jspb.Message.compareFields( 412 [{100: [{200: 'a'}]}], [, , , {100: [{200: 'a'}]}])); 413 assertTrue(jspb.Message.compareFields( 414 [, , , {100: [{200: 'a'}]}], [{100: [{200: 'a'}]}])); 415 assertTrue(jspb.Message.compareFields( 416 ['hi', {100: [{200: 'a'}]}], ['hi', , , {100: [{200: 'a'}]}])); 417 assertTrue(jspb.Message.compareFields( 418 ['hi', , , {100: [{200: 'a'}]}], ['hi', {100: [{200: 'a'}]}])); 419 }); 420 421 it('testInitializeMessageWithLastFieldNull', function() { 422 // This tests for regression to bug http://b/117298778 423 var msg = new proto.jspb.test.TestLastFieldBeforePivot([null]); 424 assertNotUndefined(msg.getLastFieldBeforePivot()); 425 }); 426 427 it('testEqualsNonFinite', function() { 428 assertTrue(jspb.Message.compareFields(NaN, NaN)); 429 assertTrue(jspb.Message.compareFields(NaN, 'NaN')); 430 assertTrue(jspb.Message.compareFields('NaN', NaN)); 431 assertTrue(jspb.Message.compareFields(Infinity, Infinity)); 432 assertTrue(jspb.Message.compareFields(Infinity, 'Infinity')); 433 assertTrue(jspb.Message.compareFields('-Infinity', -Infinity)); 434 assertTrue(jspb.Message.compareFields([NaN], ['NaN'])); 435 assertFalse(jspb.Message.compareFields(undefined, NaN)); 436 assertFalse(jspb.Message.compareFields(NaN, undefined)); 437 }); 438 439 it('testToMap', function() { 440 var p1 = new proto.jspb.test.Simple1(['k', ['v']]); 441 var p2 = new proto.jspb.test.Simple1(['k1', ['v1', 'v2']]); 442 var soymap = jspb.Message.toMap( 443 [p1, p2], proto.jspb.test.Simple1.prototype.getAString, 444 proto.jspb.test.Simple1.prototype.toObject); 445 assertEquals('k', soymap['k'].aString); 446 assertArrayEquals(['v'], soymap['k'].aRepeatedStringList); 447 var protomap = jspb.Message.toMap( 448 [p1, p2], proto.jspb.test.Simple1.prototype.getAString); 449 assertEquals('k', protomap['k'].getAString()); 450 assertArrayEquals(['v'], protomap['k'].getARepeatedStringList()); 451 }); 452 453 it('testClone', function() { 454 var supportsUint8Array = 455 !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10'); 456 var original = new proto.jspb.test.TestClone(); 457 original.setStr('v1'); 458 var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]); 459 var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]); 460 var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]); 461 original.setSimple1(simple1); 462 original.setSimple2List([simple2, simple3]); 463 var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123'; 464 original.setBytesField(bytes1); 465 var extension = new proto.jspb.test.CloneExtension(); 466 extension.setExt('e1'); 467 original.setExtension(proto.jspb.test.IsExtension.extField, extension); 468 var clone = original.clone(); 469 assertArrayEquals( 470 [ 471 'v1', , ['x1', ['y1', 'z1']], , 472 [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1, , 473 {100: [, 'e1']} 474 ], 475 clone.toArray()); 476 clone.setStr('v2'); 477 var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]); 478 var simple5 = new proto.jspb.test.Simple1(['a2', ['b2', 'c2']]); 479 var simple6 = new proto.jspb.test.Simple1(['a3', ['b3', 'c3']]); 480 clone.setSimple1(simple4); 481 clone.setSimple2List([simple5, simple6]); 482 if (supportsUint8Array) { 483 clone.getBytesField()[0] = 4; 484 assertObjectEquals(bytes1, original.getBytesField()); 485 } 486 var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456'; 487 clone.setBytesField(bytes2); 488 var newExtension = new proto.jspb.test.CloneExtension(); 489 newExtension.setExt('e2'); 490 clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension); 491 assertArrayEquals( 492 [ 493 'v2', , ['a1', ['b1', 'c1']], , 494 [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2, , 495 {100: [, 'e2']} 496 ], 497 clone.toArray()); 498 assertArrayEquals( 499 [ 500 'v1', , ['x1', ['y1', 'z1']], , 501 [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1, , 502 {100: [, 'e1']} 503 ], 504 original.toArray()); 505 }); 506 507 it('testCopyInto', function() { 508 var supportsUint8Array = 509 !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10'); 510 var original = new proto.jspb.test.TestClone(); 511 original.setStr('v1'); 512 var dest = new proto.jspb.test.TestClone(); 513 dest.setStr('override'); 514 var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]); 515 var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]); 516 var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]); 517 var destSimple1 = new proto.jspb.test.Simple1(['ox1', ['oy1', 'oz1']]); 518 var destSimple2 = new proto.jspb.test.Simple1(['ox2', ['oy2', 'oz2']]); 519 var destSimple3 = new proto.jspb.test.Simple1(['ox3', ['oy3', 'oz3']]); 520 original.setSimple1(simple1); 521 original.setSimple2List([simple2, simple3]); 522 dest.setSimple1(destSimple1); 523 dest.setSimple2List([destSimple2, destSimple3]); 524 var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123'; 525 var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456'; 526 original.setBytesField(bytes1); 527 dest.setBytesField(bytes2); 528 var extension = new proto.jspb.test.CloneExtension(); 529 extension.setExt('e1'); 530 original.setExtension(proto.jspb.test.CloneExtension.extField, extension); 531 532 jspb.Message.copyInto(original, dest); 533 assertArrayEquals(original.toArray(), dest.toArray()); 534 assertEquals('x1', dest.getSimple1().getAString()); 535 assertEquals( 536 'e1', 537 dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt()); 538 dest.getSimple1().setAString('new value'); 539 assertNotEquals( 540 dest.getSimple1().getAString(), original.getSimple1().getAString()); 541 if (supportsUint8Array) { 542 dest.getBytesField()[0] = 7; 543 assertObjectEquals(bytes1, original.getBytesField()); 544 assertObjectEquals(new Uint8Array([7, 2, 3]), dest.getBytesField()); 545 } else { 546 dest.setBytesField('789'); 547 assertObjectEquals(bytes1, original.getBytesField()); 548 assertObjectEquals('789', dest.getBytesField()); 549 } 550 dest.getExtension(proto.jspb.test.CloneExtension.extField) 551 .setExt('new value'); 552 assertNotEquals( 553 dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(), 554 original.getExtension(proto.jspb.test.CloneExtension.extField) 555 .getExt()); 556 }); 557 558 it('testCopyInto_notSameType', function() { 559 var a = new proto.jspb.test.TestClone(); 560 var b = new proto.jspb.test.Simple1(['str', ['s1', 's2']]); 561 562 var e = assertThrows(function() { 563 jspb.Message.copyInto(a, b); 564 }); 565 assertContains('should have the same type', e.message); 566 }); 567 568 it('testExtensions', function() { 569 var extension1 = new proto.jspb.test.IsExtension(['ext1field']); 570 var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2']]); 571 var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); 572 extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1); 573 extendable.setExtension( 574 proto.jspb.test.IndirectExtension.simple, extension2); 575 extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy'); 576 extendable.setExtension( 577 proto.jspb.test.IndirectExtension.repeatedStrList, ['a', 'b']); 578 var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]); 579 var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2']]); 580 extendable.setExtension( 581 proto.jspb.test.IndirectExtension.repeatedSimpleList, [s1, s2]); 582 assertObjectEquals( 583 extension1, 584 extendable.getExtension(proto.jspb.test.IsExtension.extField)); 585 assertObjectEquals( 586 extension2, 587 extendable.getExtension(proto.jspb.test.IndirectExtension.simple)); 588 assertObjectEquals( 589 'xyzzy', 590 extendable.getExtension(proto.jspb.test.IndirectExtension.str)); 591 assertObjectEquals( 592 ['a', 'b'], 593 extendable.getExtension( 594 proto.jspb.test.IndirectExtension.repeatedStrList)); 595 assertObjectEquals( 596 [s1, s2], 597 extendable.getExtension( 598 proto.jspb.test.IndirectExtension.repeatedSimpleList)); 599 // Not supported yet, but it should work... 600 extendable.setExtension(proto.jspb.test.IndirectExtension.simple, null); 601 assertNull( 602 extendable.getExtension(proto.jspb.test.IndirectExtension.simple)); 603 extendable.setExtension(proto.jspb.test.IndirectExtension.str, null); 604 assertNull(extendable.getExtension(proto.jspb.test.IndirectExtension.str)); 605 606 607 // Extension fields with jspb.ignore = true are ignored. 608 assertUndefined(proto.jspb.test.IndirectExtension['ignored']); 609 assertUndefined(proto.jspb.test.HasExtensions['ignoredFloating']); 610 }); 611 612 it('testFloatingExtensions', function() { 613 // From an autogenerated container. 614 var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); 615 var extension = new proto.jspb.test.Simple1(['foo', ['s1', 's2']]); 616 extendable.setExtension(proto.jspb.test.simple1, extension); 617 assertObjectEquals( 618 extension, extendable.getExtension(proto.jspb.test.simple1)); 619 620 // From _lib mode. 621 extension = new proto.jspb.test.ExtensionMessage(['s1']); 622 extendable = new proto.jspb.test.TestExtensionsMessage([16]); 623 extendable.setExtension(proto.jspb.test.floatingMsgField, extension); 624 extendable.setExtension(proto.jspb.test.floatingStrField, 's2'); 625 assertObjectEquals( 626 extension, extendable.getExtension(proto.jspb.test.floatingMsgField)); 627 assertObjectEquals( 628 's2', extendable.getExtension(proto.jspb.test.floatingStrField)); 629 assertNotUndefined(proto.jspb.exttest.floatingMsgField); 630 assertNotUndefined(proto.jspb.exttest.floatingMsgFieldTwo); 631 assertNotUndefined(proto.jspb.exttest.beta.floatingStrField); 632 }); 633 634 it('testNestedExtensions', function() { 635 var extendable = 636 new proto.jspb.exttest.nested.TestNestedExtensionsMessage(); 637 var extension = 638 new proto.jspb.exttest.nested.TestOuterMessage.NestedExtensionMessage( 639 ['s1']); 640 extendable.setExtension( 641 proto.jspb.exttest.nested.TestOuterMessage.innerExtension, extension); 642 assertObjectEquals( 643 extension, 644 extendable.getExtension( 645 proto.jspb.exttest.nested.TestOuterMessage.innerExtension)); 646 }); 647 648 it('testToObject_extendedObject', function() { 649 var extension1 = new proto.jspb.test.IsExtension(['ext1field']); 650 var extension2 = new proto.jspb.test.Simple1(['str', ['s1', 's2'], true]); 651 var extendable = new proto.jspb.test.HasExtensions(['v1', 'v2', 'v3']); 652 extendable.setExtension(proto.jspb.test.IsExtension.extField, extension1); 653 extendable.setExtension( 654 proto.jspb.test.IndirectExtension.simple, extension2); 655 extendable.setExtension(proto.jspb.test.IndirectExtension.str, 'xyzzy'); 656 extendable.setExtension( 657 proto.jspb.test.IndirectExtension.repeatedStrList, ['a', 'b']); 658 var s1 = new proto.jspb.test.Simple1(['foo', ['s1', 's2'], true]); 659 var s2 = new proto.jspb.test.Simple1(['bar', ['t1', 't2'], false]); 660 extendable.setExtension( 661 proto.jspb.test.IndirectExtension.repeatedSimpleList, [s1, s2]); 662 assertObjectEquals( 663 { 664 str1: 'v1', 665 str2: 'v2', 666 str3: 'v3', 667 extField: {ext1: 'ext1field'}, 668 simple: { 669 aString: 'str', 670 aRepeatedStringList: ['s1', 's2'], 671 aBoolean: true 672 }, 673 str: 'xyzzy', 674 repeatedStrList: ['a', 'b'], 675 repeatedSimpleList: [ 676 {aString: 'foo', aRepeatedStringList: ['s1', 's2'], aBoolean: true}, 677 {aString: 'bar', aRepeatedStringList: ['t1', 't2'], aBoolean: false} 678 ] 679 }, 680 extendable.toObject()); 681 682 // Now, with instances included. 683 assertObjectEquals( 684 { 685 str1: 'v1', 686 str2: 'v2', 687 str3: 'v3', 688 extField: { 689 ext1: 'ext1field', 690 $jspbMessageInstance: 691 extendable.getExtension(proto.jspb.test.IsExtension.extField) 692 }, 693 simple: { 694 aString: 'str', 695 aRepeatedStringList: ['s1', 's2'], 696 aBoolean: true, 697 $jspbMessageInstance: extendable.getExtension( 698 proto.jspb.test.IndirectExtension.simple) 699 }, 700 str: 'xyzzy', 701 repeatedStrList: ['a', 'b'], 702 repeatedSimpleList: [ 703 { 704 aString: 'foo', 705 aRepeatedStringList: ['s1', 's2'], 706 aBoolean: true, 707 $jspbMessageInstance: s1 708 }, 709 { 710 aString: 'bar', 711 aRepeatedStringList: ['t1', 't2'], 712 aBoolean: false, 713 $jspbMessageInstance: s2 714 } 715 ], 716 $jspbMessageInstance: extendable 717 }, 718 extendable.toObject(true /* opt_includeInstance */)); 719 }); 720 721 it('testInitialization_emptyArray', function() { 722 var msg = new proto.jspb.test.HasExtensions([]); 723 assertArrayEquals([], msg.toArray()); 724 }); 725 726 it('testInitialization_justExtensionObject', function() { 727 var msg = new proto.jspb.test.Empty([{1: 'hi'}]); 728 // The extensionObject is not moved from its original location. 729 assertArrayEquals([{1: 'hi'}], msg.toArray()); 730 }); 731 732 it('testInitialization_incompleteList', function() { 733 var msg = new proto.jspb.test.Empty([1, {4: 'hi'}]); 734 // The extensionObject is not moved from its original location. 735 assertArrayEquals([1, {4: 'hi'}], msg.toArray()); 736 }); 737 738 it('testInitialization_forwardCompatible', function() { 739 var msg = new proto.jspb.test.Empty([1, 2, 3, {1: 'hi'}]); 740 assertArrayEquals([1, 2, 3, {1: 'hi'}], msg.toArray()); 741 }); 742 743 it('testExtendedMessageEnsureObject', 744 /** @suppress {visibility} */ function() { 745 var data = 746 new proto.jspb.test.HasExtensions(['str1', {'a_key': 'an_object'}]); 747 assertEquals('an_object', data.extensionObject_['a_key']); 748 }); 749 750 it('testToObject_hasExtensionField', function() { 751 var data = 752 new proto.jspb.test.HasExtensions(['str1', {100: ['ext1'], 102: ''}]); 753 var obj = data.toObject(); 754 assertEquals('str1', obj.str1); 755 assertEquals('ext1', obj.extField.ext1); 756 assertEquals('', obj.str); 757 }); 758 759 it('testGetExtension', function() { 760 var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); 761 assertEquals('str1', data.getStr1()); 762 var extension = data.getExtension(proto.jspb.test.IsExtension.extField); 763 assertNotNull(extension); 764 assertEquals('ext1', extension.getExt1()); 765 }); 766 767 it('testSetExtension', function() { 768 var data = new proto.jspb.test.HasExtensions(); 769 var extensionMessage = new proto.jspb.test.IsExtension(['is_extension']); 770 data.setExtension(proto.jspb.test.IsExtension.extField, extensionMessage); 771 var obj = data.toObject(); 772 assertNotNull(data.getExtension(proto.jspb.test.IsExtension.extField)); 773 assertEquals('is_extension', obj.extField.ext1); 774 }); 775 776 /** 777 * Note that group is long deprecated, we only support it because JsPb has 778 * a goal of being able to generate JS classes for all proto descriptors. 779 */ 780 it('testGroups', function() { 781 var group = new proto.jspb.test.TestGroup(); 782 var someGroup = new proto.jspb.test.TestGroup.RepeatedGroup(); 783 someGroup.setId('g1'); 784 someGroup.setSomeBoolList([true, false]); 785 group.setRepeatedGroupList([someGroup]); 786 var groups = group.getRepeatedGroupList(); 787 assertEquals('g1', groups[0].getId()); 788 assertObjectEquals([true, false], groups[0].getSomeBoolList()); 789 assertObjectEquals( 790 {id: 'g1', someBoolList: [true, false]}, groups[0].toObject()); 791 assertObjectEquals( 792 { 793 repeatedGroupList: [{id: 'g1', someBoolList: [true, false]}], 794 requiredGroup: {id: undefined}, 795 optionalGroup: undefined, 796 requiredSimple: {aRepeatedStringList: [], aString: undefined}, 797 optionalSimple: undefined, 798 id: undefined 799 }, 800 group.toObject()); 801 var group1 = new proto.jspb.test.TestGroup1(); 802 group1.setGroup(someGroup); 803 assertEquals(someGroup, group1.getGroup()); 804 }); 805 806 it('testNonExtensionFieldsAfterExtensionRange', function() { 807 var data = [{'1': 'a_string'}]; 808 var message = new proto.jspb.test.Complex(data); 809 assertArrayEquals([], message.getARepeatedStringList()); 810 }); 811 812 it('testReservedGetterNames', function() { 813 var message = new proto.jspb.test.TestReservedNames(); 814 message.setExtension$(11); 815 message.setExtension(proto.jspb.test.TestReservedNamesExtension.foo, 12); 816 assertEquals(11, message.getExtension$()); 817 assertEquals( 818 12, 819 message.getExtension(proto.jspb.test.TestReservedNamesExtension.foo)); 820 assertObjectEquals({extension: 11, foo: 12}, message.toObject()); 821 }); 822 823 it('testInitializeMessageWithUnsetOneof', function() { 824 var message = new proto.jspb.test.TestMessageWithOneof([]); 825 assertEquals( 826 proto.jspb.test.TestMessageWithOneof.PartialOneofCase 827 .PARTIAL_ONEOF_NOT_SET, 828 message.getPartialOneofCase()); 829 assertEquals( 830 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase 831 .RECURSIVE_ONEOF_NOT_SET, 832 message.getRecursiveOneofCase()); 833 }); 834 835 it('testUnsetsOneofCaseWhenFieldIsCleared', function() { 836 var message = new proto.jspb.test.TestMessageWithOneof; 837 assertEquals( 838 proto.jspb.test.TestMessageWithOneof.PartialOneofCase 839 .PARTIAL_ONEOF_NOT_SET, 840 message.getPartialOneofCase()); 841 842 message.setPone('hi'); 843 assertEquals( 844 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, 845 message.getPartialOneofCase()); 846 847 message.clearPone(); 848 assertEquals( 849 proto.jspb.test.TestMessageWithOneof.PartialOneofCase 850 .PARTIAL_ONEOF_NOT_SET, 851 message.getPartialOneofCase()); 852 }); 853 854 it('testFloatingPointFieldsSupportNan', function() { 855 var assertNan = function(x) { 856 assertTrue( 857 'Expected ' + x + ' (' + goog.typeOf(x) + ') to be NaN.', 858 goog.isNumber(x) && isNaN(x)); 859 }; 860 861 var message = new proto.jspb.test.FloatingPointFields([ 862 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN', 'NaN', 'NaN', ['NaN', 'NaN'], 'NaN' 863 ]); 864 assertNan(message.getOptionalFloatField()); 865 assertNan(message.getRequiredFloatField()); 866 assertNan(message.getRepeatedFloatFieldList()[0]); 867 assertNan(message.getRepeatedFloatFieldList()[1]); 868 assertNan(message.getDefaultFloatField()); 869 assertNan(message.getOptionalDoubleField()); 870 assertNan(message.getRequiredDoubleField()); 871 assertNan(message.getRepeatedDoubleFieldList()[0]); 872 assertNan(message.getRepeatedDoubleFieldList()[1]); 873 assertNan(message.getDefaultDoubleField()); 874 }); 875 876 it('testFloatingPointsAreConvertedFromStringInput', function() { 877 var assertInf = function(x) { 878 assertTrue( 879 'Expected ' + x + ' (' + goog.typeOf(x) + ') to be Infinity.', 880 x === Infinity); 881 }; 882 var message = new proto.jspb.test.FloatingPointFields([ 883 Infinity, 'Infinity', ['Infinity', Infinity], 'Infinity', 'Infinity', 884 'Infinity', ['Infinity', Infinity], 'Infinity' 885 ]); 886 assertInf(message.getOptionalFloatField()); 887 assertInf(message.getRequiredFloatField()); 888 assertInf(message.getRepeatedFloatFieldList()[0]); 889 assertInf(message.getRepeatedFloatFieldList()[1]); 890 assertInf(message.getDefaultFloatField()); 891 assertInf(message.getOptionalDoubleField()); 892 assertInf(message.getRequiredDoubleField()); 893 assertInf(message.getRepeatedDoubleFieldList()[0]); 894 assertInf(message.getRepeatedDoubleFieldList()[1]); 895 assertInf(message.getDefaultDoubleField()); 896 }); 897 898 it('testBooleansAreConvertedFromNumberInput', function() { 899 var assertBooleanFieldTrue = function(x) { 900 assertTrue( 901 'Expected ' + x + ' (' + goog.typeOf(x) + ') to be True.', 902 x === true); 903 }; 904 var message = new proto.jspb.test.BooleanFields([1, 1, [true, 1]]); 905 assertBooleanFieldTrue(message.getOptionalBooleanField()); 906 assertBooleanFieldTrue(message.getRequiredBooleanField()); 907 assertBooleanFieldTrue(message.getRepeatedBooleanFieldList()[0]); 908 assertBooleanFieldTrue(message.getRepeatedBooleanFieldList()[1]); 909 assertBooleanFieldTrue(message.getDefaultBooleanField()); 910 911 var assertBooleanFieldFalse = function(x) { 912 assertTrue( 913 'Expected ' + x + ' (' + goog.typeOf(x) + ') to be False.', 914 x === false); 915 }; 916 message = new proto.jspb.test.BooleanFields([0, 0, [0, 0]]); 917 assertBooleanFieldFalse(message.getOptionalBooleanField()); 918 assertBooleanFieldFalse(message.getRequiredBooleanField()); 919 assertBooleanFieldFalse(message.getRepeatedBooleanFieldList()[0]); 920 assertBooleanFieldFalse(message.getRepeatedBooleanFieldList()[1]); 921 }); 922 923 it('testExtensionReverseOrder', function() { 924 var message2 = 925 new proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage2; 926 927 message2.setExtension( 928 proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1.a, 233); 929 message2.setExtension( 930 proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1 931 .TestExtensionReverseOrderNestedMessage1.b, 932 2333); 933 message2.setExtension(proto.jspb.exttest.reverse.c, 23333); 934 935 assertEquals( 936 233, 937 message2.getExtension( 938 proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1.a)); 939 assertEquals( 940 2333, 941 message2.getExtension( 942 proto.jspb.exttest.reverse.TestExtensionReverseOrderMessage1 943 .TestExtensionReverseOrderNestedMessage1.b)); 944 assertEquals(23333, message2.getExtension(proto.jspb.exttest.reverse.c)); 945 }); 946 947 it('testCircularDepsBaseOnMessageField', function() { 948 var nestMessage1 = new proto.jspb.circulartest.MessageField1; 949 var nestMessage2 = new proto.jspb.circulartest.MessageField2; 950 var message1 = new proto.jspb.circulartest.MessageField1; 951 var message2 = new proto.jspb.circulartest.MessageField2; 952 953 nestMessage1.setA(1); 954 nestMessage2.setA(2); 955 message1.setB(nestMessage2); 956 message2.setB(nestMessage1); 957 958 959 assertEquals(2, message1.getB().getA()); 960 assertEquals(1, message2.getB().getA()); 961 }); 962 963 964 it('testCircularDepsBaseOnRepeatedMessageField', function() { 965 var nestMessage1 = new proto.jspb.circulartest.RepeatedMessageField1; 966 var nestMessage2 = new proto.jspb.circulartest.RepeatedMessageField2; 967 var message1 = new proto.jspb.circulartest.RepeatedMessageField1; 968 var message2 = new proto.jspb.circulartest.RepeatedMessageField2; 969 970 nestMessage1.setA(1); 971 nestMessage2.setA(2); 972 message1.setB(nestMessage2); 973 message2.addB(nestMessage1); 974 975 976 assertEquals(2, message1.getB().getA()); 977 assertEquals(1, message2.getBList()[0].getA()); 978 }); 979 980 it('testCircularDepsBaseOnMapField', function() { 981 var nestMessage1 = new proto.jspb.circulartest.MapField1; 982 var nestMessage2 = new proto.jspb.circulartest.MapField2; 983 var message1 = new proto.jspb.circulartest.MapField1; 984 var message2 = new proto.jspb.circulartest.MapField2; 985 986 nestMessage1.setA(1); 987 nestMessage2.setA(2); 988 message1.setB(nestMessage2); 989 message2.getBMap().set(1, nestMessage1); 990 991 992 assertEquals(2, message1.getB().getA()); 993 assertEquals(1, message2.getBMap().get(1).getA()); 994 }); 995 996 it('testCircularDepsBaseOnNestedMessage', function() { 997 var nestMessage1 = 998 new proto.jspb.circulartest.NestedMessage1.NestedNestedMessage; 999 var nestMessage2 = new proto.jspb.circulartest.NestedMessage2; 1000 var message1 = new proto.jspb.circulartest.NestedMessage1; 1001 var message2 = new proto.jspb.circulartest.NestedMessage2; 1002 1003 nestMessage1.setA(1); 1004 nestMessage2.setA(2); 1005 message1.setB(nestMessage2); 1006 message2.setB(nestMessage1); 1007 1008 1009 assertEquals(2, message1.getB().getA()); 1010 assertEquals(1, message2.getB().getA()); 1011 }); 1012 1013 it('testCircularDepsBaseOnNestedEnum', function() { 1014 var nestMessage2 = new proto.jspb.circulartest.NestedEnum2; 1015 var message1 = new proto.jspb.circulartest.NestedEnum1; 1016 var message2 = new proto.jspb.circulartest.NestedEnum2; 1017 1018 nestMessage2.setA(2); 1019 message1.setB(nestMessage2); 1020 message2.setB(proto.jspb.circulartest.NestedEnum1.NestedNestedEnum.VALUE_1); 1021 1022 1023 assertEquals(2, message1.getB().getA()); 1024 assertEquals( 1025 proto.jspb.circulartest.NestedEnum1.NestedNestedEnum.VALUE_1, 1026 message2.getB()); 1027 }); 1028 1029 it('testCircularDepsBaseOnExtensionContainingType', function() { 1030 var nestMessage2 = new proto.jspb.circulartest.ExtensionContainingType2; 1031 var message1 = new proto.jspb.circulartest.ExtensionContainingType1; 1032 1033 nestMessage2.setA(2); 1034 message1.setB(nestMessage2); 1035 message1.setExtension( 1036 proto.jspb.circulartest.ExtensionContainingType2.c, 1); 1037 1038 1039 assertEquals(2, message1.getB().getA()); 1040 assertEquals( 1041 1, 1042 message1.getExtension( 1043 proto.jspb.circulartest.ExtensionContainingType2.c)); 1044 }); 1045 1046 it('testCircularDepsBaseOnExtensionField', function() { 1047 var nestMessage2 = new proto.jspb.circulartest.ExtensionField2; 1048 var message1 = new proto.jspb.circulartest.ExtensionField1; 1049 var message3 = new proto.jspb.circulartest.ExtensionField3; 1050 1051 nestMessage2.setA(2); 1052 message1.setB(nestMessage2); 1053 message3.setExtension(proto.jspb.circulartest.ExtensionField2.c, message1); 1054 1055 1056 assertEquals( 1057 2, 1058 message3.getExtension(proto.jspb.circulartest.ExtensionField2.c) 1059 .getB() 1060 .getA()); 1061 }); 1062 1063 it('testSameMessageNameOuputs', function() { 1064 var package1Message = new proto.jspb.filenametest.package1.TestMessage; 1065 var package2Message = new proto.jspb.filenametest.package2.TestMessage; 1066 1067 package1Message.setExtension(proto.jspb.filenametest.package1.a, 10); 1068 package1Message.setExtension(proto.jspb.filenametest.package1.b, 11); 1069 package2Message.setA(12); 1070 1071 assertEquals( 1072 10, package1Message.getExtension(proto.jspb.filenametest.package1.a)); 1073 assertEquals( 1074 11, package1Message.getExtension(proto.jspb.filenametest.package1.b)); 1075 assertEquals(12, package2Message.getA()); 1076 }); 1077 1078}); 1079