public void CheckNullRead()
        {
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            decompressing.Read(null, 0, 20);
        }
        public void CheckSetLengthProp()
        {
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            decompressing.SetLength(20);
        }
        public void CheckCompressDecompress(CompressionAlgorithm algorithm)
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            byte [] data = new byte[100000];
            for (int i = 0; i < 100000; i++)
            {
                data[i] = (byte)i;
            }
            MemoryStream  dataStream  = new MemoryStream(data);
            MemoryStream  backing     = new MemoryStream();
            DeflateStream compressing = new DeflateStream(backing, CompressionMode.Compress, algorithm, true);

            CopyStream(dataStream, compressing);
            dataStream.Close();
            compressing.Close();
            backing.Seek(0, SeekOrigin.Begin);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, algorithm);
            MemoryStream  output        = new MemoryStream();

            CopyStream(decompressing, output);
            Assert.AreNotEqual(0, output.Length, "Length should be more than 0.");
            Assert.IsTrue(compare_buffers(data, output.GetBuffer(), (int)output.Length), "Buffers are not equal.");
            decompressing.Close();
            output.Close();
        }
 [Test]         // zlib specific test
 public void Bug19313()
 {
     byte [] buffer = new byte [512];
     using (var backing = new Bug19313Stream(compressed_data))
         using (var decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib))
             decompressing.Read(buffer, 0, buffer.Length);
 }
        public void CheckSeek()
        {
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            decompressing.Seek(20, SeekOrigin.Current);
        }
        public void JunkAtTheEnd(CompressionAlgorithm algorithm)
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            // Write a deflated stream, then some additional data...
            using (MemoryStream ms = new MemoryStream())
            {
                // The compressed stream
                using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, algorithm, true))
                {
                    stream.WriteByte(1);
                    stream.Flush();
                }
                // Junk
                ms.WriteByte(2);

                ms.Position = 0;
                // Reading: this should not hang
                using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Decompress, algorithm))
                {
                    byte[] buffer = new byte[512];
                    int    len    = stream.Read(buffer, 0, buffer.Length);
                    Console.WriteLine(len == 1);
                }
            }
        }
        public void CheckClosedFlush()
        {
            MemoryStream  backing     = new MemoryStream();
            DeflateStream compressing = new DeflateStream(backing, CompressionMode.Compress, CompressionAlgorithm.Zlib);

            compressing.Close();
            compressing.Flush();
        }
        public void CheckRangeRead()
        {
            byte []       dummy         = new byte[20];
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            decompressing.Read(dummy, 10, 20);
        }
        public void CheckCompressingRead()
        {
            byte []       dummy       = new byte[20];
            MemoryStream  backing     = new MemoryStream();
            DeflateStream compressing = new DeflateStream(backing, CompressionMode.Compress, CompressionAlgorithm.Zlib);

            compressing.Read(dummy, 0, 20);
        }
        public void DisposeTest()
        {
            MemoryStream  backing    = new MemoryStream(compressed_data);
            DeflateStream decompress = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            decompress.Dispose();
            decompress.Dispose();
        }
 public void Constructor_InvalidCompressionMode()
 {
     if (!TestRuntime.CheckXcodeVersion(7, 0))
     {
         Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
     }
     DeflateStream ds = new DeflateStream(new MemoryStream(), (CompressionMode)Int32.MinValue, CompressionAlgorithm.Zlib);
 }
 public void Constructor_Null()
 {
     if (!TestRuntime.CheckXcodeVersion(7, 0))
     {
         Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
     }
     DeflateStream ds = new DeflateStream(null, CompressionMode.Compress, CompressionAlgorithm.Zlib);
 }
        [Test]         // Not passing the algorithm because the compressed data is Zlib compressed.
        public void CheckDecompress()
        {
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);
            StreamReader  reader        = new StreamReader(decompressing);

            Assert.AreEqual("Hello", reader.ReadLine());
            decompressing.Close();
        }
 public void CheckGetPositionProp()
 {
     if (!TestRuntime.CheckXcodeVersion(7, 0))
     {
         Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
     }
     MemoryStream  backing       = new MemoryStream(compressed_data);
     DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);
     long          position      = decompressing.Position;
 }
Пример #15
0
        public void CheckNullRead()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            Assert.Throws <ArgumentNullException> (() => decompressing.Read(null, 0, 20));
        }
        public void CheckSetLength()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            decompressing.SetLength(20);
        }
Пример #17
0
        public void CheckSeek()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            Assert.Throws <NotSupportedException> (() => decompressing.Seek(20, SeekOrigin.Current));
        }
 [Test]         // zlib specific test
 public void Bug19313()
 {
     if (!TestRuntime.CheckXcodeVersion(7, 0))
     {
         Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
     }
     byte [] buffer = new byte [512];
     using (var backing = new Bug19313Stream(compressed_data))
         using (var decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib))
             decompressing.Read(buffer, 0, buffer.Length);
 }
