public void testHugeFieldNumbers() throws InvalidProtocolBufferException { TestHugeFieldNumbersLite message = TestHugeFieldNumbersLite.newBuilder() .setOptionalInt32(1) .addRepeatedInt32(2) .setOptionalEnum(ForeignEnumLite.FOREIGN_LITE_FOO) .setOptionalString("xyz") .setOptionalMessage(ForeignMessageLite.newBuilder().setC(3).build()) .build(); TestHugeFieldNumbersLite parsedMessage = TestHugeFieldNumbersLite.parseFrom(message.toByteArray()); assertEquals(1, parsedMessage.getOptionalInt32()); assertEquals(2, parsedMessage.getRepeatedInt32(0)); assertEquals(ForeignEnumLite.FOREIGN_LITE_FOO, parsedMessage.getOptionalEnum()); assertEquals("xyz", parsedMessage.getOptionalString()); assertEquals(3, parsedMessage.getOptionalMessage().getC()); }
/** * Modify the repeated extensions of {@code message} to contain the values * expected by {@code assertRepeatedExtensionsModified()}. */ public static void modifyRepeatedExtensions( TestAllExtensionsLite.Builder message) { message.setExtension(repeatedInt32ExtensionLite , 1, 501); message.setExtension(repeatedInt64ExtensionLite , 1, 502L); message.setExtension(repeatedUint32ExtensionLite , 1, 503); message.setExtension(repeatedUint64ExtensionLite , 1, 504L); message.setExtension(repeatedSint32ExtensionLite , 1, 505); message.setExtension(repeatedSint64ExtensionLite , 1, 506L); message.setExtension(repeatedFixed32ExtensionLite , 1, 507); message.setExtension(repeatedFixed64ExtensionLite , 1, 508L); message.setExtension(repeatedSfixed32ExtensionLite, 1, 509); message.setExtension(repeatedSfixed64ExtensionLite, 1, 510L); message.setExtension(repeatedFloatExtensionLite , 1, 511F); message.setExtension(repeatedDoubleExtensionLite , 1, 512D); message.setExtension(repeatedBoolExtensionLite , 1, true); message.setExtension(repeatedStringExtensionLite , 1, "515"); message.setExtension(repeatedBytesExtensionLite , 1, toBytes("516")); message.setExtension(repeatedGroupExtensionLite, 1, RepeatedGroup_extension_lite.newBuilder().setA(517).build()); message.setExtension(repeatedNestedMessageExtensionLite, 1, TestAllTypesLite.NestedMessage.newBuilder().setBb(518).build()); message.setExtension(repeatedForeignMessageExtensionLite, 1, ForeignMessageLite.newBuilder().setC(519).build()); message.setExtension(repeatedImportMessageExtensionLite, 1, ImportMessageLite.newBuilder().setD(520).build()); message.setExtension(repeatedNestedEnumExtensionLite , 1, TestAllTypesLite.NestedEnum.FOO); message.setExtension(repeatedForeignEnumExtensionLite, 1, ForeignEnumLite.FOREIGN_LITE_FOO); message.setExtension(repeatedImportEnumExtensionLite , 1, ImportEnumLite.IMPORT_LITE_FOO); message.setExtension(repeatedStringPieceExtensionLite, 1, "524"); message.setExtension(repeatedCordExtensionLite, 1, "525"); }
/** * Modify the repeated extensions of {@code message} to contain the values * expected by {@code assertRepeatedExtensionsModified()}. */ public static void modifyRepeatedExtensions( TestAllExtensionsLite.Builder message) { message.setExtension(repeatedInt32ExtensionLite , 1, 501); message.setExtension(repeatedInt64ExtensionLite , 1, 502L); message.setExtension(repeatedUint32ExtensionLite , 1, 503); message.setExtension(repeatedUint64ExtensionLite , 1, 504L); message.setExtension(repeatedSint32ExtensionLite , 1, 505); message.setExtension(repeatedSint64ExtensionLite , 1, 506L); message.setExtension(repeatedFixed32ExtensionLite , 1, 507); message.setExtension(repeatedFixed64ExtensionLite , 1, 508L); message.setExtension(repeatedSfixed32ExtensionLite, 1, 509); message.setExtension(repeatedSfixed64ExtensionLite, 1, 510L); message.setExtension(repeatedFloatExtensionLite , 1, 511F); message.setExtension(repeatedDoubleExtensionLite , 1, 512D); message.setExtension(repeatedBoolExtensionLite , 1, true); message.setExtension(repeatedStringExtensionLite , 1, "515"); message.setExtension(repeatedBytesExtensionLite , 1, toBytes("516")); message.setExtension(repeatedGroupExtensionLite, 1, RepeatedGroup_extension_lite.newBuilder().setA(517).build()); message.setExtension(repeatedNestedMessageExtensionLite, 1, TestAllTypesLite.NestedMessage.newBuilder().setBb(518).build()); message.setExtension(repeatedForeignMessageExtensionLite, 1, ForeignMessageLite.newBuilder().setC(519).build()); message.setExtension(repeatedImportMessageExtensionLite, 1, ImportMessageLite.newBuilder().setD(520).build()); message.setExtension(repeatedLazyMessageExtensionLite, 1, TestAllTypesLite.NestedMessage.newBuilder().setBb(527).build()); message.setExtension(repeatedNestedEnumExtensionLite , 1, TestAllTypesLite.NestedEnum.FOO); message.setExtension(repeatedForeignEnumExtensionLite, 1, ForeignEnumLite.FOREIGN_LITE_FOO); message.setExtension(repeatedImportEnumExtensionLite , 1, ImportEnumLite.IMPORT_LITE_FOO); message.setExtension(repeatedStringPieceExtensionLite, 1, "524"); message.setExtension(repeatedCordExtensionLite, 1, "525"); }
public void testToStringForeignFields() throws Exception { TestAllTypesLite proto = TestAllTypesLite.newBuilder() .setOptionalForeignEnum(ForeignEnumLite.FOREIGN_LITE_BAR) .setOptionalForeignMessage( ForeignMessageLite.newBuilder() .setC(3)) .build(); assertToStringEquals( "optional_foreign_enum: FOREIGN_LITE_BAR\noptional_foreign_message {\n c: 3\n}", proto); }