increase test coverage

pull/7576/head
Jan Tattermusch 5 years ago
parent 7bfaaba534
commit b3cdba1cfd
  1. 6
      csharp/src/Google.Protobuf.Test/GeneratedMessageTest.Proto2.cs
  2. 12
      csharp/src/Google.Protobuf.Test/MessageParsingHelpers.cs
  3. 8
      csharp/src/Google.Protobuf.Test/WellKnownTypes/WrappersTest.cs

@ -344,6 +344,8 @@ namespace Google.Protobuf
}
};
MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(Proto2.TestAllTypes.Parser, message);
}
@ -359,6 +361,8 @@ namespace Google.Protobuf
new RepeatedGroup_extension { A = 30 }
});
MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(
TestAllExtensions.Parser.WithExtensionRegistry(new ExtensionRegistry() { UnittestExtensions.OptionalGroupExtension, UnittestExtensions.RepeatedGroupExtension }),
message);
@ -370,6 +374,8 @@ namespace Google.Protobuf
var message = new TestGroupExtension();
message.SetExtension(TestNestedExtension.Extensions.OptionalGroupExtension, new TestNestedExtension.Types.OptionalGroup_extension { A = 10 });
MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(
TestGroupExtension.Parser.WithExtensionRegistry(new ExtensionRegistry() { TestNestedExtension.Extensions.OptionalGroupExtension }),
message);

@ -108,12 +108,18 @@ namespace Google.Protobuf
// serialize using CodedOutputStream
var bytes = message.ToByteArray();
// also serialize using IBufferWriter and check it leads to the same data
int messageSize = message.CalculateSize();
Assert.AreEqual(message.CalculateSize(), bytes.Length);
// serialize using IBufferWriter and check it leads to the same output
var bufferWriter = new ArrayBufferWriter<byte>();
message.WriteTo(bufferWriter);
Assert.AreEqual(bytes, bufferWriter.WrittenSpan.ToArray(), "Both serialization approaches need to result in the same data.");
Assert.AreEqual(bytes, bufferWriter.WrittenSpan.ToArray());
Assert.AreEqual(message.CalculateSize(), bytes.Length);
// serialize into a single span and check it leads to the same output
var singleSpan = new Span<byte>(new byte[messageSize]);
message.WriteTo(singleSpan);
Assert.AreEqual(bytes, singleSpan.ToArray());
// TODO: also test different chunk sizes for IBufferWriter
}

@ -71,6 +71,8 @@ namespace Google.Protobuf.WellKnownTypes
Uint64Field = 4
};
MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(TestWellKnownTypes.Parser, message, parsed =>
{
Assert.AreEqual("x", parsed.StringField);
@ -101,6 +103,8 @@ namespace Google.Protobuf.WellKnownTypes
Uint64Field = 0
};
MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(TestWellKnownTypes.Parser, message, parsed =>
{
Assert.AreEqual("", parsed.StringField);
@ -144,6 +148,8 @@ namespace Google.Protobuf.WellKnownTypes
// Just to test a single value for sanity...
Assert.AreEqual("Second", message.StringField[1]);
MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(RepeatedWellKnownTypes.Parser, message);
}
@ -196,6 +202,8 @@ namespace Google.Protobuf.WellKnownTypes
// Just to test a single value for sanity...
Assert.AreEqual("Second", message.StringField[12]);
MessageParsingHelpers.AssertWritingMessage(message);
MessageParsingHelpers.AssertRoundtrip(MapWellKnownTypes.Parser, message);
}

Loading…
Cancel
Save