Fix bug in GeneratedBuilder.MergeFrom
This commit is contained in:
parent
b8c2fc57fc
commit
20bfd9bf50
@ -55,6 +55,7 @@ message TestOptimizedForSize {
|
||||
|
||||
extend TestOptimizedForSize {
|
||||
optional int32 test_extension = 1234;
|
||||
optional TestRequiredOptimizedForSize test_extension2 = 1235;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,5 +287,29 @@ namespace Google.ProtocolBuffers {
|
||||
).BuildPartial();
|
||||
Assert.IsTrue(message.IsInitialized);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOptimizedForSizeMergeUsesAllFieldsFromTarget() {
|
||||
TestOptimizedForSize withFieldSet = new TestOptimizedForSize.Builder { I = 10 }.Build();
|
||||
TestOptimizedForSize.Builder builder = new TestOptimizedForSize.Builder();
|
||||
builder.MergeFrom(withFieldSet);
|
||||
TestOptimizedForSize built = builder.Build();
|
||||
Assert.AreEqual(10, built.I);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UninitializedExtensionInOptimizedForSizeMakesMessageUninitialized() {
|
||||
TestOptimizedForSize.Builder builder = new TestOptimizedForSize.Builder();
|
||||
builder.SetExtension(TestOptimizedForSize.TestExtension2,
|
||||
new TestRequiredOptimizedForSize.Builder().BuildPartial());
|
||||
Assert.IsFalse(builder.IsInitialized);
|
||||
Assert.IsFalse(builder.BuildPartial().IsInitialized);
|
||||
|
||||
builder = new TestOptimizedForSize.Builder();
|
||||
builder.SetExtension(TestOptimizedForSize.TestExtension2,
|
||||
new TestRequiredOptimizedForSize.Builder { X = 10 }.BuildPartial());
|
||||
Assert.IsTrue(builder.IsInitialized);
|
||||
Assert.IsTrue(builder.BuildPartial().IsInitialized);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,15 +17,18 @@ namespace Google.ProtocolBuffers.TestProtos {
|
||||
"Citnb29nbGUvcHJvdG9idWYvdW5pdHRlc3Rfb3B0aW1pemVfZm9yLnByb3Rv" +
|
||||
"EhFwcm90b2J1Zl91bml0dGVz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z" +
|
||||
"dE9wdGlvbmFsT3B0aW1pemVkRm9yU2l6ZRI6CgFvGAEgASgLMi8ucHJvdG9i" +
|
||||
"dWZfdW5pdHRlc3QuVGVzdFJlcXVpcmVkT3B0aW1pemVkRm9yU2l6ZUJHSAKC" +
|
||||
"4gkhR29vZ2xlLlByb3RvY29sQnVmZmVycy5UZXN0UHJvdG9ziuIJHFVuaXRU" +
|
||||
"ZXN0T3B0aW1pemVGb3JQcm90b0ZpbGU="),
|
||||
new pbd::FileDescriptor[] {
|
||||
global::Google.ProtocolBuffers.DescriptorProtos.CSharpOptions.Descriptor,
|
||||
global::Google.ProtocolBuffers.DescriptorProtos.DescriptorProtoFile.Descriptor,
|
||||
@ -76,6 +79,8 @@ namespace Google.ProtocolBuffers.TestProtos {
|
||||
|
||||
public static readonly pb::GeneratedExtensionBase<int> TestExtension =
|
||||
pb::GeneratedSingleExtension<int>.CreateInstance(Descriptor.Extensions[0]);
|
||||
public static readonly pb::GeneratedExtensionBase<global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize> TestExtension2 =
|
||||
pb::GeneratedSingleExtension<global::Google.ProtocolBuffers.TestProtos.TestRequiredOptimizedForSize>.CreateInstance(Descriptor.Extensions[1]);
|
||||
private bool hasI;
|
||||
private int i_ = 0;
|
||||
public bool HasI {
|
||||
|
@ -113,7 +113,7 @@ namespace Google.ProtocolBuffers {
|
||||
throw new ArgumentException("Message type mismatch");
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<FieldDescriptor, object> entry in AllFields) {
|
||||
foreach (KeyValuePair<FieldDescriptor, object> entry in other.AllFields) {
|
||||
FieldDescriptor field = entry.Key;
|
||||
if (field.IsRepeated) {
|
||||
// Concatenate repeated fields
|
||||
|
Loading…
Reference in New Issue
Block a user