|
@@ -79,8 +79,7 @@ public class DescriptorsTest extends TestCase {
|
|
|
private static final Object STATIC_INIT_TEST = FieldDescriptor.Type.BOOL;
|
|
|
|
|
|
public void testFieldTypeEnumMapping() throws Exception {
|
|
|
- assertEquals(FieldDescriptor.Type.values().length,
|
|
|
- FieldDescriptorProto.Type.values().length);
|
|
|
+ assertEquals(FieldDescriptor.Type.values().length, FieldDescriptorProto.Type.values().length);
|
|
|
for (FieldDescriptor.Type type : FieldDescriptor.Type.values()) {
|
|
|
FieldDescriptorProto.Type protoType = type.toProto();
|
|
|
assertEquals("TYPE_" + type.name(), protoType.name());
|
|
@@ -95,11 +94,9 @@ public class DescriptorsTest extends TestCase {
|
|
|
assertEquals("protobuf_unittest", file.getPackage());
|
|
|
|
|
|
assertEquals("UnittestProto", file.getOptions().getJavaOuterClassname());
|
|
|
- assertEquals("google/protobuf/unittest.proto",
|
|
|
- file.toProto().getName());
|
|
|
+ assertEquals("google/protobuf/unittest.proto", file.toProto().getName());
|
|
|
|
|
|
- assertEquals(Arrays.asList(UnittestImport.getDescriptor()),
|
|
|
- file.getDependencies());
|
|
|
+ assertEquals(Arrays.asList(UnittestImport.getDescriptor()), file.getDependencies());
|
|
|
|
|
|
Descriptor messageType = TestAllTypes.getDescriptor();
|
|
|
assertEquals(messageType, file.getMessageTypes().get(0));
|
|
@@ -115,9 +112,9 @@ public class DescriptorsTest extends TestCase {
|
|
|
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());
|
|
|
+ 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());
|
|
|
}
|
|
@@ -127,22 +124,17 @@ public class DescriptorsTest extends TestCase {
|
|
|
assertEquals(service, file.findServiceByName("TestService"));
|
|
|
assertNull(file.findServiceByName("NoSuchType"));
|
|
|
assertNull(file.findServiceByName("protobuf_unittest.TestService"));
|
|
|
- assertEquals(Collections.emptyList(),
|
|
|
- UnittestImport.getDescriptor().getServices());
|
|
|
+ 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();
|
|
|
+ FieldDescriptor extension = UnittestProto.optionalInt32Extension.getDescriptor();
|
|
|
assertEquals(extension, file.getExtensions().get(0));
|
|
|
- assertEquals(extension,
|
|
|
- file.findExtensionByName("optional_int32_extension"));
|
|
|
+ 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());
|
|
|
+ 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());
|
|
|
}
|
|
@@ -156,13 +148,11 @@ public class DescriptorsTest extends TestCase {
|
|
|
assertEquals("protobuf_unittest.TestAllTypes", messageType.getFullName());
|
|
|
assertEquals(UnittestProto.getDescriptor(), messageType.getFile());
|
|
|
assertNull(messageType.getContainingType());
|
|
|
- assertEquals(DescriptorProtos.MessageOptions.getDefaultInstance(),
|
|
|
- messageType.getOptions());
|
|
|
+ assertEquals(DescriptorProtos.MessageOptions.getDefaultInstance(), messageType.getOptions());
|
|
|
assertEquals("TestAllTypes", messageType.toProto().getName());
|
|
|
|
|
|
assertEquals("NestedMessage", nestedType.getName());
|
|
|
- assertEquals("protobuf_unittest.TestAllTypes.NestedMessage",
|
|
|
- nestedType.getFullName());
|
|
|
+ assertEquals("protobuf_unittest.TestAllTypes.NestedMessage", nestedType.getFullName());
|
|
|
assertEquals(UnittestProto.getDescriptor(), nestedType.getFile());
|
|
|
assertEquals(messageType, nestedType.getContainingType());
|
|
|
|
|
@@ -194,36 +184,28 @@ public class DescriptorsTest extends TestCase {
|
|
|
|
|
|
public void testFieldDescriptor() throws Exception {
|
|
|
Descriptor messageType = TestAllTypes.getDescriptor();
|
|
|
- FieldDescriptor primitiveField =
|
|
|
- messageType.findFieldByName("optional_int32");
|
|
|
- FieldDescriptor enumField =
|
|
|
- messageType.findFieldByName("optional_nested_enum");
|
|
|
- FieldDescriptor messageField =
|
|
|
- messageType.findFieldByName("optional_foreign_message");
|
|
|
- FieldDescriptor cordField =
|
|
|
- messageType.findFieldByName("optional_cord");
|
|
|
- FieldDescriptor extension =
|
|
|
- UnittestProto.optionalInt32Extension.getDescriptor();
|
|
|
+ FieldDescriptor primitiveField = messageType.findFieldByName("optional_int32");
|
|
|
+ FieldDescriptor enumField = messageType.findFieldByName("optional_nested_enum");
|
|
|
+ FieldDescriptor messageField = messageType.findFieldByName("optional_foreign_message");
|
|
|
+ FieldDescriptor cordField = messageType.findFieldByName("optional_cord");
|
|
|
+ FieldDescriptor extension = UnittestProto.optionalInt32Extension.getDescriptor();
|
|
|
FieldDescriptor nestedExtension = TestRequired.single.getDescriptor();
|
|
|
|
|
|
assertEquals("optional_int32", primitiveField.getName());
|
|
|
- assertEquals("protobuf_unittest.TestAllTypes.optional_int32",
|
|
|
- primitiveField.getFullName());
|
|
|
+ assertEquals("protobuf_unittest.TestAllTypes.optional_int32", primitiveField.getFullName());
|
|
|
assertEquals(1, primitiveField.getNumber());
|
|
|
assertEquals(messageType, primitiveField.getContainingType());
|
|
|
assertEquals(UnittestProto.getDescriptor(), primitiveField.getFile());
|
|
|
assertEquals(FieldDescriptor.Type.INT32, primitiveField.getType());
|
|
|
assertEquals(FieldDescriptor.JavaType.INT, primitiveField.getJavaType());
|
|
|
- assertEquals(DescriptorProtos.FieldOptions.getDefaultInstance(),
|
|
|
- primitiveField.getOptions());
|
|
|
+ assertEquals(DescriptorProtos.FieldOptions.getDefaultInstance(), primitiveField.getOptions());
|
|
|
assertFalse(primitiveField.isExtension());
|
|
|
assertEquals("optional_int32", primitiveField.toProto().getName());
|
|
|
|
|
|
assertEquals("optional_nested_enum", enumField.getName());
|
|
|
assertEquals(FieldDescriptor.Type.ENUM, enumField.getType());
|
|
|
assertEquals(FieldDescriptor.JavaType.ENUM, enumField.getJavaType());
|
|
|
- assertEquals(TestAllTypes.NestedEnum.getDescriptor(),
|
|
|
- enumField.getEnumType());
|
|
|
+ assertEquals(TestAllTypes.NestedEnum.getDescriptor(), enumField.getEnumType());
|
|
|
|
|
|
assertEquals("optional_foreign_message", messageField.getName());
|
|
|
assertEquals(FieldDescriptor.Type.MESSAGE, messageField.getType());
|
|
@@ -233,38 +215,29 @@ public class DescriptorsTest extends TestCase {
|
|
|
assertEquals("optional_cord", cordField.getName());
|
|
|
assertEquals(FieldDescriptor.Type.STRING, cordField.getType());
|
|
|
assertEquals(FieldDescriptor.JavaType.STRING, cordField.getJavaType());
|
|
|
- assertEquals(DescriptorProtos.FieldOptions.CType.CORD,
|
|
|
- cordField.getOptions().getCtype());
|
|
|
+ assertEquals(DescriptorProtos.FieldOptions.CType.CORD, cordField.getOptions().getCtype());
|
|
|
|
|
|
assertEquals("optional_int32_extension", extension.getName());
|
|
|
- assertEquals("protobuf_unittest.optional_int32_extension",
|
|
|
- extension.getFullName());
|
|
|
+ assertEquals("protobuf_unittest.optional_int32_extension", extension.getFullName());
|
|
|
assertEquals(1, extension.getNumber());
|
|
|
- assertEquals(TestAllExtensions.getDescriptor(),
|
|
|
- extension.getContainingType());
|
|
|
+ assertEquals(TestAllExtensions.getDescriptor(), extension.getContainingType());
|
|
|
assertEquals(UnittestProto.getDescriptor(), extension.getFile());
|
|
|
assertEquals(FieldDescriptor.Type.INT32, extension.getType());
|
|
|
assertEquals(FieldDescriptor.JavaType.INT, extension.getJavaType());
|
|
|
- assertEquals(DescriptorProtos.FieldOptions.getDefaultInstance(),
|
|
|
- extension.getOptions());
|
|
|
+ assertEquals(DescriptorProtos.FieldOptions.getDefaultInstance(), extension.getOptions());
|
|
|
assertTrue(extension.isExtension());
|
|
|
assertEquals(null, extension.getExtensionScope());
|
|
|
assertEquals("optional_int32_extension", extension.toProto().getName());
|
|
|
|
|
|
assertEquals("single", nestedExtension.getName());
|
|
|
- assertEquals("protobuf_unittest.TestRequired.single",
|
|
|
- nestedExtension.getFullName());
|
|
|
- assertEquals(TestRequired.getDescriptor(),
|
|
|
- nestedExtension.getExtensionScope());
|
|
|
+ assertEquals("protobuf_unittest.TestRequired.single", nestedExtension.getFullName());
|
|
|
+ assertEquals(TestRequired.getDescriptor(), nestedExtension.getExtensionScope());
|
|
|
}
|
|
|
|
|
|
public void testFieldDescriptorLabel() throws Exception {
|
|
|
- FieldDescriptor requiredField =
|
|
|
- TestRequired.getDescriptor().findFieldByName("a");
|
|
|
- FieldDescriptor optionalField =
|
|
|
- TestAllTypes.getDescriptor().findFieldByName("optional_int32");
|
|
|
- FieldDescriptor repeatedField =
|
|
|
- TestAllTypes.getDescriptor().findFieldByName("repeated_int32");
|
|
|
+ FieldDescriptor requiredField = TestRequired.getDescriptor().findFieldByName("a");
|
|
|
+ FieldDescriptor optionalField = TestAllTypes.getDescriptor().findFieldByName("optional_int32");
|
|
|
+ FieldDescriptor repeatedField = TestAllTypes.getDescriptor().findFieldByName("repeated_int32");
|
|
|
|
|
|
assertTrue(requiredField.isRequired());
|
|
|
assertFalse(requiredField.isRepeated());
|
|
@@ -273,7 +246,7 @@ public class DescriptorsTest extends TestCase {
|
|
|
assertFalse(repeatedField.isRequired());
|
|
|
assertTrue(repeatedField.isRepeated());
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public void testFieldDescriptorJsonName() throws Exception {
|
|
|
FieldDescriptor requiredField = TestRequired.getDescriptor().findFieldByName("a");
|
|
|
FieldDescriptor optionalField = TestAllTypes.getDescriptor().findFieldByName("optional_int32");
|
|
@@ -292,9 +265,8 @@ public class DescriptorsTest extends TestCase {
|
|
|
|
|
|
d = TestExtremeDefaultValues.getDescriptor();
|
|
|
assertEquals(
|
|
|
- ByteString.copyFrom(
|
|
|
- "\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes(Internal.ISO_8859_1)),
|
|
|
- d.findFieldByName("escaped_bytes").getDefaultValue());
|
|
|
+ ByteString.copyFrom("\0\001\007\b\f\n\r\t\013\\\'\"\u00fe".getBytes(Internal.ISO_8859_1)),
|
|
|
+ d.findFieldByName("escaped_bytes").getDefaultValue());
|
|
|
assertEquals(-1, d.findFieldByName("large_uint32").getDefaultValue());
|
|
|
assertEquals(-1L, d.findFieldByName("large_uint64").getDefaultValue());
|
|
|
}
|
|
@@ -307,12 +279,10 @@ public class DescriptorsTest extends TestCase {
|
|
|
assertEquals("protobuf_unittest.ForeignEnum", enumType.getFullName());
|
|
|
assertEquals(UnittestProto.getDescriptor(), enumType.getFile());
|
|
|
assertNull(enumType.getContainingType());
|
|
|
- assertEquals(DescriptorProtos.EnumOptions.getDefaultInstance(),
|
|
|
- enumType.getOptions());
|
|
|
+ assertEquals(DescriptorProtos.EnumOptions.getDefaultInstance(), enumType.getOptions());
|
|
|
|
|
|
assertEquals("NestedEnum", nestedType.getName());
|
|
|
- assertEquals("protobuf_unittest.TestAllTypes.NestedEnum",
|
|
|
- nestedType.getFullName());
|
|
|
+ assertEquals("protobuf_unittest.TestAllTypes.NestedEnum", nestedType.getFullName());
|
|
|
assertEquals(UnittestProto.getDescriptor(), nestedType.getFile());
|
|
|
assertEquals(TestAllTypes.getDescriptor(), nestedType.getContainingType());
|
|
|
|
|
@@ -339,18 +309,14 @@ public class DescriptorsTest extends TestCase {
|
|
|
|
|
|
MethodDescriptor fooMethod = service.getMethods().get(0);
|
|
|
assertEquals("Foo", fooMethod.getName());
|
|
|
- assertEquals(UnittestProto.FooRequest.getDescriptor(),
|
|
|
- fooMethod.getInputType());
|
|
|
- assertEquals(UnittestProto.FooResponse.getDescriptor(),
|
|
|
- fooMethod.getOutputType());
|
|
|
+ assertEquals(UnittestProto.FooRequest.getDescriptor(), fooMethod.getInputType());
|
|
|
+ assertEquals(UnittestProto.FooResponse.getDescriptor(), fooMethod.getOutputType());
|
|
|
assertEquals(fooMethod, service.findMethodByName("Foo"));
|
|
|
|
|
|
MethodDescriptor barMethod = service.getMethods().get(1);
|
|
|
assertEquals("Bar", barMethod.getName());
|
|
|
- assertEquals(UnittestProto.BarRequest.getDescriptor(),
|
|
|
- barMethod.getInputType());
|
|
|
- assertEquals(UnittestProto.BarResponse.getDescriptor(),
|
|
|
- barMethod.getOutputType());
|
|
|
+ assertEquals(UnittestProto.BarRequest.getDescriptor(), barMethod.getInputType());
|
|
|
+ assertEquals(UnittestProto.BarResponse.getDescriptor(), barMethod.getOutputType());
|
|
|
assertEquals(barMethod, service.findMethodByName("Bar"));
|
|
|
|
|
|
assertNull(service.findMethodByName("NoSuchMethod"));
|
|
@@ -367,58 +333,53 @@ public class DescriptorsTest extends TestCase {
|
|
|
// dependencies are also properly initialized.
|
|
|
Descriptor descriptor =
|
|
|
TestCustomOptions.TestMessageWithCustomOptionsContainer.getDescriptor()
|
|
|
- .findFieldByName("field").getMessageType();
|
|
|
+ .findFieldByName("field")
|
|
|
+ .getMessageType();
|
|
|
|
|
|
- assertTrue(
|
|
|
- descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
|
|
|
- assertEquals(Integer.valueOf(-56),
|
|
|
- descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
|
|
|
+ assertTrue(descriptor.getOptions().hasExtension(UnittestCustomOptions.messageOpt1));
|
|
|
+ assertEquals(
|
|
|
+ Integer.valueOf(-56),
|
|
|
+ descriptor.getOptions().getExtension(UnittestCustomOptions.messageOpt1));
|
|
|
|
|
|
FieldDescriptor field = descriptor.findFieldByName("field1");
|
|
|
assertNotNull(field);
|
|
|
|
|
|
- assertTrue(
|
|
|
- field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
|
|
|
- assertEquals(Long.valueOf(8765432109L),
|
|
|
- field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
|
|
|
+ assertTrue(field.getOptions().hasExtension(UnittestCustomOptions.fieldOpt1));
|
|
|
+ assertEquals(
|
|
|
+ Long.valueOf(8765432109L),
|
|
|
+ field.getOptions().getExtension(UnittestCustomOptions.fieldOpt1));
|
|
|
|
|
|
OneofDescriptor oneof = descriptor.getOneofs().get(0);
|
|
|
assertNotNull(oneof);
|
|
|
|
|
|
- assertTrue(
|
|
|
- oneof.getOptions().hasExtension(UnittestCustomOptions.oneofOpt1));
|
|
|
- assertEquals(Integer.valueOf(-99),
|
|
|
- oneof.getOptions().getExtension(UnittestCustomOptions.oneofOpt1));
|
|
|
+ assertTrue(oneof.getOptions().hasExtension(UnittestCustomOptions.oneofOpt1));
|
|
|
+ assertEquals(
|
|
|
+ Integer.valueOf(-99), oneof.getOptions().getExtension(UnittestCustomOptions.oneofOpt1));
|
|
|
|
|
|
EnumDescriptor enumType =
|
|
|
- UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
|
|
|
+ UnittestCustomOptions.TestMessageWithCustomOptions.AnEnum.getDescriptor();
|
|
|
|
|
|
- assertTrue(
|
|
|
- enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
|
|
|
- assertEquals(Integer.valueOf(-789),
|
|
|
- enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
|
|
|
+ assertTrue(enumType.getOptions().hasExtension(UnittestCustomOptions.enumOpt1));
|
|
|
+ assertEquals(
|
|
|
+ Integer.valueOf(-789), enumType.getOptions().getExtension(UnittestCustomOptions.enumOpt1));
|
|
|
|
|
|
- ServiceDescriptor service =
|
|
|
- UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
|
|
|
+ ServiceDescriptor service = UnittestCustomOptions.TestServiceWithCustomOptions.getDescriptor();
|
|
|
|
|
|
- assertTrue(
|
|
|
- service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
|
|
|
- assertEquals(Long.valueOf(-9876543210L),
|
|
|
- service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
|
|
|
+ assertTrue(service.getOptions().hasExtension(UnittestCustomOptions.serviceOpt1));
|
|
|
+ assertEquals(
|
|
|
+ Long.valueOf(-9876543210L),
|
|
|
+ service.getOptions().getExtension(UnittestCustomOptions.serviceOpt1));
|
|
|
|
|
|
MethodDescriptor method = service.findMethodByName("Foo");
|
|
|
assertNotNull(method);
|
|
|
|
|
|
- assertTrue(
|
|
|
- method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
|
|
|
- assertEquals(UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
|
|
|
- method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
|
|
|
+ assertTrue(method.getOptions().hasExtension(UnittestCustomOptions.methodOpt1));
|
|
|
+ assertEquals(
|
|
|
+ UnittestCustomOptions.MethodOpt1.METHODOPT1_VAL2,
|
|
|
+ method.getOptions().getExtension(UnittestCustomOptions.methodOpt1));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Test that the FieldDescriptor.Type enum is the same as the
|
|
|
- * WireFormat.FieldType enum.
|
|
|
- */
|
|
|
+ /** Test that the FieldDescriptor.Type enum is the same as the WireFormat.FieldType enum. */
|
|
|
public void testFieldTypeTablesMatch() throws Exception {
|
|
|
FieldDescriptor.Type[] values1 = FieldDescriptor.Type.values();
|
|
|
WireFormat.FieldType[] values2 = WireFormat.FieldType.values();
|
|
@@ -430,10 +391,7 @@ public class DescriptorsTest extends TestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Test that the FieldDescriptor.JavaType enum is the same as the
|
|
|
- * WireFormat.JavaType enum.
|
|
|
- */
|
|
|
+ /** Test that the FieldDescriptor.JavaType enum is the same as the WireFormat.JavaType enum. */
|
|
|
public void testJavaTypeTablesMatch() throws Exception {
|
|
|
FieldDescriptor.JavaType[] values1 = FieldDescriptor.JavaType.values();
|
|
|
WireFormat.JavaType[] values2 = WireFormat.JavaType.values();
|
|
@@ -448,31 +406,29 @@ public class DescriptorsTest extends TestCase {
|
|
|
public void testEnormousDescriptor() throws Exception {
|
|
|
// The descriptor for this file is larger than 64k, yet it did not cause
|
|
|
// a compiler error due to an over-long string literal.
|
|
|
- assertTrue(
|
|
|
- UnittestEnormousDescriptor.getDescriptor()
|
|
|
- .toProto().getSerializedSize() > 65536);
|
|
|
+ assertTrue(UnittestEnormousDescriptor.getDescriptor().toProto().getSerializedSize() > 65536);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Tests that the DescriptorValidationException works as intended.
|
|
|
- */
|
|
|
+ /** Tests that the DescriptorValidationException works as intended. */
|
|
|
public void testDescriptorValidatorException() throws Exception {
|
|
|
- FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto")
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("Foo")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
- .setType(FieldDescriptorProto.Type.TYPE_INT32)
|
|
|
- .setName("foo")
|
|
|
- .setNumber(1)
|
|
|
- .setDefaultValue("invalid")
|
|
|
- .build())
|
|
|
- .build())
|
|
|
- .build();
|
|
|
+ FileDescriptorProto fileDescriptorProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("foo.proto")
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("Foo")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
+ .setType(FieldDescriptorProto.Type.TYPE_INT32)
|
|
|
+ .setName("foo")
|
|
|
+ .setNumber(1)
|
|
|
+ .setDefaultValue("invalid")
|
|
|
+ .build())
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
try {
|
|
|
- Descriptors.FileDescriptor.buildFrom(fileDescriptorProto,
|
|
|
- new FileDescriptor[0]);
|
|
|
+ Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]);
|
|
|
fail("DescriptorValidationException expected");
|
|
|
} catch (DescriptorValidationException e) {
|
|
|
// Expected; check that the error message contains some useful hints
|
|
@@ -485,35 +441,39 @@ public class DescriptorsTest extends TestCase {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Tests the translate/crosslink for an example where a message field's name
|
|
|
- * and type name are the same.
|
|
|
+ * Tests the translate/crosslink for an example where a message field's name and type name are the
|
|
|
+ * same.
|
|
|
*/
|
|
|
public void testDescriptorComplexCrosslink() throws Exception {
|
|
|
- FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto")
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("Foo")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
- .setType(FieldDescriptorProto.Type.TYPE_INT32)
|
|
|
- .setName("foo")
|
|
|
- .setNumber(1)
|
|
|
- .build())
|
|
|
- .build())
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("Bar")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
- .setTypeName("Foo")
|
|
|
- .setName("Foo")
|
|
|
- .setNumber(1)
|
|
|
- .build())
|
|
|
- .build())
|
|
|
- .build();
|
|
|
+ FileDescriptorProto fileDescriptorProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("foo.proto")
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("Foo")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
+ .setType(FieldDescriptorProto.Type.TYPE_INT32)
|
|
|
+ .setName("foo")
|
|
|
+ .setNumber(1)
|
|
|
+ .build())
|
|
|
+ .build())
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("Bar")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
+ .setTypeName("Foo")
|
|
|
+ .setName("Foo")
|
|
|
+ .setNumber(1)
|
|
|
+ .build())
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
// translate and crosslink
|
|
|
FileDescriptor file =
|
|
|
- Descriptors.FileDescriptor.buildFrom(fileDescriptorProto,
|
|
|
- new FileDescriptor[0]);
|
|
|
+ Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]);
|
|
|
// verify resulting descriptors
|
|
|
assertNotNull(file);
|
|
|
List<Descriptor> msglist = file.getMessageTypes();
|
|
@@ -535,62 +495,57 @@ public class DescriptorsTest extends TestCase {
|
|
|
}
|
|
|
|
|
|
public void testDependencyOrder() throws Exception {
|
|
|
- FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto").build();
|
|
|
- FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("bar.proto")
|
|
|
- .addDependency("foo.proto")
|
|
|
- .build();
|
|
|
- FileDescriptorProto bazProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("baz.proto")
|
|
|
- .addDependency("foo.proto")
|
|
|
- .addDependency("bar.proto")
|
|
|
- .addPublicDependency(0)
|
|
|
- .addPublicDependency(1)
|
|
|
- .build();
|
|
|
- FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto,
|
|
|
- new FileDescriptor[0]);
|
|
|
- FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(barProto,
|
|
|
- new FileDescriptor[] {fooFile});
|
|
|
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder().setName("foo.proto").build();
|
|
|
+ FileDescriptorProto barProto =
|
|
|
+ FileDescriptorProto.newBuilder().setName("bar.proto").addDependency("foo.proto").build();
|
|
|
+ FileDescriptorProto bazProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("baz.proto")
|
|
|
+ .addDependency("foo.proto")
|
|
|
+ .addDependency("bar.proto")
|
|
|
+ .addPublicDependency(0)
|
|
|
+ .addPublicDependency(1)
|
|
|
+ .build();
|
|
|
+ FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0]);
|
|
|
+ FileDescriptor barFile =
|
|
|
+ Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[] {fooFile});
|
|
|
|
|
|
// Items in the FileDescriptor array can be in any order.
|
|
|
- Descriptors.FileDescriptor.buildFrom(bazProto,
|
|
|
- new FileDescriptor[] {fooFile, barFile});
|
|
|
- Descriptors.FileDescriptor.buildFrom(bazProto,
|
|
|
- new FileDescriptor[] {barFile, fooFile});
|
|
|
+ Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {fooFile, barFile});
|
|
|
+ Descriptors.FileDescriptor.buildFrom(bazProto, new FileDescriptor[] {barFile, fooFile});
|
|
|
}
|
|
|
|
|
|
public void testInvalidPublicDependency() throws Exception {
|
|
|
- FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto").build();
|
|
|
- FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("boo.proto")
|
|
|
- .addDependency("foo.proto")
|
|
|
- .addPublicDependency(1) // Error, should be 0.
|
|
|
- .build();
|
|
|
- FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto,
|
|
|
- new FileDescriptor[0]);
|
|
|
+ FileDescriptorProto fooProto = FileDescriptorProto.newBuilder().setName("foo.proto").build();
|
|
|
+ FileDescriptorProto barProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("boo.proto")
|
|
|
+ .addDependency("foo.proto")
|
|
|
+ .addPublicDependency(1) // Error, should be 0.
|
|
|
+ .build();
|
|
|
+ FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0]);
|
|
|
try {
|
|
|
- Descriptors.FileDescriptor.buildFrom(barProto,
|
|
|
- new FileDescriptor[] {fooFile});
|
|
|
+ Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[] {fooFile});
|
|
|
fail("DescriptorValidationException expected");
|
|
|
} catch (DescriptorValidationException e) {
|
|
|
- assertTrue(
|
|
|
- e.getMessage().indexOf("Invalid public dependency index.") != -1);
|
|
|
+ assertTrue(e.getMessage().indexOf("Invalid public dependency index.") != -1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testUnknownFieldsDenied() throws Exception {
|
|
|
- FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto")
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("Foo")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
- .setTypeName("Bar")
|
|
|
- .setName("bar")
|
|
|
- .setNumber(1)))
|
|
|
- .build();
|
|
|
+ FileDescriptorProto fooProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("foo.proto")
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("Foo")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
+ .setTypeName("Bar")
|
|
|
+ .setName("bar")
|
|
|
+ .setNumber(1)))
|
|
|
+ .build();
|
|
|
|
|
|
try {
|
|
|
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0]);
|
|
@@ -602,48 +557,54 @@ public class DescriptorsTest extends TestCase {
|
|
|
}
|
|
|
|
|
|
public void testUnknownFieldsAllowed() throws Exception {
|
|
|
- FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto")
|
|
|
- .addDependency("bar.proto")
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("Foo")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
- .setTypeName("Bar")
|
|
|
- .setName("bar")
|
|
|
- .setNumber(1)))
|
|
|
- .build();
|
|
|
+ FileDescriptorProto fooProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("foo.proto")
|
|
|
+ .addDependency("bar.proto")
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("Foo")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
+ .setTypeName("Bar")
|
|
|
+ .setName("bar")
|
|
|
+ .setNumber(1)))
|
|
|
+ .build();
|
|
|
Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0], true);
|
|
|
}
|
|
|
|
|
|
public void testHiddenDependency() throws Exception {
|
|
|
- FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("bar.proto")
|
|
|
- .addMessageType(DescriptorProto.newBuilder().setName("Bar"))
|
|
|
- .build();
|
|
|
- FileDescriptorProto forwardProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("forward.proto")
|
|
|
- .addDependency("bar.proto")
|
|
|
- .build();
|
|
|
- FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto")
|
|
|
- .addDependency("forward.proto")
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("Foo")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
- .setTypeName("Bar")
|
|
|
- .setName("bar")
|
|
|
- .setNumber(1)))
|
|
|
- .build();
|
|
|
- FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
|
|
|
- barProto, new FileDescriptor[0]);
|
|
|
- FileDescriptor forwardFile = Descriptors.FileDescriptor.buildFrom(
|
|
|
- forwardProto, new FileDescriptor[] {barFile});
|
|
|
+ FileDescriptorProto barProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("bar.proto")
|
|
|
+ .addMessageType(DescriptorProto.newBuilder().setName("Bar"))
|
|
|
+ .build();
|
|
|
+ FileDescriptorProto forwardProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("forward.proto")
|
|
|
+ .addDependency("bar.proto")
|
|
|
+ .build();
|
|
|
+ FileDescriptorProto fooProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("foo.proto")
|
|
|
+ .addDependency("forward.proto")
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("Foo")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
+ .setTypeName("Bar")
|
|
|
+ .setName("bar")
|
|
|
+ .setNumber(1)))
|
|
|
+ .build();
|
|
|
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[0]);
|
|
|
+ FileDescriptor forwardFile =
|
|
|
+ Descriptors.FileDescriptor.buildFrom(forwardProto, new FileDescriptor[] {barFile});
|
|
|
|
|
|
try {
|
|
|
- Descriptors.FileDescriptor.buildFrom(
|
|
|
- fooProto, new FileDescriptor[] {forwardFile});
|
|
|
+ Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile});
|
|
|
fail("DescriptorValidationException expected");
|
|
|
} catch (DescriptorValidationException e) {
|
|
|
assertTrue(e.getMessage().indexOf("Bar") != -1);
|
|
@@ -652,65 +613,67 @@ public class DescriptorsTest extends TestCase {
|
|
|
}
|
|
|
|
|
|
public void testPublicDependency() throws Exception {
|
|
|
- FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("bar.proto")
|
|
|
- .addMessageType(DescriptorProto.newBuilder().setName("Bar"))
|
|
|
- .build();
|
|
|
- FileDescriptorProto forwardProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("forward.proto")
|
|
|
- .addDependency("bar.proto")
|
|
|
- .addPublicDependency(0)
|
|
|
- .build();
|
|
|
- FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto")
|
|
|
- .addDependency("forward.proto")
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("Foo")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
- .setTypeName("Bar")
|
|
|
- .setName("bar")
|
|
|
- .setNumber(1)))
|
|
|
- .build();
|
|
|
- FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
|
|
|
- barProto, new FileDescriptor[0]);
|
|
|
- FileDescriptor forwardFile = Descriptors.FileDescriptor.buildFrom(
|
|
|
- forwardProto, new FileDescriptor[]{barFile});
|
|
|
- Descriptors.FileDescriptor.buildFrom(
|
|
|
- fooProto, new FileDescriptor[] {forwardFile});
|
|
|
+ FileDescriptorProto barProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("bar.proto")
|
|
|
+ .addMessageType(DescriptorProto.newBuilder().setName("Bar"))
|
|
|
+ .build();
|
|
|
+ FileDescriptorProto forwardProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("forward.proto")
|
|
|
+ .addDependency("bar.proto")
|
|
|
+ .addPublicDependency(0)
|
|
|
+ .build();
|
|
|
+ FileDescriptorProto fooProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("foo.proto")
|
|
|
+ .addDependency("forward.proto")
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("Foo")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL)
|
|
|
+ .setTypeName("Bar")
|
|
|
+ .setName("bar")
|
|
|
+ .setNumber(1)))
|
|
|
+ .build();
|
|
|
+ FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[0]);
|
|
|
+ FileDescriptor forwardFile =
|
|
|
+ Descriptors.FileDescriptor.buildFrom(forwardProto, new FileDescriptor[] {barFile});
|
|
|
+ Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[] {forwardFile});
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Tests the translate/crosslink for an example with a more complex namespace
|
|
|
- * referencing.
|
|
|
- */
|
|
|
+ /** Tests the translate/crosslink for an example with a more complex namespace referencing. */
|
|
|
public void testComplexNamespacePublicDependency() throws Exception {
|
|
|
- FileDescriptorProto fooProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("bar.proto")
|
|
|
- .setPackage("a.b.c.d.bar.shared")
|
|
|
- .addEnumType(EnumDescriptorProto.newBuilder()
|
|
|
- .setName("MyEnum")
|
|
|
- .addValue(EnumValueDescriptorProto.newBuilder()
|
|
|
- .setName("BLAH")
|
|
|
- .setNumber(1)))
|
|
|
- .build();
|
|
|
- FileDescriptorProto barProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto")
|
|
|
- .addDependency("bar.proto")
|
|
|
- .setPackage("a.b.c.d.foo.shared")
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("MyMessage")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
|
|
|
- .setTypeName("bar.shared.MyEnum")
|
|
|
- .setName("MyField")
|
|
|
- .setNumber(1)))
|
|
|
- .build();
|
|
|
+ FileDescriptorProto fooProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("bar.proto")
|
|
|
+ .setPackage("a.b.c.d.bar.shared")
|
|
|
+ .addEnumType(
|
|
|
+ EnumDescriptorProto.newBuilder()
|
|
|
+ .setName("MyEnum")
|
|
|
+ .addValue(EnumValueDescriptorProto.newBuilder().setName("BLAH").setNumber(1)))
|
|
|
+ .build();
|
|
|
+ FileDescriptorProto barProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("foo.proto")
|
|
|
+ .addDependency("bar.proto")
|
|
|
+ .setPackage("a.b.c.d.foo.shared")
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("MyMessage")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
|
|
|
+ .setTypeName("bar.shared.MyEnum")
|
|
|
+ .setName("MyField")
|
|
|
+ .setNumber(1)))
|
|
|
+ .build();
|
|
|
// translate and crosslink
|
|
|
- FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(
|
|
|
- fooProto, new FileDescriptor[0]);
|
|
|
- FileDescriptor barFile = Descriptors.FileDescriptor.buildFrom(
|
|
|
- barProto, new FileDescriptor[]{fooFile});
|
|
|
+ FileDescriptor fooFile = Descriptors.FileDescriptor.buildFrom(fooProto, new FileDescriptor[0]);
|
|
|
+ FileDescriptor barFile =
|
|
|
+ Descriptors.FileDescriptor.buildFrom(barProto, new FileDescriptor[] {fooFile});
|
|
|
// verify resulting descriptors
|
|
|
assertNotNull(barFile);
|
|
|
List<Descriptor> msglist = barFile.getMessageTypes();
|
|
@@ -726,15 +689,13 @@ public class DescriptorsTest extends TestCase {
|
|
|
assertTrue(field.getType() == FieldDescriptor.Type.ENUM);
|
|
|
assertTrue(field.getEnumType().getName().equals("MyEnum"));
|
|
|
assertTrue(field.getEnumType().getFile().getName().equals("bar.proto"));
|
|
|
- assertTrue(field.getEnumType().getFile().getPackage().equals(
|
|
|
- "a.b.c.d.bar.shared"));
|
|
|
+ assertTrue(field.getEnumType().getFile().getPackage().equals("a.b.c.d.bar.shared"));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void testOneofDescriptor() throws Exception {
|
|
|
Descriptor messageType = TestAllTypes.getDescriptor();
|
|
|
- FieldDescriptor field =
|
|
|
- messageType.findFieldByName("oneof_nested_message");
|
|
|
+ FieldDescriptor field = messageType.findFieldByName("oneof_nested_message");
|
|
|
OneofDescriptor oneofDescriptor = field.getContainingOneof();
|
|
|
assertNotNull(oneofDescriptor);
|
|
|
assertSame(oneofDescriptor, messageType.getOneofs().get(0));
|
|
@@ -774,36 +735,38 @@ public class DescriptorsTest extends TestCase {
|
|
|
}
|
|
|
|
|
|
public void testToString() {
|
|
|
- assertEquals("protobuf_unittest.TestAllTypes.optional_uint64",
|
|
|
- UnittestProto.TestAllTypes.getDescriptor().findFieldByNumber(
|
|
|
- UnittestProto.TestAllTypes.OPTIONAL_UINT64_FIELD_NUMBER).toString());
|
|
|
+ assertEquals(
|
|
|
+ "protobuf_unittest.TestAllTypes.optional_uint64",
|
|
|
+ UnittestProto.TestAllTypes.getDescriptor()
|
|
|
+ .findFieldByNumber(UnittestProto.TestAllTypes.OPTIONAL_UINT64_FIELD_NUMBER)
|
|
|
+ .toString());
|
|
|
}
|
|
|
|
|
|
public void testPackedEnumField() throws Exception {
|
|
|
- FileDescriptorProto fileDescriptorProto = FileDescriptorProto.newBuilder()
|
|
|
- .setName("foo.proto")
|
|
|
- .addEnumType(EnumDescriptorProto.newBuilder()
|
|
|
- .setName("Enum")
|
|
|
- .addValue(EnumValueDescriptorProto.newBuilder()
|
|
|
- .setName("FOO")
|
|
|
- .setNumber(1)
|
|
|
- .build())
|
|
|
- .build())
|
|
|
- .addMessageType(DescriptorProto.newBuilder()
|
|
|
- .setName("Message")
|
|
|
- .addField(FieldDescriptorProto.newBuilder()
|
|
|
- .setName("foo")
|
|
|
- .setTypeName("Enum")
|
|
|
- .setNumber(1)
|
|
|
- .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
|
|
|
- .setOptions(DescriptorProtos.FieldOptions.newBuilder()
|
|
|
- .setPacked(true)
|
|
|
- .build())
|
|
|
- .build())
|
|
|
- .build())
|
|
|
- .build();
|
|
|
- Descriptors.FileDescriptor.buildFrom(
|
|
|
- fileDescriptorProto, new FileDescriptor[0]);
|
|
|
+ FileDescriptorProto fileDescriptorProto =
|
|
|
+ FileDescriptorProto.newBuilder()
|
|
|
+ .setName("foo.proto")
|
|
|
+ .addEnumType(
|
|
|
+ EnumDescriptorProto.newBuilder()
|
|
|
+ .setName("Enum")
|
|
|
+ .addValue(
|
|
|
+ EnumValueDescriptorProto.newBuilder().setName("FOO").setNumber(1).build())
|
|
|
+ .build())
|
|
|
+ .addMessageType(
|
|
|
+ DescriptorProto.newBuilder()
|
|
|
+ .setName("Message")
|
|
|
+ .addField(
|
|
|
+ FieldDescriptorProto.newBuilder()
|
|
|
+ .setName("foo")
|
|
|
+ .setTypeName("Enum")
|
|
|
+ .setNumber(1)
|
|
|
+ .setLabel(FieldDescriptorProto.Label.LABEL_REPEATED)
|
|
|
+ .setOptions(
|
|
|
+ DescriptorProtos.FieldOptions.newBuilder().setPacked(true).build())
|
|
|
+ .build())
|
|
|
+ .build())
|
|
|
+ .build();
|
|
|
+ Descriptors.FileDescriptor.buildFrom(fileDescriptorProto, new FileDescriptor[0]);
|
|
|
}
|
|
|
|
|
|
public void testFieldJsonName() throws Exception {
|