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