Use proto2 and proto3 in unknown field tests

This commit is contained in:
Sydney Acksman 2019-08-29 18:07:02 -05:00
parent bdc6cd1d0b
commit 4d5ae5b4a4

View File

@ -40,6 +40,18 @@ namespace Google.Protobuf
{
public class UnknownFieldSetTest
{
public class Data
{
public static System.Collections.IEnumerable Messages
{
get
{
yield return SampleMessages.CreateFullTestAllTypesProto2();
yield return SampleMessages.CreateFullTestAllTypes();
}
}
}
[Test]
public void EmptyUnknownFieldSet()
{
@ -61,24 +73,23 @@ namespace Google.Protobuf
}
[Test]
public void TestMergeCodedInput()
[TestCaseSource(typeof(Data), "Messages")]
public void TestMergeCodedInput(IMessage message)
{
var message = SampleMessages.CreateFullTestAllTypesProto2();
var emptyMessage = new TestEmptyMessage();
emptyMessage.MergeFrom(message.ToByteArray());
Assert.AreEqual(message.CalculateSize(), emptyMessage.CalculateSize());
Assert.AreEqual(message.ToByteArray(), emptyMessage.ToByteArray());
var newMessage = new Proto2.TestAllTypes();
newMessage.MergeFrom(emptyMessage.ToByteArray());
var newMessage = message.Descriptor.Parser.ParseFrom(emptyMessage.ToByteArray());
Assert.AreEqual(message, newMessage);
Assert.AreEqual(message.CalculateSize(), newMessage.CalculateSize());
}
[Test]
public void TestMergeMessage()
[TestCaseSource(typeof(Data), "Messages")]
public void TestMergeMessage(IMessage message)
{
var message = SampleMessages.CreateFullTestAllTypesProto2();
var emptyMessage = new TestEmptyMessage();
var otherEmptyMessage = new TestEmptyMessage();
emptyMessage.MergeFrom(message.ToByteArray());
@ -89,9 +100,9 @@ namespace Google.Protobuf
}
[Test]
public void TestEquals()
[TestCaseSource(typeof(Data), "Messages")]
public void TestEquals(IMessage message)
{
var message = SampleMessages.CreateFullTestAllTypesProto2();
var emptyMessage = new TestEmptyMessage();
var otherEmptyMessage = new TestEmptyMessage();
Assert.AreEqual(emptyMessage, otherEmptyMessage);
@ -102,9 +113,9 @@ namespace Google.Protobuf
}
[Test]
public void TestHashCode()
[TestCaseSource(typeof(Data), "Messages")]
public void TestHashCode(IMessage message)
{
var message = SampleMessages.CreateFullTestAllTypesProto2();
var emptyMessage = new TestEmptyMessage();
int hashCode = emptyMessage.GetHashCode();
emptyMessage.MergeFrom(message.ToByteArray());
@ -112,7 +123,8 @@ namespace Google.Protobuf
}
[Test]
public void TestClone()
[TestCaseSource(typeof(Data), "Messages")]
public void TestClone(IMessage message)
{
var emptyMessage = new TestEmptyMessage();
var otherEmptyMessage = new TestEmptyMessage();
@ -120,7 +132,6 @@ namespace Google.Protobuf
Assert.AreEqual(emptyMessage.CalculateSize(), otherEmptyMessage.CalculateSize());
Assert.AreEqual(emptyMessage.ToByteArray(), otherEmptyMessage.ToByteArray());
var message = SampleMessages.CreateFullTestAllTypesProto2();
emptyMessage.MergeFrom(message.ToByteArray());
otherEmptyMessage = emptyMessage.Clone();
Assert.AreEqual(message.CalculateSize(), otherEmptyMessage.CalculateSize());
@ -128,9 +139,9 @@ namespace Google.Protobuf
}
[Test]
public void TestDiscardUnknownFields()
[TestCaseSource(typeof(Data), "Messages")]
public void TestDiscardUnknownFields(IMessage message)
{
var message = SampleMessages.CreateFullTestAllTypesProto2();
var goldenEmptyMessage = new TestEmptyMessage();
byte[] data = message.ToByteArray();
int fullSize = message.CalculateSize();