|
|
|
@ -32,6 +32,7 @@ |
|
|
|
|
|
|
|
|
|
using Google.Protobuf.TestProtos; |
|
|
|
|
using NUnit.Framework; |
|
|
|
|
using ProtobufUnittest; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
@ -247,6 +248,7 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
FieldDescriptor enumField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_nested_enum"); |
|
|
|
|
FieldDescriptor foreignMessageField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_foreign_message"); |
|
|
|
|
FieldDescriptor importMessageField = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("single_import_message"); |
|
|
|
|
FieldDescriptor fieldInOneof = testAllTypesDescriptor.FindDescriptor<FieldDescriptor>("oneof_string"); |
|
|
|
|
|
|
|
|
|
Assert.AreEqual("single_int32", primitiveField.Name); |
|
|
|
|
Assert.AreEqual("protobuf_unittest3.TestAllTypes.single_int32", |
|
|
|
@ -268,6 +270,10 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
Assert.AreEqual("single_import_message", importMessageField.Name); |
|
|
|
|
Assert.AreEqual(FieldType.Message, importMessageField.FieldType); |
|
|
|
|
Assert.AreEqual(importMessageDescriptor, importMessageField.MessageType); |
|
|
|
|
|
|
|
|
|
// For a field in a regular onoef, ContainingOneof and RealContainingOneof should be the same. |
|
|
|
|
Assert.AreEqual("oneof_field", fieldInOneof.ContainingOneof.Name); |
|
|
|
|
Assert.AreSame(fieldInOneof.ContainingOneof, fieldInOneof.RealContainingOneof); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
@ -318,6 +324,7 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
public void OneofDescriptor() |
|
|
|
|
{ |
|
|
|
|
OneofDescriptor descriptor = TestAllTypes.Descriptor.FindDescriptor<OneofDescriptor>("oneof_field"); |
|
|
|
|
Assert.IsFalse(descriptor.IsSynthetic); |
|
|
|
|
Assert.AreEqual("oneof_field", descriptor.Name); |
|
|
|
|
Assert.AreEqual("protobuf_unittest3.TestAllTypes.oneof_field", descriptor.FullName); |
|
|
|
|
|
|
|
|
@ -383,5 +390,48 @@ namespace Google.Protobuf.Reflection |
|
|
|
|
var importingDescriptor = TestProtos.OldGenerator.OldExtensions1Reflection.Descriptor; |
|
|
|
|
Assert.NotNull(importingDescriptor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void Proto3OptionalDescriptors() |
|
|
|
|
{ |
|
|
|
|
var descriptor = TestProto3Optional.Descriptor; |
|
|
|
|
var field = descriptor.Fields[TestProto3Optional.OptionalInt32FieldNumber]; |
|
|
|
|
Assert.NotNull(field.ContainingOneof); |
|
|
|
|
Assert.IsTrue(field.ContainingOneof.IsSynthetic); |
|
|
|
|
Assert.Null(field.RealContainingOneof); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test] |
|
|
|
|
public void SyntheticOneofReflection() |
|
|
|
|
{ |
|
|
|
|
// Expect every oneof in TestProto3Optional to be synthetic |
|
|
|
|
var proto3OptionalDescriptor = TestProto3Optional.Descriptor; |
|
|
|
|
Assert.AreEqual(0, proto3OptionalDescriptor.RealOneofCount); |
|
|
|
|
foreach (var oneof in proto3OptionalDescriptor.Oneofs) |
|
|
|
|
{ |
|
|
|
|
Assert.True(oneof.IsSynthetic); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Expect no oneof in the original proto3 unit test file to be synthetic. |
|
|
|
|
foreach (var descriptor in ProtobufTestMessages.Proto3.TestMessagesProto3Reflection.Descriptor.MessageTypes) |
|
|
|
|
{ |
|
|
|
|
Assert.AreEqual(descriptor.Oneofs.Count, descriptor.RealOneofCount); |
|
|
|
|
foreach (var oneof in descriptor.Oneofs) |
|
|
|
|
{ |
|
|
|
|
Assert.False(oneof.IsSynthetic); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Expect no oneof in the original proto2 unit test file to be synthetic. |
|
|
|
|
foreach (var descriptor in ProtobufTestMessages.Proto2.TestMessagesProto2Reflection.Descriptor.MessageTypes) |
|
|
|
|
{ |
|
|
|
|
Assert.AreEqual(descriptor.Oneofs.Count, descriptor.RealOneofCount); |
|
|
|
|
foreach (var oneof in descriptor.Oneofs) |
|
|
|
|
{ |
|
|
|
|
Assert.False(oneof.IsSynthetic); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|