示例#1
0
 public void testPNGCompression()
 {
     // itterate over all test images
     string[] files = new string[] { "files/ev.png", "files/test01.png", "files/test02.png" };
     for (int i = 0; i < files.Length; i++)
     {
         // make sure compression works, file should be smaller
         byte[] uncompressed = File.ReadAllBytes(files[i]);
         int    before       = uncompressed.Length;
         byte[] compressed   = ZopfliPNG.compress(uncompressed);
         int    after        = compressed.Length;
         before.Should().BeGreaterOrEqualTo(after);
     }
 }
示例#2
0
        public void testPNGCompressionbyFilePath()
        {
            // copy a test file
            string tempFile = Path.GetTempPath() + Guid.NewGuid().ToString("N") + ".png";

            File.Copy("files/ev.png", tempFile);

            // capture initial file size
            FileInfo fi     = new FileInfo(tempFile);
            long     before = fi.Length;

            // compress image
            ZopfliPNG.compress(tempFile);

            // capture compressed file size
            FileInfo fi2   = new FileInfo(tempFile);
            long     after = fi2.Length;

            // remove file
            File.Delete(tempFile);

            // verify
            before.Should().BeGreaterOrEqualTo(after);
        }
示例#3
0
        public void testPNGCorrupt()
        {
            Action action = () => { byte[] compressed = ZopfliPNG.compress(File.ReadAllBytes("files/corrupt.png")); };

            action.ShouldThrow <ZopfliPNGException>().WithMessage("incorrect PNG signature, it's no PNG or corrupted");
        }
示例#4
0
        public void testPNGSmallHeader()
        {
            Action action = () => { byte[] compressed = ZopfliPNG.compress(File.ReadAllBytes("files/small-header.png")); };

            action.ShouldThrow <ZopfliPNGException>().WithMessage("PNG file is smaller than a PNG header");
        }
示例#5
0
        public void testPNGEmpty()
        {
            Action action = () => { byte[] compressed = ZopfliPNG.compress(File.ReadAllBytes("files/empty.png")); };

            action.ShouldThrow <ZopfliPNGException>().WithMessage("empty input or file doesn't exist");
        }