You've already forked linux-packaging-mono
Imported Upstream version 3.10.0
Former-commit-id: 172c8e3c300b39d5785c7a3e8dfb08ebdbc1a99b
This commit is contained in:
@ -14,6 +14,7 @@ using NUnit.Framework;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
|
||||
namespace MonoTests.System.IO.Compression
|
||||
{
|
||||
@ -297,6 +298,60 @@ namespace MonoTests.System.IO.Compression
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Bug19313Stream : MemoryStream
|
||||
{
|
||||
public Bug19313Stream (byte [] buffer)
|
||||
: base (buffer)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Read (byte [] buffer, int offset, int count)
|
||||
{
|
||||
// Thread was blocking when DeflateStream uses a NetworkStream.
|
||||
// Because the NetworkStream.Read calls Socket.Receive that
|
||||
// blocks the thread waiting for at least a byte to return.
|
||||
// This assert guarantees that Read is called only when there
|
||||
// is something to be read.
|
||||
Assert.IsTrue (Position < Length, "Trying to read empty stream.");
|
||||
|
||||
return base.Read (buffer, offset, count);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Bug19313 ()
|
||||
{
|
||||
byte [] buffer = new byte [512];
|
||||
using (var backing = new Bug19313Stream (compressed_data))
|
||||
using (var decompressing = new DeflateStream (backing, CompressionMode.Decompress))
|
||||
decompressing.Read (buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public MemoryStream GenerateStreamFromString(string s)
|
||||
{
|
||||
return new MemoryStream (Encoding.UTF8.GetBytes (s));
|
||||
}
|
||||
|
||||
#if NET_4_5
|
||||
[Test]
|
||||
public void CheckNet45Overloads () // Xambug #21982
|
||||
{
|
||||
MemoryStream dataStream = GenerateStreamFromString("Hello");
|
||||
MemoryStream backing = new MemoryStream ();
|
||||
DeflateStream compressing = new DeflateStream (backing, CompressionLevel.Fastest, true);
|
||||
CopyStream (dataStream, compressing);
|
||||
dataStream.Close();
|
||||
compressing.Close();
|
||||
|
||||
backing.Seek (0, SeekOrigin.Begin);
|
||||
DeflateStream decompressing = new DeflateStream (backing, CompressionMode.Decompress);
|
||||
StreamReader reader = new StreamReader (decompressing);
|
||||
Assert.AreEqual ("Hello", reader.ReadLine ());
|
||||
decompressing.Close();
|
||||
backing.Close();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user