public void TestImageProperties(string allPath, ulong hash, ImageFormat format) { var path = Path.Combine("data", Path.Combine(allPath.Split('\\'))); var data = File.ReadAllBytes(path); var image = Pfim.FromFile(path); var image2 = Pfim.FromStream(new MemoryStream(data), new PfimConfig()); Assert.NotEqual(0, image.DataLen); Assert.NotEqual(0, image2.DataLen); var allocator = new PfimAllocator(); Assert.Equal(0, allocator.Rented); using (var image3 = Pfim.FromStream(new MemoryStream(data), new PfimConfig(allocator: allocator))) { Assert.Equal(format, image.Format); Assert.Equal(image.Format, image2.Format); Assert.Equal(hash, Hash64(image.Data, image.DataLen)); Assert.Equal(hash, Hash64(image2.Data, image2.DataLen)); Assert.Equal(hash, Hash64(image3.Data, image3.DataLen)); var mipMapSuffix = image.MipMaps.Sum(x => x.DataLen); Assert.Equal(image.Data.Length - mipMapSuffix, image.DataLen); Assert.Equal(image.Data.Length, image2.Data.Length); Assert.Equal(image3.DataLen, image.Data.Length - mipMapSuffix); Assert.NotEqual(0, image.DataLen); Assert.NotEqual(0, allocator.Rented); } Assert.Equal(0, allocator.Rented); }
public void InvalidTargaException() { var data = Encoding.ASCII.GetBytes("Hello world! A wonderful evening"); var ex = Assert.ThrowsAny <Exception>(() => Pfim.FromStream(new MemoryStream(data))); Assert.Equal("Detected invalid targa image", ex.Message); }