diff options
author | Jon Skeet <skeet@pobox.com> | 2008-08-19 21:24:21 +0100 |
---|---|---|
committer | Jon Skeet <skeet@pobox.com> | 2008-08-19 21:24:21 +0100 |
commit | ad6903fe33ca0a79e7618a25e83de769438d18ce (patch) | |
tree | d6fe0b324922129167108298d6c0458607ac030b /csharp/ProtocolBuffers.Test/MessageStreamWriterTest.cs | |
parent | f09fed217f86d1fdb2db97631178060d6d50cda1 (diff) | |
download | protobuf-ad6903fe33ca0a79e7618a25e83de769438d18ce.tar.gz protobuf-ad6903fe33ca0a79e7618a25e83de769438d18ce.tar.bz2 protobuf-ad6903fe33ca0a79e7618a25e83de769438d18ce.zip |
Fix to constructor access for nested types, and first pass at streaming.
Diffstat (limited to 'csharp/ProtocolBuffers.Test/MessageStreamWriterTest.cs')
-rw-r--r-- | csharp/ProtocolBuffers.Test/MessageStreamWriterTest.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/csharp/ProtocolBuffers.Test/MessageStreamWriterTest.cs b/csharp/ProtocolBuffers.Test/MessageStreamWriterTest.cs new file mode 100644 index 00000000..9cbe2b33 --- /dev/null +++ b/csharp/ProtocolBuffers.Test/MessageStreamWriterTest.cs @@ -0,0 +1,36 @@ +using System.IO; +using NUnit.Framework; +using NestedMessage = Google.ProtocolBuffers.TestProtos.TestAllTypes.Types.NestedMessage; + +namespace Google.ProtocolBuffers { + [TestFixture] + public class MessageStreamWriterTest { + + internal static readonly byte[] ThreeMessageData = new byte[] { + (1 << 3) | 2, 2, // Field 1, 2 bytes long (first message) + (1 << 3) | 0, 5, // Field 1, value 5 + (1 << 3) | 2, 3, // Field 1, 3 bytes long (second message) + (1 << 3) | 0, (1500 & 0x7f) | 0x80, 1500 >> 7, // Field 1, value 1500 + (1 << 3) | 2, 0, // Field 1, no data (third message) + }; + + [Test] + public void ThreeMessages() { + NestedMessage message1 = new NestedMessage.Builder { Bb = 5 }.Build(); + NestedMessage message2 = new NestedMessage.Builder { Bb = 1500 }.Build(); + NestedMessage message3 = new NestedMessage.Builder().Build(); + + byte[] data; + using (MemoryStream stream = new MemoryStream()) { + MessageStreamWriter<NestedMessage> writer = new MessageStreamWriter<NestedMessage>(stream); + writer.Write(message1); + writer.Write(message2); + writer.Write(message3); + writer.Flush(); + data = stream.ToArray(); + } + + TestUtil.AssertEqualBytes(ThreeMessageData, data); + } + } +} |