Update APNGInspector class and add tests (fixes #2237)

This commit is contained in:
Type-kun
2016-09-18 14:13:11 +05:00
parent a718560554
commit 9147a1b178
12 changed files with 175 additions and 69 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
test/files/apng/broken.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
test/files/apng/jpg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 989 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,64 @@
require "test_helper"
class DTextTest < ActiveSupport::TestCase
def inspect(filename)
apng = APNGInspector.new("#{Rails.root}/test/files/apng/#{filename}")
apng.inspect!
apng
end
context "APNG inspector" do
should "correctly parse normal APNG file" do
apng = inspect('normal_apng.png')
assert_equal(3, apng.frames)
assert_equal(true, apng.animated?)
assert_equal(false, apng.corrupted?)
end
should "recognize 1-frame APNG as animated" do
apng = inspect('single_frame.png')
assert_equal(1, apng.frames)
assert_equal(true, apng.animated?)
assert_equal(false, apng.corrupted?)
end
should "correctly parse normal PNG file" do
apng = inspect('not_apng.png')
assert_equal(false, apng.animated?)
assert_equal(false, apng.corrupted?)
end
should "handle empty file" do
apng = inspect('empty.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
should "handle corrupted files" do
apng = inspect('iend_missing.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
apng = inspect('misaligned_chunks.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
apng = inspect('broken.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
should "handle incorrect acTL chunk" do
apng = inspect('actl_wronglen.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
apng = inspect('actl_zero_frames.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
should "handle non-png files" do
apng = inspect('jpg.png')
assert_equal(false, apng.animated?)
assert_equal(true, apng.corrupted?)
end
end
end