コード例 #1
0
        public void TgaDecoder_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10);
            ImageFormatException ex = Assert.Throws <ImageFormatException>(() => provider.GetImage(TgaDecoder));

            Assert.IsType <InvalidMemoryOperationException>(ex.InnerException);
        }
コード例 #2
0
        public void DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : struct, IPixel <TPixel>
        {
            provider.LimitAllocatorBufferCapacity().InBytesSqrt(10);
            ImageFormatException ex = Assert.Throws <ImageFormatException>(() => provider.GetImage(JpegDecoder));

            this.Output.WriteLine(ex.Message);
            Assert.IsType <InvalidMemoryOperationException>(ex.InnerException);
        }
コード例 #3
0
        [InlineData((uint)PngChunkType.End)]     // IEND
        public void Decode_IncorrectCRCForCriticalChunk_ExceptionIsThrown(uint chunkType)
        {
            string chunkName = GetChunkTypeName(chunkType);

            using (var memStream = new MemoryStream())
            {
                WriteHeaderChunk(memStream);
                WriteChunk(memStream, chunkName);
                WriteDataChunk(memStream);

                var decoder = new PngDecoder();

                ImageFormatException exception = Assert.Throws <ImageFormatException>(() => decoder.Decode <Rgb24>(null, memStream));

                Assert.Equal($"CRC Error. PNG {chunkName} chunk is corrupt!", exception.Message);
            }
        }
コード例 #4
0
        public void Decode_IncorrectCRCForCriticalChunk_ExceptionIsThrown(string chunkName)
        {
            using (var memStream = new MemoryStream())
            {
                memStream.Skip(8);

                WriteChunk(memStream, chunkName);

                CompressStream(memStream);

                var decoder = new PngDecoder();

                ImageFormatException exception = Assert.Throws <ImageFormatException>(() =>
                {
                    decoder.Decode <Rgb24>(null, memStream);
                });

                Assert.Equal($"CRC Error. PNG {chunkName} chunk is corrupt!", exception.Message);
            }
        }