Пример #19
0
        public void CheckGetLengthProp()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            Assert.Throws <NotSupportedException> (() => { var length = decompressing.Length; });
        }
        public void CheckClosedFlush()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            MemoryStream  backing     = new MemoryStream();
            DeflateStream compressing = new DeflateStream(backing, CompressionMode.Compress, CompressionAlgorithm.Zlib);

            compressing.Close();
            compressing.Flush();
        }
        public void CheckRangeRead()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            byte []       dummy         = new byte[20];
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            decompressing.Read(dummy, 10, 20);
        }
Пример #22
0
        public void CheckCompressingRead()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            byte []       dummy       = new byte[20];
            MemoryStream  backing     = new MemoryStream();
            DeflateStream compressing = new DeflateStream(backing, CompressionMode.Compress, CompressionAlgorithm.Zlib);

            Assert.Throws <InvalidOperationException> (() => compressing.Read(dummy, 0, 20));
        }
        [Test]         // Not passing the algorithm because the compressed data is Zlib compressed.
        public void CheckDecompress()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);
            StreamReader  reader        = new StreamReader(decompressing);

            Assert.AreEqual("Hello", reader.ReadLine());
            decompressing.Close();
        }
Пример #24
0
        public void CheckClosedRead()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            byte []       dummy         = new byte[20];
            MemoryStream  backing       = new MemoryStream(compressed_data);
            DeflateStream decompressing = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            decompressing.Close();
            Assert.Throws <ObjectDisposedException> (() => decompressing.Read(dummy, 0, 20));
        }
        public void CheckGetCanWriteProp()
        {
            MemoryStream  backing    = new MemoryStream();
            DeflateStream decompress = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            Assert.IsFalse(decompress.CanWrite, "#A1");
            Assert.IsTrue(backing.CanWrite, "#A2");
            decompress.Dispose();
            Assert.IsFalse(decompress.CanWrite, "#A3");
            Assert.IsFalse(backing.CanWrite, "#A4");

            backing = new MemoryStream();
            DeflateStream compress = new DeflateStream(backing, CompressionMode.Compress, CompressionAlgorithm.Zlib);

            Assert.IsTrue(compress.CanWrite, "#B1");
            Assert.IsTrue(backing.CanWrite, "#B2");
            compress.Dispose();
            Assert.IsFalse(decompress.CanWrite, "#B3");
            Assert.IsFalse(backing.CanWrite, "#B4");
        }
Пример #26
0
            public CopyToAsyncStream(CompressionStream deflateStream, Stream destination, int bufferSize, CancellationToken cancellationToken)
            {
                if (deflateStream == null)
                {
                    throw new ArgumentNullException(nameof(deflateStream));
                }
                if (destination == null)
                {
                    throw new ArgumentNullException(nameof(destination));
                }
                if (bufferSize <= 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(bufferSize));
                }

                _deflateStream     = deflateStream;
                _destination       = destination;
                _cancellationToken = cancellationToken;
                _arrayPoolBuffer   = ArrayPool <byte> .Shared.Rent(bufferSize);
            }
        public void JunkAtTheEnd(CompressionAlgorithm algorithm)
        {
            // Write a deflated stream, then some additional data...
            using (MemoryStream ms = new MemoryStream())
            {
                // The compressed stream
                using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, algorithm, true))
                {
                    stream.WriteByte(1);
                    stream.Flush();
                }
                // Junk
                ms.WriteByte(2);

                ms.Position = 0;
                // Reading: this should not hang
                using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Decompress, algorithm))
                {
                    byte[] buffer = new byte[512];
                    int    len    = stream.Read(buffer, 0, buffer.Length);
                    Console.WriteLine(len == 1);
                }
            }
        }
        public void CheckGetCanWriteProp()
        {
            if (!TestRuntime.CheckXcodeVersion(7, 0))
            {
                Assert.Ignore("Requires iOS 9.0+ or macOS 10.11+");
            }
            MemoryStream  backing    = new MemoryStream();
            DeflateStream decompress = new DeflateStream(backing, CompressionMode.Decompress, CompressionAlgorithm.Zlib);

            Assert.IsFalse(decompress.CanWrite, "#A1");
            Assert.IsTrue(backing.CanWrite, "#A2");
            decompress.Dispose();
            Assert.IsFalse(decompress.CanWrite, "#A3");
            Assert.IsFalse(backing.CanWrite, "#A4");

            backing = new MemoryStream();
            DeflateStream compress = new DeflateStream(backing, CompressionMode.Compress, CompressionAlgorithm.Zlib);

            Assert.IsTrue(compress.CanWrite, "#B1");
            Assert.IsTrue(backing.CanWrite, "#B2");
            compress.Dispose();
            Assert.IsFalse(decompress.CanWrite, "#B3");
            Assert.IsFalse(backing.CanWrite, "#B4");
        }
 public void Constructor_Null()
 {
     DeflateStream ds = new DeflateStream(null, CompressionMode.Compress, CompressionAlgorithm.Zlib);
 }
 public void Constructor_InvalidCompressionMode()
 {
     DeflateStream ds = new DeflateStream(new MemoryStream(), (CompressionMode)Int32.MinValue, CompressionAlgorithm.Zlib);
 }