Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Jan 26, 2021
1 parent 356e831 commit de8d196
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
Expand Up @@ -35,6 +35,7 @@
using Google.Protobuf.TestProtos;
using Google.Protobuf.Buffers;
using NUnit.Framework;
using System.Text;

namespace Google.Protobuf
{
Expand Down Expand Up @@ -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());
}
}
}
}

0 comments on commit de8d196

Please sign in to comment.