diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs index 1c77e121d3eb..1e5333c96501 100644 --- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs +++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs @@ -35,6 +35,7 @@ using Google.Protobuf.TestProtos; using Google.Protobuf.Buffers; using NUnit.Framework; +using System.Text; namespace Google.Protobuf { @@ -516,5 +517,28 @@ public void Dispose_FromByteArray() var stream = new CodedOutputStream(new byte[10]); stream.Dispose(); } + + [Test] + public void WriteStringsOfDifferentSizes() + { + for (int i = 1; i <= 1024; i++) + { + var buffer = new byte[4096]; + var output = new CodedOutputStream(buffer); + var sb = new StringBuilder(); + for (int j = 0; j < i; j++) + { + sb.Append((j % 10).ToString()); // incrementing numbers, repeating + } + var s = sb.ToString(); + output.WriteString(s); + + output.Flush(); + + // Verify written content + var input = new CodedInputStream(buffer); + Assert.AreEqual(s, input.ReadString()); + } + } } } \ No newline at end of file