add test for clone of non-empty message (#9193)

* add test for clone

* use var

* reorder
This commit is contained in:
Elliotte Rusty Harold 2022-02-04 11:54:43 -05:00 committed by GitHub
parent 3be46483ba
commit 867436c0b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -138,6 +138,29 @@ namespace Google.Protobuf
Assert.AreEqual(message.ToByteArray(), otherEmptyMessage.ToByteArray());
}
[Test]
public void TestClone_LengthDelimited()
{
var unknownVarintField = new UnknownField();
unknownVarintField.AddVarint(99);
var unknownLengthDelimitedField1 = new UnknownField();
unknownLengthDelimitedField1.AddLengthDelimited(ByteString.CopyFromUtf8("some data"));
var unknownLengthDelimitedField2 = new UnknownField();
unknownLengthDelimitedField2.AddLengthDelimited(ByteString.CopyFromUtf8("some more data"));
var destUnknownFieldSet = new UnknownFieldSet();
destUnknownFieldSet.AddOrReplaceField(997, unknownVarintField);
destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField1);
destUnknownFieldSet.AddOrReplaceField(999, unknownLengthDelimitedField2);
var clone = UnknownFieldSet.Clone(destUnknownFieldSet);
Assert.IsTrue(clone.HasField(997));
Assert.IsTrue(clone.HasField(999));
}
[Test]
[TestCaseSource(typeof(Data), "Messages")]
public void TestDiscardUnknownFields(IMessage message)