Esempio n. 1
0
 public virtual void TestSnappyCompressorSetInputNullPointerException()
 {
     try
     {
         SnappyCompressor compressor = new SnappyCompressor();
         compressor.SetInput(null, 0, 10);
         NUnit.Framework.Assert.Fail("testSnappyCompressorSetInputNullPointerException error !!!"
                                     );
     }
     catch (ArgumentNullException)
     {
     }
     catch (Exception)
     {
         // excepted
         NUnit.Framework.Assert.Fail("testSnappyCompressorSetInputNullPointerException ex error !!!"
                                     );
     }
 }
Esempio n. 2
0
 public virtual void TestSnappyCompressorSetInputAIOBException()
 {
     try
     {
         SnappyCompressor compressor = new SnappyCompressor();
         compressor.SetInput(new byte[] {  }, -5, 10);
         NUnit.Framework.Assert.Fail("testSnappyCompressorSetInputAIOBException error !!!"
                                     );
     }
     catch (IndexOutOfRangeException)
     {
     }
     catch (Exception)
     {
         // expected
         NUnit.Framework.Assert.Fail("testSnappyCompressorSetInputAIOBException ex error !!!"
                                     );
     }
 }
Esempio n. 3
0
        /// <exception cref="System.IO.IOException"/>
        private void CompressDecompressLoop(int rawDataSize)
        {
            byte[]           rawData          = TestSnappyCompressorDecompressor.BytesGenerator.Get(rawDataSize);
            byte[]           compressedResult = new byte[rawDataSize + 20];
            int              directBufferSize = Math.Max(rawDataSize * 2, 64 * 1024);
            SnappyCompressor compressor       = new SnappyCompressor(directBufferSize);

            compressor.SetInput(rawData, 0, rawDataSize);
            int compressedSize = compressor.Compress(compressedResult, 0, compressedResult.Length
                                                     );

            SnappyDecompressor.SnappyDirectDecompressor decompressor = new SnappyDecompressor.SnappyDirectDecompressor
                                                                           ();
            ByteBuffer inBuf  = ByteBuffer.AllocateDirect(compressedSize);
            ByteBuffer outBuf = ByteBuffer.AllocateDirect(rawDataSize);

            inBuf.Put(compressedResult, 0, compressedSize);
            inBuf.Flip();
            ByteBuffer expected = ByteBuffer.Wrap(rawData);

            outBuf.Clear();
            while (!decompressor.Finished())
            {
                decompressor.Decompress(inBuf, outBuf);
                if (outBuf.Remaining() == 0)
                {
                    outBuf.Flip();
                    while (outBuf.Remaining() > 0)
                    {
                        Assert.Equal(expected.Get(), outBuf.Get());
                    }
                    outBuf.Clear();
                }
            }
            outBuf.Flip();
            while (outBuf.Remaining() > 0)
            {
                Assert.Equal(expected.Get(), outBuf.Get());
            }
            outBuf.Clear();
            Assert.Equal(0, expected.Remaining());
        }
Esempio n. 4
0
        public virtual void TestSnappyBlockCompression()
        {
            int ByteSize  = 1024 * 50;
            int BlockSize = 512;
            ByteArrayOutputStream @out = new ByteArrayOutputStream();

            byte[] block = new byte[BlockSize];
            byte[] bytes = TestSnappyCompressorDecompressor.BytesGenerator.Get(ByteSize);
            try
            {
                // Use default of 512 as bufferSize and compressionOverhead of
                // (1% of bufferSize + 12 bytes) = 18 bytes (zlib algorithm).
                SnappyCompressor compressor = new SnappyCompressor();
                int off     = 0;
                int len     = ByteSize;
                int maxSize = BlockSize - 18;
                if (ByteSize > maxSize)
                {
                    do
                    {
                        int bufLen = Math.Min(len, maxSize);
                        compressor.SetInput(bytes, off, bufLen);
                        compressor.Finish();
                        while (!compressor.Finished())
                        {
                            compressor.Compress(block, 0, block.Length);
                            @out.Write(block);
                        }
                        compressor.Reset();
                        off += bufLen;
                        len -= bufLen;
                    }while (len > 0);
                }
                Assert.True("testSnappyBlockCompression error !!!", @out.ToByteArray
                                ().Length > 0);
            }
            catch (Exception)
            {
                NUnit.Framework.Assert.Fail("testSnappyBlockCompression ex error !!!");
            }
        }
Esempio n. 5
0
 public virtual void TestSnappyCompressorCompressAIOBException()
 {
     try
     {
         SnappyCompressor compressor = new SnappyCompressor();
         byte[]           bytes      = TestSnappyCompressorDecompressor.BytesGenerator.Get(1024 * 6);
         compressor.SetInput(bytes, 0, bytes.Length);
         compressor.Compress(new byte[] {  }, 0, -1);
         NUnit.Framework.Assert.Fail("testSnappyCompressorCompressAIOBException error !!!"
                                     );
     }
     catch (IndexOutOfRangeException)
     {
     }
     catch (Exception)
     {
         // expected
         NUnit.Framework.Assert.Fail("testSnappyCompressorCompressAIOBException ex error !!!"
                                     );
     }
 }
Esempio n. 6
0
 public virtual void TestSnappyCompressorCompressNullPointerException()
 {
     try
     {
         SnappyCompressor compressor = new SnappyCompressor();
         byte[]           bytes      = TestSnappyCompressorDecompressor.BytesGenerator.Get(1024 * 6);
         compressor.SetInput(bytes, 0, bytes.Length);
         compressor.Compress(null, 0, 0);
         NUnit.Framework.Assert.Fail("testSnappyCompressorCompressNullPointerException error !!!"
                                     );
     }
     catch (ArgumentNullException)
     {
     }
     catch (Exception)
     {
         // expected
         NUnit.Framework.Assert.Fail("testSnappyCompressorCompressNullPointerException ex error !!!"
                                     );
     }
 }
Esempio n. 7
0
        public virtual void TestSnappyCompressDecompress()
        {
            int ByteSize = 1024 * 54;

            byte[]           bytes      = TestSnappyCompressorDecompressor.BytesGenerator.Get(ByteSize);
            SnappyCompressor compressor = new SnappyCompressor();

            try
            {
                compressor.SetInput(bytes, 0, bytes.Length);
                Assert.True("SnappyCompressDecompress getBytesRead error !!!",
                            compressor.GetBytesRead() > 0);
                Assert.True("SnappyCompressDecompress getBytesWritten before compress error !!!"
                            , compressor.GetBytesWritten() == 0);
                byte[] compressed = new byte[ByteSize];
                int    cSize      = compressor.Compress(compressed, 0, compressed.Length);
                Assert.True("SnappyCompressDecompress getBytesWritten after compress error !!!"
                            , compressor.GetBytesWritten() > 0);
                SnappyDecompressor decompressor = new SnappyDecompressor(ByteSize);
                // set as input for decompressor only compressed data indicated with cSize
                decompressor.SetInput(compressed, 0, cSize);
                byte[] decompressed = new byte[ByteSize];
                decompressor.Decompress(decompressed, 0, decompressed.Length);
                Assert.True("testSnappyCompressDecompress finished error !!!",
                            decompressor.Finished());
                Assert.AssertArrayEquals(bytes, decompressed);
                compressor.Reset();
                decompressor.Reset();
                Assert.True("decompressor getRemaining error !!!", decompressor
                            .GetRemaining() == 0);
            }
            catch (Exception)
            {
                NUnit.Framework.Assert.Fail("testSnappyCompressDecompress ex error!!!");
            }
        }