/** * Modify the repeated fields of {@code message} to contain the values * expected by {@code assertRepeatedFieldsModified()}. */ public static void modifyRepeatedFields(TestAllTypes.Builder message) { message.setRepeatedInt32 (1, 501); message.setRepeatedInt64 (1, 502); message.setRepeatedUint32 (1, 503); message.setRepeatedUint64 (1, 504); message.setRepeatedSint32 (1, 505); message.setRepeatedSint64 (1, 506); message.setRepeatedFixed32 (1, 507); message.setRepeatedFixed64 (1, 508); message.setRepeatedSfixed32(1, 509); message.setRepeatedSfixed64(1, 510); message.setRepeatedFloat (1, 511); message.setRepeatedDouble (1, 512); message.setRepeatedBool (1, true); message.setRepeatedString (1, "515"); message.setRepeatedBytes (1, toBytes("516")); message.setRepeatedGroup(1, TestAllTypes.RepeatedGroup.newBuilder().setA(517).build()); message.setRepeatedNestedMessage(1, TestAllTypes.NestedMessage.newBuilder().setBb(518).build()); message.setRepeatedForeignMessage(1, ForeignMessage.newBuilder().setC(519).build()); message.setRepeatedImportMessage(1, ImportMessage.newBuilder().setD(520).build()); message.setRepeatedNestedEnum (1, TestAllTypes.NestedEnum.FOO); message.setRepeatedForeignEnum(1, ForeignEnum.FOREIGN_FOO); message.setRepeatedImportEnum (1, ImportEnum.IMPORT_FOO); message.setRepeatedStringPiece(1, "524"); message.setRepeatedCord(1, "525"); }
/** * Modify the repeated extensions of {@code message} to contain the values * expected by {@code assertRepeatedExtensionsModified()}. */ public static void modifyRepeatedExtensions( TestAllExtensions.Builder message) { message.setExtension(repeatedInt32Extension , 1, 501); message.setExtension(repeatedInt64Extension , 1, 502L); message.setExtension(repeatedUint32Extension , 1, 503); message.setExtension(repeatedUint64Extension , 1, 504L); message.setExtension(repeatedSint32Extension , 1, 505); message.setExtension(repeatedSint64Extension , 1, 506L); message.setExtension(repeatedFixed32Extension , 1, 507); message.setExtension(repeatedFixed64Extension , 1, 508L); message.setExtension(repeatedSfixed32Extension, 1, 509); message.setExtension(repeatedSfixed64Extension, 1, 510L); message.setExtension(repeatedFloatExtension , 1, 511F); message.setExtension(repeatedDoubleExtension , 1, 512D); message.setExtension(repeatedBoolExtension , 1, true); message.setExtension(repeatedStringExtension , 1, "515"); message.setExtension(repeatedBytesExtension , 1, toBytes("516")); message.setExtension(repeatedGroupExtension, 1, RepeatedGroup_extension.newBuilder().setA(517).build()); message.setExtension(repeatedNestedMessageExtension, 1, TestAllTypes.NestedMessage.newBuilder().setBb(518).build()); message.setExtension(repeatedForeignMessageExtension, 1, ForeignMessage.newBuilder().setC(519).build()); message.setExtension(repeatedImportMessageExtension, 1, ImportMessage.newBuilder().setD(520).build()); message.setExtension(repeatedNestedEnumExtension , 1, TestAllTypes.NestedEnum.FOO); message.setExtension(repeatedForeignEnumExtension, 1, ForeignEnum.FOREIGN_FOO); message.setExtension(repeatedImportEnumExtension , 1, ImportEnum.IMPORT_FOO); message.setExtension(repeatedStringPieceExtension, 1, "524"); message.setExtension(repeatedCordExtension, 1, "525"); }
/** * Modify the repeated fields of {@code message} to contain the values * expected by {@code assertRepeatedFieldsModified()}. */ public static void modifyRepeatedFields(TestAllTypes.Builder message) { message.setRepeatedInt32 (1, 501); message.setRepeatedInt64 (1, 502); message.setRepeatedUint32 (1, 503); message.setRepeatedUint64 (1, 504); message.setRepeatedSint32 (1, 505); message.setRepeatedSint64 (1, 506); message.setRepeatedFixed32 (1, 507); message.setRepeatedFixed64 (1, 508); message.setRepeatedSfixed32(1, 509); message.setRepeatedSfixed64(1, 510); message.setRepeatedFloat (1, 511); message.setRepeatedDouble (1, 512); message.setRepeatedBool (1, true); message.setRepeatedString (1, "515"); message.setRepeatedBytes (1, toBytes("516")); message.setRepeatedGroup(1, TestAllTypes.RepeatedGroup.newBuilder().setA(517).build()); message.setRepeatedNestedMessage(1, TestAllTypes.NestedMessage.newBuilder().setBb(518).build()); message.setRepeatedForeignMessage(1, ForeignMessage.newBuilder().setC(519).build()); message.setRepeatedImportMessage(1, ImportMessage.newBuilder().setD(520).build()); message.setRepeatedLazyMessage(1, TestAllTypes.NestedMessage.newBuilder().setBb(527).build()); message.setRepeatedNestedEnum (1, TestAllTypes.NestedEnum.FOO); message.setRepeatedForeignEnum(1, ForeignEnum.FOREIGN_FOO); message.setRepeatedImportEnum (1, ImportEnum.IMPORT_FOO); message.setRepeatedStringPiece(1, "524"); message.setRepeatedCord(1, "525"); }
/** * Modify the repeated extensions of {@code message} to contain the values * expected by {@code assertRepeatedExtensionsModified()}. */ public static void modifyRepeatedExtensions( TestAllExtensions.Builder message) { message.setExtension(repeatedInt32Extension , 1, 501); message.setExtension(repeatedInt64Extension , 1, 502L); message.setExtension(repeatedUint32Extension , 1, 503); message.setExtension(repeatedUint64Extension , 1, 504L); message.setExtension(repeatedSint32Extension , 1, 505); message.setExtension(repeatedSint64Extension , 1, 506L); message.setExtension(repeatedFixed32Extension , 1, 507); message.setExtension(repeatedFixed64Extension , 1, 508L); message.setExtension(repeatedSfixed32Extension, 1, 509); message.setExtension(repeatedSfixed64Extension, 1, 510L); message.setExtension(repeatedFloatExtension , 1, 511F); message.setExtension(repeatedDoubleExtension , 1, 512D); message.setExtension(repeatedBoolExtension , 1, true); message.setExtension(repeatedStringExtension , 1, "515"); message.setExtension(repeatedBytesExtension , 1, toBytes("516")); message.setExtension(repeatedGroupExtension, 1, RepeatedGroup_extension.newBuilder().setA(517).build()); message.setExtension(repeatedNestedMessageExtension, 1, TestAllTypes.NestedMessage.newBuilder().setBb(518).build()); message.setExtension(repeatedForeignMessageExtension, 1, ForeignMessage.newBuilder().setC(519).build()); message.setExtension(repeatedImportMessageExtension, 1, ImportMessage.newBuilder().setD(520).build()); message.setExtension(repeatedLazyMessageExtension, 1, TestAllTypes.NestedMessage.newBuilder().setBb(527).build()); message.setExtension(repeatedNestedEnumExtension , 1, TestAllTypes.NestedEnum.FOO); message.setExtension(repeatedForeignEnumExtension, 1, ForeignEnum.FOREIGN_FOO); message.setExtension(repeatedImportEnumExtension , 1, ImportEnum.IMPORT_FOO); message.setExtension(repeatedStringPieceExtension, 1, "524"); message.setExtension(repeatedCordExtension, 1, "525"); }
private static void assertEqualsExactType(ImportEnum a, ImportEnum b) { Assert.assertEquals(a, b); }
public void testFileDescriptor() throws Exception { FileDescriptor file = UnittestProto.getDescriptor(); assertEquals("google/protobuf/unittest.proto", file.getName()); assertEquals("protobuf_unittest", file.getPackage()); assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname()); assertEquals("google/protobuf/unittest.proto", file.toProto().getName()); assertEquals(Arrays.asList(UnittestImport.getDescriptor()), file.getDependencies()); Descriptor messageType = TestAllTypes.getDescriptor(); assertEquals(messageType, file.getMessageTypes().get(0)); assertEquals(messageType, file.findMessageTypeByName("TestAllTypes")); assertNull(file.findMessageTypeByName("NoSuchType")); assertNull(file.findMessageTypeByName("protobuf_unittest.TestAllTypes")); for (int i = 0; i < file.getMessageTypes().size(); i++) { assertEquals(i, file.getMessageTypes().get(i).getIndex()); } EnumDescriptor enumType = ForeignEnum.getDescriptor(); assertEquals(enumType, file.getEnumTypes().get(0)); assertEquals(enumType, file.findEnumTypeByName("ForeignEnum")); assertNull(file.findEnumTypeByName("NoSuchType")); assertNull(file.findEnumTypeByName("protobuf_unittest.ForeignEnum")); assertEquals(Arrays.asList(ImportEnum.getDescriptor()), UnittestImport.getDescriptor().getEnumTypes()); for (int i = 0; i < file.getEnumTypes().size(); i++) { assertEquals(i, file.getEnumTypes().get(i).getIndex()); } ServiceDescriptor service = TestService.getDescriptor(); assertEquals(service, file.getServices().get(0)); assertEquals(service, file.findServiceByName("TestService")); assertNull(file.findServiceByName("NoSuchType")); assertNull(file.findServiceByName("protobuf_unittest.TestService")); assertEquals(Collections.emptyList(), UnittestImport.getDescriptor().getServices()); for (int i = 0; i < file.getServices().size(); i++) { assertEquals(i, file.getServices().get(i).getIndex()); } FieldDescriptor extension = UnittestProto.optionalInt32Extension.getDescriptor(); assertEquals(extension, file.getExtensions().get(0)); assertEquals(extension, file.findExtensionByName("optional_int32_extension")); assertNull(file.findExtensionByName("no_such_ext")); assertNull(file.findExtensionByName( "protobuf_unittest.optional_int32_extension")); assertEquals(Collections.emptyList(), UnittestImport.getDescriptor().getExtensions()); for (int i = 0; i < file.getExtensions().size(); i++) { assertEquals(i, file.getExtensions().get(i).getIndex()); } }
public void testFileDescriptor() throws Exception { FileDescriptor file = UnittestProto.getDescriptor(); assertEquals("google/protobuf/unittest.proto", file.getName()); assertEquals("protobuf_unittest", file.getPackage()); assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname()); assertEquals("google/protobuf/unittest.proto", file.toProto().getName()); assertEquals(Arrays.asList(UnittestImport.getDescriptor()), file.getDependencies()); Descriptor messageType = TestAllTypes.getDescriptor(); assertEquals(messageType, file.getMessageTypes().get(0)); assertEquals(messageType, file.findMessageTypeByName("TestAllTypes")); assertNull(file.findMessageTypeByName("NoSuchType")); assertNull(file.findMessageTypeByName("protobuf_unittest.TestAllTypes")); for (int i = 0; i < file.getMessageTypes().size(); i++) { assertEquals(i, file.getMessageTypes().get(i).getIndex()); } EnumDescriptor enumType = ForeignEnum.getDescriptor(); assertEquals(enumType, file.getEnumTypes().get(0)); assertEquals(enumType, file.findEnumTypeByName("ForeignEnum")); assertNull(file.findEnumTypeByName("NoSuchType")); assertNull(file.findEnumTypeByName("protobuf_unittest.ForeignEnum")); assertEquals(Arrays.asList(ImportEnum.getDescriptor(), ImportEnumForMap.getDescriptor()), UnittestImport.getDescriptor().getEnumTypes()); for (int i = 0; i < file.getEnumTypes().size(); i++) { assertEquals(i, file.getEnumTypes().get(i).getIndex()); } ServiceDescriptor service = TestService.getDescriptor(); assertEquals(service, file.getServices().get(0)); assertEquals(service, file.findServiceByName("TestService")); assertNull(file.findServiceByName("NoSuchType")); assertNull(file.findServiceByName("protobuf_unittest.TestService")); assertEquals(Collections.emptyList(), UnittestImport.getDescriptor().getServices()); for (int i = 0; i < file.getServices().size(); i++) { assertEquals(i, file.getServices().get(i).getIndex()); } FieldDescriptor extension = UnittestProto.optionalInt32Extension.getDescriptor(); assertEquals(extension, file.getExtensions().get(0)); assertEquals(extension, file.findExtensionByName("optional_int32_extension")); assertNull(file.findExtensionByName("no_such_ext")); assertNull(file.findExtensionByName( "protobuf_unittest.optional_int32_extension")); assertEquals(Collections.emptyList(), UnittestImport.getDescriptor().getExtensions()); for (int i = 0; i < file.getExtensions().size(); i++) { assertEquals(i, file.getExtensions().get(i).getIndex()); } }