aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
diff options
context:
space:
mode:
authorPete Warden <pete@petewarden.com>2016-03-09 13:05:15 -0800
committerPete Warden <pete@petewarden.com>2016-03-09 13:05:15 -0800
commitbc2d6c2504b38dda4345e9960948d96102daccc3 (patch)
tree48ad357a166b3bf9715a20714db8c117d8150c41 /csharp/src/Google.Protobuf.Test/CodedOutputStreamTest.cs
parentf0c1a8637218a03a083901493c9b3acdb6e5db57 (diff)
parent48ebb29a8ec118bf6b9ee39f6be42b57321c099a (diff)
downloadprotobuf-bc2d6c2504b38dda4345e9960948d96102daccc3.tar.gz
protobuf-bc2d6c2504b38dda4345e9960948d96102daccc3.tar.bz2
protobuf-bc2d6c2504b38dda4345e9960948d96102daccc3.zip
Merge remote-tracking branch 'upstream/master'
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