aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2016-02-29 11:51:56 +0000
committerJon Skeet <jonskeet@google.com>2016-02-29 11:51:56 +0000
commitc0cf71bec95fabafb4860564aecd464ba59254ef (patch)
tree3fda6b8950846b51fa0d17752cd368b5a572e489 /csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
parent60a0d41a2988a40cf3a94a4cb602f5f1c94135e9 (diff)
downloadprotobuf-c0cf71bec95fabafb4860564aecd464ba59254ef.tar.gz
protobuf-c0cf71bec95fabafb4860564aecd464ba59254ef.tar.bz2
protobuf-c0cf71bec95fabafb4860564aecd464ba59254ef.zip
Implement IDisposable for CodedInputStream and CodedOutputStream
This fixes issue #679 and issue #1282. (The .gitignore change is just around ncrunch; I can put it in a separate PR if you really want.)
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs28
1 files changed, 28 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
index 3297fe87..48bf6d60 100644
--- a/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
+++ b/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
@@ -387,5 +387,33 @@ namespace Google.Protobuf
Assert.IsTrue(cin.IsAtEnd);
}
}
+
+ [Test]
+ public void Dispose_DisposesUnderlyingStream()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanWrite);
+ using (var cos = new CodedOutputStream(memoryStream))
+ {
+ cos.WriteRawByte(0);
+ Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
+ }
+ Assert.AreEqual(1, memoryStream.ToArray().Length); // Flushed data from CodedOutputStream to MemoryStream
+ Assert.IsFalse(memoryStream.CanWrite); // Disposed
+ }
+
+ [Test]
+ public void Dispose_WithLeaveOpen()
+ {
+ var memoryStream = new MemoryStream();
+ Assert.IsTrue(memoryStream.CanWrite);
+ using (var cos = new CodedOutputStream(memoryStream, true))
+ {
+ cos.WriteRawByte(0);
+ Assert.AreEqual(0, memoryStream.Position); // Not flushed yet
+ }
+ Assert.AreEqual(1, memoryStream.Position); // Flushed data from CodedOutputStream to MemoryStream
+ Assert.IsTrue(memoryStream.CanWrite); // We left the stream open
+ }
}
} \ No newline at end of file