| OLD | NEW |
| 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 16 matching lines...) Expand all Loading... |
| 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 // Test suite is written using Jasmine -- see http://jasmine.github.io/ | 31 // Test suite is written using Jasmine -- see http://jasmine.github.io/ |
| 32 | 32 |
| 33 goog.setTestOnly(); | 33 goog.setTestOnly(); |
| 34 | 34 |
| 35 goog.require('goog.json'); | 35 goog.require('goog.json'); |
| 36 goog.require('goog.testing.asserts'); | 36 goog.require('goog.testing.asserts'); |
| 37 goog.require('goog.userAgent'); |
| 37 | 38 |
| 38 // CommonJS-LoadFromFile: google-protobuf jspb | 39 // CommonJS-LoadFromFile: google-protobuf jspb |
| 39 goog.require('jspb.Message'); | 40 goog.require('jspb.Message'); |
| 40 | 41 |
| 41 // CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta | 42 // CommonJS-LoadFromFile: test5_pb proto.jspb.exttest.beta |
| 42 goog.require('proto.jspb.exttest.beta.floatingStrField'); | 43 goog.require('proto.jspb.exttest.beta.floatingStrField'); |
| 43 | 44 |
| 44 // CommonJS-LoadFromFile: test3_pb proto.jspb.exttest | 45 // CommonJS-LoadFromFile: test3_pb proto.jspb.exttest |
| 45 goog.require('proto.jspb.exttest.floatingMsgField'); | 46 goog.require('proto.jspb.exttest.floatingMsgField'); |
| 46 | 47 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 goog.require('proto.jspb.test.HasExtensions'); | 60 goog.require('proto.jspb.test.HasExtensions'); |
| 60 goog.require('proto.jspb.test.IndirectExtension'); | 61 goog.require('proto.jspb.test.IndirectExtension'); |
| 61 goog.require('proto.jspb.test.IsExtension'); | 62 goog.require('proto.jspb.test.IsExtension'); |
| 62 goog.require('proto.jspb.test.OptionalFields'); | 63 goog.require('proto.jspb.test.OptionalFields'); |
| 63 goog.require('proto.jspb.test.OuterEnum'); | 64 goog.require('proto.jspb.test.OuterEnum'); |
| 64 goog.require('proto.jspb.test.OuterMessage.Complex'); | 65 goog.require('proto.jspb.test.OuterMessage.Complex'); |
| 65 goog.require('proto.jspb.test.Simple1'); | 66 goog.require('proto.jspb.test.Simple1'); |
| 66 goog.require('proto.jspb.test.Simple2'); | 67 goog.require('proto.jspb.test.Simple2'); |
| 67 goog.require('proto.jspb.test.SpecialCases'); | 68 goog.require('proto.jspb.test.SpecialCases'); |
| 68 goog.require('proto.jspb.test.TestClone'); | 69 goog.require('proto.jspb.test.TestClone'); |
| 70 goog.require('proto.jspb.test.TestEndsWithBytes'); |
| 69 goog.require('proto.jspb.test.TestGroup'); | 71 goog.require('proto.jspb.test.TestGroup'); |
| 70 goog.require('proto.jspb.test.TestGroup1'); | 72 goog.require('proto.jspb.test.TestGroup1'); |
| 71 goog.require('proto.jspb.test.TestMessageWithOneof'); | 73 goog.require('proto.jspb.test.TestMessageWithOneof'); |
| 72 goog.require('proto.jspb.test.TestReservedNames'); | 74 goog.require('proto.jspb.test.TestReservedNames'); |
| 73 goog.require('proto.jspb.test.TestReservedNamesExtension'); | 75 goog.require('proto.jspb.test.TestReservedNamesExtension'); |
| 76 goog.require('proto.jspb.test.Deeply.Nested.Message'); |
| 74 | 77 |
| 75 // CommonJS-LoadFromFile: test2_pb proto.jspb.test | 78 // CommonJS-LoadFromFile: test2_pb proto.jspb.test |
| 76 goog.require('proto.jspb.test.ExtensionMessage'); | 79 goog.require('proto.jspb.test.ExtensionMessage'); |
| 77 goog.require('proto.jspb.test.TestExtensionsMessage'); | 80 goog.require('proto.jspb.test.TestExtensionsMessage'); |
| 81 goog.require('proto.jspb.test.ForeignNestedFieldMessage'); |
| 78 | 82 |
| 79 | 83 |
| 80 | 84 |
| 81 | 85 |
| 82 describe('Message test suite', function() { | 86 describe('Message test suite', function() { |
| 83 it('testEmptyProto', function() { | 87 it('testEmptyProto', function() { |
| 84 var empty1 = new proto.jspb.test.Empty([]); | 88 var empty1 = new proto.jspb.test.Empty([]); |
| 85 var empty2 = new proto.jspb.test.Empty([]); | 89 var empty2 = new proto.jspb.test.Empty([]); |
| 86 assertObjectEquals({}, empty1.toObject()); | 90 assertObjectEquals({}, empty1.toObject()); |
| 87 assertObjectEquals('Message should not be corrupted:', empty2, empty1); | 91 assertObjectEquals('Message should not be corrupted:', empty2, empty1); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return new proto.jspb.test.DefaultValues(values); | 210 return new proto.jspb.test.DefaultValues(values); |
| 207 } | 211 } |
| 208 | 212 |
| 209 // Test with undefined values, | 213 // Test with undefined values, |
| 210 // Use push to workaround IE treating undefined array elements as holes. | 214 // Use push to workaround IE treating undefined array elements as holes. |
| 211 response = makeDefault([undefined, undefined, undefined, undefined]); | 215 response = makeDefault([undefined, undefined, undefined, undefined]); |
| 212 assertEquals(defaultString, response.getStringField()); | 216 assertEquals(defaultString, response.getStringField()); |
| 213 assertEquals(true, response.getBoolField()); | 217 assertEquals(true, response.getBoolField()); |
| 214 assertEquals(11, response.getIntField()); | 218 assertEquals(11, response.getIntField()); |
| 215 assertEquals(13, response.getEnumField()); | 219 assertEquals(13, response.getEnumField()); |
| 220 assertFalse(response.hasStringField()); |
| 221 assertFalse(response.hasBoolField()); |
| 222 assertFalse(response.hasIntField()); |
| 223 assertFalse(response.hasEnumField()); |
| 216 | 224 |
| 217 // Test with null values, as would be returned by a JSON serializer. | 225 // Test with null values, as would be returned by a JSON serializer. |
| 218 response = makeDefault([null, null, null, null]); | 226 response = makeDefault([null, null, null, null]); |
| 219 assertEquals(defaultString, response.getStringField()); | 227 assertEquals(defaultString, response.getStringField()); |
| 220 assertEquals(true, response.getBoolField()); | 228 assertEquals(true, response.getBoolField()); |
| 221 assertEquals(11, response.getIntField()); | 229 assertEquals(11, response.getIntField()); |
| 222 assertEquals(13, response.getEnumField()); | 230 assertEquals(13, response.getEnumField()); |
| 231 assertFalse(response.hasStringField()); |
| 232 assertFalse(response.hasBoolField()); |
| 233 assertFalse(response.hasIntField()); |
| 234 assertFalse(response.hasEnumField()); |
| 223 | 235 |
| 224 // Test with false-like values. | 236 // Test with false-like values. |
| 225 response = makeDefault(['', false, 0, 0]); | 237 response = makeDefault(['', false, 0, 0]); |
| 226 assertEquals('', response.getStringField()); | 238 assertEquals('', response.getStringField()); |
| 227 assertEquals(false, response.getBoolField()); | 239 assertEquals(false, response.getBoolField()); |
| 228 assertEquals(true, response.getIntField() == 0); | 240 assertEquals(true, response.getIntField() == 0); |
| 229 assertEquals(true, response.getEnumField() == 0); | 241 assertEquals(true, response.getEnumField() == 0); |
| 242 assertTrue(response.hasStringField()); |
| 243 assertTrue(response.hasBoolField()); |
| 244 assertTrue(response.hasIntField()); |
| 245 assertTrue(response.hasEnumField()); |
| 230 | 246 |
| 231 // Test that clearing the values reverts them to the default state. | 247 // Test that clearing the values reverts them to the default state. |
| 232 response = makeDefault(['blah', false, 111, 77]); | 248 response = makeDefault(['blah', false, 111, 77]); |
| 233 response.clearStringField(); response.clearBoolField(); | 249 response.clearStringField(); response.clearBoolField(); |
| 234 response.clearIntField(); response.clearEnumField(); | 250 response.clearIntField(); response.clearEnumField(); |
| 235 assertEquals(defaultString, response.getStringField()); | 251 assertEquals(defaultString, response.getStringField()); |
| 236 assertEquals(true, response.getBoolField()); | 252 assertEquals(true, response.getBoolField()); |
| 237 assertEquals(11, response.getIntField()); | 253 assertEquals(11, response.getIntField()); |
| 238 assertEquals(13, response.getEnumField()); | 254 assertEquals(13, response.getEnumField()); |
| 255 assertFalse(response.hasStringField()); |
| 256 assertFalse(response.hasBoolField()); |
| 257 assertFalse(response.hasIntField()); |
| 258 assertFalse(response.hasEnumField()); |
| 239 | 259 |
| 240 // Test that setFoo(null) clears the values. | 260 // Test that setFoo(null) clears the values. |
| 241 response = makeDefault(['blah', false, 111, 77]); | 261 response = makeDefault(['blah', false, 111, 77]); |
| 242 response.setStringField(null); response.setBoolField(null); | 262 response.setStringField(null); response.setBoolField(null); |
| 243 response.setIntField(undefined); response.setEnumField(undefined); | 263 response.setIntField(undefined); response.setEnumField(undefined); |
| 244 assertEquals(defaultString, response.getStringField()); | 264 assertEquals(defaultString, response.getStringField()); |
| 245 assertEquals(true, response.getBoolField()); | 265 assertEquals(true, response.getBoolField()); |
| 246 assertEquals(11, response.getIntField()); | 266 assertEquals(11, response.getIntField()); |
| 247 assertEquals(13, response.getEnumField()); | 267 assertEquals(13, response.getEnumField()); |
| 268 assertFalse(response.hasStringField()); |
| 269 assertFalse(response.hasBoolField()); |
| 270 assertFalse(response.hasIntField()); |
| 271 assertFalse(response.hasEnumField()); |
| 248 }); | 272 }); |
| 249 | 273 |
| 250 it('testMessageRegistration', function() { | 274 it('testMessageRegistration', /** @suppress {visibility} */ function() { |
| 251 // goog.require(SomeResponse) will include its library, which will in | 275 // goog.require(SomeResponse) will include its library, which will in |
| 252 // turn add SomeResponse to the message registry. | 276 // turn add SomeResponse to the message registry. |
| 253 assertEquals(jspb.Message.registry_['res'], proto.jspb.test.SomeResponse); | 277 assertEquals(jspb.Message.registry_['res'], proto.jspb.test.SomeResponse); |
| 254 }); | 278 }); |
| 255 | 279 |
| 256 it('testClearFields', function() { | 280 it('testClearFields', function() { |
| 257 // We don't set 'proper' defaults, rather, bools, strings, | |
| 258 // etc, are cleared to undefined or null and take on the Javascript | |
| 259 // meaning for that value. Repeated fields are set to [] when cleared. | |
| 260 var data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; | 281 var data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; |
| 261 var foo = new proto.jspb.test.OptionalFields(data); | 282 var foo = new proto.jspb.test.OptionalFields(data); |
| 262 foo.clearAString(); | 283 foo.clearAString(); |
| 263 foo.clearABool(); | 284 foo.clearABool(); |
| 264 foo.clearANestedMessage(); | 285 foo.clearANestedMessage(); |
| 265 foo.clearARepeatedMessageList(); | 286 foo.clearARepeatedMessageList(); |
| 266 foo.clearARepeatedStringList(); | 287 foo.clearARepeatedStringList(); |
| 267 assertUndefined(foo.getAString()); | 288 assertEquals('', foo.getAString()); |
| 268 assertUndefined(foo.getABool()); | 289 assertEquals(false, foo.getABool()); |
| 269 assertUndefined(foo.getANestedMessage()); | 290 assertUndefined(foo.getANestedMessage()); |
| 291 assertFalse(foo.hasAString()); |
| 292 assertFalse(foo.hasABool()); |
| 270 assertObjectEquals([], foo.getARepeatedMessageList()); | 293 assertObjectEquals([], foo.getARepeatedMessageList()); |
| 271 assertObjectEquals([], foo.getARepeatedStringList()); | 294 assertObjectEquals([], foo.getARepeatedStringList()); |
| 272 // NOTE: We want the missing fields in 'expected' to be undefined, | 295 // NOTE: We want the missing fields in 'expected' to be undefined, |
| 273 // but we actually get a sparse array instead. We could use something | 296 // but we actually get a sparse array instead. We could use something |
| 274 // like [1,undefined,2] to avoid this, except that this is still | 297 // like [1,undefined,2] to avoid this, except that this is still |
| 275 // sparse on IE. No comment... | 298 // sparse on IE. No comment... |
| 276 var expected = [,,, [], []]; | 299 var expected = [,,, [], []]; |
| 277 expected[0] = expected[1] = expected[2] = undefined; | 300 expected[0] = expected[1] = expected[2] = undefined; |
| 278 assertObjectEquals(expected, foo.toArray()); | 301 assertObjectEquals(expected, foo.toArray()); |
| 279 | |
| 280 // Test set(null). We could deprecated this in favor of clear(), but | |
| 281 // it's also convenient to have. | |
| 282 data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; | |
| 283 foo = new proto.jspb.test.OptionalFields(data); | |
| 284 foo.setAString(null); | |
| 285 foo.setABool(null); | |
| 286 foo.setANestedMessage(null); | |
| 287 foo.setARepeatedMessageList(null); | |
| 288 foo.setARepeatedStringList(null); | |
| 289 assertNull(foo.getAString()); | |
| 290 assertNull(foo.getABool()); | |
| 291 assertNull(foo.getANestedMessage()); | |
| 292 assertObjectEquals([], foo.getARepeatedMessageList()); | |
| 293 assertObjectEquals([], foo.getARepeatedStringList()); | |
| 294 assertObjectEquals([null, null, null, [], []], foo.toArray()); | |
| 295 | |
| 296 // Test set(undefined). Again, not something we really need, and not | |
| 297 // supported directly by our typing, but it should 'do the right thing'. | |
| 298 data = ['str', true, [11], [[22], [33]], ['s1', 's2']]; | |
| 299 foo = new proto.jspb.test.OptionalFields(data); | |
| 300 foo.setAString(undefined); | |
| 301 foo.setABool(undefined); | |
| 302 foo.setANestedMessage(undefined); | |
| 303 foo.setARepeatedMessageList(undefined); | |
| 304 foo.setARepeatedStringList(undefined); | |
| 305 assertUndefined(foo.getAString()); | |
| 306 assertUndefined(foo.getABool()); | |
| 307 assertUndefined(foo.getANestedMessage()); | |
| 308 assertObjectEquals([], foo.getARepeatedMessageList()); | |
| 309 assertObjectEquals([], foo.getARepeatedStringList()); | |
| 310 expected = [,,, [], []]; | |
| 311 expected[0] = expected[1] = expected[2] = undefined; | |
| 312 assertObjectEquals(expected, foo.toArray()); | |
| 313 }); | 302 }); |
| 314 | 303 |
| 315 it('testDifferenceRawObject', function() { | 304 it('testDifferenceRawObject', /** @suppress {visibility} */ function() { |
| 316 var p1 = new proto.jspb.test.HasExtensions(['hi', 'diff', {}]); | 305 var p1 = new proto.jspb.test.HasExtensions(['hi', 'diff', {}]); |
| 317 var p2 = new proto.jspb.test.HasExtensions(['hi', 'what', | 306 var p2 = new proto.jspb.test.HasExtensions(['hi', 'what', |
| 318 {1000: 'unique'}]); | 307 {1000: 'unique'}]); |
| 319 var diff = /** @type {proto.jspb.test.HasExtensions} */ | 308 var diff = /** @type {proto.jspb.test.HasExtensions} */ |
| 320 (jspb.Message.difference(p1, p2)); | 309 (jspb.Message.difference(p1, p2)); |
| 321 assertUndefined(diff.getStr1()); | 310 assertEquals('', diff.getStr1()); |
| 322 assertEquals('what', diff.getStr2()); | 311 assertEquals('what', diff.getStr2()); |
| 323 assertUndefined(diff.getStr3()); | 312 assertEquals('', diff.getStr3()); |
| 324 assertEquals('unique', diff.extensionObject_[1000]); | 313 assertEquals('unique', diff.extensionObject_[1000]); |
| 325 }); | 314 }); |
| 326 | 315 |
| 327 it('testEqualsSimple', function() { | 316 it('testEqualsSimple', function() { |
| 328 var s1 = new proto.jspb.test.Simple1(['hi']); | 317 var s1 = new proto.jspb.test.Simple1(['hi']); |
| 329 assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi']))); | 318 assertTrue(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['hi']))); |
| 330 assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye']))); | 319 assertFalse(jspb.Message.equals(s1, new proto.jspb.test.Simple1(['bye']))); |
| 331 var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]); | 320 var s1b = new proto.jspb.test.Simple1(['hi', ['hello']]); |
| 332 assertTrue(jspb.Message.equals(s1b, | 321 assertTrue(jspb.Message.equals(s1b, |
| 333 new proto.jspb.test.Simple1(['hi', ['hello']]))); | 322 new proto.jspb.test.Simple1(['hi', ['hello']]))); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 proto.jspb.test.Simple1.prototype.toObject); | 420 proto.jspb.test.Simple1.prototype.toObject); |
| 432 assertEquals('k', soymap['k'].aString); | 421 assertEquals('k', soymap['k'].aString); |
| 433 assertArrayEquals(['v'], soymap['k'].aRepeatedStringList); | 422 assertArrayEquals(['v'], soymap['k'].aRepeatedStringList); |
| 434 var protomap = jspb.Message.toMap([p1, p2], | 423 var protomap = jspb.Message.toMap([p1, p2], |
| 435 proto.jspb.test.Simple1.prototype.getAString); | 424 proto.jspb.test.Simple1.prototype.getAString); |
| 436 assertEquals('k', protomap['k'].getAString()); | 425 assertEquals('k', protomap['k'].getAString()); |
| 437 assertArrayEquals(['v'], protomap['k'].getARepeatedStringList()); | 426 assertArrayEquals(['v'], protomap['k'].getARepeatedStringList()); |
| 438 }); | 427 }); |
| 439 | 428 |
| 440 it('testClone', function() { | 429 it('testClone', function() { |
| 430 var supportsUint8Array = |
| 431 !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10'); |
| 441 var original = new proto.jspb.test.TestClone(); | 432 var original = new proto.jspb.test.TestClone(); |
| 442 original.setStr('v1'); | 433 original.setStr('v1'); |
| 443 var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]); | 434 var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]); |
| 444 var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]); | 435 var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]); |
| 445 var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]); | 436 var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]); |
| 446 original.setSimple1(simple1); | 437 original.setSimple1(simple1); |
| 447 original.setSimple2List([simple2, simple3]); | 438 original.setSimple2List([simple2, simple3]); |
| 439 var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123'; |
| 440 original.setBytesField(bytes1); |
| 448 var extension = new proto.jspb.test.CloneExtension(); | 441 var extension = new proto.jspb.test.CloneExtension(); |
| 449 extension.setExt('e1'); | 442 extension.setExt('e1'); |
| 450 original.setExtension(proto.jspb.test.IsExtension.extField, extension); | 443 original.setExtension(proto.jspb.test.IsExtension.extField, extension); |
| 451 var clone = original.cloneMessage(); | 444 var clone = original.clone(); |
| 452 assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, | 445 assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, |
| 453 [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]],,, { 100: [, 'e1'] }], | 446 [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }], |
| 454 clone.toArray()); | 447 clone.toArray()); |
| 455 clone.setStr('v2'); | 448 clone.setStr('v2'); |
| 456 var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]); | 449 var simple4 = new proto.jspb.test.Simple1(['a1', ['b1', 'c1']]); |
| 457 var simple5 = new proto.jspb.test.Simple1(['a2', ['b2', 'c2']]); | 450 var simple5 = new proto.jspb.test.Simple1(['a2', ['b2', 'c2']]); |
| 458 var simple6 = new proto.jspb.test.Simple1(['a3', ['b3', 'c3']]); | 451 var simple6 = new proto.jspb.test.Simple1(['a3', ['b3', 'c3']]); |
| 459 clone.setSimple1(simple4); | 452 clone.setSimple1(simple4); |
| 460 clone.setSimple2List([simple5, simple6]); | 453 clone.setSimple2List([simple5, simple6]); |
| 454 if (supportsUint8Array) { |
| 455 clone.getBytesField()[0] = 4; |
| 456 assertObjectEquals(bytes1, original.getBytesField()); |
| 457 } |
| 458 var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456'; |
| 459 clone.setBytesField(bytes2); |
| 461 var newExtension = new proto.jspb.test.CloneExtension(); | 460 var newExtension = new proto.jspb.test.CloneExtension(); |
| 462 newExtension.setExt('e2'); | 461 newExtension.setExt('e2'); |
| 463 clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension); | 462 clone.setExtension(proto.jspb.test.CloneExtension.extField, newExtension); |
| 464 assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],, | 463 assertArrayEquals(['v2',, ['a1', ['b1', 'c1']],, |
| 465 [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]],,, { 100: [, 'e2'] }], | 464 [['a2', ['b2', 'c2']], ['a3', ['b3', 'c3']]], bytes2,, { 100: [, 'e2'] }], |
| 466 clone.toArray()); | 465 clone.toArray()); |
| 467 assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, | 466 assertArrayEquals(['v1',, ['x1', ['y1', 'z1']],, |
| 468 [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]],,, { 100: [, 'e1'] }], | 467 [['x2', ['y2', 'z2']], ['x3', ['y3', 'z3']]], bytes1,, { 100: [, 'e1'] }], |
| 469 original.toArray()); | 468 original.toArray()); |
| 470 }); | 469 }); |
| 471 | 470 |
| 472 it('testCopyInto', function() { | 471 it('testCopyInto', function() { |
| 472 var supportsUint8Array = |
| 473 !goog.userAgent.IE || goog.userAgent.isVersionOrHigher('10'); |
| 473 var original = new proto.jspb.test.TestClone(); | 474 var original = new proto.jspb.test.TestClone(); |
| 474 original.setStr('v1'); | 475 original.setStr('v1'); |
| 475 var dest = new proto.jspb.test.TestClone(); | 476 var dest = new proto.jspb.test.TestClone(); |
| 476 dest.setStr('override'); | 477 dest.setStr('override'); |
| 477 var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]); | 478 var simple1 = new proto.jspb.test.Simple1(['x1', ['y1', 'z1']]); |
| 478 var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]); | 479 var simple2 = new proto.jspb.test.Simple1(['x2', ['y2', 'z2']]); |
| 479 var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]); | 480 var simple3 = new proto.jspb.test.Simple1(['x3', ['y3', 'z3']]); |
| 480 var destSimple1 = new proto.jspb.test.Simple1(['ox1', ['oy1', 'oz1']]); | 481 var destSimple1 = new proto.jspb.test.Simple1(['ox1', ['oy1', 'oz1']]); |
| 481 var destSimple2 = new proto.jspb.test.Simple1(['ox2', ['oy2', 'oz2']]); | 482 var destSimple2 = new proto.jspb.test.Simple1(['ox2', ['oy2', 'oz2']]); |
| 482 var destSimple3 = new proto.jspb.test.Simple1(['ox3', ['oy3', 'oz3']]); | 483 var destSimple3 = new proto.jspb.test.Simple1(['ox3', ['oy3', 'oz3']]); |
| 483 original.setSimple1(simple1); | 484 original.setSimple1(simple1); |
| 484 original.setSimple2List([simple2, simple3]); | 485 original.setSimple2List([simple2, simple3]); |
| 485 dest.setSimple1(destSimple1); | 486 dest.setSimple1(destSimple1); |
| 486 dest.setSimple2List([destSimple2, destSimple3]); | 487 dest.setSimple2List([destSimple2, destSimple3]); |
| 488 var bytes1 = supportsUint8Array ? new Uint8Array([1, 2, 3]) : '123'; |
| 489 var bytes2 = supportsUint8Array ? new Uint8Array([4, 5, 6]) : '456'; |
| 490 original.setBytesField(bytes1); |
| 491 dest.setBytesField(bytes2); |
| 487 var extension = new proto.jspb.test.CloneExtension(); | 492 var extension = new proto.jspb.test.CloneExtension(); |
| 488 extension.setExt('e1'); | 493 extension.setExt('e1'); |
| 489 original.setExtension(proto.jspb.test.CloneExtension.extField, extension); | 494 original.setExtension(proto.jspb.test.CloneExtension.extField, extension); |
| 490 | 495 |
| 491 jspb.Message.copyInto(original, dest); | 496 jspb.Message.copyInto(original, dest); |
| 492 assertArrayEquals(original.toArray(), dest.toArray()); | 497 assertArrayEquals(original.toArray(), dest.toArray()); |
| 493 assertEquals('x1', dest.getSimple1().getAString()); | 498 assertEquals('x1', dest.getSimple1().getAString()); |
| 494 assertEquals('e1', | 499 assertEquals('e1', |
| 495 dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt()); | 500 dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt()); |
| 496 dest.getSimple1().setAString('new value'); | 501 dest.getSimple1().setAString('new value'); |
| 497 assertNotEquals(dest.getSimple1().getAString(), | 502 assertNotEquals(dest.getSimple1().getAString(), |
| 498 original.getSimple1().getAString()); | 503 original.getSimple1().getAString()); |
| 504 if (supportsUint8Array) { |
| 505 dest.getBytesField()[0] = 7; |
| 506 assertObjectEquals(bytes1, original.getBytesField()); |
| 507 assertObjectEquals(new Uint8Array([7, 2, 3]), dest.getBytesField()); |
| 508 } else { |
| 509 dest.setBytesField('789'); |
| 510 assertObjectEquals(bytes1, original.getBytesField()); |
| 511 assertObjectEquals('789', dest.getBytesField()); |
| 512 } |
| 499 dest.getExtension(proto.jspb.test.CloneExtension.extField). | 513 dest.getExtension(proto.jspb.test.CloneExtension.extField). |
| 500 setExt('new value'); | 514 setExt('new value'); |
| 501 assertNotEquals( | 515 assertNotEquals( |
| 502 dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(), | 516 dest.getExtension(proto.jspb.test.CloneExtension.extField).getExt(), |
| 503 original.getExtension( | 517 original.getExtension( |
| 504 proto.jspb.test.CloneExtension.extField).getExt()); | 518 proto.jspb.test.CloneExtension.extField).getExt()); |
| 505 }); | 519 }); |
| 506 | 520 |
| 507 it('testCopyInto_notSameType', function() { | 521 it('testCopyInto_notSameType', function() { |
| 508 var a = new proto.jspb.test.TestClone(); | 522 var a = new proto.jspb.test.TestClone(); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 var msg = new proto.jspb.test.Empty([1, {4: 'hi'}]); | 669 var msg = new proto.jspb.test.Empty([1, {4: 'hi'}]); |
| 656 // The extensionObject is not moved from its original location. | 670 // The extensionObject is not moved from its original location. |
| 657 assertArrayEquals([1, {4: 'hi'}], msg.toArray()); | 671 assertArrayEquals([1, {4: 'hi'}], msg.toArray()); |
| 658 }); | 672 }); |
| 659 | 673 |
| 660 it('testInitialization_forwardCompatible', function() { | 674 it('testInitialization_forwardCompatible', function() { |
| 661 var msg = new proto.jspb.test.Empty([1, 2, 3, {1: 'hi'}]); | 675 var msg = new proto.jspb.test.Empty([1, 2, 3, {1: 'hi'}]); |
| 662 assertArrayEquals([1, 2, 3, {1: 'hi'}], msg.toArray()); | 676 assertArrayEquals([1, 2, 3, {1: 'hi'}], msg.toArray()); |
| 663 }); | 677 }); |
| 664 | 678 |
| 665 it('testExtendedMessageEnsureObject', function() { | 679 it('testExtendedMessageEnsureObject', |
| 666 var data = new proto.jspb.test.HasExtensions(['str1', | 680 /** @suppress {visibility} */ function() { |
| 667 {'a_key': 'an_object'}]); | 681 var data = |
| 668 assertEquals('an_object', data.extensionObject_['a_key']); | 682 new proto.jspb.test.HasExtensions(['str1', {'a_key': 'an_object'}]); |
| 669 }); | 683 assertEquals('an_object', data.extensionObject_['a_key']); |
| 684 }); |
| 670 | 685 |
| 671 it('testToObject_hasExtensionField', function() { | 686 it('testToObject_hasExtensionField', function() { |
| 672 var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); | 687 var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); |
| 673 var obj = data.toObject(); | 688 var obj = data.toObject(); |
| 674 assertEquals('str1', obj.str1); | 689 assertEquals('str1', obj.str1); |
| 675 assertEquals('ext1', obj.extField.ext1); | 690 assertEquals('ext1', obj.extField.ext1); |
| 676 }); | 691 }); |
| 677 | 692 |
| 678 it('testGetExtension', function() { | 693 it('testGetExtension', function() { |
| 679 var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); | 694 var data = new proto.jspb.test.HasExtensions(['str1', {100: ['ext1']}]); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 assertEquals( | 761 assertEquals( |
| 747 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase. | 762 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase. |
| 748 RECURSIVE_ONEOF_NOT_SET, | 763 RECURSIVE_ONEOF_NOT_SET, |
| 749 message.getRecursiveOneofCase()); | 764 message.getRecursiveOneofCase()); |
| 750 }); | 765 }); |
| 751 | 766 |
| 752 it('testInitializeMessageWithSingleValueSetInOneof', function() { | 767 it('testInitializeMessageWithSingleValueSetInOneof', function() { |
| 753 var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']); | 768 var message = new proto.jspb.test.TestMessageWithOneof([,, 'x']); |
| 754 | 769 |
| 755 assertEquals('x', message.getPone()); | 770 assertEquals('x', message.getPone()); |
| 756 assertUndefined(message.getPthree()); | 771 assertEquals('', message.getPthree()); |
| 757 assertEquals( | 772 assertEquals( |
| 758 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, | 773 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, |
| 759 message.getPartialOneofCase()); | 774 message.getPartialOneofCase()); |
| 760 }); | 775 }); |
| 761 | 776 |
| 762 it('testKeepsLastWireValueSetInUnion_multipleValues', function() { | 777 it('testKeepsLastWireValueSetInUnion_multipleValues', function() { |
| 763 var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']); | 778 var message = new proto.jspb.test.TestMessageWithOneof([,, 'x',, 'y']); |
| 764 | 779 |
| 765 assertUndefined('x', message.getPone()); | 780 assertEquals('', message.getPone()); |
| 766 assertEquals('y', message.getPthree()); | 781 assertEquals('y', message.getPthree()); |
| 767 assertEquals( | 782 assertEquals( |
| 768 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE, | 783 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PTHREE, |
| 769 message.getPartialOneofCase()); | 784 message.getPartialOneofCase()); |
| 770 }); | 785 }); |
| 771 | 786 |
| 772 it('testSettingOneofFieldClearsOthers', function() { | 787 it('testSettingOneofFieldClearsOthers', function() { |
| 773 var message = new proto.jspb.test.TestMessageWithOneof; | 788 var message = new proto.jspb.test.TestMessageWithOneof; |
| 774 assertUndefined(message.getPone()); | 789 assertEquals('', message.getPone()); |
| 775 assertUndefined(message.getPthree()); | 790 assertEquals('', message.getPthree()); |
| 791 assertFalse(message.hasPone()); |
| 792 assertFalse(message.hasPthree()); |
| 776 | 793 |
| 777 message.setPone('hi'); | 794 message.setPone('hi'); |
| 778 assertEquals('hi', message.getPone()); | 795 assertEquals('hi', message.getPone()); |
| 779 assertUndefined(message.getPthree()); | 796 assertEquals('', message.getPthree()); |
| 797 assertTrue(message.hasPone()); |
| 798 assertFalse(message.hasPthree()); |
| 780 | 799 |
| 781 message.setPthree('bye'); | 800 message.setPthree('bye'); |
| 782 assertUndefined(message.getPone()); | 801 assertEquals('', message.getPone()); |
| 783 assertEquals('bye', message.getPthree()); | 802 assertEquals('bye', message.getPthree()); |
| 803 assertFalse(message.hasPone()); |
| 804 assertTrue(message.hasPthree()); |
| 784 }); | 805 }); |
| 785 | 806 |
| 786 it('testSettingOneofFieldDoesNotClearFieldsFromOtherUnions', function() { | 807 it('testSettingOneofFieldDoesNotClearFieldsFromOtherUnions', function() { |
| 787 var other = new proto.jspb.test.TestMessageWithOneof; | 808 var other = new proto.jspb.test.TestMessageWithOneof; |
| 788 var message = new proto.jspb.test.TestMessageWithOneof; | 809 var message = new proto.jspb.test.TestMessageWithOneof; |
| 789 assertUndefined(message.getPone()); | 810 assertEquals('', message.getPone()); |
| 790 assertUndefined(message.getPthree()); | 811 assertEquals('', message.getPthree()); |
| 791 assertUndefined(message.getRone()); | 812 assertUndefined(message.getRone()); |
| 813 assertFalse(message.hasPone()); |
| 814 assertFalse(message.hasPthree()); |
| 792 | 815 |
| 793 message.setPone('hi'); | 816 message.setPone('hi'); |
| 794 message.setRone(other); | 817 message.setRone(other); |
| 795 assertEquals('hi', message.getPone()); | 818 assertEquals('hi', message.getPone()); |
| 796 assertUndefined(message.getPthree()); | 819 assertEquals('', message.getPthree()); |
| 797 assertEquals(other, message.getRone()); | 820 assertEquals(other, message.getRone()); |
| 821 assertTrue(message.hasPone()); |
| 822 assertFalse(message.hasPthree()); |
| 798 | 823 |
| 799 message.setPthree('bye'); | 824 message.setPthree('bye'); |
| 800 assertUndefined(message.getPone()); | 825 assertEquals('', message.getPone()); |
| 801 assertEquals('bye', message.getPthree()); | 826 assertEquals('bye', message.getPthree()); |
| 802 assertEquals(other, message.getRone()); | 827 assertEquals(other, message.getRone()); |
| 828 assertFalse(message.hasPone()); |
| 829 assertTrue(message.hasPthree()); |
| 803 }); | 830 }); |
| 804 | 831 |
| 805 it('testUnsetsOneofCaseWhenFieldIsCleared', function() { | 832 it('testUnsetsOneofCaseWhenFieldIsCleared', function() { |
| 806 var message = new proto.jspb.test.TestMessageWithOneof; | 833 var message = new proto.jspb.test.TestMessageWithOneof; |
| 807 assertEquals( | 834 assertEquals( |
| 808 proto.jspb.test.TestMessageWithOneof.PartialOneofCase. | 835 proto.jspb.test.TestMessageWithOneof.PartialOneofCase. |
| 809 PARTIAL_ONEOF_NOT_SET, | 836 PARTIAL_ONEOF_NOT_SET, |
| 810 message.getPartialOneofCase()); | 837 message.getPartialOneofCase()); |
| 811 | 838 |
| 812 message.setPone('hi'); | 839 message.setPone('hi'); |
| 813 assertEquals( | 840 assertEquals( |
| 814 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, | 841 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, |
| 815 message.getPartialOneofCase()); | 842 message.getPartialOneofCase()); |
| 816 | 843 |
| 817 message.clearPone(); | 844 message.clearPone(); |
| 818 assertEquals( | 845 assertEquals( |
| 819 proto.jspb.test.TestMessageWithOneof.PartialOneofCase. | 846 proto.jspb.test.TestMessageWithOneof.PartialOneofCase. |
| 820 PARTIAL_ONEOF_NOT_SET, | 847 PARTIAL_ONEOF_NOT_SET, |
| 821 message.getPartialOneofCase()); | 848 message.getPartialOneofCase()); |
| 822 }); | 849 }); |
| 823 | 850 |
| 824 it('testMessageWithDefaultOneofValues', function() { | 851 it('testMessageWithDefaultOneofValues', function() { |
| 825 var message = new proto.jspb.test.TestMessageWithOneof; | 852 var message = new proto.jspb.test.TestMessageWithOneof; |
| 826 assertEquals(1234, message.getAone()); | 853 assertEquals(1234, message.getAone()); |
| 827 assertUndefined(message.getAtwo()); | 854 assertEquals(0, message.getAtwo()); |
| 828 assertEquals( | 855 assertEquals( |
| 829 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase | 856 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase |
| 830 .DEFAULT_ONEOF_A_NOT_SET, | 857 .DEFAULT_ONEOF_A_NOT_SET, |
| 831 message.getDefaultOneofACase()); | 858 message.getDefaultOneofACase()); |
| 832 | 859 |
| 833 message.setAone(567); | 860 message.setAone(567); |
| 834 assertEquals(567, message.getAone()); | 861 assertEquals(567, message.getAone()); |
| 835 assertUndefined(message.getAtwo()); | 862 assertEquals(0, message.getAtwo()); |
| 836 assertEquals( | 863 assertEquals( |
| 837 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE, | 864 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE, |
| 838 message.getDefaultOneofACase()); | 865 message.getDefaultOneofACase()); |
| 839 | 866 |
| 840 message.setAtwo(890); | 867 message.setAtwo(890); |
| 841 assertEquals(1234, message.getAone()); | 868 assertEquals(1234, message.getAone()); |
| 842 assertEquals(890, message.getAtwo()); | 869 assertEquals(890, message.getAtwo()); |
| 843 assertEquals( | 870 assertEquals( |
| 844 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO, | 871 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO, |
| 845 message.getDefaultOneofACase()); | 872 message.getDefaultOneofACase()); |
| 846 | 873 |
| 847 message.clearAtwo(); | 874 message.clearAtwo(); |
| 848 assertEquals(1234, message.getAone()); | 875 assertEquals(1234, message.getAone()); |
| 849 assertUndefined(message.getAtwo()); | 876 assertEquals(0, message.getAtwo()); |
| 850 assertEquals( | 877 assertEquals( |
| 851 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase | 878 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase |
| 852 .DEFAULT_ONEOF_A_NOT_SET, | 879 .DEFAULT_ONEOF_A_NOT_SET, |
| 853 message.getDefaultOneofACase()); | 880 message.getDefaultOneofACase()); |
| 854 }); | 881 }); |
| 855 | 882 |
| 856 it('testMessageWithDefaultOneofValues_defaultNotOnFirstField', function() { | 883 it('testMessageWithDefaultOneofValues_defaultNotOnFirstField', function() { |
| 857 var message = new proto.jspb.test.TestMessageWithOneof; | 884 var message = new proto.jspb.test.TestMessageWithOneof; |
| 858 assertUndefined(message.getBone()); | 885 assertEquals(0, message.getBone()); |
| 859 assertEquals(1234, message.getBtwo()); | 886 assertEquals(1234, message.getBtwo()); |
| 887 assertFalse(message.hasBone()); |
| 888 assertFalse(message.hasBtwo()); |
| 860 assertEquals( | 889 assertEquals( |
| 861 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase | 890 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase |
| 862 .DEFAULT_ONEOF_B_NOT_SET, | 891 .DEFAULT_ONEOF_B_NOT_SET, |
| 863 message.getDefaultOneofBCase()); | 892 message.getDefaultOneofBCase()); |
| 864 | 893 |
| 865 message.setBone(2); | 894 message.setBone(2); |
| 866 assertEquals(2, message.getBone()); | 895 assertEquals(2, message.getBone()); |
| 867 assertEquals(1234, message.getBtwo()); | 896 assertEquals(1234, message.getBtwo()); |
| 897 assertTrue(message.hasBone()); |
| 898 assertFalse(message.hasBtwo()); |
| 868 assertEquals( | 899 assertEquals( |
| 869 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE, | 900 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE, |
| 870 message.getDefaultOneofBCase()); | 901 message.getDefaultOneofBCase()); |
| 871 | 902 |
| 872 message.setBtwo(3); | 903 message.setBtwo(3); |
| 873 assertUndefined(message.getBone()); | 904 assertEquals(0, message.getBone()); |
| 905 assertFalse(message.hasBone()); |
| 906 assertTrue(message.hasBtwo()); |
| 874 assertEquals(3, message.getBtwo()); | 907 assertEquals(3, message.getBtwo()); |
| 875 assertEquals( | 908 assertEquals( |
| 876 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, | 909 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, |
| 877 message.getDefaultOneofBCase()); | 910 message.getDefaultOneofBCase()); |
| 878 | 911 |
| 879 message.clearBtwo(); | 912 message.clearBtwo(); |
| 880 assertUndefined(message.getBone()); | 913 assertEquals(0, message.getBone()); |
| 914 assertFalse(message.hasBone()); |
| 915 assertFalse(message.hasBtwo()); |
| 881 assertEquals(1234, message.getBtwo()); | 916 assertEquals(1234, message.getBtwo()); |
| 882 assertEquals( | 917 assertEquals( |
| 883 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase | 918 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase |
| 884 .DEFAULT_ONEOF_B_NOT_SET, | 919 .DEFAULT_ONEOF_B_NOT_SET, |
| 885 message.getDefaultOneofBCase()); | 920 message.getDefaultOneofBCase()); |
| 886 }); | 921 }); |
| 887 | 922 |
| 888 it('testInitializeMessageWithOneofDefaults', function() { | 923 it('testInitializeMessageWithOneofDefaults', function() { |
| 889 var message = | 924 var message = |
| 890 new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567)); | 925 new proto.jspb.test.TestMessageWithOneof(new Array(9).concat(567)); |
| 891 assertEquals(567, message.getAone()); | 926 assertEquals(567, message.getAone()); |
| 892 assertUndefined(message.getAtwo()); | 927 assertEquals(0, message.getAtwo()); |
| 893 assertEquals( | 928 assertEquals( |
| 894 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE, | 929 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.AONE, |
| 895 message.getDefaultOneofACase()); | 930 message.getDefaultOneofACase()); |
| 896 | 931 |
| 897 message = | 932 message = |
| 898 new proto.jspb.test.TestMessageWithOneof(new Array(10).concat(890)); | 933 new proto.jspb.test.TestMessageWithOneof(new Array(10).concat(890)); |
| 899 assertEquals(1234, message.getAone()); | 934 assertEquals(1234, message.getAone()); |
| 900 assertEquals(890, message.getAtwo()); | 935 assertEquals(890, message.getAtwo()); |
| 901 assertEquals( | 936 assertEquals( |
| 902 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO, | 937 proto.jspb.test.TestMessageWithOneof.DefaultOneofACase.ATWO, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 918 message = | 953 message = |
| 919 new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567)); | 954 new proto.jspb.test.TestMessageWithOneof(new Array(11).concat(567)); |
| 920 assertEquals(567, message.getBone()); | 955 assertEquals(567, message.getBone()); |
| 921 assertEquals(1234, message.getBtwo()); | 956 assertEquals(1234, message.getBtwo()); |
| 922 assertEquals( | 957 assertEquals( |
| 923 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE, | 958 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BONE, |
| 924 message.getDefaultOneofBCase()); | 959 message.getDefaultOneofBCase()); |
| 925 | 960 |
| 926 message = | 961 message = |
| 927 new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890)); | 962 new proto.jspb.test.TestMessageWithOneof(new Array(12).concat(890)); |
| 928 assertUndefined(message.getBone()); | 963 assertEquals(0, message.getBone()); |
| 929 assertEquals(890, message.getBtwo()); | 964 assertEquals(890, message.getBtwo()); |
| 930 assertEquals( | 965 assertEquals( |
| 931 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, | 966 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, |
| 932 message.getDefaultOneofBCase()); | 967 message.getDefaultOneofBCase()); |
| 933 | 968 |
| 934 message = new proto.jspb.test.TestMessageWithOneof( | 969 message = new proto.jspb.test.TestMessageWithOneof( |
| 935 new Array(11).concat(567, 890)); | 970 new Array(11).concat(567, 890)); |
| 936 assertUndefined(message.getBone()); | 971 assertEquals(0, message.getBone()); |
| 937 assertEquals(890, message.getBtwo()); | 972 assertEquals(890, message.getBtwo()); |
| 938 assertEquals( | 973 assertEquals( |
| 939 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, | 974 proto.jspb.test.TestMessageWithOneof.DefaultOneofBCase.BTWO, |
| 940 message.getDefaultOneofBCase()); | 975 message.getDefaultOneofBCase()); |
| 941 }); | 976 }); |
| 942 | 977 |
| 943 it('testOneofContainingAnotherMessage', function() { | 978 it('testOneofContainingAnotherMessage', function() { |
| 944 var message = new proto.jspb.test.TestMessageWithOneof; | 979 var message = new proto.jspb.test.TestMessageWithOneof; |
| 945 assertEquals( | 980 assertEquals( |
| 946 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase. | 981 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase. |
| 947 RECURSIVE_ONEOF_NOT_SET, | 982 RECURSIVE_ONEOF_NOT_SET, |
| 948 message.getRecursiveOneofCase()); | 983 message.getRecursiveOneofCase()); |
| 949 | 984 |
| 950 var other = new proto.jspb.test.TestMessageWithOneof; | 985 var other = new proto.jspb.test.TestMessageWithOneof; |
| 951 message.setRone(other); | 986 message.setRone(other); |
| 952 assertEquals(other, message.getRone()); | 987 assertEquals(other, message.getRone()); |
| 953 assertUndefined(message.getRtwo()); | 988 assertEquals('', message.getRtwo()); |
| 954 assertEquals( | 989 assertEquals( |
| 955 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RONE, | 990 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RONE, |
| 956 message.getRecursiveOneofCase()); | 991 message.getRecursiveOneofCase()); |
| 957 | 992 |
| 958 message.setRtwo('hi'); | 993 message.setRtwo('hi'); |
| 959 assertUndefined(message.getRone()); | 994 assertUndefined(message.getRone()); |
| 960 assertEquals('hi', message.getRtwo()); | 995 assertEquals('hi', message.getRtwo()); |
| 961 assertEquals( | 996 assertEquals( |
| 962 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RTWO, | 997 proto.jspb.test.TestMessageWithOneof.RecursiveOneofCase.RTWO, |
| 963 message.getRecursiveOneofCase()); | 998 message.getRecursiveOneofCase()); |
| 964 }); | 999 }); |
| 965 | 1000 |
| 966 it('testQueryingOneofCaseEnsuresOnlyOneFieldIsSetInUnderlyingArray', | 1001 it('testQueryingOneofCaseEnsuresOnlyOneFieldIsSetInUnderlyingArray', |
| 967 function() { | 1002 function() { |
| 968 var message = new proto.jspb.test.TestMessageWithOneof; | 1003 var message = new proto.jspb.test.TestMessageWithOneof; |
| 969 message.setPone('x'); | 1004 message.setPone('x'); |
| 970 assertEquals('x', message.getPone()); | 1005 assertEquals('x', message.getPone()); |
| 971 assertUndefined(message.getPthree()); | 1006 assertEquals('', message.getPthree()); |
| 972 assertEquals( | 1007 assertEquals( |
| 973 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, | 1008 proto.jspb.test.TestMessageWithOneof.PartialOneofCase.PONE, |
| 974 message.getPartialOneofCase()); | 1009 message.getPartialOneofCase()); |
| 975 | 1010 |
| 976 var array = message.toArray(); | 1011 var array = message.toArray(); |
| 977 assertEquals('x', array[2]); | 1012 assertEquals('x', array[2]); |
| 978 assertUndefined(array[4]); | 1013 assertUndefined(array[4]); |
| 979 array[4] = 'y'; | 1014 array[4] = 'y'; |
| 980 | 1015 |
| 981 assertEquals( | 1016 assertEquals( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1000 assertNan(message.getRepeatedFloatFieldList()[0]); | 1035 assertNan(message.getRepeatedFloatFieldList()[0]); |
| 1001 assertNan(message.getRepeatedFloatFieldList()[1]); | 1036 assertNan(message.getRepeatedFloatFieldList()[1]); |
| 1002 assertNan(message.getDefaultFloatField()); | 1037 assertNan(message.getDefaultFloatField()); |
| 1003 assertNan(message.getOptionalDoubleField()); | 1038 assertNan(message.getOptionalDoubleField()); |
| 1004 assertNan(message.getRequiredDoubleField()); | 1039 assertNan(message.getRequiredDoubleField()); |
| 1005 assertNan(message.getRepeatedDoubleFieldList()[0]); | 1040 assertNan(message.getRepeatedDoubleFieldList()[0]); |
| 1006 assertNan(message.getRepeatedDoubleFieldList()[1]); | 1041 assertNan(message.getRepeatedDoubleFieldList()[1]); |
| 1007 assertNan(message.getDefaultDoubleField()); | 1042 assertNan(message.getDefaultDoubleField()); |
| 1008 }); | 1043 }); |
| 1009 | 1044 |
| 1045 // Verify that we can successfully use a field referring to a nested message |
| 1046 // from a different .proto file. |
| 1047 it('testForeignNestedMessage', function() { |
| 1048 var msg = new proto.jspb.test.ForeignNestedFieldMessage(); |
| 1049 var nested = new proto.jspb.test.Deeply.Nested.Message(); |
| 1050 nested.setCount(5); |
| 1051 msg.setDeeplyNestedMessage(nested); |
| 1052 assertEquals(5, msg.getDeeplyNestedMessage().getCount()); |
| 1053 |
| 1054 // After a serialization-deserialization round trip we should get back the |
| 1055 // same data we started with. |
| 1056 var serialized = msg.serializeBinary(); |
| 1057 var deserialized = |
| 1058 proto.jspb.test.ForeignNestedFieldMessage.deserializeBinary(serialized); |
| 1059 assertEquals(5, deserialized.getDeeplyNestedMessage().getCount()); |
| 1060 }); |
| 1061 |
| 1010 }); | 1062 }); |
| OLD | NEW |