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