PageRenderTime 85ms CodeModel.GetById 15ms app.highlight 60ms RepoModel.GetById 1ms app.codeStats 1ms

/thirdparty/breakpad/third_party/protobuf/protobuf/java/src/test/java/com/google/protobuf/TestUtil.java

http://github.com/tomahawk-player/tomahawk
Java | 1278 lines | 1021 code | 127 blank | 130 comment | 0 complexity | e96d58a1d50e576fb4df7cb2ff66b36a MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1// Protocol Buffers - Google's data interchange format
  2// Copyright 2008 Google Inc.  All rights reserved.
  3// http://code.google.com/p/protobuf/
  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
 31package com.google.protobuf;
 32
 33import protobuf_unittest.UnittestProto;
 34import com.google.protobuf.UnittestLite;
 35
 36// The static imports are to avoid 100+ char lines.  The following is roughly equivalent to
 37// import static protobuf_unittest.UnittestProto.*;
 38import static protobuf_unittest.UnittestProto.defaultInt32Extension;
 39import static protobuf_unittest.UnittestProto.defaultInt64Extension;
 40import static protobuf_unittest.UnittestProto.defaultUint32Extension;
 41import static protobuf_unittest.UnittestProto.defaultUint64Extension;
 42import static protobuf_unittest.UnittestProto.defaultSint32Extension;
 43import static protobuf_unittest.UnittestProto.defaultSint64Extension;
 44import static protobuf_unittest.UnittestProto.defaultFixed32Extension;
 45import static protobuf_unittest.UnittestProto.defaultFixed64Extension;
 46import static protobuf_unittest.UnittestProto.defaultSfixed32Extension;
 47import static protobuf_unittest.UnittestProto.defaultSfixed64Extension;
 48import static protobuf_unittest.UnittestProto.defaultFloatExtension;
 49import static protobuf_unittest.UnittestProto.defaultDoubleExtension;
 50import static protobuf_unittest.UnittestProto.defaultBoolExtension;
 51import static protobuf_unittest.UnittestProto.defaultStringExtension;
 52import static protobuf_unittest.UnittestProto.defaultBytesExtension;
 53import static protobuf_unittest.UnittestProto.defaultNestedEnumExtension;
 54import static protobuf_unittest.UnittestProto.defaultForeignEnumExtension;
 55import static protobuf_unittest.UnittestProto.defaultImportEnumExtension;
 56import static protobuf_unittest.UnittestProto.defaultStringPieceExtension;
 57import static protobuf_unittest.UnittestProto.defaultCordExtension;
 58
 59import static protobuf_unittest.UnittestProto.optionalInt32Extension;
 60import static protobuf_unittest.UnittestProto.optionalInt64Extension;
 61import static protobuf_unittest.UnittestProto.optionalUint32Extension;
 62import static protobuf_unittest.UnittestProto.optionalUint64Extension;
 63import static protobuf_unittest.UnittestProto.optionalSint32Extension;
 64import static protobuf_unittest.UnittestProto.optionalSint64Extension;
 65import static protobuf_unittest.UnittestProto.optionalFixed32Extension;
 66import static protobuf_unittest.UnittestProto.optionalFixed64Extension;
 67import static protobuf_unittest.UnittestProto.optionalSfixed32Extension;
 68import static protobuf_unittest.UnittestProto.optionalSfixed64Extension;
 69import static protobuf_unittest.UnittestProto.optionalFloatExtension;
 70import static protobuf_unittest.UnittestProto.optionalDoubleExtension;
 71import static protobuf_unittest.UnittestProto.optionalBoolExtension;
 72import static protobuf_unittest.UnittestProto.optionalStringExtension;
 73import static protobuf_unittest.UnittestProto.optionalBytesExtension;
 74import static protobuf_unittest.UnittestProto.optionalGroupExtension;
 75import static protobuf_unittest.UnittestProto.optionalNestedMessageExtension;
 76import static protobuf_unittest.UnittestProto.optionalForeignMessageExtension;
 77import static protobuf_unittest.UnittestProto.optionalImportMessageExtension;
 78import static protobuf_unittest.UnittestProto.optionalNestedEnumExtension;
 79import static protobuf_unittest.UnittestProto.optionalForeignEnumExtension;
 80import static protobuf_unittest.UnittestProto.optionalImportEnumExtension;
 81import static protobuf_unittest.UnittestProto.optionalStringPieceExtension;
 82import static protobuf_unittest.UnittestProto.optionalCordExtension;
 83
 84import static protobuf_unittest.UnittestProto.repeatedInt32Extension;
 85import static protobuf_unittest.UnittestProto.repeatedInt64Extension;
 86import static protobuf_unittest.UnittestProto.repeatedUint32Extension;
 87import static protobuf_unittest.UnittestProto.repeatedUint64Extension;
 88import static protobuf_unittest.UnittestProto.repeatedSint32Extension;
 89import static protobuf_unittest.UnittestProto.repeatedSint64Extension;
 90import static protobuf_unittest.UnittestProto.repeatedFixed32Extension;
 91import static protobuf_unittest.UnittestProto.repeatedFixed64Extension;
 92import static protobuf_unittest.UnittestProto.repeatedSfixed32Extension;
 93import static protobuf_unittest.UnittestProto.repeatedSfixed64Extension;
 94import static protobuf_unittest.UnittestProto.repeatedFloatExtension;
 95import static protobuf_unittest.UnittestProto.repeatedDoubleExtension;
 96import static protobuf_unittest.UnittestProto.repeatedBoolExtension;
 97import static protobuf_unittest.UnittestProto.repeatedStringExtension;
 98import static protobuf_unittest.UnittestProto.repeatedBytesExtension;
 99import static protobuf_unittest.UnittestProto.repeatedGroupExtension;
