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"); }
public static void setPackedExtensions(TestPackedExtensionsLite.Builder message) { message.addExtension(packedInt32ExtensionLite , 601); message.addExtension(packedInt64ExtensionLite , 602L); message.addExtension(packedUint32ExtensionLite , 603); message.addExtension(packedUint64ExtensionLite , 604L); message.addExtension(packedSint32ExtensionLite , 605); message.addExtension(packedSint64ExtensionLite , 606L); message.addExtension(packedFixed32ExtensionLite , 607); message.addExtension(packedFixed64ExtensionLite , 608L); message.addExtension(packedSfixed32ExtensionLite, 609); message.addExtension(packedSfixed64ExtensionLite, 610L); message.addExtension(packedFloatExtensionLite , 611F); message.addExtension(packedDoubleExtensionLite , 612D); message.addExtension(packedBoolExtensionLite , true); message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAR); // Add a second one of each field. message.addExtension(packedInt32ExtensionLite , 701); message.addExtension(packedInt64ExtensionLite , 702L); message.addExtension(packedUint32ExtensionLite , 703); message.addExtension(packedUint64ExtensionLite , 704L); message.addExtension(packedSint32ExtensionLite , 705); message.addExtension(packedSint64ExtensionLite , 706L); message.addExtension(packedFixed32ExtensionLite , 707); message.addExtension(packedFixed64ExtensionLite , 708L); message.addExtension(packedSfixed32ExtensionLite, 709); message.addExtension(packedSfixed64ExtensionLite, 710L); message.addExtension(packedFloatExtensionLite , 711F); message.addExtension(packedDoubleExtensionLite , 712D); message.addExtension(packedBoolExtensionLite , false); message.addExtension(packedEnumExtensionLite, ForeignEnumLite.FOREIGN_LITE_BAZ); }
/** * 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); }
public void testForNumberLite() { ForeignEnumLite e = ForeignEnumLite.forNumber(ForeignEnumLite.FOREIGN_LITE_BAR.getNumber()); assertEquals(ForeignEnumLite.FOREIGN_LITE_BAR, e); e = ForeignEnumLite.forNumber(1000); assertEquals(null, e); }
private static void assertEqualsExactType(ForeignEnumLite a, ForeignEnumLite b) { Assert.assertEquals(a, b); }
public static void assertPackedExtensionsSet(TestPackedExtensionsLite message) { Assert.assertEquals(2, message.getExtensionCount(packedInt32ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedInt64ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedUint32ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedUint64ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedSint32ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedSint64ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedFixed32ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedFixed64ExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedSfixed32ExtensionLite)); Assert.assertEquals(2, message.getExtensionCount(packedSfixed64ExtensionLite)); Assert.assertEquals(2, message.getExtensionCount(packedFloatExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedDoubleExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedBoolExtensionLite )); Assert.assertEquals(2, message.getExtensionCount(packedEnumExtensionLite)); assertEqualsExactType(601 , message.getExtension(packedInt32ExtensionLite , 0)); assertEqualsExactType(602L , message.getExtension(packedInt64ExtensionLite , 0)); assertEqualsExactType(603 , message.getExtension(packedUint32ExtensionLite , 0)); assertEqualsExactType(604L , message.getExtension(packedUint64ExtensionLite , 0)); assertEqualsExactType(605 , message.getExtension(packedSint32ExtensionLite , 0)); assertEqualsExactType(606L , message.getExtension(packedSint64ExtensionLite , 0)); assertEqualsExactType(607 , message.getExtension(packedFixed32ExtensionLite , 0)); assertEqualsExactType(608L , message.getExtension(packedFixed64ExtensionLite , 0)); assertEqualsExactType(609 , message.getExtension(packedSfixed32ExtensionLite, 0)); assertEqualsExactType(610L , message.getExtension(packedSfixed64ExtensionLite, 0)); assertEqualsExactType(611F , message.getExtension(packedFloatExtensionLite , 0)); assertEqualsExactType(612D , message.getExtension(packedDoubleExtensionLite , 0)); assertEqualsExactType(true , message.getExtension(packedBoolExtensionLite , 0)); assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAR, message.getExtension(packedEnumExtensionLite, 0)); assertEqualsExactType(701 , message.getExtension(packedInt32ExtensionLite , 1)); assertEqualsExactType(702L , message.getExtension(packedInt64ExtensionLite , 1)); assertEqualsExactType(703 , message.getExtension(packedUint32ExtensionLite , 1)); assertEqualsExactType(704L , message.getExtension(packedUint64ExtensionLite , 1)); assertEqualsExactType(705 , message.getExtension(packedSint32ExtensionLite , 1)); assertEqualsExactType(706L , message.getExtension(packedSint64ExtensionLite , 1)); assertEqualsExactType(707 , message.getExtension(packedFixed32ExtensionLite , 1)); assertEqualsExactType(708L , message.getExtension(packedFixed64ExtensionLite , 1)); assertEqualsExactType(709 , message.getExtension(packedSfixed32ExtensionLite, 1)); assertEqualsExactType(710L , message.getExtension(packedSfixed64ExtensionLite, 1)); assertEqualsExactType(711F , message.getExtension(packedFloatExtensionLite , 1)); assertEqualsExactType(712D , message.getExtension(packedDoubleExtensionLite , 1)); assertEqualsExactType(false, message.getExtension(packedBoolExtensionLite , 1)); assertEqualsExactType(ForeignEnumLite.FOREIGN_LITE_BAZ, message.getExtension(packedEnumExtensionLite, 1)); }