diff options
Diffstat (limited to 'src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs')
-rw-r--r-- | src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs b/src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs index 7eebde39..c7f31c0f 100644 --- a/src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs +++ b/src/ProtocolBuffers.Test/MessageStreamIteratorTest.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using NUnit.Framework; using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage; +using Google.ProtocolBuffers.TestProtos; namespace Google.ProtocolBuffers { [TestFixture] @@ -19,5 +20,31 @@ namespace Google.ProtocolBuffers { Assert.AreEqual(1500, messages[1].Bb); Assert.IsFalse(messages[2].HasBb); } + + [Test] + public void ManyMessagesShouldNotTriggerSizeAlert() { + int messageSize = TestUtil.GetAllSet().SerializedSize; + // Enough messages to trigger the alert unless we've reset the size + // Note that currently we need to make this big enough to copy two whole buffers, + // as otherwise when we refill the buffer the second type, the alert triggers instantly. + int correctCount = (CodedInputStream.BufferSize * 2) / messageSize + 1; + using (MemoryStream stream = new MemoryStream()) { + MessageStreamWriter<TestAllTypes> writer = new MessageStreamWriter<TestAllTypes>(stream); + for (int i = 0; i < correctCount; i++) { + writer.Write(TestUtil.GetAllSet()); + } + writer.Flush(); + + stream.Position = 0; + + int count = 0; + foreach (var message in MessageStreamIterator<TestAllTypes>.FromStreamProvider(() => stream) + .WithSizeLimit(CodedInputStream.BufferSize * 2)) { + count++; + TestUtil.AssertAllFieldsSet(message); + } + Assert.AreEqual(correctCount, count); + } + } } } |