100import static protobuf_unittest.UnittestProto.repeatedNestedMessageExtension;
101import static protobuf_unittest.UnittestProto.repeatedForeignMessageExtension;
102import static protobuf_unittest.UnittestProto.repeatedImportMessageExtension;
103import static protobuf_unittest.UnittestProto.repeatedNestedEnumExtension;
104import static protobuf_unittest.UnittestProto.repeatedForeignEnumExtension;
105import static protobuf_unittest.UnittestProto.repeatedImportEnumExtension;
106import static protobuf_unittest.UnittestProto.repeatedStringPieceExtension;
107import static protobuf_unittest.UnittestProto.repeatedCordExtension;
108
109import static protobuf_unittest.UnittestProto.OptionalGroup_extension;
110import static protobuf_unittest.UnittestProto.RepeatedGroup_extension;
111
112import static protobuf_unittest.UnittestProto.packedInt32Extension;
113import static protobuf_unittest.UnittestProto.packedInt64Extension;
114import static protobuf_unittest.UnittestProto.packedUint32Extension;
115import static protobuf_unittest.UnittestProto.packedUint64Extension;
116import static protobuf_unittest.UnittestProto.packedSint32Extension;
117import static protobuf_unittest.UnittestProto.packedSint64Extension;
118import static protobuf_unittest.UnittestProto.packedFixed32Extension;
119import static protobuf_unittest.UnittestProto.packedFixed64Extension;
120import static protobuf_unittest.UnittestProto.packedSfixed32Extension;
121import static protobuf_unittest.UnittestProto.packedSfixed64Extension;
122import static protobuf_unittest.UnittestProto.packedFloatExtension;
123import static protobuf_unittest.UnittestProto.packedDoubleExtension;
124import static protobuf_unittest.UnittestProto.packedBoolExtension;
125import static protobuf_unittest.UnittestProto.packedEnumExtension;
126
127import static com.google.protobuf.UnittestLite.defaultInt32ExtensionLite;
128import static com.google.protobuf.UnittestLite.defaultInt64ExtensionLite;
129import static com.google.protobuf.UnittestLite.defaultUint32ExtensionLite;
130import static com.google.protobuf.UnittestLite.defaultUint64ExtensionLite;
131import static com.google.protobuf.UnittestLite.defaultSint32ExtensionLite;
132import static com.google.protobuf.UnittestLite.defaultSint64ExtensionLite;
133import static com.google.protobuf.UnittestLite.defaultFixed32ExtensionLite;
134import static com.google.protobuf.UnittestLite.defaultFixed64ExtensionLite;
135import static com.google.protobuf.UnittestLite.defaultSfixed32ExtensionLite;
136import static com.google.protobuf.UnittestLite.defaultSfixed64ExtensionLite;
137import static com.google.protobuf.UnittestLite.defaultFloatExtensionLite;
138import static com.google.protobuf.UnittestLite.defaultDoubleExtensionLite;
139import static com.google.protobuf.UnittestLite.defaultBoolExtensionLite;
140import static com.google.protobuf.UnittestLite.defaultStringExtensionLite;
141import static com.google.protobuf.UnittestLite.defaultBytesExtensionLite;
142import static com.google.protobuf.UnittestLite.defaultNestedEnumExtensionLite;
143import static com.google.protobuf.UnittestLite.defaultForeignEnumExtensionLite;
144import static com.google.protobuf.UnittestLite.defaultImportEnumExtensionLite;
145import static com.google.protobuf.UnittestLite.defaultStringPieceExtensionLite;
146import static com.google.protobuf.UnittestLite.defaultCordExtensionLite;
147
148import static com.google.protobuf.UnittestLite.optionalInt32ExtensionLite;
149import static com.google.protobuf.UnittestLite.optionalInt64ExtensionLite;
150import static com.google.protobuf.UnittestLite.optionalUint32ExtensionLite;
151import static com.google.protobuf.UnittestLite.optionalUint64ExtensionLite;
152import static com.google.protobuf.UnittestLite.optionalSint32ExtensionLite;
153import static com.google.protobuf.UnittestLite.optionalSint64ExtensionLite;
154import static com.google.protobuf.UnittestLite.optionalFixed32ExtensionLite;
155import static com.google.protobuf.UnittestLite.optionalFixed64ExtensionLite;
156import static com.google.protobuf.UnittestLite.optionalSfixed32ExtensionLite;
157import static com.google.protobuf.UnittestLite.optionalSfixed64ExtensionLite;
158import static com.google.protobuf.UnittestLite.optionalFloatExtensionLite;
159import static com.google.protobuf.UnittestLite.optionalDoubleExtensionLite;
160import static com.google.protobuf.UnittestLite.optionalBoolExtensionLite;
161import static com.google.protobuf.UnittestLite.optionalStringExtensionLite;
162import static com.google.protobuf.UnittestLite.optionalBytesExtensionLite;
163import static com.google.protobuf.UnittestLite.optionalGroupExtensionLite;
164import static com.google.protobuf.UnittestLite.optionalNestedMessageExtensionLite;
165import static com.google.protobuf.UnittestLite.optionalForeignMessageExtensionLite;
166import static com.google.protobuf.UnittestLite.optionalImportMessageExtensionLite;
167import static com.google.protobuf.UnittestLite.optionalNestedEnumExtensionLite;
168import static com.google.protobuf.UnittestLite.optionalForeignEnumExtensionLite;
169import static com.google.protobuf.UnittestLite.optionalImportEnumExtensionLite;
170import static com.google.protobuf.UnittestLite.optionalStringPieceExtensionLite;
171import static com.google.protobuf.UnittestLite.optionalCordExtensionLite;
172
173import static com.google.protobuf.UnittestLite.repeatedInt32ExtensionLite;
174import static com.google.protobuf.UnittestLite.repeatedInt64ExtensionLite;
175import static com.google.protobuf.UnittestLite.repeatedUint32ExtensionLite;
176import static com.google.protobuf.UnittestLite.repeatedUint64ExtensionLite;
177import static com.google.protobuf.UnittestLite.repeatedSint32ExtensionLite;
178import static com.google.protobuf.UnittestLite.repeatedSint64ExtensionLite;
179import static com.google.protobuf.UnittestLite.repeatedFixed32ExtensionLite;
180import static com.google.protobuf.UnittestLite.repeatedFixed64ExtensionLite;
181import static com.google.protobuf.UnittestLite.repeatedSfixed32ExtensionLite;
182import static com.google.protobuf.UnittestLite.repeatedSfixed64ExtensionLite;
183import static com.google.protobuf.UnittestLite.repeatedFloatExtensionLite;
184import static com.google.protobuf.UnittestLite.repeatedDoubleExtensionLite;
185import static com.google.protobuf.UnittestLite.repeatedBoolExtensionLite;
186import static com.google.protobuf.UnittestLite.repeatedStringExtensionLite;
187import static com.google.protobuf.UnittestLite.repeatedBytesExtensionLite;
188import static com.google.protobuf.UnittestLite.repeatedGroupExtensionLite;
189import static com.google.protobuf.UnittestLite.repeatedNestedMessageExtensionLite;
190import static com.google.protobuf.UnittestLite.repeatedForeignMessageExtensionLite;
191import static com.google.protobuf.UnittestLite.repeatedImportMessageExtensionLite;
192import static com.google.protobuf.UnittestLite.repeatedNestedEnumExtensionLite;
193import static com.google.protobuf.UnittestLite.repeatedForeignEnumExtensionLite;
194import static com.google.protobuf.UnittestLite.repeatedImportEnumExtensionLite;
195import static com.google.protobuf.UnittestLite.repeatedStringPieceExtensionLite;
196import static com.google.protobuf.UnittestLite.repeatedCordExtensionLite;
197
198import static com.google.protobuf.UnittestLite.OptionalGroup_extension_lite;
199import static com.google.protobuf.UnittestLite.RepeatedGroup_extension_lite;
200
201import static com.google.protobuf.UnittestLite.packedInt32ExtensionLite;
202import static com.google.protobuf.UnittestLite.packedInt64ExtensionLite;
203import static com.google.protobuf.UnittestLite.packedUint32ExtensionLite;
204import static com.google.protobuf.UnittestLite.packedUint64ExtensionLite;
205import static com.google.protobuf.UnittestLite.packedSint32ExtensionLite;
206import static com.google.protobuf.UnittestLite.packedSint64ExtensionLite;
207import static com.google.protobuf.UnittestLite.packedFixed32ExtensionLite;
208import static com.google.protobuf.UnittestLite.packedFixed64ExtensionLite;
209import static com.google.protobuf.UnittestLite.packedSfixed32ExtensionLite;
210import static com.google.protobuf.UnittestLite.packedSfixed64ExtensionLite;
211import static com.google.protobuf.UnittestLite.packedFloatExtensionLite;
212import static com.google.protobuf.UnittestLite.packedDoubleExtensionLite;
213import static com.google.protobuf.UnittestLite.packedBoolExtensionLite;
214import static com.google.protobuf.UnittestLite.packedEnumExtensionLite;
215
216import protobuf_unittest.UnittestProto.TestAllExtensions;
217import protobuf_unittest.UnittestProto.TestAllExtensionsOrBuilder;
218import protobuf_unittest.UnittestProto.TestAllTypes;
219import protobuf_unittest.UnittestProto.TestAllTypesOrBuilder;
220import protobuf_unittest.UnittestProto.TestPackedExtensions;
221import protobuf_unittest.UnittestProto.TestPackedTypes;
222import protobuf_unittest.UnittestProto.TestUnpackedTypes;
223import protobuf_unittest.UnittestProto.ForeignMessage;
224import protobuf_unittest.UnittestProto.ForeignEnum;
225import com.google.protobuf.test.UnittestImport.ImportMessage;
226import com.google.protobuf.test.UnittestImport.ImportEnum;
227
228import com.google.protobuf.UnittestLite.TestAllTypesLite;
229import com.google.protobuf.UnittestLite.TestAllExtensionsLite;
230import com.google.protobuf.UnittestLite.TestAllExtensionsLiteOrBuilder;
231import com.google.protobuf.UnittestLite.TestPackedExtensionsLite;
232import com.google.protobuf.UnittestLite.ForeignMessageLite;
233import com.google.protobuf.UnittestLite.ForeignEnumLite;
234import com.google.protobuf.UnittestImportLite.ImportMessageLite;
235import com.google.protobuf.UnittestImportLite.ImportEnumLite;
236
237import junit.framework.Assert;
238
239import java.io.File;
240import java.io.IOException;
241import java.io.RandomAccessFile;
242
243/**
244 * Contains methods for setting all fields of {@code TestAllTypes} to
245 * some vaules as well as checking that all the fields are set to those values.
246 * These are useful for testing various protocol message features, e.g.
247 * set all fields of a message, serialize it, parse it, and check that all
248 * fields are set.
249 *
250 * <p>This code is not to be used outside of {@code com.google.protobuf} and
251 * subpackages.
252 *
253 * @author kenton@google.com Kenton Varda
254 */
255public final class TestUtil {
256  private TestUtil() {}
257
258  /** Helper to convert a String to ByteString. */
259  static ByteString toBytes(String str) {
260    try {
261      return ByteString.copyFrom(str.getBytes("UTF-8"));
262    } catch(java.io.UnsupportedEncodingException e) {
263      throw new RuntimeException("UTF-8 not supported.", e);
264    }
265  }
266
267  /**
268   * Get a {@code TestAllTypes} with all fields set as they would be by
269   * {@link #setAllFields(TestAllTypes.Builder)}.
270   */
271  public static TestAllTypes getAllSet() {
272    TestAllTypes.Builder builder = TestAllTypes.newBuilder();
273    setAllFields(builder);
274    return builder.build();
275  }
276
277  /**
278   * Get a {@code TestAllExtensions} with all fields set as they would be by
279   * {@link #setAllExtensions(TestAllExtensions.Builder)}.
280   */
281  public static TestAllExtensions getAllExtensionsSet() {
282    TestAllExtensions.Builder builder = TestAllExtensions.newBuilder();
283    setAllExtensions(builder);
284    return builder.build();
285  }
286
287  public static TestAllExtensionsLite getAllLiteExtensionsSet() {
288    TestAllExtensionsLite.Builder builder = TestAllExtensionsLite.newBuilder();
289    setAllExtensions(builder);
290    return builder.build();
291  }
292
293  public static TestPackedTypes getPackedSet() {
294    TestPackedTypes.Builder builder = TestPackedTypes.newBuilder();
295    setPackedFields(builder);
296    return builder.build();
297  }
298
299  public static TestUnpackedTypes getUnpackedSet() {
300    TestUnpackedTypes.Builder builder = TestUnpackedTypes.newBuilder();
301    setUnpackedFields(builder);
302    return builder.build();
303  }
304
305  public static TestPackedExtensions getPackedExtensionsSet() {
306    TestPackedExtensions.Builder builder = TestPackedExtensions.newBuilder();
307    setPackedExtensions(builder);
308    return builder.build();
309  }
310
311  public static TestPackedExtensionsLite getLitePackedExtensionsSet() {
312    TestPackedExtensionsLite.Builder builder =
313        TestPackedExtensionsLite.newBuilder();
314    setPackedExtensions(builder);
315    return builder.build();
316  }
317
318  /**
319   * Set every field of {@code message} to the values expected by
320   * {@code assertAllFieldsSet()}.
321   */
322  public static void setAllFields(TestAllTypes.Builder message) {
323    message.setOptionalInt32   (101);
324    message.setOptionalInt64   (102);
325    message.setOptionalUint32  (103);
326    message.setOptionalUint64  (104);
327    message.setOptionalSint32  (105);
328    message.setOptionalSint64  (106);
329    message.setOptionalFixed32 (107);
330    message.setOptionalFixed64 (108);
331    message.setOptionalSfixed32(109);
332    message.setOptionalSfixed64(110);
333    message.setOptionalFloat   (111);
334    message.setOptionalDouble  (112);
335    message.setOptionalBool    (true);
336    message.setOptionalString  ("115");
337    message.setOptionalBytes   (toBytes("116"));
338
339    message.setOptionalGroup(
340      TestAllTypes.OptionalGroup.newBuilder().setA(117).build());
341    message.setOptionalNestedMessage(
342      TestAllTypes.NestedMessage.newBuilder().setBb(118).build());
343    message.setOptionalForeignMessage(
344      ForeignMessage.newBuilder().setC(119).build());
345    message.setOptionalImportMessage(
346      ImportMessage.newBuilder().setD(120).build());
347
348    message.setOptionalNestedEnum (TestAllTypes.NestedEnum.BAZ);
349    message.setOptionalForeignEnum(ForeignEnum.FOREIGN_BAZ);
350    message.setOptionalImportEnum (ImportEnum.IMPORT_BAZ);
351
352    message.setOptionalStringPiece("124");
353    message.setOptionalCord("125");
354
355    // -----------------------------------------------------------------
356
357    message.addRepeatedInt32   (201);
358    message.addRepeatedInt64   (202);
359    message.addRepeatedUint32  (203);
360    message.addRepeatedUint64  (204);
361    message.addRepeatedSint32  (205);
362    message.addRepeatedSint64  (206);
363    message.addRepeatedFixed32 (207);
364    message.addRepeatedFixed64 (208);
365    message.addRepeatedSfixed32(209);
366    message.addRepeatedSfixed64(210);
367    message.addRepeatedFloat   (211);
368    message.addRepeatedDouble  (212);
369    message.addRepeatedBool    (true);
370    message.addRepeatedString  ("215");
371    message.addRepeatedBytes   (toBytes("216"));
372
373    message.addRepeatedGroup(
374      TestAllTypes.RepeatedGroup.newBuilder().setA(217).build());
375    message.addRepeatedNestedMessage(
376      TestAllTypes.NestedMessage.newBuilder().setBb(218).build());
377    message.addRepeatedForeignMessage(
378      ForeignMessage.newBuilder().setC(219).build());
379    message.addRepeatedImportMessage(
380      ImportMessage.newBuilder().setD(220).build());
381
382    message.addRepeatedNestedEnum (TestAllTypes.NestedEnum.BAR);
383    message.addRepeatedForeignEnum(ForeignEnum.FOREIGN_BAR);
384    message.addRepeatedImportEnum (ImportEnum.IMPORT_BAR);
385
386    message.addRepeatedStringPiece("224");
387    message.addRepeatedCord("225");
388
389    // Add a second one of each field.
390    message.addRepeatedInt32   (301);
391    message.addRepeatedInt64   (302);
392    message.addRepeatedUint32  (303);
393    message.addRepeatedUint64  (304);
394    message.addRepeatedSint32  (305);
395    message.addRepeatedSint64  (306);
396    message.addRepeatedFixed32 (307);
397    message.addRepeatedFixed64 (308);
398    message.addRepeatedSfixed32(309);
399    message.addRepeatedSfixed64(310);
400    message.addRepeatedFloat   (311);
401    message.addRepeatedDouble  (312);
402    message.addRepeatedBool    (false);
403    message.addRepeatedString  ("315");
404    message.addRepeatedBytes   (toBytes("316"));
405
406    message.addRepeatedGroup(
407      TestAllTypes.RepeatedGroup.newBuilder().setA(317).build());
408    message.addRepeatedNestedMessage(
409      TestAllTypes.NestedMessage.newBuilder().setBb(318).build());
410    message.addRepeatedForeignMessage(
411      ForeignMessage.newBuilder().setC(319).build());
412    message.addRepeatedImportMessage(
413      ImportMessage.newBuilder().setD(320).build());
414
415    message.addRepeatedNestedEnum (TestAllTypes.NestedEnum.BAZ);
416    message.addRepeatedForeignEnum(ForeignEnum.FOREIGN_BAZ);
417    message.addRepeatedImportEnum (ImportEnum.IMPORT_BAZ);
418
419    message.addRepeatedStringPiece("324");
420    message.addRepeatedCord("325");
421
422    // -----------------------------------------------------------------
423
424    message.setDefaultInt32   (401);
425    message.setDefaultInt64   (402);
426    message.setDefaultUint32  (403);
427    message.setDefaultUint64  (404);
428    message.setDefaultSint32  (405);
429    message.setDefaultSint64  (406);
430    message.setDefaultFixed32 (407);
431    message.setDefaultFixed64 (408);
432    message.setDefaultSfixed32(409);
433    message.setDefaultSfixed64(410);
434    message.setDefaultFloat   (411);
435    message.setDefaultDouble  (412);
436    message.setDefaultBool    (false);
437    message.setDefaultString  ("415");
438    message.setDefaultBytes   (toBytes("416"));
439
440    message.setDefaultNestedEnum (TestAllTypes.NestedEnum.FOO);
441    message.setDefaultForeignEnum(ForeignEnum.FOREIGN_FOO);
442    message.setDefaultImportEnum (ImportEnum.IMPORT_FOO);
443
444    message.setDefaultStringPiece("424");
445    message.setDefaultCord("425");
446  }
447
448  // -------------------------------------------------------------------
449
450  /**
451   * Modify the repeated fields of {@code message} to contain the values
452   * expected by {@code assertRepeatedFieldsModified()}.
453   */
454  public static void modifyRepeatedFields(TestAllTypes.Builder message) {
455    message.setRepeatedInt32   (1, 501);
456    message.setRepeatedInt64   (1, 502);
457    message.setRepeatedUint32  (1, 503);
458    message.setRepeatedUint64  (1, 504);
459    message.setRepeatedSint32  (1, 505);
460    message.setRepeatedSint64  (1, 506);
461    message.setRepeatedFixed32 (1, 507);
462    message.setRepeatedFixed64 (1, 508);
463    message.setRepeatedSfixed32(1, 509);
464    message.setRepeatedSfixed64(1, 510);
465    message.setRepeatedFloat   (1, 511);
466    message.setRepeatedDouble  (1, 512);
467    message.setRepeatedBool    (1, true);
468    message.setRepeatedString  (1, "515");
469    message.setRepeatedBytes   (1, toBytes("516"));
470
471    message.setRepeatedGroup(1,
472      TestAllTypes.RepeatedGroup.newBuilder().setA(517).build());
473    message.setRepeatedNestedMessage(1,
474      TestAllTypes.NestedMessage.newBuilder().setBb(518).build());
475    message.setRepeatedForeignMessage(1,
476      ForeignMessage.newBuilder().setC(519).build());
477    message.setRepeatedImportMessage(1,
478      ImportMessage.newBuilder().setD(520).build());
479
480    message.setRepeatedNestedEnum (1, TestAllTypes.NestedEnum.FOO);
481    message.setRepeatedForeignEnum(1, ForeignEnum.FOREIGN_FOO);
482    message.setRepeatedImportEnum (1, ImportEnum.IMPORT_FOO);
483
484    message.setRepeatedStringPiece(1, "524");
485    message.setRepeatedCord(1, "525");
486  }
487
488  // -------------------------------------------------------------------
489
490  /**
491   * Assert (using {@code junit.framework.Assert}} that all fields of
492   * {@code message} are set to the values assigned by {@code setAllFields}.
493   */
494  public static void assertAllFieldsSet(TestAllTypesOrBuilder message) {
495    Assert.assertTrue(message.hasOptionalInt32   ());
496    Assert.assertTrue(message.hasOptionalInt64   ());
497    Assert.assertTrue(message.hasOptionalUint32  ());
498    Assert.assertTrue(message.hasOptionalUint64  ());
499    Assert.assertTrue(message.hasOptionalSint32  ());
500    Assert.assertTrue(message.hasOptionalSint64  ());
501    Assert.assertTrue(message.hasOptionalFixed32 ());
502    Assert.assertTrue(message.hasOptionalFixed64 ());
503    Assert.assertTrue(message.hasOptionalSfixed32());
504    Assert.assertTrue(message.hasOptionalSfixed64());
505    Assert.assertTrue(message.hasOptionalFloat   ());
506    Assert.assertTrue(message.hasOptionalDouble  ());
507    Assert.assertTrue(message.hasOptionalBool    ());
508    Assert.assertTrue(message.hasOptionalString  ());
509    Assert.assertTrue(message.hasOptionalBytes   ());
510
511    Assert.assertTrue(message.hasOptionalGroup         ());
512    Assert.assertTrue(message.hasOptionalNestedMessage ());
513    Assert.assertTrue(message.hasOptionalForeignMessage());
514    Assert.assertTrue(message.hasOptionalImportMessage ());
515
516    Assert.assertTrue(message.getOptionalGroup         ().hasA());
517    Assert.assertTrue(message.getOptionalNestedMessage ().hasBb());
518    Assert.assertTrue(message.getOptionalForeignMessage().hasC());
519    Assert.assertTrue(message.getOptionalImportMessage ().hasD());
520
521    Assert.assertTrue(message.hasOptionalNestedEnum ());
522    Assert.assertTrue(message.hasOptionalForeignEnum());
523    Assert.assertTrue(message.hasOptionalImportEnum ());
524
525    Assert.assertTrue(message.hasOptionalStringPiece());
526    Assert.assertTrue(message.hasOptionalCord());
527
528    Assert.assertEquals(101  , message.getOptionalInt32   ());
529    Assert.assertEquals(102  , message.getOptionalInt64   ());
530    Assert.assertEquals(103  , message.getOptionalUint32  ());
531    Assert.assertEquals(104  , message.getOptionalUint64  ());
532    Assert.assertEquals(105  , message.getOptionalSint32  ());
533    Assert.assertEquals(106  , message.getOptionalSint64  ());
534    Assert.assertEquals(107  , message.getOptionalFixed32 ());
535    Assert.assertEquals(108  , message.getOptionalFixed64 ());
536    Assert.assertEquals(109  , message.getOptionalSfixed32());
537    Assert.assertEquals(110  , message.getOptionalSfixed64());
538    Assert.assertEquals(111  , message.getOptionalFloat   (), 0.0);
539    Assert.assertEquals(112  , message.getOptionalDouble  (), 0.0);
540    Assert.assertEquals(true , message.getOptionalBool    ());
541    Assert.assertEquals("115", message.getOptionalString  ());
542    Assert.assertEquals(toBytes("116"), message.getOptionalBytes());
543
544    Assert.assertEquals(117, message.getOptionalGroup         ().getA());
545    Assert.assertEquals(118, message.getOptionalNestedMessage ().getBb());
546    Assert.assertEquals(119, message.getOptionalForeignMessage().getC());
547    Assert.assertEquals(120, message.getOptionalImportMessage ().getD());
548
549    Assert.assertEquals(TestAllTypes.NestedEnum.BAZ, message.getOptionalNestedEnum());
550    Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getOptionalForeignEnum());
551    Assert.assertEquals(ImportEnum.IMPORT_BAZ, message.getOptionalImportEnum());
552
553    Assert.assertEquals("124", message.getOptionalStringPiece());
554    Assert.assertEquals("125", message.getOptionalCord());
555
556    // -----------------------------------------------------------------
557
558    Assert.assertEquals(2, message.getRepeatedInt32Count   ());
559    Assert.assertEquals(2, message.getRepeatedInt64Count   ());
560    Assert.assertEquals(2, message.getRepeatedUint32Count  ());
561    Assert.assertEquals(2, message.getRepeatedUint64Count  ());
562    Assert.assertEquals(2, message.getRepeatedSint32Count  ());
563    Assert.assertEquals(2, message.getRepeatedSint64Count  ());
564    Assert.assertEquals(2, message.getRepeatedFixed32Count ());
565    Assert.assertEquals(2, message.getRepeatedFixed64Count ());
566    Assert.assertEquals(2, message.getRepeatedSfixed32Count());
567    Assert.assertEquals(2, message.getRepeatedSfixed64Count());
568    Assert.assertEquals(2, message.getRepeatedFloatCount   ());
569    Assert.assertEquals(2, message.getRepeatedDoubleCount  ());
570    Assert.assertEquals(2, message.getRepeatedBoolCount    ());
571    Assert.assertEquals(2, message.getRepeatedStringCount  ());
572    Assert.assertEquals(2, message.getRepeatedBytesCount   ());
573
574    Assert.assertEquals(2, message.getRepeatedGroupCount         ());
575    Assert.assertEquals(2, message.getRepeatedNestedMessageCount ());
576    Assert.assertEquals(2, message.getRepeatedForeignMessageCount());
577    Assert.assertEquals(2, message.getRepeatedImportMessageCount ());
578    Assert.assertEquals(2, message.getRepeatedNestedEnumCount    ());
579    Assert.assertEquals(2, message.getRepeatedForeignEnumCount   ());
580    Assert.assertEquals(2, message.getRepeatedImportEnumCount    ());
581
582    Assert.assertEquals(2, message.getRepeatedStringPieceCount());
583    Assert.assertEquals(2, message.getRepeatedCordCount());
584
585    Assert.assertEquals(201  , message.getRepeatedInt32   (0));
586    Assert.assertEquals(202  , message.getRepeatedInt64   (0));
587    Assert.assertEquals(203  , message.getRepeatedUint32  (0));
588    Assert.assertEquals(204  , message.getRepeatedUint64  (0));
589    Assert.assertEquals(205  , message.getRepeatedSint32  (0));
590    Assert.assertEquals(206  , message.getRepeatedSint64  (0));
591    Assert.assertEquals(207  , message.getRepeatedFixed32 (0));
592    Assert.assertEquals(208  , message.getRepeatedFixed64 (0));
593    Assert.assertEquals(209  , message.getRepeatedSfixed32(0));
594    Assert.assertEquals(210  , message.getRepeatedSfixed64(0));
595    Assert.assertEquals(211  , message.getRepeatedFloat   (0), 0.0);
596    Assert.assertEquals(212  , message.getRepeatedDouble  (0), 0.0);
597    Assert.assertEquals(true , message.getRepeatedBool    (0));
598    Assert.assertEquals("215", message.getRepeatedString  (0));
599    Assert.assertEquals(toBytes("216"), message.getRepeatedBytes(0));
600
601    Assert.assertEquals(217, message.getRepeatedGroup         (0).getA());
602    Assert.assertEquals(218, message.getRepeatedNestedMessage (0).getBb());
603    Assert.assertEquals(219, message.getRepeatedForeignMessage(0).getC());
604    Assert.assertEquals(220, message.getRepeatedImportMessage (0).getD());
605
606    Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getRepeatedNestedEnum (0));
607    Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getRepeatedForeignEnum(0));
608    Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getRepeatedImportEnum(0));
609
610    Assert.assertEquals("224", message.getRepeatedStringPiece(0));
611    Assert.assertEquals("225", message.getRepeatedCord(0));
612
613    Assert.assertEquals(301  , message.getRepeatedInt32   (1));
614    Assert.assertEquals(302  , message.getRepeatedInt64   (1));
615    Assert.assertEquals(303  , message.getRepeatedUint32  (1));
616    Assert.assertEquals(304  , message.getRepeatedUint64  (1));
617    Assert.assertEquals(305  , message.getRepeatedSint32  (1));
618    Assert.assertEquals(306  , message.getRepeatedSint64  (1));
619    Assert.assertEquals(307  , message.getRepeatedFixed32 (1));
620    Assert.assertEquals(308  , message.getRepeatedFixed64 (1));
621    Assert.assertEquals(309  , message.getRepeatedSfixed32(1));
622    Assert.assertEquals(310  , message.getRepeatedSfixed64(1));
623    Assert.assertEquals(311  , message.getRepeatedFloat   (1), 0.0);
624    Assert.assertEquals(312  , message.getRepeatedDouble  (1), 0.0);
625    Assert.assertEquals(false, message.getRepeatedBool    (1));
626    Assert.assertEquals("315", message.getRepeatedString  (1));
627    Assert.assertEquals(toBytes("316"), message.getRepeatedBytes(1));
628
629    Assert.assertEquals(317, message.getRepeatedGroup         (1).getA());
630    Assert.assertEquals(318, message.getRepeatedNestedMessage (1).getBb());
631    Assert.assertEquals(319, message.getRepeatedForeignMessage(1).getC());
632    Assert.assertEquals(320, message.getRepeatedImportMessage (1).getD());
633
634    Assert.assertEquals(TestAllTypes.NestedEnum.BAZ, message.getRepeatedNestedEnum (1));
635    Assert.assertEquals(ForeignEnum.FOREIGN_BAZ, message.getRepeatedForeignEnum(1));
636    Assert.assertEquals(ImportEnum.IMPORT_BAZ, message.getRepeatedImportEnum(1));
637
638    Assert.assertEquals("324", message.getRepeatedStringPiece(1));
639    Assert.assertEquals("325", message.getRepeatedCord(1));
640
641    // -----------------------------------------------------------------
642
643    Assert.assertTrue(message.hasDefaultInt32   ());
644    Assert.assertTrue(message.hasDefaultInt64   ());
645    Assert.assertTrue(message.hasDefaultUint32  ());
646    Assert.assertTrue(message.hasDefaultUint64  ());
647    Assert.assertTrue(message.hasDefaultSint32  ());
648    Assert.assertTrue(message.hasDefaultSint64  ());
649    Assert.assertTrue(message.hasDefaultFixed32 ());
650    Assert.assertTrue(message.hasDefaultFixed64 ());
651    Assert.assertTrue(message.hasDefaultSfixed32());
652    Assert.assertTrue(message.hasDefaultSfixed64());
653    Assert.assertTrue(message.hasDefaultFloat   ());
654    Assert.assertTrue(message.hasDefaultDouble  ());
655    Assert.assertTrue(message.hasDefaultBool    ());
656    Assert.assertTrue(message.hasDefaultString  ());
657    Assert.assertTrue(message.hasDefaultBytes   ());
658
659    Assert.assertTrue(message.hasDefaultNestedEnum ());
660    Assert.assertTrue(message.hasDefaultForeignEnum());
661    Assert.assertTrue(message.hasDefaultImportEnum ());
662
663    Assert.assertTrue(message.hasDefaultStringPiece());
664    Assert.assertTrue(message.hasDefaultCord());
665
666    Assert.assertEquals(401  , message.getDefaultInt32   ());
667    Assert.assertEquals(402  , message.getDefaultInt64   ());
668    Assert.assertEquals(403  , message.getDefaultUint32  ());
669    Assert.assertEquals(404  , message.getDefaultUint64  ());
670    Assert.assertEquals(405  , message.getDefaultSint32  ());
671    Assert.assertEquals(406  , message.getDefaultSint64  ());
672    Assert.assertEquals(407  , message.getDefaultFixed32 ());
673    Assert.assertEquals(408  , message.getDefaultFixed64 ());
674    Assert.assertEquals(409  , message.getDefaultSfixed32());
675    Assert.assertEquals(410  , message.getDefaultSfixed64());
676    Assert.assertEquals(411  , message.getDefaultFloat   (), 0.0);
677    Assert.assertEquals(412  , message.getDefaultDouble  (), 0.0);
678    Assert.assertEquals(false, message.getDefaultBool    ());
679    Assert.assertEquals("415", message.getDefaultString  ());
680    Assert.assertEquals(toBytes("416"), message.getDefaultBytes());
681
682    Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getDefaultNestedEnum ());
683    Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getDefaultForeignEnum());
684    Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getDefaultImportEnum());
685
686    Assert.assertEquals("424", message.getDefaultStringPiece());
687    Assert.assertEquals("425", message.getDefaultCord());
688  }
689
690  // -------------------------------------------------------------------
691  /**
692   * Assert (using {@code junit.framework.Assert}} that all fields of
693   * {@code message} are cleared, and that getting the fields returns their
694   * default values.
695   */
696  public static void assertClear(TestAllTypesOrBuilder message) {
697    // hasBlah() should initially be false for all optional fields.
698    Assert.assertFalse(message.hasOptionalInt32   ());
699    Assert.assertFalse(message.hasOptionalInt64   ());
700    Assert.assertFalse(message.hasOptionalUint32  ());
701    Assert.assertFalse(message.hasOptionalUint64  ());
702    Assert.assertFalse(message.hasOptionalSint32  ());
703    Assert.assertFalse(message.hasOptionalSint64  ());
704    Assert.assertFalse(message.hasOptionalFixed32 ());
705    Assert.assertFalse(message.hasOptionalFixed64 ());
706    Assert.assertFalse(message.hasOptionalSfixed32());
707    Assert.assertFalse(message.hasOptionalSfixed64());
708    Assert.assertFalse(message.hasOptionalFloat   ());
709    Assert.assertFalse(message.hasOptionalDouble  ());
710    Assert.assertFalse(message.hasOptionalBool    ());
711    Assert.assertFalse(message.hasOptionalString  ());
712    Assert.assertFalse(message.hasOptionalBytes   ());
713
714    Assert.assertFalse(message.hasOptionalGroup         ());
715    Assert.assertFalse(message.hasOptionalNestedMessage ());
716    Assert.assertFalse(message.hasOptionalForeignMessage());
717    Assert.assertFalse(message.hasOptionalImportMessage ());
718
719    Assert.assertFalse(message.hasOptionalNestedEnum ());
720    Assert.assertFalse(message.hasOptionalForeignEnum());
721    Assert.assertFalse(message.hasOptionalImportEnum ());
722
723    Assert.assertFalse(message.hasOptionalStringPiece());
724    Assert.assertFalse(message.hasOptionalCord());
725
726    // Optional fields without defaults are set to zero or something like it.
727    Assert.assertEquals(0    , message.getOptionalInt32   ());
728    Assert.assertEquals(0    , message.getOptionalInt64   ());
729    Assert.assertEquals(0    , message.getOptionalUint32  ());
730    Assert.assertEquals(0    , message.getOptionalUint64  ());
731    Assert.assertEquals(0    , message.getOptionalSint32  ());
732    Assert.assertEquals(0    , message.getOptionalSint64  ());
733    Assert.assertEquals(0    , message.getOptionalFixed32 ());
734    Assert.assertEquals(0    , message.getOptionalFixed64 ());
735    Assert.assertEquals(0    , message.getOptionalSfixed32());
736    Assert.assertEquals(0    , message.getOptionalSfixed64());
737    Assert.assertEquals(0    , message.getOptionalFloat   (), 0.0);
738    Assert.assertEquals(0    , message.getOptionalDouble  (), 0.0);
739    Assert.assertEquals(false, message.getOptionalBool    ());
740    Assert.assertEquals(""   , message.getOptionalString  ());
741    Assert.assertEquals(ByteString.EMPTY, message.getOptionalBytes());
742
743    // Embedded messages should also be clear.
744    Assert.assertFalse(message.getOptionalGroup         ().hasA());
745    Assert.assertFalse(message.getOptionalNestedMessage ().hasBb());
746    Assert.assertFalse(message.getOptionalForeignMessage().hasC());
747    Assert.assertFalse(message.getOptionalImportMessage ().hasD());
748
749    Assert.assertEquals(0, message.getOptionalGroup         ().getA());
750    Assert.assertEquals(0, message.getOptionalNestedMessage ().getBb());
751    Assert.assertEquals(0, message.getOptionalForeignMessage().getC());
752    Assert.assertEquals(0, message.getOptionalImportMessage ().getD());
753
754    // Enums without defaults are set to the first value in the enum.
755    Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getOptionalNestedEnum ());
756    Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getOptionalForeignEnum());
757    Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getOptionalImportEnum());
758
759    Assert.assertEquals("", message.getOptionalStringPiece());
760    Assert.assertEquals("", message.getOptionalCord());
761
762    // Repeated fields are empty.
763    Assert.assertEquals(0, message.getRepeatedInt32Count   ());
764    Assert.assertEquals(0, message.getRepeatedInt64Count   ());
765    Assert.assertEquals(0, message.getRepeatedUint32Count  ());
766    Assert.assertEquals(0, message.getRepeatedUint64Count  ());
767    Assert.assertEquals(0, message.getRepeatedSint32Count  ());
768    Assert.assertEquals(0, message.getRepeatedSint64Count  ());
769    Assert.assertEquals(0, message.getRepeatedFixed32Count ());
770    Assert.assertEquals(0, message.getRepeatedFixed64Count ());
771    Assert.assertEquals(0, message.getRepeatedSfixed32Count());
772    Assert.assertEquals(0, message.getRepeatedSfixed64Count());
773    Assert.assertEquals(0, message.getRepeatedFloatCount   ());
774    Assert.assertEquals(0, message.getRepeatedDoubleCount  ());
775    Assert.assertEquals(0, message.getRepeatedBoolCount    ());
776    Assert.assertEquals(0, message.getRepeatedStringCount  ());
777    Assert.assertEquals(0, message.getRepeatedBytesCount   ());
778
779    Assert.assertEquals(0, message.getRepeatedGroupCount         ());
780    Assert.assertEquals(0, message.getRepeatedNestedMessageCount ());
781    Assert.assertEquals(0, message.getRepeatedForeignMessageCount());
782    Assert.assertEquals(0, message.getRepeatedImportMessageCount ());
783    Assert.assertEquals(0, message.getRepeatedNestedEnumCount    ());
784    Assert.assertEquals(0, message.getRepeatedForeignEnumCount   ());
785    Assert.assertEquals(0, message.getRepeatedImportEnumCount    ());
786
787    Assert.assertEquals(0, message.getRepeatedStringPieceCount());
788    Assert.assertEquals(0, message.getRepeatedCordCount());
789
790    // hasBlah() should also be false for all default fields.
791    Assert.assertFalse(message.hasDefaultInt32   ());
792    Assert.assertFalse(message.hasDefaultInt64   ());
793    Assert.assertFalse(message.hasDefaultUint32  ());
794    Assert.assertFalse(message.hasDefaultUint64  ());
795    Assert.assertFalse(message.hasDefaultSint32  ());
796    Assert.assertFalse(message.hasDefaultSint64  ());
797    Assert.assertFalse(message.hasDefaultFixed32 ());
798    Assert.assertFalse(message.hasDefaultFixed64 ());
799    Assert.assertFalse(message.hasDefaultSfixed32());
800    Assert.assertFalse(message.hasDefaultSfixed64());
801    Assert.assertFalse(message.hasDefaultFloat   ());
802    Assert.assertFalse(message.hasDefaultDouble  ());
803    Assert.assertFalse(message.hasDefaultBool    ());
804    Assert.assertFalse(message.hasDefaultString  ());
805    Assert.assertFalse(message.hasDefaultBytes   ());
806
807    Assert.assertFalse(message.hasDefaultNestedEnum ());
808    Assert.assertFalse(message.hasDefaultForeignEnum());
809    Assert.assertFalse(message.hasDefaultImportEnum ());
810
811    Assert.assertFalse(message.hasDefaultStringPiece());
812    Assert.assertFalse(message.hasDefaultCord());
813
814    // Fields with defaults have their default values (duh).
815    Assert.assertEquals( 41    , message.getDefaultInt32   ());
816    Assert.assertEquals( 42    , message.getDefaultInt64   ());
817    Assert.assertEquals( 43    , message.getDefaultUint32  ());
818    Assert.assertEquals( 44    , message.getDefaultUint64  ());
819    Assert.assertEquals(-45    , message.getDefaultSint32  ());
820    Assert.assertEquals( 46    , message.getDefaultSint64  ());
821    Assert.assertEquals( 47    , message.getDefaultFixed32 ());
822    Assert.assertEquals( 48    , message.getDefaultFixed64 ());
823    Assert.assertEquals( 49    , message.getDefaultSfixed32());
824    Assert.assertEquals(-50    , message.getDefaultSfixed64());
825    Assert.assertEquals( 51.5  , message.getDefaultFloat   (), 0.0);
826    Assert.assertEquals( 52e3  , message.getDefaultDouble  (), 0.0);
827    Assert.assertEquals(true   , message.getDefaultBool    ());
828    Assert.assertEquals("hello", message.getDefaultString  ());
829    Assert.assertEquals(toBytes("world"), message.getDefaultBytes());
830
831    Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getDefaultNestedEnum ());
832    Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getDefaultForeignEnum());
833    Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getDefaultImportEnum());
834
835    Assert.assertEquals("abc", message.getDefaultStringPiece());
836    Assert.assertEquals("123", message.getDefaultCord());
837  }
838
839  // -------------------------------------------------------------------
840
841  /**
842   * Assert (using {@code junit.framework.Assert}} that all fields of
843   * {@code message} are set to the values assigned by {@code setAllFields}
844   * followed by {@code modifyRepeatedFields}.
845   */
846  public static void assertRepeatedFieldsModified(
847      TestAllTypesOrBuilder message) {
848    // ModifyRepeatedFields only sets the second repeated element of each
849    // field.  In addition to verifying this, we also verify that the first
850    // element and size were *not* modified.
851    Assert.assertEquals(2, message.getRepeatedInt32Count   ());
852    Assert.assertEquals(2, message.getRepeatedInt64Count   ());
853    Assert.assertEquals(2, message.getRepeatedUint32Count  ());
854    Assert.assertEquals(2, message.getRepeatedUint64Count  ());
855    Assert.assertEquals(2, message.getRepeatedSint32Count  ());
856    Assert.assertEquals(2, message.getRepeatedSint64Count  ());
857    Assert.assertEquals(2, message.getRepeatedFixed32Count ());
858    Assert.assertEquals(2, message.getRepeatedFixed64Count ());
859    Assert.assertEquals(2, message.getRepeatedSfixed32Count());
860    Assert.assertEquals(2, message.getRepeatedSfixed64Count());
861    Assert.assertEquals(2, message.getRepeatedFloatCount   ());
862    Assert.assertEquals(2, message.getRepeatedDoubleCount  ());
863    Assert.assertEquals(2, message.getRepeatedBoolCount    ());
864    Assert.assertEquals(2, message.getRepeatedStringCount  ());
865    Assert.assertEquals(2, message.getRepeatedBytesCount   ());
866
867    Assert.assertEquals(2, message.getRepeatedGroupCount         ());
868    Assert.assertEquals(2, message.getRepeatedNestedMessageCount ());
869    Assert.assertEquals(2, message.getRepeatedForeignMessageCount());
870    Assert.assertEquals(2, message.getRepeatedImportMessageCount ());
871    Assert.assertEquals(2, message.getRepeatedNestedEnumCount    ());
872    Assert.assertEquals(2, message.getRepeatedForeignEnumCount   ());
873    Assert.assertEquals(2, message.getRepeatedImportEnumCount    ());
874
875    Assert.assertEquals(2, message.getRepeatedStringPieceCount());
876    Assert.assertEquals(2, message.getRepeatedCordCount());
877
878    Assert.assertEquals(201  , message.getRepeatedInt32   (0));
879    Assert.assertEquals(202L , message.getRepeatedInt64   (0));
880    Assert.assertEquals(203  , message.getRepeatedUint32  (0));
881    Assert.assertEquals(204L , message.getRepeatedUint64  (0));
882    Assert.assertEquals(205  , message.getRepeatedSint32  (0));
883    Assert.assertEquals(206L , message.getRepeatedSint64  (0));
884    Assert.assertEquals(207  , message.getRepeatedFixed32 (0));
885    Assert.assertEquals(208L , message.getRepeatedFixed64 (0));
886    Assert.assertEquals(209  , message.getRepeatedSfixed32(0));
887    Assert.assertEquals(210L , message.getRepeatedSfixed64(0));
888    Assert.assertEquals(211F , message.getRepeatedFloat   (0));
889    Assert.assertEquals(212D , message.getRepeatedDouble  (0));
890    Assert.assertEquals(true , message.getRepeatedBool    (0));
891    Assert.assertEquals("215", message.getRepeatedString  (0));
892    Assert.assertEquals(toBytes("216"), message.getRepeatedBytes(0));
893
894    Assert.assertEquals(217, message.getRepeatedGroup         (0).getA());
895    Assert.assertEquals(218, message.getRepeatedNestedMessage (0).getBb());
896    Assert.assertEquals(219, message.getRepeatedForeignMessage(0).getC());
897    Assert.assertEquals(220, message.getRepeatedImportMessage (0).getD());
898
899    Assert.assertEquals(TestAllTypes.NestedEnum.BAR, message.getRepeatedNestedEnum (0));
900    Assert.assertEquals(ForeignEnum.FOREIGN_BAR, message.getRepeatedForeignEnum(0));
901    Assert.assertEquals(ImportEnum.IMPORT_BAR, message.getRepeatedImportEnum(0));
902
903    Assert.assertEquals("224", message.getRepeatedStringPiece(0));
904    Assert.assertEquals("225", message.getRepeatedCord(0));
905
906    // Actually verify the second (modified) elements now.
907    Assert.assertEquals(501  , message.getRepeatedInt32   (1));
908    Assert.assertEquals(502L , message.getRepeatedInt64   (1));
909    Assert.assertEquals(503  , message.getRepeatedUint32  (1));
910    Assert.assertEquals(504L , message.getRepeatedUint64  (1));
911    Assert.assertEquals(505  , message.getRepeatedSint32  (1));
912    Assert.assertEquals(506L , message.getRepeatedSint64  (1));
913    Assert.assertEquals(507  , message.getRepeatedFixed32 (1));
914    Assert.assertEquals(508L , message.getRepeatedFixed64 (1));
915    Assert.assertEquals(509  , message.getRepeatedSfixed32(1));
916    Assert.assertEquals(510L , message.getRepeatedSfixed64(1));
917    Assert.assertEquals(511F , message.getRepeatedFloat   (1));
918    Assert.assertEquals(512D , message.getRepeatedDouble  (1));
919    Assert.assertEquals(true , message.getRepeatedBool    (1));
920    Assert.assertEquals("515", message.getRepeatedString  (1));
921    Assert.assertEquals(toBytes("516"), message.getRepeatedBytes(1));
922
923    Assert.assertEquals(517, message.getRepeatedGroup         (1).getA());
924    Assert.assertEquals(518, message.getRepeatedNestedMessage (1).getBb());
925    Assert.assertEquals(519, message.getRepeatedForeignMessage(1).getC());
926    Assert.assertEquals(520, message.getRepeatedImportMessage (1).getD());
927
928    Assert.assertEquals(TestAllTypes.NestedEnum.FOO, message.getRepeatedNestedEnum (1));
929    Assert.assertEquals(ForeignEnum.FOREIGN_FOO, message.getRepeatedForeignEnum(1));
930    Assert.assertEquals(ImportEnum.IMPORT_FOO, message.getRepeatedImportEnum(1));
931
932    Assert.assertEquals("524", message.getRepeatedStringPiece(1));
933    Assert.assertEquals("525", message.getRepeatedCord(1));
934  }
935
936  /**
937   * Set every field of {@code message} to a unique value.
938   */
939  public static void setPackedFields(TestPackedTypes.Builder message) {
940    message.addPackedInt32   (601);
941    message.addPackedInt64   (602);
942    message.addPackedUint32  (603);
943    message.addPackedUint64  (604);
944    message.addPackedSint32  (605);
945    message.addPackedSint64  (606);
946    message.addPackedFixed32 (607);
947    message.addPackedFixed64 (608);
948    message.addPackedSfixed32(609);
949    message.addPackedSfixed64(610);
950    message.addPackedFloat   (611);
951    message.addPackedDouble  (612);
952    message.addPackedBool    (true);
953    message.addPackedEnum    (ForeignEnum.FOREIGN_BAR);
954    // Add a second one of each field.
955    message.addPackedInt32   (701);
956    message.addPackedInt64   (702);
957    message.addPackedUint32  (703);
958    message.addPackedUint64  (704);
959    message.addPacked

Large files files are truncated, but you can click here to view the full file