Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: third_party/protobuf/js/message_test.js

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

Powered by Google App Engine
This is Rietveld 408576698