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

* add test for clone

* use var

* reorder
pull/9476/head
Elliotte Rusty Harold 3 years ago committed by GitHub
parent 3be46483ba
commit 867436c0b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      csharp/src/Google.Protobuf.Test/UnknownFieldSetTest.cs

@ -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)

Loading…
Cancel
Save